Improve economy-related item usage prevention #6
No files matched your search
@@ -56,7 +56,7 @@ internal object AutoCompress {
|
||||
.sumOf { 64 - it.amount }
|
||||
|
||||
if (changeInDiamonds > emptySlots + leftOverSpaceDiamonds) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond-related items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ internal object AutoCompress {
|
||||
.sumOf { 64 - it.amount }
|
||||
|
||||
if (changeInDiamondBlocks > emptySlots + leftOverSpaceDiamondBlocks) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond-related items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your inventory to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ internal object AutoCompress {
|
||||
if (changeInShards < 0) {
|
||||
val removeMap = player.inventory.removeItem(Shard.createItemStack(abs(changeInShards)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your inventory."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
}
|
||||
@@ -85,13 +85,13 @@ internal object AutoCompress {
|
||||
if (changeInDiamonds > 0) {
|
||||
val addMap = player.inventory.addItem(ItemStack(Material.DIAMOND, changeInDiamonds))
|
||||
if (addMap.isNotEmpty()) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your inventory."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
} else if (changeInDiamonds < 0) {
|
||||
val removeMap = player.inventory.removeItem(ItemStack(Material.DIAMOND, abs(changeInDiamonds)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your inventory."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
}
|
||||
@@ -99,14 +99,14 @@ internal object AutoCompress {
|
||||
if (changeInDiamondBlocks > 0) {
|
||||
val addMap = player.inventory.addItem(ItemStack(Material.DIAMOND_BLOCK, changeInDiamondBlocks))
|
||||
if (addMap.isNotEmpty()) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your inventory."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
} else if (changeInDiamondBlocks < 0) {
|
||||
val removeMap =
|
||||
player.inventory.removeItem(ItemStack(Material.DIAMOND_BLOCK, abs(changeInDiamondBlocks)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your inventory."))
|
||||
player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your inventory."))
|
||||
return@runOnMainThread
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,14 @@ import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockPlaceEvent
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.event.inventory.InventoryType
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent
|
||||
import org.bukkit.event.player.PlayerDropItemEvent
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.scheduler.BukkitRunnable
|
||||
@@ -215,15 +216,68 @@ internal class Events : Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
fun onBlockPlace(event: BlockPlaceEvent) {
|
||||
val worldName = event.player.world.name
|
||||
fun onPlayerInteract(event: PlayerInteractEvent) {
|
||||
val player = event.player
|
||||
val worldName = player.world.name
|
||||
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
|
||||
|
||||
if (event.block.type != Material.DIAMOND_BLOCK && event.block.type != Material.SHULKER_BOX) return
|
||||
val clickedBlock = event.clickedBlock
|
||||
if (clickedBlock == null) return
|
||||
if (clickedBlock.type == Material.AIR) return
|
||||
|
||||
if (event.action.isLeftClick) {
|
||||
if (clickedBlock.type != Material.DIAMOND_BLOCK && clickedBlock.type != Material.SHULKER_BOX) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
val itemStack = event.item
|
||||
if (itemStack == null) return
|
||||
val itemType = itemStack.type
|
||||
|
||||
if (itemType != Material.DIAMOND && itemType != Material.DIAMOND_BLOCK && itemType != Material.SHULKER_BOX && !(itemType == Material.PRISMARINE_SHARD && itemStack.persistentDataContainer.has(
|
||||
Shard.namespacedKey
|
||||
))
|
||||
) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (DiamondBankOG.economyDisabled) {
|
||||
event.isCancelled = true
|
||||
event.player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot place any economy-related items while the economy is disabled."))
|
||||
event.player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."))
|
||||
return
|
||||
}
|
||||
|
||||
if (DiamondBankOG.transactionLock.isLocked(event.player.uniqueId)) {
|
||||
event.isCancelled = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
fun onPlayerInteractEntity(event: PlayerInteractEntityEvent) {
|
||||
val player = event.player
|
||||
val worldName = player.world.name
|
||||
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
|
||||
|
||||
val itemStackInMainHand = player.inventory.itemInMainHand
|
||||
val itemTypeInMainHand = itemStackInMainHand.type
|
||||
|
||||
val itemStackInOffHand = player.inventory.itemInOffHand
|
||||
val itemTypeInOffHand = itemStackInOffHand.type
|
||||
|
||||
if ((itemTypeInMainHand != Material.DIAMOND && itemTypeInMainHand != Material.DIAMOND_BLOCK && itemTypeInMainHand != Material.SHULKER_BOX && !(itemTypeInMainHand == Material.PRISMARINE_SHARD && itemStackInMainHand.persistentDataContainer.has(
|
||||
Shard.namespacedKey
|
||||
)) && (itemTypeInOffHand != Material.DIAMOND && itemTypeInOffHand != Material.DIAMOND_BLOCK && itemTypeInOffHand != Material.SHULKER_BOX && !(itemTypeInOffHand == Material.PRISMARINE_SHARD && itemStackInOffHand.persistentDataContainer.has(
|
||||
Shard.namespacedKey
|
||||
))))
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
if (DiamondBankOG.economyDisabled) {
|
||||
event.isCancelled = true
|
||||
event.player.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You cannot interact with any economy-related items while the economy is disabled."))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ internal class Compress : CommandExecutor {
|
||||
}
|
||||
|
||||
if (sender.inventory.itemInMainHand.type == Material.SHULKER_BOX && !isShulkerBox) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <#FFA500>Are you sure you want to compress the Diamond-related items in the shulker box you're holding? If so, run \"/compress yes\""))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <#FFA500>Are you sure you want to compress the Diamond currency items in the shulker box you're holding? If so, run \"/compress yes\""))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ internal class Compress : CommandExecutor {
|
||||
.sumOf { 64 - it.amount }
|
||||
|
||||
if (changeInDiamonds > emptySlots + leftOverSpaceDiamonds) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond-related items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamonds <aqua>Diamonds<red>)."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ internal class Compress : CommandExecutor {
|
||||
.sumOf { 64 - it.amount }
|
||||
|
||||
if (changeInDiamondBlocks > emptySlots + leftOverSpaceDiamondBlocks) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond-related items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>You do not have enough space in your ${if (isShulkerBox) "shulker box" else "inventory"} to compress all the Diamond currency items (<green>+$changeInDiamondBlocks <aqua>Diamond Blocks<red>)."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ internal class Compress : CommandExecutor {
|
||||
if (changeInShards < 0) {
|
||||
val removeMap = inventory.removeItem(Shard.createItemStack(abs(changeInShards)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
}
|
||||
@@ -146,13 +146,13 @@ internal class Compress : CommandExecutor {
|
||||
if (changeInDiamonds > 0) {
|
||||
val addMap = inventory.addItem(ItemStack(Material.DIAMOND, changeInDiamonds))
|
||||
if (addMap.isNotEmpty()) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
} else if (changeInDiamonds < 0) {
|
||||
val removeMap = inventory.removeItem(ItemStack(Material.DIAMOND, abs(changeInDiamonds)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
}
|
||||
@@ -160,14 +160,14 @@ internal class Compress : CommandExecutor {
|
||||
if (changeInDiamondBlocks > 0) {
|
||||
val addMap = inventory.addItem(ItemStack(Material.DIAMOND_BLOCK, changeInDiamondBlocks))
|
||||
if (addMap.isNotEmpty()) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
} else if (changeInDiamondBlocks < 0) {
|
||||
val removeMap =
|
||||
inventory.removeItem(ItemStack(Material.DIAMOND_BLOCK, abs(changeInDiamondBlocks)))
|
||||
if (removeMap.isNotEmpty()) {
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <red>Something went wrong while trying to compress the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}."))
|
||||
return@runOnMainThread RunOnMainThreadResult(true, null, null, null)
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ internal class Compress : CommandExecutor {
|
||||
return@launch
|
||||
}
|
||||
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully compressed all the Diamond-related items in your ${if (isShulkerBox) "shulker box" else "inventory"}!"))
|
||||
sender.sendMessage(DiamondBankOG.mm.deserialize("${Config.prefix}<reset>: <green>Successfully compressed all the Diamond currency items in your ${if (isShulkerBox) "shulker box" else "inventory"}!"))
|
||||
|
||||
val shardsLine =
|
||||
if (changeInShards < 0) "|<red>$changeInShards Diamond Shard${if (abs(changeInShards) != 1) "s" else ""}\n" else ""
|
||||
|
||||
Reference in new issue
Block a user