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

Open
wants to merge 12 commits into
base: dev/feature
Choose a base branch
from
27 changes: 16 additions & 11 deletions src/main/java/ch/njol/skript/effects/EffKill.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,45 @@
"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"})
@Since("1.0")
"kill all endermen, witches and bats",
"kill the player ignoring totem of undying",
"kill target entity ignoring the totem",
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
"kill target player ignoring resurrection"})
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
@Since("1.0, INSERT VERSION (ignoring totem of undying)")
public class EffKill extends Effect {

static {
Skript.registerEffect(EffKill.class, "kill %entities%");
Skript.registerEffect(EffKill.class, "kill %entities%", "kill %entities% ignoring [the|any] totem[s] of undying");
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}

// Absolutely make sure it dies
public static final int DAMAGE_AMOUNT = Integer.MAX_VALUE;

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

@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];
ignoreTotem = matchedPattern == 1;
return true;
}

@Override
protected void execute(final Event e) {
protected void execute(Event e) {
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
for (Entity entity : entities.getArray(e)) {

if (entity instanceof EnderDragonPart) {
entity = ((EnderDragonPart) entity).getParent();
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}

if (ignoreTotem) {
HealthUtils.setHealth((Damageable) entity, 0);
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}

if (entity instanceof Damageable) {
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
final boolean creative = entity instanceof Player && ((Player) entity).getGameMode() == GameMode.CREATIVE;
boolean creative = entity instanceof Player player && player.getGameMode() == GameMode.CREATIVE;
if (creative) // Set player to survival before applying damage
((Player) entity).setGameMode(GameMode.SURVIVAL);
Efnilite marked this conversation as resolved.
Show resolved Hide resolved

HealthUtils.damage((Damageable) entity, HealthUtils.getMaxHealth((Damageable) entity) * 100); // just to make sure that it really dies >:)
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved

if (creative) // Set creative player back to creative
Efnilite marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -75,7 +80,7 @@ protected void execute(final Event e) {
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
public String toString(@Nullable Event e, boolean debug) {
return "kill" + entities.toString(e, debug);
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading