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