From 74d99b6c3db19b2aebf4da0605fd3438d0674a8f Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Wed, 15 Sep 2021 23:15:58 +0200 Subject: [PATCH] Implement landmine-specific tracking for manager --- .../dev/w1zzrd/spigot/landmines2/LandmineManager.kt | 9 ++++++--- .../dev/w1zzrd/spigot/landmines2/LandminePlugin.kt | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandmineManager.kt b/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandmineManager.kt index 48f0144..42ca2b4 100644 --- a/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandmineManager.kt +++ b/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandmineManager.kt @@ -4,6 +4,7 @@ import org.bukkit.Location import org.bukkit.Material import org.bukkit.OfflinePlayer import org.bukkit.configuration.file.FileConfiguration +import org.bukkit.enchantments.Enchantment import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.HandlerList @@ -31,6 +32,7 @@ private val threadLocalBuffer = ThreadLocal.withInitial { ByteBuffer.allocate(16 class LandmineManager( private val plugin: Plugin, + private val enchantment: Enchantment, private val landmineData: YamlFile ): Listener { private var landmines: SortedList = SortedList.create(comparator = LANDMINE_COMPARATOR) @@ -174,10 +176,11 @@ class LandmineManager( @EventHandler(priority = EventPriority.HIGHEST) fun onPlayerPlaceMine(placeEvent: BlockPlaceEvent) { - if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE && !placeEvent.isCancelled) { - if (placeMine(placeEvent.player, placeEvent.blockPlaced.location)) { + if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE && + placeEvent.itemInHand.itemMeta?.enchants?.contains(enchantment) == true && + !placeEvent.isCancelled) { + if (placeMine(placeEvent.player, placeEvent.blockPlaced.location)) --placeEvent.player.inventory.getItem(placeEvent.hand).amount - } placeEvent.isCancelled = true } diff --git a/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandminePlugin.kt b/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandminePlugin.kt index d7a6f5b..10d84cd 100644 --- a/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandminePlugin.kt +++ b/src/main/kotlin/dev/w1zzrd/spigot/landmines2/LandminePlugin.kt @@ -52,7 +52,11 @@ class LandminePlugin: JavaPlugin() { stack.itemMeta = meta saveDefaultConfig() - landmineManager = LandmineManager(this, YamlFile(File(dataFolder, "data.yml"))) + landmineManager = LandmineManager( + this, + enchantment, + YamlFile(File(dataFolder, "data.yml")) + ) landmineManager!!.onEnable() Bukkit.addRecipe(ShapelessRecipe(recipeKey, stack).addIngredient(Material.STONE_PRESSURE_PLATE).addIngredient(Material.TNT))