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 @@
+
+
+
+
+
+
+
+
@@ -15,7 +23,7 @@
-
+
\ No newline at end of file
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..48950b9
--- /dev/null
+++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/MinionChestLinkEvent.kt
@@ -0,0 +1,47 @@
+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
+ private var failMessage: String? = null
+
+ override fun getHandlers(): HandlerList {
+ return handlerList
+ }
+
+ fun getLinker(): Player {
+ return player
+ }
+
+ fun getFailMessage(): String? {
+ return failMessage
+ }
+
+ fun setFailMessage(message: String) {
+ failMessage = message
+ }
+
+ 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/PreMinionPickupEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPickupEvent.kt
new file mode 100644
index 0000000..e966037
--- /dev/null
+++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPickupEvent.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 PreMinionPickupEvent(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 PreMinionPickupEvent.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/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt
new file mode 100644
index 0000000..bf536c7
--- /dev/null
+++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreMinionPlaceEvent.kt
@@ -0,0 +1,47 @@
+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 PreMinionPlaceEvent(private val player: Player, private val location: Location) : Cancellable, Event() {
+ companion object {
+ private val handlerList = HandlerList()
+
+ @JvmStatic
+ fun getHandlerList(): HandlerList = handlerList
+ }
+
+ private var isCancelled = false
+ private var shouldOverridePlayerLimit = false
+
+ override fun getHandlers(): HandlerList {
+ return PreMinionPlaceEvent.handlerList
+ }
+
+ override fun isCancelled(): Boolean {
+ return isCancelled
+ }
+
+ fun getPlacer(): Player {
+ 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
+ }
+}
\ No newline at end of file
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/LinkingListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt
index 8fc721c..bba31a3 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
@@ -26,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()
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..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,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.PreMinionPlaceEvent
+import org.bukkit.Bukkit
class MinionPlaceListener : Listener {
@@ -45,6 +47,8 @@ class MinionPlaceListener : Listener {
return
}
+ 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
val charge = meta.persistentDataContainer.get(Keys.CHARGE, PersistentDataType.LONG) ?: 0
@@ -55,6 +59,10 @@ 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
@@ -63,10 +71,11 @@ class MinionPlaceListener : Listener {
val maxMinions = AxMinionsAPI.INSTANCE.getMinionLimit(event.player)
val chunk = location.chunk
+
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(),
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 d357a2b..7377eed 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,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.PreMinionPickupEvent
import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
@@ -39,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
@@ -164,6 +164,10 @@ class Minion(
}
private fun breakMinion(event: PacketEntityInteractEvent) {
+ val preBreakEvent = PreMinionPickupEvent(event.player, this)
+ Bukkit.getPluginManager().callEvent(preBreakEvent)
+ if (preBreakEvent.isCancelled) return
+
LinkingListener.linking.remove(event.player)
remove()
setTicking(false)