From f1363ceadf75f1a08822b2c3e5d5a0501eb48acc Mon Sep 17 00:00:00 2001 From: HoosierTransfer <97118529+HoosierTransfer@users.noreply.github.com> Date: Fri, 6 Sep 2024 08:12:26 -0400 Subject: [PATCH] feat: Add RadiationDamageEvent to the api (#4225) --- .../api/events/RadiationDamageEvent.java | 69 +++++++++++++++++++ .../tasks/armor/RadiationTask.java | 10 +++ 2 files changed, 79 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 000000000..b3ef284e7 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/RadiationDamageEvent.java @@ -0,0 +1,69 @@ +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 final 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.exposure = exposure; + } + + /** + * 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; + } + + public static @Nonnull 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 6899bdf0d..85e4c4bfe 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 io.github.thebusybiscuit.slimefun4.utils.RadiationUtils; 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 @@ public class RadiationTask extends AbstractArmorTask { int exposureLevelAfter = RadiationUtils.getExposure(p); Slimefun.runSync(() -> { + RadiationDamageEvent event = new RadiationDamageEvent(p, exposureLevelAfter); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return; + } + for (RadiationSymptom symptom : symptoms) { if (symptom.shouldApply(exposureLevelAfter)) { symptom.apply(p);