Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add RadiationDamageEvent to the api #4225

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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
*/

JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
HoosierTransfer marked this conversation as resolved.
Show resolved Hide resolved

for (RadiationSymptom symptom : symptoms) {
if (symptom.shouldApply(exposureLevelAfter)) {
symptom.apply(p);
Expand Down
Loading