From 0d960e66cb434f160f978f15300be6e7037bcd21 Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:37:37 -0400 Subject: [PATCH 1/7] feat: Add RadiationDamageEvent to the api --- .../api/events/RadiationDamageEvent.java | 71 +++++++++++++++++++ .../tasks/armor/RadiationTask.java | 10 +++ 2 files changed, 81 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java new file mode 100644 index 0000000000..e38a6288ed --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -0,0 +1,71 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * The {@link RadiationDamageEvent} is called when a player takes radiation damage. + * + * @author HoosierTransfer + * + */ +public class RadiationDamageEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private final Player player; + private int exposure; + private boolean cancelled; + + /** + * This constructs a new {@link RadiationDamageEvent}. + * + * @param player The {@link Player} who took radiation damage + * @param exposure The amount of radiation exposure + */ + public RadiationDamageEvent(@Nonnull Player player, int exposure) { + this.player = player; + } + + /** + * This returns the {@link Player} who took radiation damage. + * + * @return The {@link Player} who took radiation damage + */ + + public @Nonnull Player getPlayer() { + return player; + } + + /** + * This returns the amount of radiation exposure. + * + * @return The amount of radiation exposure + */ + public int getExposure() { + return exposure; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @Nonnull + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public @Nonnull HandlerList getHandlers() { + return getHandlerList(); + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java index 6899bdf0d1..7c49e605e0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks.armor; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.thebusybiscuit.slimefun4.api.events.RadiationDamageEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; @@ -12,6 +13,8 @@ import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ComponentBuilder; + +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -71,6 +74,13 @@ protected void onPlayerTick(Player p, PlayerProfile profile) { int exposureLevelAfter = RadiationUtils.getExposure(p); Slimefun.runSync(() -> { + RadiationDamageEvent e = new RadiationDamageEvent(p, exposureLevelAfter); + Bukkit.getPluginManager().callEvent(e); + + if (e.isCancelled()) { + return; + } + for (RadiationSymptom symptom : symptoms) { if (symptom.shouldApply(exposureLevelAfter)) { symptom.apply(p); From 19b41a36e5e29688ee60edba97172c6deea5d9c8 Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:08:18 -0400 Subject: [PATCH 2/7] Update src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java Co-authored-by: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> --- .../slimefun4/api/events/RadiationDamageEvent.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java index e38a6288ed..ebf9270390 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -59,8 +59,7 @@ public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - @Nonnull - public static HandlerList getHandlerList() { + public static @Nonnull HandlerList getHandlerList() { return handlers; } From dd3b75b91c92abab067e52f96bb4db86d70ddd15 Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:08:28 -0400 Subject: [PATCH 3/7] Update src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java Co-authored-by: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> --- .../slimefun4/api/events/RadiationDamageEvent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java index ebf9270390..25c8cdd7d0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -11,7 +11,6 @@ * The {@link RadiationDamageEvent} is called when a player takes radiation damage. * * @author HoosierTransfer - * */ public class RadiationDamageEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); From 3fad638586d8ff019a31e6d88a9e63616ca65e74 Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:09:51 -0400 Subject: [PATCH 4/7] Make exposure final --- .../slimefun4/api/events/RadiationDamageEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java index 25c8cdd7d0..a4c4a42d0b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -16,7 +16,7 @@ public class RadiationDamageEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final Player player; - private int exposure; + private final int exposure; private boolean cancelled; /** From dd2e8de8ec182f407325992ba097d7f784cd4f69 Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:10:14 -0400 Subject: [PATCH 5/7] Update RadiationDamageEvent.java --- .../slimefun4/api/events/RadiationDamageEvent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java index a4c4a42d0b..0f89382de2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -27,6 +27,7 @@ public class RadiationDamageEvent extends Event implements Cancellable { */ public RadiationDamageEvent(@Nonnull Player player, int exposure) { this.player = player; + this.exposure = exposure; } /** From 04bf0b5a00f8eb07cc385f27ba7987661294c5db Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:26:50 -0500 Subject: [PATCH 6/7] remove empty line --- .../slimefun4/api/events/RadiationDamageEvent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java index 0f89382de2..b3ef284e75 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -35,7 +35,6 @@ public RadiationDamageEvent(@Nonnull Player player, int exposure) { * * @return The {@link Player} who took radiation damage */ - public @Nonnull Player getPlayer() { return player; } From f93f0b36459e1fbdd1697354cd00a5347b8dd30e Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:42:38 -0400 Subject: [PATCH 7/7] Update src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java Co-authored-by: J3fftw <44972470+J3fftw1@users.noreply.github.com> --- .../slimefun4/implementation/tasks/armor/RadiationTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java index 7c49e605e0..85e4c4bfe8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java @@ -74,10 +74,10 @@ protected void onPlayerTick(Player p, PlayerProfile profile) { int exposureLevelAfter = RadiationUtils.getExposure(p); Slimefun.runSync(() -> { - RadiationDamageEvent e = new RadiationDamageEvent(p, exposureLevelAfter); - Bukkit.getPluginManager().callEvent(e); + RadiationDamageEvent event = new RadiationDamageEvent(p, exposureLevelAfter); + Bukkit.getPluginManager().callEvent(event); - if (e.isCancelled()) { + if (event.isCancelled()) { return; }