diff --git a/src/main/java/net/knarcraft/blacksmith/event/AbstractBlacksmithPluginEvent.java b/src/main/java/net/knarcraft/blacksmith/event/AbstractBlacksmithPluginEvent.java index 3087ae2..5372d84 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/AbstractBlacksmithPluginEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/AbstractBlacksmithPluginEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; @@ -13,15 +14,18 @@ public abstract class AbstractBlacksmithPluginEvent extends Event implements Bla protected final NPC npc; protected final Player player; + protected final Entity entity; /** * Instantiates a new blacksmith plugin event * * @param npc
The NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
*/ - public AbstractBlacksmithPluginEvent(@NotNull NPC npc, @NotNull Player player) { + public AbstractBlacksmithPluginEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player) { this.npc = npc; + this.entity = entity; this.player = player; } @@ -31,6 +35,12 @@ public abstract class AbstractBlacksmithPluginEvent extends Event implements Bla return this.npc; } + @Override + @NotNull + public Entity getEntity() { + return this.entity; + } + @Override @NotNull public Player getPlayer() { diff --git a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithPluginEvent.java b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithPluginEvent.java index a5ae014..abee100 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithPluginEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithPluginEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -18,6 +19,14 @@ public interface BlacksmithPluginEvent { @NotNull NPC getNpc(); + /** + * Gets the entity of the NPC + * + * @returnThe NPC entity
+ */ + @NotNull + Entity getEntity(); + /** * Gets the player involved in the event * diff --git a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeFailEvent.java b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeFailEvent.java index d69877b..46791f2 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeFailEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeFailEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -15,10 +16,12 @@ public class BlacksmithReforgeFailEvent extends AbstractBlacksmithPluginEvent im /** * Instantiates a new blacksmith reforge fail event * - * @param npcThe NPC involved in the event
+ * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
+ * @param playerThe player that initiated the session
*/ - public BlacksmithReforgeFailEvent(@NotNull NPC npc, @NotNull Player player) { - super(npc, player); + public BlacksmithReforgeFailEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player) { + super(npc, entity, player); } /** diff --git a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeStartEvent.java b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeStartEvent.java index 7c9061e..db905cc 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeStartEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeStartEvent.java @@ -2,6 +2,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -19,13 +20,14 @@ public class BlacksmithReforgeStartEvent extends AbstractBlacksmithPluginEvent i * Instantiates a new blacksmith reforge start event * * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
* @param durationTicksThe duration of the reforge
* @param craftingStationThe appropriate crafting station for this reforging
*/ - public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks, + public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player, long durationTicks, @NotNull Material craftingStation) { - super(npc, player); + super(npc, entity, player); this.durationTicks = durationTicks; this.craftingStation = craftingStation; } diff --git a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeSucceedEvent.java b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeSucceedEvent.java index 269a40c..fff4861 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeSucceedEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/BlacksmithReforgeSucceedEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -16,10 +17,11 @@ public class BlacksmithReforgeSucceedEvent extends AbstractBlacksmithPluginEvent * Instantiates a new blacksmith reforge succeed event * * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
*/ - public BlacksmithReforgeSucceedEvent(@NotNull NPC npc, @NotNull Player player) { - super(npc, player); + public BlacksmithReforgeSucceedEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player) { + super(npc, entity, player); } /** diff --git a/src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java b/src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java index 9e41d22..e341514 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java @@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Sound; import org.bukkit.SoundCategory; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -25,15 +26,16 @@ public class NPCSoundEvent extends AbstractBlacksmithPluginEvent implements Canc * Instantiates a new NPC sound event * * @param npcThe NPC playing the sound
+ * @param entityThe entity playing the sound
* @param playerThe player whose interaction triggered the sound
* @param soundCategoryThe category the sound is to play in
* @param soundThe sound to play
* @param volumeThe volume of the played sound
* @param pitchThe pitch of the played sound
*/ - public NPCSoundEvent(@NotNull NPC npc, @NotNull Player player, @NotNull SoundCategory soundCategory, + public NPCSoundEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player, @NotNull SoundCategory soundCategory, @NotNull Sound sound, float volume, float pitch) { - super(npc, player); + super(npc, entity, player); this.soundCategory = soundCategory; this.sound = sound; this.volume = volume; diff --git a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageFailEvent.java b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageFailEvent.java index 1441efa..129446d 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageFailEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageFailEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -16,10 +17,11 @@ public class ScrapperSalvageFailEvent extends AbstractBlacksmithPluginEvent impl * Instantiates a new scrapper salvage fail event * * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
*/ - public ScrapperSalvageFailEvent(@NotNull NPC npc, @NotNull Player player) { - super(npc, player); + public ScrapperSalvageFailEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player) { + super(npc, entity, player); } /** diff --git a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageStartEvent.java b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageStartEvent.java index 0d3c7b9..94d7605 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageStartEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageStartEvent.java @@ -2,6 +2,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -20,13 +21,14 @@ public class ScrapperSalvageStartEvent extends AbstractBlacksmithPluginEvent imp * Instantiates a new scrapper salvage start event * * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
* @param durationTicksThe duration of the salvage
* @param craftingStationThe appropriate crafting station for this salvaging
*/ - public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks, + public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player, long durationTicks, @NotNull Material craftingStation) { - super(npc, player); + super(npc, entity, player); this.durationTicks = durationTicks; this.craftingStation = craftingStation; } diff --git a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageSucceedEvent.java b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageSucceedEvent.java index 4eb67a4..6f9c438 100644 --- a/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageSucceedEvent.java +++ b/src/main/java/net/knarcraft/blacksmith/event/ScrapperSalvageSucceedEvent.java @@ -1,6 +1,7 @@ package net.knarcraft.blacksmith.event; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -16,10 +17,11 @@ public class ScrapperSalvageSucceedEvent extends AbstractBlacksmithPluginEvent i * Instantiates a new scrapper salvage succeed event * * @param npcThe NPC involved in the event
+ * @param entityThe entity of the NPC
* @param playerThe player involved in the event
*/ - public ScrapperSalvageSucceedEvent(@NotNull NPC npc, @NotNull Player player) { - super(npc, player); + public ScrapperSalvageSucceedEvent(@NotNull NPC npc, @NotNull Entity entity, @NotNull Player player) { + super(npc, entity, player); } /** diff --git a/src/main/java/net/knarcraft/blacksmith/trait/CustomTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/CustomTrait.java index 1860486..1312ecd 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/CustomTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/CustomTrait.java @@ -2,14 +2,17 @@ package net.knarcraft.blacksmith.trait; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; +import net.knarcraft.blacksmith.BlacksmithPlugin; import net.knarcraft.blacksmith.config.Setting; import net.knarcraft.blacksmith.config.Settings; import net.knarcraft.blacksmith.config.TraitSettings; import net.knarcraft.blacksmith.formatting.TimeFormatter; import net.knarcraft.blacksmith.manager.EconomyManager; import net.knarcraft.knarlib.formatting.StringFormatter; +import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.jetbrains.annotations.NotNull; @@ -18,7 +21,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Calendar; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.UUID; import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.sendNPCMessage; @@ -153,8 +155,13 @@ public abstract class CustomTraitWhether the session was delayed, or if the item was processed instantly
* @param dropItemWhether the item should be dropped on the ground
- * @param npcThe NPC holding the item
* @param itemToReturnThe item to return to the player
*/ - protected void giveResultingItem(boolean hasDelay, boolean dropItem, @NotNull NPC npc, @NotNull ItemStack itemToReturn) { + protected void giveResultingItem(boolean hasDelay, boolean dropItem, @NotNull ItemStack itemToReturn) { if (hasDelay) { //If the player isn't online, or the player cannot fit the item, drop the item to prevent it from disappearing if (dropItem || !this.player.isOnline() || !ItemHelper.canFitItem(this.player.getInventory(), itemToReturn)) { - this.player.getWorld().dropItemNaturally(npc.getEntity().getLocation(), itemToReturn); + this.player.getWorld().dropItemNaturally(this.entity.getLocation(), itemToReturn); } else { this.player.getInventory().addItem(itemToReturn); } @@ -172,7 +176,7 @@ public abstract class Session implements Runnable { * @param soundThe sound to play
*/ protected void playSound(Sound sound) { - playSound(this.npc.getEntity(), sound); + playSound(this.entity, sound); } /** @@ -187,14 +191,13 @@ public abstract class Session implements Runnable { return; } - NPCSoundEvent event = new NPCSoundEvent(this.npc, this.player, SoundCategory.AMBIENT, sound, 0.5f, 1.0f); + NPCSoundEvent event = new NPCSoundEvent(this.npc, this.entity, this.player, SoundCategory.AMBIENT, sound, 0.5f, 1.0f); BlacksmithPlugin.getInstance().callEvent(event); if (event.isCancelled()) { return; } - world.playSound(event.getNpc().getEntity(), event.getSound(), event.getSoundCategory(), event.getVolume(), - event.getPitch()); + world.playSound(event.getEntity(), event.getSound(), event.getSoundCategory(), event.getVolume(), event.getPitch()); } }