diff --git a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java
index dc43dace85d..278ad30b7d2 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java
@@ -1,21 +1,3 @@
-/**
- * This file is part of Skript.
- *
- * Skript is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Skript is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Skript. If not, see .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.conditions.base.PropertyCondition;
@@ -25,13 +7,14 @@
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
+import org.bukkit.entity.Wither;
import org.bukkit.entity.WitherSkull;
@Name("Is Charged")
-@Description("Checks if a creeper or wither skull is charged (powered).")
+@Description("Checks if a creeper, wither, or wither skull is charged (powered).")
@Examples({"if the last spawned creeper is charged:",
"\tbroadcast \"A charged creeper is at %location of last spawned creeper%\""})
-@Since("2.5, INSERT VERSION (wither skulls)")
+@Since("2.5, INSERT VERSION (withers, wither skulls)")
public class CondIsCharged extends PropertyCondition {
static {
@@ -40,10 +23,13 @@ public class CondIsCharged extends PropertyCondition {
@Override
public boolean check(Entity entity) {
- if (entity instanceof Creeper)
- return ((Creeper) entity).isPowered();
- else if (entity instanceof WitherSkull)
- return ((WitherSkull) entity).isCharged();
+ if (entity instanceof Creeper creeper) {
+ return creeper.isPowered();
+ } else if (entity instanceof WitherSkull witherSkull) {
+ return witherSkull.isCharged();
+ } else if (entity instanceof Wither wither) {
+ return wither.isCharged();
+ }
return false;
}
diff --git a/src/main/java/ch/njol/skript/effects/EffCharge.java b/src/main/java/ch/njol/skript/effects/EffCharge.java
index 54cccdca807..6e10efbe4ba 100644
--- a/src/main/java/ch/njol/skript/effects/EffCharge.java
+++ b/src/main/java/ch/njol/skript/effects/EffCharge.java
@@ -1,21 +1,3 @@
-/**
- * This file is part of Skript.
- *
- * Skript is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Skript is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Skript. If not, see .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.effects;
import ch.njol.skript.Skript;
@@ -39,7 +21,7 @@
"on spawn of creeper:",
"\tcharge the event-entity"
})
-@Since("2.5")
+@Since("2.5, INSERT VERSION (wither skulls)")
public class EffCharge extends Effect {
static {
@@ -48,9 +30,8 @@ public class EffCharge extends Effect {
"[:un](charge|power) %entities%");
}
- @SuppressWarnings("null")
+ @SuppressWarnings("NotNullFieldNotInitialized")
private Expression entities;
-
private boolean charge;
@SuppressWarnings({"unchecked", "null"})
@@ -64,11 +45,11 @@ public boolean init(Expression>[] exprs, int matchedPattern, Kleenean isDelaye
@Override
protected void execute(Event event) {
for (Entity entity : entities.getArray(event)) {
- if (entity instanceof Creeper) {
- ((Creeper) entity).setPowered(charge);
- } else if (entity instanceof WitherSkull) {
- ((WitherSkull) entity).setCharged(charge);
- }
+ if (entity instanceof Creeper creeper) {
+ creeper.setPowered(charge);
+ } else if (entity instanceof WitherSkull witherSkull) {
+ witherSkull.setCharged(charge);
+ }
}
}
diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk
index 1362a3196a5..58131c3dff1 100644
--- a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk
+++ b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk
@@ -1,31 +1,35 @@
test "is charged":
spawn a creeper at (spawn of world "world"):
- set {_e} to entity
- shoot a wither skull from {_e}
- set {_w} to last shot entity
+ set {_c} to entity
+ spawn a wither at (spawn of world "world"):
+ set {_w} to entity
+ shoot a wither skull from {_w}
+ set {_s} to last shot entity
- assert {_e} is not charged with "a normally spawned creeper should not be charged"
- assert {_w} is not charged with "a normally spawned wither skull should not be charged"
+ assert {_c} is not charged with "a normally spawned creeper should not be charged"
+ assert {_w} is not charged with "a normally spawned wither should not be charged"
+ assert {_s} is not charged with "a normally spawned wither skull should not be charged"
- charge {_e}
- charge {_w}
- assert {_e} is charged with "charging a creeper should do exactly that"
- assert {_w} is charged with "charging a wither skull should do exactly that"
+ charge {_c}
+ charge {_s}
+ assert {_c} is charged with "charging a creeper should do exactly that"
+ assert {_s} is charged with "charging a wither skull should do exactly that"
- uncharge {_e}
- uncharge {_w}
- assert {_e} is not charged with "uncharging a creeper should do exactly that"
- assert {_w} is not charged with "uncharging a wither skull should do exactly that"
+ uncharge {_c}
+ uncharge {_s}
+ assert {_c} is not charged with "uncharging a creeper should do exactly that"
+ assert {_s} is not charged with "uncharging a wither skull should do exactly that"
spawn an adult zombie at (spawn of world "world"):
set {_z} to entity
- assert {_z} is not charged with "a non-creeper/wither skull should never be charged"
+ assert {_z} is not charged with "a non-supported entity should never be charged"
charge {_z}
- assert {_z} is not charged with "charging a non-creeper/wither skull should do nothing"
+ assert {_z} is not charged with "charging a non-supported entity should do nothing"
uncharge {_z}
- assert {_z} is not charged with "uncharging a non-creeper/wither skull should do nothing"
+ assert {_z} is not charged with "uncharging a non-supported entity should do nothing"
- delete entity within {_e}
+ delete entity within {_c}
delete entity within {_w}
+ delete entity within {_s}
delete entity within {_z}