Skip to content

Commit d8d7bdd

Browse files
Happy Ghast Equipment (#8086)
1 parent fd98830 commit d8d7bdd

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

src/main/java/ch/njol/skript/effects/EffEquip.java

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ch.njol.skript.effects;
22

33
import ch.njol.skript.Skript;
4-
import ch.njol.skript.aliases.ItemData;
54
import ch.njol.skript.aliases.ItemType;
65
import ch.njol.skript.bukkitutil.PlayerUtils;
76
import ch.njol.skript.doc.Description;
@@ -19,6 +18,7 @@
1918
import org.bukkit.entity.Horse;
2019
import org.bukkit.entity.LivingEntity;
2120
import org.bukkit.entity.Llama;
21+
import org.bukkit.entity.Mob;
2222
import org.bukkit.entity.Player;
2323
import org.bukkit.entity.Steerable;
2424
import org.bukkit.entity.Wolf;
@@ -43,21 +43,31 @@
4343
"unequip diamond chestplate from player",
4444
"unequip player's armor"
4545
})
46-
@Since("1.0, 2.7 (multiple entities, unequip), 2.10 (wolves)")
46+
@Since({
47+
"1.0, 2.7 (multiple entities, unequip), 2.10 (wolves)",
48+
"INSERT VERSION (happy ghasts)"
49+
})
4750
public class EffEquip extends Effect {
4851

49-
private static ItemType CHESTPLATE;
50-
private static ItemType LEGGINGS;
51-
private static ItemType BOOTS;
52-
private static ItemType CARPET = new ItemType(Tag.WOOL_CARPETS);
53-
private static ItemType WOLF_ARMOR;
52+
private static final ItemType CHESTPLATE;
53+
private static final ItemType LEGGINGS;
54+
private static final ItemType BOOTS;
55+
private static final ItemType CARPET = new ItemType(Tag.WOOL_CARPETS);
56+
private static final ItemType WOLF_ARMOR;
5457
private static final ItemType HORSE_ARMOR = new ItemType(Material.LEATHER_HORSE_ARMOR, Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR);
5558
private static final ItemType SADDLE = new ItemType(Material.SADDLE);
5659
private static final ItemType CHEST = new ItemType(Material.CHEST);
60+
private static final ItemType HAPPY_GHAST_HARNESS;
61+
62+
private static final Class<?> HAPPY_GHAST_CLASS;
5763

5864
static {
59-
boolean hasWolfArmor = Skript.fieldExists(Material.class, "WOLF_ARMOR");
60-
WOLF_ARMOR = hasWolfArmor ? new ItemType(Material.WOLF_ARMOR) : new ItemType();
65+
// added in 1.20.5
66+
if (Skript.fieldExists(Material.class, "WOLF_ARMOR")) {
67+
WOLF_ARMOR = new ItemType(Material.WOLF_ARMOR);
68+
} else {
69+
WOLF_ARMOR = new ItemType();
70+
}
6171

6272
// added in 1.20.6
6373
if (Skript.fieldExists(Tag.class, "ITEM_CHEST_ARMOR")) {
@@ -71,7 +81,7 @@ public class EffEquip extends Effect {
7181
Material.GOLDEN_CHESTPLATE,
7282
Material.IRON_CHESTPLATE,
7383
Material.DIAMOND_CHESTPLATE,
74-
Material.NETHERITE_CHESTPLATE,
84+
Material.NETHERITE_CHESTPLATE,
7585
Material.ELYTRA
7686
);
7787

@@ -81,7 +91,7 @@ public class EffEquip extends Effect {
8191
Material.GOLDEN_LEGGINGS,
8292
Material.IRON_LEGGINGS,
8393
Material.DIAMOND_LEGGINGS,
84-
Material.NETHERITE_LEGGINGS
94+
Material.NETHERITE_LEGGINGS
8595
);
8696

8797
BOOTS = new ItemType(
@@ -90,12 +100,25 @@ public class EffEquip extends Effect {
90100
Material.GOLDEN_BOOTS,
91101
Material.IRON_BOOTS,
92102
Material.DIAMOND_BOOTS,
93-
Material.NETHERITE_BOOTS
103+
Material.NETHERITE_BOOTS
94104
);
95105
}
106+
107+
// added in 1.21.6
108+
if (Skript.fieldExists(Tag.class, "ITEMS_HARNESSES")) {
109+
HAPPY_GHAST_HARNESS = new ItemType(Tag.ITEMS_HARNESSES);
110+
try {
111+
HAPPY_GHAST_CLASS = Class.forName("org.bukkit.entity.HappyGhast");
112+
} catch (ClassNotFoundException e) {
113+
throw new RuntimeException(e);
114+
}
115+
} else {
116+
HAPPY_GHAST_HARNESS = new ItemType();
117+
HAPPY_GHAST_CLASS = null;
118+
}
96119
}
97120

98-
private static final ItemType[] ALL_EQUIPMENT = new ItemType[] {CHESTPLATE, LEGGINGS, BOOTS, HORSE_ARMOR, SADDLE, CHEST, CARPET, WOLF_ARMOR};
121+
private static final ItemType[] ALL_EQUIPMENT = new ItemType[] {CHESTPLATE, LEGGINGS, BOOTS, HORSE_ARMOR, SADDLE, CHEST, CARPET, WOLF_ARMOR, HAPPY_GHAST_HARNESS};
99122

100123
static {
101124
Skript.registerEffect(EffEquip.class,
@@ -177,6 +200,14 @@ protected void execute(Event event) {
177200
equipment.setItem(EquipmentSlot.BODY, equip ? item : null);
178201
}
179202
}
203+
} else if (HAPPY_GHAST_CLASS != null && HAPPY_GHAST_CLASS.isInstance(entity)) {
204+
EntityEquipment equipment = ((Mob) entity).getEquipment();
205+
for (ItemType itemType : itemTypes) {
206+
for (ItemStack itemStack : itemType.getAll()) {
207+
if (HAPPY_GHAST_HARNESS.isOfType(itemStack))
208+
equipment.setItem(EquipmentSlot.BODY, equip ? itemStack : null);
209+
}
210+
}
180211
} else {
181212
EntityEquipment equipment = entity.getEquipment();
182213
if (equipment == null)

src/main/java/ch/njol/skript/expressions/ExprArmorSlot.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@
1515
import ch.njol.skript.util.slot.Slot;
1616
import ch.njol.util.Kleenean;
1717
import org.bukkit.Material;
18-
import org.bukkit.entity.AbstractHorse;
19-
import org.bukkit.entity.Entity;
20-
import org.bukkit.entity.Horse;
21-
import org.bukkit.entity.LivingEntity;
22-
import org.bukkit.entity.Llama;
23-
import org.bukkit.entity.Pig;
24-
import org.bukkit.entity.Strider;
25-
import org.bukkit.entity.TraderLlama;
26-
import org.bukkit.entity.Wolf;
18+
import org.bukkit.entity.*;
2719
import org.bukkit.event.Event;
2820
import org.bukkit.inventory.EntityEquipment;
2921
import org.jetbrains.annotations.Nullable;
@@ -43,6 +35,7 @@
4335
"<li>Horses: Horse armour (doesn't work on zombie or skeleton horses)</li>",
4436
"<li>Wolves: Wolf Armor</li>",
4537
"<li>Llamas (regular or trader): Carpet</li>",
38+
"<li>Happy Ghasts: Harness</li>",
4639
"</ul>",
4740
"Saddle is a special slot that can only be used for: pigs, striders and horse types (horse, camel, llama, mule, donkey)."
4841
})
@@ -51,7 +44,10 @@
5144
"helmet of player is neither tag values of tag \"paper:helmets\" nor air # player is wearing a block, e.g. from another plugin"
5245
})
5346
@Keywords("armor")
54-
@Since("1.0, 2.8.0 (armor), 2.10 (body armor), 2.12 (saddle)")
47+
@Since({
48+
"1.0, 2.8.0 (armor), 2.10 (body armor), 2.12 (saddle)",
49+
"INSERT VERSION (happy ghast)"
50+
})
5551
public class ExprArmorSlot extends PropertyExpression<LivingEntity, Slot> {
5652

5753
private static final Set<Class<? extends Entity>> BODY_ENTITIES =
@@ -71,6 +67,8 @@ public class ExprArmorSlot extends PropertyExpression<LivingEntity, Slot> {
7167
static {
7268
if (Material.getMaterial("WOLF_ARMOR") != null)
7369
BODY_ENTITIES.add(Wolf.class);
70+
if (Skript.classExists("org.bukkit.entity.HappyGhast"))
71+
BODY_ENTITIES.add(HappyGhast.class);
7472

7573
register(ExprArmorSlot.class, Slot.class, "(%-*equipmentslots%|[the] armo[u]r[s]) [item:item[s]]", "livingentities");
7674
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test "happy ghast equipment" when running minecraft "1.21.6":
2+
spawn a happy ghast at test-location:
3+
set {_entity} to entity
4+
5+
equip {_entity} with a red harness
6+
assert the body slot of {_entity} is a red harness with "Equip effect did not equip harness to happy ghast"
7+
unequip a red harness from {_entity}
8+
assert the body slot of {_entity} is air with "Equip effect did not unequip harness from happy ghast"
9+
10+
set the body slot of {_entity} to a blue harness
11+
assert the body slot of {_entity} is a blue harness with "ExprArmorSlot did not set body slot of happy ghast"
12+
clear the body slot of {_entity}
13+
assert the body slot of {_entity} is air with "ExprArmorSlot did not clear body slot of happy ghast"
14+
15+
clear entity within {_entity}

0 commit comments

Comments
 (0)