From 12773889cdc6c670a92629e9d39aebbba5e7788d Mon Sep 17 00:00:00 2001 From: rudde Date: Tue, 30 Apr 2024 11:59:18 +0300 Subject: [PATCH 1/6] Add MinionPrePlaceEvent --- .idea/codeStyles/Project.xml | 10 ++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/misc.xml | 10 +++++- .../api/events/MinionPrePlaceEvent.kt | 34 +++++++++++++++++++ .../listeners/MinionPlaceListener.kt | 8 +++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d4bd17d..b6a1c48 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,15 @@ - + \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt new file mode 100644 index 0000000..44f5d1c --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt @@ -0,0 +1,34 @@ +package com.artillexstudios.axminions.api.events + +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +class MinionPrePlaceEvent(private val player: Player) : Cancellable, Event() { + companion object { + private val handlerList = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList = handlerList + } + + private var isCancelled = false + + + override fun getHandlers(): HandlerList { + return MinionPrePlaceEvent.handlerList + } + + override fun isCancelled(): Boolean { + return isCancelled + } + + fun getPlacer(): Player { + return player + } + + override fun setCancelled(cancelled: Boolean) { + isCancelled = cancelled + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt index ab6b5d6..bad1ad8 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt @@ -20,6 +20,8 @@ import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import org.bukkit.event.block.BlockPlaceEvent +import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent +import org.bukkit.Bukkit class MinionPlaceListener : Listener { @@ -55,6 +57,12 @@ class MinionPlaceListener : Listener { } if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return + + val prePlaceEvent = MinionPrePlaceEvent(event.player) + Bukkit.getPluginManager().callEvent(prePlaceEvent) + + if(prePlaceEvent.isCancelled) return + meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0) item.itemMeta = meta From d478a3c4eb547487fd0e992f5518fe0044b6a6ab Mon Sep 17 00:00:00 2001 From: rudde Date: Tue, 30 Apr 2024 12:51:48 +0300 Subject: [PATCH 2/6] improve MinionPrePlaceEvent + add MinionChestLinkEvent --- .../api/events/MinionChestLinkEvent.kt | 39 +++++++++++++++++++ .../api/events/MinionPrePlaceEvent.kt | 17 +++++++- .../axminions/listeners/LinkingListener.kt | 14 +++++++ .../listeners/MinionPlaceListener.kt | 12 +++--- 4 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt new file mode 100644 index 0000000..c07ca27 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt @@ -0,0 +1,39 @@ +package com.artillexstudios.axminions.api.events + +import com.artillexstudios.axminions.api.minions.Minion +import org.bukkit.block.Block +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.HandlerList + +class MinionChestLinkEvent(minion: Minion, private val player: Player, private val block: Block) : MinionEvent(minion), Cancellable { + companion object { + private val handlerList = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList = handlerList + } + + private var isCancelled = false + + + override fun getHandlers(): HandlerList { + return handlerList + } + + fun getLinker(): Player { + return player + } + + fun getBlock(): Block { + return block + } + + override fun isCancelled(): Boolean { + return isCancelled + } + + override fun setCancelled(cancelled: Boolean) { + isCancelled = cancelled + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt index 44f5d1c..44f0fc7 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt @@ -1,11 +1,12 @@ package com.artillexstudios.axminions.api.events +import org.bukkit.Location import org.bukkit.entity.Player import org.bukkit.event.Cancellable import org.bukkit.event.Event import org.bukkit.event.HandlerList -class MinionPrePlaceEvent(private val player: Player) : Cancellable, Event() { +class MinionPrePlaceEvent(private val player: Player, private val location: Location) : Cancellable, Event() { companion object { private val handlerList = HandlerList() @@ -14,7 +15,7 @@ class MinionPrePlaceEvent(private val player: Player) : Cancellable, Event() { } private var isCancelled = false - + private var shouldOverridePlayerLimit = false override fun getHandlers(): HandlerList { return MinionPrePlaceEvent.handlerList @@ -28,6 +29,18 @@ class MinionPrePlaceEvent(private val player: Player) : Cancellable, Event() { return player } + fun getLocation(): Location { + return location + } + + fun getShouldOverridePlayerLimit(): Boolean { + return shouldOverridePlayerLimit + } + + fun setShouldOverridePlayerLimit(should: Boolean) { + shouldOverridePlayerLimit = should + } + override fun setCancelled(cancelled: Boolean) { isCancelled = cancelled } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt index 8fc721c..2608a03 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt @@ -4,9 +4,13 @@ import com.artillexstudios.axapi.utils.StringUtils import com.artillexstudios.axminions.AxMinionsPlugin import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages +import com.artillexstudios.axminions.api.events.MinionChestLinkEvent +import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent import com.artillexstudios.axminions.api.minions.Minion +import org.bukkit.Bukkit import java.util.WeakHashMap import org.bukkit.Material +import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener @@ -25,6 +29,16 @@ class LinkingListener : Listener { if (event.clickedBlock!!.type !in CONTAINERS) return if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return + val linkEvent = MinionChestLinkEvent( + linking.getValue(event.player), + event.player, + event.clickedBlock!! + ) + Bukkit.getPluginManager().callEvent(linkEvent) + if (linkEvent.isCancelled) { + return + } + val minion = linking.remove(event.player) ?: return event.isCancelled = true if (minion.getLocation() diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt index bad1ad8..29aa1ca 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt @@ -58,11 +58,6 @@ class MinionPlaceListener : Listener { if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return - val prePlaceEvent = MinionPrePlaceEvent(event.player) - Bukkit.getPluginManager().callEvent(prePlaceEvent) - - if(prePlaceEvent.isCancelled) return - meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0) item.itemMeta = meta @@ -71,10 +66,15 @@ class MinionPlaceListener : Listener { val maxMinions = AxMinionsAPI.INSTANCE.getMinionLimit(event.player) val chunk = location.chunk + + val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location) + Bukkit.getPluginManager().callEvent(prePlaceEvent) + if(prePlaceEvent.isCancelled) return + AxMinionsPlugin.dataQueue.submit { val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId) - if (placed >= maxMinions && !event.player.hasPermission("axminions.limit.*")) { + if (placed >= maxMinions && !prePlaceEvent.getShouldOverridePlayerLimit() && !event.player.hasPermission("axminions.limit.*")) { event.player.sendMessage( StringUtils.formatToString( Messages.PREFIX() + Messages.PLACE_LIMIT_REACHED(), From 05b36a366913d0fa38e5a5a8776299114a4bb19d Mon Sep 17 00:00:00 2001 From: rudde Date: Tue, 30 Apr 2024 12:53:44 +0300 Subject: [PATCH 3/6] don't call MinionChestLinkEvent for unlink --- .../axminions/listeners/LinkingListener.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt index 2608a03..ea335d6 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt @@ -29,6 +29,15 @@ class LinkingListener : Listener { if (event.clickedBlock!!.type !in CONTAINERS) return if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return + val minion = linking.remove(event.player) ?: return + event.isCancelled = true + if (minion.getLocation() + .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() + ) { + event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_FAIL())) + return + } + val linkEvent = MinionChestLinkEvent( linking.getValue(event.player), event.player, @@ -39,15 +48,6 @@ class LinkingListener : Listener { return } - val minion = linking.remove(event.player) ?: return - event.isCancelled = true - if (minion.getLocation() - .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() - ) { - event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_FAIL())) - return - } - event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_SUCCESS())) minion.setLinkedChest(event.clickedBlock!!.location) } From 9410d7483272429c5c577bd955e59b2965a0d812 Mon Sep 17 00:00:00 2001 From: rudde Date: Tue, 30 Apr 2024 13:12:23 +0300 Subject: [PATCH 4/6] custom fail message for MinionChestLinkEvent --- .../api/events/MinionChestLinkEvent.kt | 10 ++++++++- .../axminions/listeners/LinkingListener.kt | 22 ++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt index c07ca27..48950b9 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt @@ -15,7 +15,7 @@ class MinionChestLinkEvent(minion: Minion, private val player: Player, private v } private var isCancelled = false - + private var failMessage: String? = null override fun getHandlers(): HandlerList { return handlerList @@ -25,6 +25,14 @@ class MinionChestLinkEvent(minion: Minion, private val player: Player, private v return player } + fun getFailMessage(): String? { + return failMessage + } + + fun setFailMessage(message: String) { + failMessage = message + } + fun getBlock(): Block { return block } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt index ea335d6..bba31a3 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt @@ -30,6 +30,18 @@ class LinkingListener : Listener { if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return val minion = linking.remove(event.player) ?: return + + val linkEvent = MinionChestLinkEvent( + minion, + event.player, + event.clickedBlock!! + ) + Bukkit.getPluginManager().callEvent(linkEvent) + if (linkEvent.isCancelled) { + event.player.sendMessage(StringUtils.formatToString(linkEvent.getFailMessage() ?: (Messages.PREFIX() + Messages.LINK_FAIL()))) + return + } + event.isCancelled = true if (minion.getLocation() .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() @@ -38,16 +50,6 @@ class LinkingListener : Listener { return } - val linkEvent = MinionChestLinkEvent( - linking.getValue(event.player), - event.player, - event.clickedBlock!! - ) - Bukkit.getPluginManager().callEvent(linkEvent) - if (linkEvent.isCancelled) { - return - } - event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_SUCCESS())) minion.setLinkedChest(event.clickedBlock!!.location) } From 0d2725ec8d66980a4075f008a1e7bc0f916e1476 Mon Sep 17 00:00:00 2001 From: rudde Date: Tue, 30 Apr 2024 15:24:18 +0300 Subject: [PATCH 5/6] add MinionPreBreakEvent --- .../api/events/MinionPreBreakEvent.kt | 33 +++++++++++++++++++ .../listeners/MinionPlaceListener.kt | 9 ++--- .../axminions/minions/Minion.kt | 6 ++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt new file mode 100644 index 0000000..5c3f851 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt @@ -0,0 +1,33 @@ +package com.artillexstudios.axminions.api.events + +import com.artillexstudios.axminions.api.minions.Minion +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.HandlerList + +class MinionPreBreakEvent(private val player: Player, minion: Minion) : MinionEvent(minion), Cancellable { + companion object { + private val handlerList = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList = handlerList + } + + private var isCancelled = false + + override fun getHandlers(): HandlerList { + return MinionPreBreakEvent.handlerList + } + + fun getPlayer(): Player { + return player + } + + override fun isCancelled(): Boolean { + return isCancelled + } + + override fun setCancelled(cancelled: Boolean) { + isCancelled = cancelled + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt index 29aa1ca..bdf9e7f 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt @@ -47,6 +47,8 @@ class MinionPlaceListener : Listener { return } + val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location) + val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0 val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0 val charge = meta.persistentDataContainer.get(Keys.CHARGE, PersistentDataType.LONG) ?: 0 @@ -58,6 +60,9 @@ class MinionPlaceListener : Listener { if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return + Bukkit.getPluginManager().callEvent(prePlaceEvent) + if(prePlaceEvent.isCancelled) return + meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0) item.itemMeta = meta @@ -67,10 +72,6 @@ class MinionPlaceListener : Listener { val chunk = location.chunk - val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location) - Bukkit.getPluginManager().callEvent(prePlaceEvent) - if(prePlaceEvent.isCancelled) return - AxMinionsPlugin.dataQueue.submit { val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId) diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 3ce0dd1..4758f4c 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -16,6 +16,8 @@ import com.artillexstudios.axminions.AxMinionsPlugin import com.artillexstudios.axminions.api.AxMinionsAPI import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages +import com.artillexstudios.axminions.api.events.MinionPreBreakEvent +import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent import com.artillexstudios.axminions.api.minions.Direction import com.artillexstudios.axminions.api.minions.Minion import com.artillexstudios.axminions.api.minions.miniontype.MinionType @@ -164,6 +166,10 @@ class Minion( } private fun breakMinion(event: PacketEntityInteractEvent) { + val preBreakEvent = MinionPreBreakEvent(event.player, this) + Bukkit.getPluginManager().callEvent(preBreakEvent) + if(preBreakEvent.isCancelled) return + LinkingListener.linking.remove(event.player) remove() setTicking(false) From d26f2c0da0a8426522bd8733cf6c62ea28575ece Mon Sep 17 00:00:00 2001 From: rudde Date: Thu, 2 May 2024 00:04:03 +0300 Subject: [PATCH 6/6] requested changes --- .../{MinionPreBreakEvent.kt => PreMinionPickupEvent.kt} | 4 ++-- .../{MinionPrePlaceEvent.kt => PreMinionPlaceEvent.kt} | 4 ++-- .../axminions/commands/AxMinionsCommand.kt | 2 +- .../axminions/listeners/MinionPlaceListener.kt | 6 +++--- .../com/artillexstudios/axminions/minions/Minion.kt | 8 +++----- 5 files changed, 11 insertions(+), 13 deletions(-) rename api/src/main/kotlin/com/artillexstudios/axminions/api/events/{MinionPreBreakEvent.kt => PreMinionPickupEvent.kt} (81%) rename api/src/main/kotlin/com/artillexstudios/axminions/api/events/{MinionPrePlaceEvent.kt => PreMinionPlaceEvent.kt} (90%) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPickupEvent.kt similarity index 81% rename from api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt rename to api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPickupEvent.kt index 5c3f851..e966037 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPreBreakEvent.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPickupEvent.kt @@ -5,7 +5,7 @@ import org.bukkit.entity.Player import org.bukkit.event.Cancellable import org.bukkit.event.HandlerList -class MinionPreBreakEvent(private val player: Player, minion: Minion) : MinionEvent(minion), Cancellable { +class PreMinionPickupEvent(private val player: Player, minion: Minion) : MinionEvent(minion), Cancellable { companion object { private val handlerList = HandlerList() @@ -16,7 +16,7 @@ class MinionPreBreakEvent(private val player: Player, minion: Minion) : MinionEv private var isCancelled = false override fun getHandlers(): HandlerList { - return MinionPreBreakEvent.handlerList + return PreMinionPickupEvent.handlerList } fun getPlayer(): Player { diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt similarity index 90% rename from api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt rename to api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt index 44f0fc7..bf536c7 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionPrePlaceEvent.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt @@ -6,7 +6,7 @@ import org.bukkit.event.Cancellable import org.bukkit.event.Event import org.bukkit.event.HandlerList -class MinionPrePlaceEvent(private val player: Player, private val location: Location) : Cancellable, Event() { +class PreMinionPlaceEvent(private val player: Player, private val location: Location) : Cancellable, Event() { companion object { private val handlerList = HandlerList() @@ -18,7 +18,7 @@ class MinionPrePlaceEvent(private val player: Player, private val location: Loca private var shouldOverridePlayerLimit = false override fun getHandlers(): HandlerList { - return MinionPrePlaceEvent.handlerList + return PreMinionPlaceEvent.handlerList } override fun isCancelled(): Boolean { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt index a38d778..728e906 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt @@ -48,7 +48,7 @@ class AxMinionsCommand { receiver: Player ) { AxMinionsAPI.INSTANCE.getMinions().fastFor { - if(it.getOwnerUUID() == receiver.uniqueId) { + if (it.getOwnerUUID() == receiver.uniqueId) { it.remove() } } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt index bdf9e7f..3ce0552 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt @@ -20,7 +20,7 @@ import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import org.bukkit.event.block.BlockPlaceEvent -import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent +import com.artillexstudios.axminions.api.events.PreMinionPlaceEvent import org.bukkit.Bukkit class MinionPlaceListener : Listener { @@ -47,7 +47,7 @@ class MinionPlaceListener : Listener { return } - val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location) + val prePlaceEvent = PreMinionPlaceEvent(event.player, event.clickedBlock!!.location) val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0 val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0 @@ -61,7 +61,7 @@ class MinionPlaceListener : Listener { if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return Bukkit.getPluginManager().callEvent(prePlaceEvent) - if(prePlaceEvent.isCancelled) return + if (prePlaceEvent.isCancelled) return meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0) item.itemMeta = meta diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 4758f4c..84ba82e 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -16,8 +16,7 @@ import com.artillexstudios.axminions.AxMinionsPlugin import com.artillexstudios.axminions.api.AxMinionsAPI import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages -import com.artillexstudios.axminions.api.events.MinionPreBreakEvent -import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent +import com.artillexstudios.axminions.api.events.PreMinionPickupEvent import com.artillexstudios.axminions.api.minions.Direction import com.artillexstudios.axminions.api.minions.Minion import com.artillexstudios.axminions.api.minions.miniontype.MinionType @@ -41,7 +40,6 @@ import org.bukkit.block.Container import org.bukkit.enchantments.Enchantment import org.bukkit.entity.EntityType import org.bukkit.entity.Player -import org.bukkit.inventory.CreativeCategory import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable @@ -166,9 +164,9 @@ class Minion( } private fun breakMinion(event: PacketEntityInteractEvent) { - val preBreakEvent = MinionPreBreakEvent(event.player, this) + val preBreakEvent = PreMinionPickupEvent(event.player, this) Bukkit.getPluginManager().callEvent(preBreakEvent) - if(preBreakEvent.isCancelled) return + if (preBreakEvent.isCancelled) return LinkingListener.linking.remove(event.player) remove()