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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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); }