Skip to content

Commit

Permalink
Updates EffEquip and its test
Browse files Browse the repository at this point in the history
- The test now uses CondIsSaddled, and tries to test wolf armor as well
- Removed the Steerable check in EffEquip, as 1.19.4+ (2.10) will always have it
  • Loading branch information
cheeezburga committed Sep 3, 2024
1 parent 9e42efe commit d59ea69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/main/java/ch/njol/skript/effects/EffEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.entity.Steerable;
import org.bukkit.entity.Wolf;
Expand Down Expand Up @@ -81,8 +81,6 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
return true;
}

private static final boolean SUPPORTS_STEERABLE = Skript.classExists("org.bukkit.entity.Steerable");

private static ItemType CHESTPLATE;
private static ItemType LEGGINGS;
private static ItemType BOOTS;
Expand Down Expand Up @@ -152,19 +150,12 @@ protected void execute(Event event) {
unequipHelmet = true;
}
for (LivingEntity entity : entities.getArray(event)) {
if (SUPPORTS_STEERABLE && entity instanceof Steerable steerable) {
if (entity instanceof Steerable steerable) {
for (ItemType itemType : itemTypes) {
if (SADDLE.isOfType(itemType.getMaterial())) {
steerable.setSaddle(equip);
}
}
} else if (entity instanceof Pig pig) {
for (ItemType itemType : itemTypes) {
if (itemType.isOfType(Material.SADDLE)) {
pig.setSaddle(equip);
break;
}
}
} else if (entity instanceof Llama llama) {
LlamaInventory inv = llama.getInventory();
for (ItemType itemType : itemTypes) {
Expand Down
31 changes: 26 additions & 5 deletions src/test/skript/tests/syntaxes/effects/EffEquip.sk
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
test "equip effect":

# === ARMOUR ===

spawn a zombie at (spawn of world "world"):
set {_z} to entity

assert helmet of {_z} is air with "a normally spawned zombie shouldn't be wearing a helmet"
assert chestplate of {_z} is air with "a normally spawned zombie shouldn't be wearing a chestplate"
assert leggings of {_z} is air with "a normally spawned zombie shouldn't be wearing leggings"
assert boots of {_z} is air with "a normally spawned zombie shouldn't be wearing boots"
clear helmet of {_z}
clear chestplate of {_z}
clear leggings of {_z}
clear boots of {_z}

assert helmet of {_z} is air with "the modified zombie shouldn't be wearing a helmet"
assert chestplate of {_z} is air with "the modified zombie shouldn't be wearing a chestplate"
assert leggings of {_z} is air with "the modified zombie shouldn't be wearing leggings"
assert boots of {_z} is air with "the modified zombie shouldn't be wearing boots"

equip {_z} with iron helmet
equip {_z} with diamond chestplate
Expand All @@ -22,19 +30,32 @@ test "equip effect":
assert leggings of {_z} is air with "unequipping an entity should remove its armour"
assert boots of {_z} is air with "unequipping an entity should remove its armour"

# === SADDLES ===

spawn a horse at (spawn of world "world"):
set {_h} to entity
spawn a pig at (spawn of world "world"):
set {_p} to entity

assert {_h} and {_p} don't have saddles with "normally spawned horses and pigs should not have saddles"

equip {_h} and {_p} with saddle
# not sure how to assert here that the horse and pig are equipped with a saddle, or that they didnt spawn with one
assert {_h} and {_p} have saddles with "equipping a horse or pig with a saddle should do exactly that"

unequip saddle from {_h} and {_p}
assert {_h} and {_p} don't have saddles with "unequipping a saddle from a horse or pig should do exactly that"

# === WOLF ARMOUR ===

parse if running minecraft "1.20.5":
spawn a wolf at (spawn of world "world"):
set {_w} to entity

equip {_w} with wolf armor
assert {_w} is wearing wolf armor with "equipping a wolf with wolf armor should do exactly that"

unequip wolf armor from {_w}
assert {_w} is not wearing wolf armor with "unequipping wolf armor from a wolf should do exactly that"

delete entity within {_z}
delete entity within {_h}
Expand Down

0 comments on commit d59ea69

Please sign in to comment.