Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.artillexstudios.axminions.api.events

import com.artillexstudios.axminions.api.minions.Minion
import org.bukkit.block.Block
import org.bukkit.event.Cancellable
import org.bukkit.event.HandlerList

class MinionMineBlockEvent(minion: Minion, 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 MinionMineBlockEvent.handlerList
}

override fun isCancelled(): Boolean {
return isCancelled
}

override fun setCancelled(cancelled: Boolean) {
isCancelled = cancelled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.artillexstudios.axminions.minions.miniontype
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axapi.scheduler.impl.FoliaScheduler
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.events.MinionMineBlockEvent
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
import com.artillexstudios.axminions.api.utils.LocationUtils
Expand Down Expand Up @@ -109,6 +111,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val possible = gen?.isBlockPossibleToMine(location) ?: false

if (possible) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

gen?.scheduleGeneratorRegeneration()
return@fastFor
}
Expand All @@ -118,6 +125,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource

if (isStoneGenerator) {
val block = location.block
val blockEvent = MinionMineBlockEvent(minion, block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
drops.forEach {
Expand Down Expand Up @@ -145,6 +157,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val possible = gen?.isBlockPossibleToMine(location) ?: false

if (possible) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return@fastFor

gen?.scheduleGeneratorRegeneration()
return@fastFor
}
Expand All @@ -153,6 +170,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val isStoneGenerator = MinionUtils.isStoneGenerator(location)

if (isStoneGenerator) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return@fastFor

Scheduler.get().run {
val block = location.block
val drops = block.getDrops(minion.getTool())
Expand All @@ -176,6 +198,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val possible = gen?.isBlockPossibleToMine(location) ?: false

if (possible) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

gen?.scheduleGeneratorRegeneration()
return@fastFor
}
Expand All @@ -185,6 +212,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource

if (isStoneGenerator) {
val block = location.block
val blockEvent = MinionMineBlockEvent(minion, block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
drops.forEach {
Expand All @@ -207,6 +239,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val possible = gen?.isBlockPossibleToMine(location) ?: false

if (possible) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

gen?.scheduleGeneratorRegeneration()
return@fastFor
}
Expand All @@ -216,6 +253,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource

if (isStoneGenerator) {
val block = location.block
val blockEvent = MinionMineBlockEvent(minion, block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
drops.forEach { item ->
Expand All @@ -238,6 +280,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val possible = gen?.isBlockPossibleToMine(location) ?: false

if (possible) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

gen?.scheduleGeneratorRegeneration()
return@fastFor
}
Expand All @@ -246,6 +293,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
if (AxMinionsPlugin.integrations.itemsAdderIntegration) {
val block = CustomBlock.byAlreadyPlaced(location.block)
if (block !== null) {
val blockEvent = MinionMineBlockEvent(minion, location.block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

val drops = block.getLoot(minion.getTool(), false)
drops.forEach {
amount += it.amount
Expand All @@ -260,6 +312,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource

if (isStoneGenerator) {
val block = location.block
val blockEvent = MinionMineBlockEvent(minion, block)
Bukkit.getPluginManager().callEvent(blockEvent)

if(blockEvent.isCancelled) return;

val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
drops.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.artillexstudios.axminions.nms.NMSHandler
import kotlin.math.roundToInt
import org.bukkit.Material
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.EntityType
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.entity.Tameable
Expand Down Expand Up @@ -56,6 +57,7 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour

Warnings.remove(minion, Warnings.NO_TOOL)

var amount = 0;
minion.getLocation().world!!.getNearbyEntities(
minion.getLocation(),
minion.getRange(),
Expand All @@ -64,6 +66,8 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour
).filterIsInstance<LivingEntity>().fastFor {
if (it is Player) return@fastFor

if(it.type == EntityType.ARMOR_STAND) return@fastFor

if (!getConfig().getBoolean("damage-animals") && NMSHandler.get().isAnimal(it)) {
return@fastFor
}
Expand All @@ -78,6 +82,9 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour

NMSHandler.get().attack(minion, it)
minion.damageTool()
amount++
}

minion.setActions(minion.getActionAmount() + amount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minion stores the actions, but on kill. Refer to MinionDamageListener.

}
}