Skip to content

Commit

Permalink
Fixes wolf armor test failing
Browse files Browse the repository at this point in the history
- Due to CondIsWearing not accounting for the wolf armor in the BODY slot, which apparently isn't returned by EntityEquipment#getArmorContents()
- Moves wolf test to separate structure
  • Loading branch information
cheeezburga committed Sep 3, 2024
1 parent d59ea69 commit f90975e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/main/java/ch/njol/skript/conditions/CondIsWearing.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;

import java.util.Arrays;
import java.util.stream.Stream;

/**
* @author Peter Güttinger
*/
Expand Down Expand Up @@ -56,8 +60,12 @@ public boolean check(Event event) {
EntityEquipment equip = entity.getEquipment();
if (equip == null)
return false; // No equipment -> not wearing anything
for (ItemStack armorContent : equip.getArmorContents()) {
if (type.isOfType(armorContent) ^ type.isAll())

ItemStack[] contents = Arrays.copyOf(equip.getArmorContents(), equip.getArmorContents().length + 1);
contents[contents.length - 1] = equip.getItem(EquipmentSlot.BODY);

for (ItemStack content : contents) {
if (type.isOfType(content) ^ type.isAll())
return !type.isAll();
}
return type.isAll();
Expand Down
24 changes: 13 additions & 11 deletions src/test/skript/tests/syntaxes/effects/EffEquip.sk
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ test "equip effect":
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"
# === CLEANUP ===

delete entity within {_z}
delete entity within {_h}
delete entity within {_p}

test "equip - wolf armor" when 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 {_w}

0 comments on commit f90975e

Please sign in to comment.