From bdbb9ad9d3df19e7e7b8be75622f92ad1b36a11d Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Tue, 25 Jul 2023 10:16:27 -0400 Subject: [PATCH 01/23] Update Talisman.java --- .../implementation/items/magical/talismans/Talisman.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 7ecc6f6fab..b3120ec412 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -206,7 +206,7 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman consumeItem(inv, talisman, talismanItem); applyTalismanEffects(p, talisman); cancelEvent(e, talisman); - + Bukkit.getServer().getPluginManager().callEvent(new TalismanActivatedEvent(p, talisman, talismanItem)); if (sendMessage) { talisman.sendMessage(p); } From 0bb8cb967dfaa044c42559de0462821b8da9ef84 Mon Sep 17 00:00:00 2001 From: cworldstar Date: Tue, 25 Jul 2023 11:03:54 -0400 Subject: [PATCH 02/23] Adds TalismanActivatedEvent to Slimefun. Activates when a Talisman is activated. --- .../api/events/TalismanActivatedEvent.java | 76 +++++++++++++++++++ .../items/magical/talismans/Talisman.java | 5 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java new file mode 100644 index 0000000000..9605be1cc4 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -0,0 +1,76 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; + +/** + * + * This {@link PlayerEvent} is called when a {@link Player} activates a {@link Talisman} + * + * @author cworldstar + * + */ + +public class TalismanActivatedEvent extends PlayerEvent { + + private static HandlerList Handlers = new HandlerList(); + private Talisman Talisman; + private ItemStack TalismanItem; + + + /** + * + * @param who + * The {@link Player} who activated the talisman. + * + * @param talisman + * The {@link Talisman} that was activated. + * + * @param talismanItem + * The {@link ItemStack} corresponding to the Talisman. + */ + @ParametersAreNonnullByDefault + public TalismanActivatedEvent(Player who, Talisman talisman, ItemStack talismanItem) { + super(who); + this.Talisman = talisman; + this.TalismanItem = talismanItem; + // TODO Auto-generated constructor stub + } + /** + * + * @return The {@link Talisman} used. + * + */ + @Nonnull + public Talisman getTalisman() { + return this.Talisman; + } + /** + * + * @return The {@link ItemStack} of the used {@link Talisman}. + */ + @Nonnull + public ItemStack getTalismanItem() { + return this.TalismanItem; + } + + public static HandlerList getHandlerList() { + return Handlers; + } + + @Override + public HandlerList getHandlers() { + // TODO Auto-generated method stub + return getHandlerList(); + } + + + +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index b3120ec412..ee376fe455 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -10,6 +10,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; @@ -27,6 +28,7 @@ import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.bakedlibs.dough.items.ItemUtils; +import io.github.thebusybiscuit.slimefun4.api.events.TalismanActivatedEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -206,7 +208,8 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman consumeItem(inv, talisman, talismanItem); applyTalismanEffects(p, talisman); cancelEvent(e, talisman); - Bukkit.getServer().getPluginManager().callEvent(new TalismanActivatedEvent(p, talisman, talismanItem)); + TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem); + Bukkit.getServer().getPluginManager().callEvent(TalismanEvent); if (sendMessage) { talisman.sendMessage(p); } From f7b7566f556d0b4663c15b2df6efa4ac69d9c35b Mon Sep 17 00:00:00 2001 From: cworldstar Date: Tue, 25 Jul 2023 17:51:34 -0400 Subject: [PATCH 03/23] implements cancellable --- .../api/events/TalismanActivatedEvent.java | 14 +++++++++++++- .../items/magical/talismans/Talisman.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index 9605be1cc4..277bdf22c5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -4,6 +4,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; import org.bukkit.inventory.ItemStack; @@ -18,11 +19,12 @@ * */ -public class TalismanActivatedEvent extends PlayerEvent { +public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { private static HandlerList Handlers = new HandlerList(); private Talisman Talisman; private ItemStack TalismanItem; + private boolean cancelled; /** @@ -70,6 +72,16 @@ public HandlerList getHandlers() { // TODO Auto-generated method stub return getHandlerList(); } + @Override + public boolean isCancelled() { + // TODO Auto-generated method stub + return this.cancelled; + } + @Override + public void setCancelled(boolean cancel) { + // TODO Auto-generated method stub + this.cancelled = cancel; + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index ee376fe455..5bec0625b3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -209,7 +209,7 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman applyTalismanEffects(p, talisman); cancelEvent(e, talisman); TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem); - Bukkit.getServer().getPluginManager().callEvent(TalismanEvent); + Bukkit.getPluginManager().callEvent(TalismanEvent); if (sendMessage) { talisman.sendMessage(p); } From c449de298d2c14576559b6734c0e35e1d83df8f1 Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Tue, 25 Jul 2023 17:59:28 -0400 Subject: [PATCH 04/23] Update TalismanActivatedEvent.java woops --- .../slimefun4/api/events/TalismanActivatedEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index 277bdf22c5..a959b17ba0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -24,7 +24,7 @@ public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { private static HandlerList Handlers = new HandlerList(); private Talisman Talisman; private ItemStack TalismanItem; - private boolean cancelled; + private boolean cancelled = false; /** @@ -85,4 +85,4 @@ public void setCancelled(boolean cancel) { -} \ No newline at end of file +} From 3520e2167c8a2ab41de7931f5f46e733e06c1fe7 Mon Sep 17 00:00:00 2001 From: cworldstar Date: Wed, 26 Jul 2023 08:22:17 -0400 Subject: [PATCH 05/23] added cancelling logic & changed variable names to camel case --- .../api/events/TalismanActivatedEvent.java | 19 +++++++++---------- .../items/magical/talismans/Talisman.java | 12 +++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index 277bdf22c5..0887467278 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -22,14 +22,14 @@ public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { private static HandlerList Handlers = new HandlerList(); - private Talisman Talisman; - private ItemStack TalismanItem; + private Talisman talisman; + private ItemStack talismanItemStack; private boolean cancelled; /** * - * @param who + * @param player * The {@link Player} who activated the talisman. * * @param talisman @@ -39,11 +39,10 @@ public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { * The {@link ItemStack} corresponding to the Talisman. */ @ParametersAreNonnullByDefault - public TalismanActivatedEvent(Player who, Talisman talisman, ItemStack talismanItem) { - super(who); - this.Talisman = talisman; - this.TalismanItem = talismanItem; - // TODO Auto-generated constructor stub + public TalismanActivatedEvent(Player player, Talisman talisman, ItemStack talismanItem) { + super(player); + this.talisman = talisman; + this.talismanItemStack = talismanItem; } /** * @@ -52,7 +51,7 @@ public TalismanActivatedEvent(Player who, Talisman talisman, ItemStack talismanI */ @Nonnull public Talisman getTalisman() { - return this.Talisman; + return this.talisman; } /** * @@ -60,7 +59,7 @@ public Talisman getTalisman() { */ @Nonnull public ItemStack getTalismanItem() { - return this.TalismanItem; + return this.talismanItemStack; } public static HandlerList getHandlerList() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 5bec0625b3..95b981e6ff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -205,13 +205,15 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { @ParametersAreNonnullByDefault private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman, ItemStack talismanItem, boolean sendMessage) { - consumeItem(inv, talisman, talismanItem); - applyTalismanEffects(p, talisman); - cancelEvent(e, talisman); TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem); Bukkit.getPluginManager().callEvent(TalismanEvent); - if (sendMessage) { - talisman.sendMessage(p); + if(!TalismanEvent.isCancelled()) { + consumeItem(inv, talisman, talismanItem); + applyTalismanEffects(p, talisman); + cancelEvent(e, talisman); + if (sendMessage) { + talisman.sendMessage(p); + } } } From 9612538dcb8e5b1bc623da279d9000123ce5f6af Mon Sep 17 00:00:00 2001 From: cworldstar Date: Wed, 26 Jul 2023 08:25:34 -0400 Subject: [PATCH 06/23] forgot to remove some TODO stubs --- .../slimefun4/api/events/TalismanActivatedEvent.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index 0887467278..6ae14d56ed 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -68,17 +68,14 @@ public static HandlerList getHandlerList() { @Override public HandlerList getHandlers() { - // TODO Auto-generated method stub return getHandlerList(); } @Override public boolean isCancelled() { - // TODO Auto-generated method stub return this.cancelled; } @Override public void setCancelled(boolean cancel) { - // TODO Auto-generated method stub this.cancelled = cancel; } From 41440754bcdb2d1476293ccface1de355c39716c Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Wed, 26 Jul 2023 08:28:41 -0400 Subject: [PATCH 07/23] Update src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java changes variable names to camel case Co-authored-by: TheBusyBiscuit --- .../slimefun4/api/events/TalismanActivatedEvent.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index a959b17ba0..ddfa08e120 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -22,8 +22,9 @@ public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { private static HandlerList Handlers = new HandlerList(); - private Talisman Talisman; - private ItemStack TalismanItem; + private Talisman talisman; + private ItemStack talismanItemStack; + private boolean cancelled = false; From de786954750672f82bb0aa109f666b645d85b25a Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Wed, 26 Jul 2023 08:29:33 -0400 Subject: [PATCH 08/23] Update src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java changes the who variable to a more clear player variable Co-authored-by: Sefiraat --- .../slimefun4/api/events/TalismanActivatedEvent.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java index ddfa08e120..047acca8b8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java @@ -40,7 +40,8 @@ public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { * The {@link ItemStack} corresponding to the Talisman. */ @ParametersAreNonnullByDefault - public TalismanActivatedEvent(Player who, Talisman talisman, ItemStack talismanItem) { + public TalismanActivatedEvent(Player player, Talisman talisman, ItemStack talismanItem) { + super(who); this.Talisman = talisman; this.TalismanItem = talismanItem; From 2d248e5c43481637aeb5166115728725760defb8 Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:12:37 -0400 Subject: [PATCH 09/23] Update src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java adds a space for readability Co-authored-by: J3fftw <44972470+J3fftw1@users.noreply.github.com> --- .../implementation/items/magical/talismans/Talisman.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 95b981e6ff..3f9fd2922f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -207,7 +207,7 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman, ItemStack talismanItem, boolean sendMessage) { TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem); Bukkit.getPluginManager().callEvent(TalismanEvent); - if(!TalismanEvent.isCancelled()) { + if (!TalismanEvent.isCancelled()) { consumeItem(inv, talisman, talismanItem); applyTalismanEffects(p, talisman); cancelEvent(e, talisman); From ffb88998a675a090448f2f8afc4364c01d99121f Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:12:54 -0400 Subject: [PATCH 10/23] Update src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java more spaces for readability Co-authored-by: J3fftw <44972470+J3fftw1@users.noreply.github.com> --- .../implementation/items/magical/talismans/Talisman.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 3f9fd2922f..78b4b2e5e1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -211,6 +211,7 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman consumeItem(inv, talisman, talismanItem); applyTalismanEffects(p, talisman); cancelEvent(e, talisman); + if (sendMessage) { talisman.sendMessage(p); } From 3c6803e39fc2438927889b3053d7f6865cfb9551 Mon Sep 17 00:00:00 2001 From: China Worldstar <40675557+Sniperkaos@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:04:57 -0400 Subject: [PATCH 11/23] Update src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java didnt commit the first time I guess Co-authored-by: J3fftw <44972470+J3fftw1@users.noreply.github.com> --- .../implementation/items/magical/talismans/Talisman.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 78b4b2e5e1..9a0fca65a0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -212,6 +212,7 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman applyTalismanEffects(p, talisman); cancelEvent(e, talisman); + if (sendMessage) { talisman.sendMessage(p); } From 903144e460b4a8b649c8a0ac8cec8d78dedd5746 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:21:50 -0600 Subject: [PATCH 12/23] Suggestions, Formatting, and cleanup --- ...dEvent.java => TalismanActivateEvent.java} | 158 +++++++++--------- .../items/magical/talismans/Talisman.java | 9 +- 2 files changed, 79 insertions(+), 88 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/api/events/{TalismanActivatedEvent.java => TalismanActivateEvent.java} (68%) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java similarity index 68% rename from src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java index 4ded742237..3b89284eae 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivatedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java @@ -1,84 +1,76 @@ -package io.github.thebusybiscuit.slimefun4.api.events; - -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; - -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.inventory.ItemStack; - -import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; - -/** - * - * This {@link PlayerEvent} is called when a {@link Player} activates a {@link Talisman} - * - * @author cworldstar - * - */ - -public class TalismanActivatedEvent extends PlayerEvent implements Cancellable { - - private static HandlerList Handlers = new HandlerList(); - private Talisman talisman; - private ItemStack talismanItemStack; - private boolean cancelled = false; - - - /** - * - * @param player - * The {@link Player} who activated the talisman. - * - * @param talisman - * The {@link Talisman} that was activated. - * - * @param talismanItem - * The {@link ItemStack} corresponding to the Talisman. - */ - @ParametersAreNonnullByDefault - public TalismanActivatedEvent(Player player, Talisman talisman, ItemStack talismanItem) { - super(player); - this.talisman = talisman; - this.talismanItemStack = talismanItem; - } - /** - * - * @return The {@link Talisman} used. - * - */ - @Nonnull - public Talisman getTalisman() { - return this.talisman; - } - /** - * - * @return The {@link ItemStack} of the used {@link Talisman}. - */ - @Nonnull - public ItemStack getTalismanItem() { - return this.talismanItemStack; - } - - public static HandlerList getHandlerList() { - return Handlers; - } - - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } - @Override - public boolean isCancelled() { - return this.cancelled; - } - @Override - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } - - - +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; + +/** + * This {@link PlayerEvent} is called when a {@link Player} activates a {@link Talisman} + * + * @author cworldstar + */ + +public class TalismanActivateEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private final Talisman talisman; + private final ItemStack talismanItemStack; + private boolean cancelled = false; + + /** + * @param player + * The {@link Player} who activated the talisman. + * + * @param talisman + * The {@link Talisman} that was activated. + * + * @param talismanItem + * The {@link ItemStack} corresponding to the Talisman. + */ + @ParametersAreNonnullByDefault + public TalismanActivateEvent(Player player, Talisman talisman, ItemStack talismanItem) { + super(player); + this.talisman = talisman; + this.talismanItemStack = talismanItem; + } + + /** + * @return The {@link Talisman} used. + */ + public @Nonnull Talisman getTalisman() { + return this.talisman; + } + + /** + * @return The {@link ItemStack} of the used {@link Talisman}. + */ + public @Nonnull ItemStack getTalismanItem() { + return this.talismanItemStack; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public @Nonnull HandlerList getHandlers() { + return getHandlerList(); + } + + public static @Nonnull HandlerList getHandlerList() { + return handlers; + } } \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 9a0fca65a0..39bc4a1ddf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -28,7 +28,7 @@ import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.bakedlibs.dough.items.ItemUtils; -import io.github.thebusybiscuit.slimefun4.api.events.TalismanActivatedEvent; +import io.github.thebusybiscuit.slimefun4.api.events.TalismanActivateEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -205,14 +205,13 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { @ParametersAreNonnullByDefault private static void activateTalisman(Event e, Player p, Inventory inv, Talisman talisman, ItemStack talismanItem, boolean sendMessage) { - TalismanActivatedEvent TalismanEvent = new TalismanActivatedEvent(p, talisman, talismanItem); - Bukkit.getPluginManager().callEvent(TalismanEvent); - if (!TalismanEvent.isCancelled()) { + TalismanActivateEvent talismanEvent = new TalismanActivateEvent(p, talisman, talismanItem); + Bukkit.getPluginManager().callEvent(talismanEvent); + if (!talismanEvent.isCancelled()) { consumeItem(inv, talisman, talismanItem); applyTalismanEffects(p, talisman); cancelEvent(e, talisman); - if (sendMessage) { talisman.sendMessage(p); } From cd520d0e9306bcfb5356b92ab8e13f3a1c79a2da Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:47:09 -0600 Subject: [PATCH 13/23] remove empty line Co-authored-by: Daniel Walsh --- .../slimefun4/api/events/TalismanActivateEvent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java index 3b89284eae..63853c0436 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java @@ -16,7 +16,6 @@ * * @author cworldstar */ - public class TalismanActivateEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); From 0a776802a6693a20a618ab3a6ed0a24a10f84b1d Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:18:18 -0600 Subject: [PATCH 14/23] Add test *and change some logic* --- .../api/events/TalismanActivateEvent.java | 21 +++ .../items/magical/talismans/Talisman.java | 15 +- .../api/events/TestTalismanActivateEvent.java | 160 ++++++++++++++++++ 3 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java index 63853c0436..775691a0a6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java @@ -21,6 +21,7 @@ public class TalismanActivateEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final Talisman talisman; private final ItemStack talismanItemStack; + private boolean preventConsumption = false; private boolean cancelled = false; /** @@ -54,6 +55,26 @@ public TalismanActivateEvent(Player player, Talisman talisman, ItemStack talisma return this.talismanItemStack; } + /** + * Only applies if {@link Talisman#isConsumable()} is true. + * Defaults to false. + * + * @return Whether the {@link ItemStack} should not be consumed. + */ + public boolean preventsConsumption() { + return this.preventConsumption; + } + + /** + * Only applies if {@link Talisman#isConsumable()} is true. + * + * @param preventConsumption + * Whether the {@link ItemStack} should not be consumed. + */ + public void setPreventConsumption(boolean preventConsumption) { + this.preventConsumption = preventConsumption; + } + @Override public boolean isCancelled() { return this.cancelled; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 39bc4a1ddf..9f97f19892 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -188,11 +188,15 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { return false; } } else { - ItemStack enderTalisman = talisman.getEnderVariant(); + SlimefunItemStack enderTalismanItem = talisman.getEnderVariant(); + if (enderTalismanItem == null) { + return false; + } - if (SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalisman, true)) { + EnderTalisman enderTalisman = enderTalismanItem.getItem(EnderTalisman.class); + if (enderTalisman != null && SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalismanItem, true)) { if (talisman.canUse(p, true)) { - activateTalisman(e, p, p.getEnderChest(), talisman, enderTalisman, sendMessage); + activateTalisman(e, p, p.getEnderChest(), enderTalisman, enderTalismanItem, sendMessage); return true; } else { return false; @@ -208,7 +212,10 @@ private static void activateTalisman(Event e, Player p, Inventory inv, Talisman TalismanActivateEvent talismanEvent = new TalismanActivateEvent(p, talisman, talismanItem); Bukkit.getPluginManager().callEvent(talismanEvent); if (!talismanEvent.isCancelled()) { - consumeItem(inv, talisman, talismanItem); + if (!talismanEvent.preventsConsumption()) { + consumeItem(inv, talisman, talismanItem); + } + applyTalismanEffects(p, talisman); cancelEvent(e, talisman); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java new file mode 100644 index 0000000000..bec9802903 --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -0,0 +1,160 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; +import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListener; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerItemBreakEvent; +import org.bukkit.inventory.ItemStack; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class TestTalismanActivateEvent { + + private static ServerMock server; + private static Slimefun plugin; + private static Player player; + private static SlimefunItem talisman; + private static SlimefunItem enderTalisman; + + @BeforeAll + public static void load() { + server = MockBukkit.mock(); + plugin = MockBukkit.load(Slimefun.class); + + new TalismanListener(plugin); + + talisman = new Talisman(SlimefunItems.TALISMAN_ANVIL, new ItemStack[] {}, true, false, "anvil"); + talisman.register(plugin); + + enderTalisman = SlimefunItem.getById("ENDER_" + talisman.getId()); + + player = server.addPlayer(); + } + + @AfterAll + public static void unload() { + MockBukkit.unmock(); + } + + void activateAnvilTalisman(boolean ender) { + player.getInventory().clear(); + player.getEnderChest().clear(); + + ItemStack talismanItem = ender ? enderTalisman.getItem() : talisman.getItem(); + ItemStack breakableItem = new ItemStack(Material.IRON_PICKAXE); + + if (ender) { + player.getEnderChest().addItem(talismanItem); + } else { + player.getInventory().addItem(talismanItem); + } + + player.getInventory().setItemInMainHand(breakableItem); + + PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, breakableItem); + server.getPluginManager().callEvent(event); + } + + @Test + @DisplayName("Test that TalismanActivateEvent is fired when an anvil talisman activates") + void testEventIsFired() { + // Assert the talisman activates in the inventory + activateAnvilTalisman(false); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); + server.getPluginManager().clearEvents(); + + // Assert the talisman activates in the ender chest + activateAnvilTalisman(true); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); + server.getPluginManager().clearEvents(); + } + + @Test + @DisplayName("Test that the TalismanActivateEvent has the correct fields") + void testEventFields() { + // Assert the talisman activates in the inventory + activateAnvilTalisman(false); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertEquals(talisman, event.getTalisman()); + Assertions.assertEquals(talisman.getItem(), event.getTalismanItem()); + Assertions.assertEquals(player, event.getPlayer()); + return true; + }); + server.getPluginManager().clearEvents(); + + // Assert the talisman activates in the ender chest + activateAnvilTalisman(true); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertEquals(enderTalisman, event.getTalisman()); + Assertions.assertEquals(enderTalisman.getItem(), event.getTalismanItem()); + Assertions.assertEquals(player, event.getPlayer()); + return true; + }); + server.getPluginManager().clearEvents(); + } + + @Test + @DisplayName("Test that the TalismanActivateEvent can be cancelled") + void testEventCanBeCancelled() { + server.getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onTalismanActivate(TalismanActivateEvent event) { + event.setCancelled(true); + } + }, plugin); + + // Assert the talisman activates in the inventory + activateAnvilTalisman(false); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertTrue(event.isCancelled()); + return true; + }); + server.getPluginManager().clearEvents(); + + // Assert the talisman activates in the ender chest + activateAnvilTalisman(true); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertTrue(event.isCancelled()); + return true; + }); + server.getPluginManager().clearEvents(); + } + + @Test + @DisplayName("Test that the TalismanActivateEvent can prevent consumption") + void testEventCanPreventConsumption() { + server.getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onTalismanActivate(TalismanActivateEvent event) { + event.setPreventConsumption(true); + } + }, plugin); + + // Assert the talisman activates in the inventory + activateAnvilTalisman(false); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertTrue(event.preventsConsumption()); + return true; + }); + server.getPluginManager().clearEvents(); + + // Assert the talisman activates in the ender chest + activateAnvilTalisman(true); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { + Assertions.assertTrue(event.preventsConsumption()); + return true; + }); + server.getPluginManager().clearEvents(); + } +} From c28244cc18983a00dcfa95a58e79ea07ce1429e4 Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:27:37 +0100 Subject: [PATCH 15/23] Added negation tests --- .../api/events/TestTalismanActivateEvent.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index bec9802903..bc6c8aa76f 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -78,6 +78,23 @@ void testEventIsFired() { activateAnvilTalisman(true); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); server.getPluginManager().clearEvents(); + // Assert the normal talisman does not activate in the ender chest + activateAnvilTalisman(false, true); + try { + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); + } catch (AssertionError ignored) { + return; // This is expected; the event should not have fired + } + server.getPluginManager().clearEvents(); + + // Assert the ender talisman does not activate in the inventory + try { + activateAnvilTalisman(true, false); + server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); + } catch (AssertionError ignored) { + return; // This is expected; the event should not have fired + } + server.getPluginManager().clearEvents(); } @Test From 657f380484db31373d88a98fbb7dd850cbf5ca31 Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:31:14 +0100 Subject: [PATCH 16/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index bc6c8aa76f..c5d9249e0c 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -132,7 +132,7 @@ public void onTalismanActivate(TalismanActivateEvent event) { }, plugin); // Assert the talisman activates in the inventory - activateAnvilTalisman(false); + activateAnvilTalisman(false, false); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertTrue(event.isCancelled()); return true; From 2b412433273e1a101c3bb3cf96f25d5e423179f5 Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:31:25 +0100 Subject: [PATCH 17/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index c5d9249e0c..12792a7dbe 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -101,7 +101,7 @@ void testEventIsFired() { @DisplayName("Test that the TalismanActivateEvent has the correct fields") void testEventFields() { // Assert the talisman activates in the inventory - activateAnvilTalisman(false); + activateAnvilTalisman(false, false); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertEquals(talisman, event.getTalisman()); Assertions.assertEquals(talisman.getItem(), event.getTalismanItem()); From 5c09027cbd91b4c4404620e670aab5a9604e4a4d Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:31:33 +0100 Subject: [PATCH 18/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index 12792a7dbe..291a73f99d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -75,7 +75,7 @@ void testEventIsFired() { server.getPluginManager().clearEvents(); // Assert the talisman activates in the ender chest - activateAnvilTalisman(true); + activateAnvilTalisman(true, true); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); server.getPluginManager().clearEvents(); // Assert the normal talisman does not activate in the ender chest From 012da241b3f1456271959b0da3a70190367aabcc Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:31:44 +0100 Subject: [PATCH 19/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index 291a73f99d..ba189c24f9 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -140,7 +140,7 @@ public void onTalismanActivate(TalismanActivateEvent event) { server.getPluginManager().clearEvents(); // Assert the talisman activates in the ender chest - activateAnvilTalisman(true); + activateAnvilTalisman(true, true); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertTrue(event.isCancelled()); return true; From e7d2500ef325d978e32e33327d0647b911b3e2bb Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:31:59 +0100 Subject: [PATCH 20/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index ba189c24f9..530c155a94 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -70,7 +70,7 @@ void activateAnvilTalisman(boolean ender) { @DisplayName("Test that TalismanActivateEvent is fired when an anvil talisman activates") void testEventIsFired() { // Assert the talisman activates in the inventory - activateAnvilTalisman(false); + activateAnvilTalisman(false, false); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, ignored -> true); server.getPluginManager().clearEvents(); From 8509070e6712d66b9ee42af9871dff955c5b61fe Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:32:13 +0100 Subject: [PATCH 21/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index 530c155a94..006a18a56c 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -111,7 +111,7 @@ void testEventFields() { server.getPluginManager().clearEvents(); // Assert the talisman activates in the ender chest - activateAnvilTalisman(true); + activateAnvilTalisman(true, true); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertEquals(enderTalisman, event.getTalisman()); Assertions.assertEquals(enderTalisman.getItem(), event.getTalismanItem()); From 2e16d2bdfdd7dc9e8a16b82939ca0b8c19b93d93 Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:34:05 +0100 Subject: [PATCH 22/23] Update src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index 006a18a56c..be4788905d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -47,14 +47,14 @@ public static void unload() { MockBukkit.unmock(); } - void activateAnvilTalisman(boolean ender) { + void activateAnvilTalisman(boolean enderVariant, boolean inEnderChest) { player.getInventory().clear(); player.getEnderChest().clear(); - ItemStack talismanItem = ender ? enderTalisman.getItem() : talisman.getItem(); + ItemStack talismanItem = enderVariant ? enderTalisman.getItem() : talisman.getItem(); ItemStack breakableItem = new ItemStack(Material.IRON_PICKAXE); - if (ender) { + if (inEnderChest) { player.getEnderChest().addItem(talismanItem); } else { player.getInventory().addItem(talismanItem); From 74e6f25ef2c1d1e4e0e9c4faa96695633f6fa48d Mon Sep 17 00:00:00 2001 From: Alessio Colombo <37039432+Sfiguz7@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:37:02 +0100 Subject: [PATCH 23/23] Apply suggestions from code review --- .../slimefun4/api/events/TestTalismanActivateEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java index be4788905d..83b49fa231 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java @@ -159,7 +159,7 @@ public void onTalismanActivate(TalismanActivateEvent event) { }, plugin); // Assert the talisman activates in the inventory - activateAnvilTalisman(false); + activateAnvilTalisman(false, false); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertTrue(event.preventsConsumption()); return true; @@ -167,7 +167,7 @@ public void onTalismanActivate(TalismanActivateEvent event) { server.getPluginManager().clearEvents(); // Assert the talisman activates in the ender chest - activateAnvilTalisman(true); + activateAnvilTalisman(true, true); server.getPluginManager().assertEventFired(TalismanActivateEvent.class, event -> { Assertions.assertTrue(event.preventsConsumption()); return true;