diff --git a/src/main/java/ch/njol/skript/effects/EffKill.java b/src/main/java/ch/njol/skript/effects/EffKill.java index 0ecc6146756..cd181dedd35 100644 --- a/src/main/java/ch/njol/skript/effects/EffKill.java +++ b/src/main/java/ch/njol/skript/effects/EffKill.java @@ -26,7 +26,8 @@ "Note: This effect does not set the entity's health to 0 (which causes issues), but damages the entity by 100 times its maximum health."}) @Examples({"kill the player", "kill all creepers in the player's world", - "kill all endermen, witches and bats"}) + "kill all endermen, witches and bats", +}) @Since("1.0") public class EffKill extends Effect { @@ -34,36 +35,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; - @SuppressWarnings("null") private Expression entities; @SuppressWarnings({"unchecked", "null"}) @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) 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 @@ -75,8 +66,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); } }