限制商店购买点击频率为200ms一次(防止连点器)
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ taboolib {
|
||||
name("xbaimiao")
|
||||
}
|
||||
val bukkitNodes = bukkitNodes as MutableMap<Any, Any>
|
||||
bukkitNodes["update-info"] = "添加API 可供其他插件添加物品解析"
|
||||
bukkitNodes["update-info"] = "限制商店购买点击频率为200ms一次(防止连点器)"
|
||||
}
|
||||
env {
|
||||
install(NMS_UTIL, UI)
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
group=com.github.xbaimiao.shoppro
|
||||
version=1.3.1-SNAPSHOT
|
||||
version=1.3.2-SNAPSHOT
|
||||
|
||||
@@ -23,11 +23,26 @@ import taboolib.platform.util.giveItem
|
||||
import taboolib.platform.util.hasItem
|
||||
import taboolib.platform.util.sendLang
|
||||
import taboolib.platform.util.takeItem
|
||||
import java.util.*
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
class ShopImpl(private val configuration: Configuration) : Shop() {
|
||||
|
||||
private val slots = configuration.getStringList("slots").map { it.toCharArray().toList() }
|
||||
private val clickCache = WeakHashMap<Player, Long>()
|
||||
|
||||
private fun canClick(player: Player): Boolean {
|
||||
val lastClick = clickCache[player]
|
||||
if (lastClick == null) {
|
||||
clickCache[player] = System.currentTimeMillis()
|
||||
return true
|
||||
}
|
||||
if (System.currentTimeMillis() - lastClick < 200) {
|
||||
return false
|
||||
}
|
||||
clickCache[player] = System.currentTimeMillis()
|
||||
return true
|
||||
}
|
||||
|
||||
private val items = ArrayList<Item>()
|
||||
|
||||
@@ -104,6 +119,9 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
||||
if (item is ShopItem) {
|
||||
if (getType() == ShopType.BUY) {
|
||||
onClick(item.key) { event ->
|
||||
if (!canClick(player)) {
|
||||
return@onClick
|
||||
}
|
||||
if (event.clickType != ClickType.CLICK) {
|
||||
return@onClick
|
||||
}
|
||||
@@ -120,6 +138,9 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
||||
}
|
||||
if (getType() == ShopType.SELL) {
|
||||
onClick(item.key) { event ->
|
||||
if (!canClick(player)) {
|
||||
return@onClick
|
||||
}
|
||||
if (event.clickType != ClickType.CLICK) {
|
||||
return@onClick
|
||||
}
|
||||
@@ -144,6 +165,9 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
||||
}
|
||||
} else {
|
||||
onClick(item.key) {
|
||||
if (!canClick(player)) {
|
||||
return@onClick
|
||||
}
|
||||
item.exeCommands(player, 1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user