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

Improve kill effect #7148

Merged
merged 19 commits into from
Dec 31, 2024
Merged
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/main/java/ch/njol/skript/effects/EffKill.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.GameMode;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.EnderDragonPart;
import org.bukkit.entity.Entity;
Expand All @@ -34,36 +33,26 @@ public class EffKill extends Effect {
Skript.registerEffect(EffKill.class, "kill %entities%");
}

// Absolutely make sure it dies
public static final int DAMAGE_AMOUNT = Integer.MAX_VALUE;
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("null")
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
private Expression<Entity> entities;

@SuppressWarnings({"unchecked", "null"})
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
entities = (Expression<Entity>) exprs[0];
return true;
}

@Override
protected void execute(final Event e) {
for (Entity entity : entities.getArray(e)) {
protected void execute(Event event) {
for (Entity entity : entities.getArray(event)) {

if (entity instanceof EnderDragonPart) {
entity = ((EnderDragonPart) entity).getParent();
if (entity instanceof EnderDragonPart part) {
entity = part.getParent();
}

if (entity instanceof Damageable) {
final boolean creative = entity instanceof Player && ((Player) entity).getGameMode() == GameMode.CREATIVE;
if (creative) // Set player to survival before applying damage
((Player) entity).setGameMode(GameMode.SURVIVAL);

HealthUtils.damage((Damageable) entity, HealthUtils.getMaxHealth((Damageable) entity) * 100); // just to make sure that it really dies >:)

if (creative) // Set creative player back to creative
((Player) entity).setGameMode(GameMode.CREATIVE);
if (entity instanceof Damageable damageable) {
HealthUtils.setHealth(damageable, 0);
}

// if everything done so far has failed to kill this thing
Expand All @@ -75,8 +64,8 @@ protected void execute(final Event e) {
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "kill" + entities.toString(e, debug);
public String toString(@Nullable Event event, boolean debug) {
return "kill " + entities.toString(event, debug);
}

}
Loading