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

ExprArmorSlot - Body Armor #7061

Merged
merged 29 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b4c29d2
Starter Commit
TheAbsolutionism Sep 8, 2024
8c92c3e
Repurposing
TheAbsolutionism Sep 8, 2024
b6184fb
Repurposing - 2
TheAbsolutionism Sep 8, 2024
ad09a1f
Final Repurpose
TheAbsolutionism Sep 8, 2024
f9a4122
ExprTest
TheAbsolutionism Sep 8, 2024
6fef5eb
Fixed test
TheAbsolutionism Sep 8, 2024
a872264
Requested Changes
TheAbsolutionism Sep 9, 2024
1e2915b
Merge branch 'dev/feature' into dev/equip-wolf-armor
Moderocky Sep 9, 2024
1e63ee4
Requested Changes
TheAbsolutionism Sep 9, 2024
ed049bf
Merge branch 'dev/equip-wolf-armor' of https://github.com/TheAbsoluti…
TheAbsolutionism Sep 9, 2024
5c0757b
Revert "Merge branch 'dev/equip-wolf-armor' of https://github.com/The…
TheAbsolutionism Sep 9, 2024
a9d1aac
Reapply "Merge branch 'dev/equip-wolf-armor' of https://github.com/Th…
TheAbsolutionism Sep 9, 2024
791fca5
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Sep 19, 2024
31f15d2
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Sep 21, 2024
5822f14
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Sep 22, 2024
fbd3c6f
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Sep 22, 2024
06a3da4
Miniscule Changes
TheAbsolutionism Sep 24, 2024
7bf35a0
Change check for wolf
TheAbsolutionism Sep 29, 2024
806dcae
Requested Change
TheAbsolutionism Sep 29, 2024
136e815
idk
TheAbsolutionism Sep 29, 2024
1453b04
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 1, 2024
4d5fa13
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 2, 2024
15795da
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 6, 2024
f934e89
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 13, 2024
6ff0fdd
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 15, 2024
469f991
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Oct 27, 2024
d6581b8
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Nov 11, 2024
c02e655
Merge branch 'dev/feature' into dev/equip-wolf-armor
TheAbsolutionism Nov 16, 2024
a76c970
Merge branch 'dev/feature' into dev/equip-wolf-armor
sovdeeth Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprArmorSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Keywords;
Expand All @@ -30,39 +31,53 @@
import ch.njol.skript.util.slot.EquipmentSlot.EquipSlot;
import ch.njol.skript.util.slot.Slot;
import ch.njol.util.Kleenean;
import org.bukkit.entity.LivingEntity;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.jetbrains.annotations.Nullable;

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

@Name("Armour Slot")
@Description("Equipment of living entities, i.e. the boots, leggings, chestplate or helmet.")
@Name("Armor Slot")
@Description({
"Equipment of living entities, i.e. the boots, leggings, chestplate or helmet.",
"Body armor is a special slot that can only be used for:",
"<ul>",
"<li>Horses: Horse armour (doesn't work on zombie or skeleton horses)</li>",
"<li>Wolves: Wolf Armor</li>",
"<li>Llamas (regular or trader): Carpet</li>",
"</ul>"
})
@Examples({
"set chestplate of the player to a diamond chestplate",
"helmet of player is neither a helmet nor air # player is wearing a block, e.g. from another plugin"
})
@Keywords("armor")
@Since("1.0, 2.8.0 (Armour)")
@Since("1.0, 2.8.0 (armor), INSERT VERSION (body armor)")
public class ExprArmorSlot extends PropertyExpression<LivingEntity, Slot> {

private static final Set<Class<?>> bodyEntities = new HashSet<>(Arrays.asList(Horse.class, Llama.class, TraderLlama.class));

static {
register(ExprArmorSlot.class, Slot.class, "((boots:(boots|shoes)|leggings:leg[ging]s|chestplate:chestplate[s]|helmet:helmet[s]) [(item|:slot)]|armour:armo[u]r[s])", "livingentities");
if (Material.getMaterial("WOLF_ARMOR") != null)
bodyEntities.add(Wolf.class);

register(ExprArmorSlot.class, Slot.class, "((boots:(boots|shoes)|leggings:leg[ging]s|chestplate:chestplate[s]|helmet:helmet[s]) [(item|:slot)]|armour:armo[u]r[s]|bodyarmor:body armo[u]r)", "livingentities");
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

@Nullable
private EquipSlot slot;
private @Nullable EquipSlot slot;
private boolean explicitSlot;
private boolean isArmor;
private boolean isBody;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
isBody = parseResult.hasTag("bodyarmor");
isArmor = parseResult.hasTag("armour");
slot = isArmor ? null : EquipSlot.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH));
slot = (isArmor || isBody) ? null : EquipSlot.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH));
explicitSlot = parseResult.hasTag("slot"); // User explicitly asked for SLOT, not item
setExpr((Expression<? extends LivingEntity>) exprs[0]);
return true;
Expand All @@ -76,6 +91,11 @@ protected Slot[] get(Event event, LivingEntity[] source) {
.flatMap(equipment -> {
if (equipment == null)
return null;
if (isBody) {
if (!bodyEntities.contains(equipment.getHolder().getType().getEntityClass()))
return null;
return Stream.of(new EquipmentSlot(equipment, EquipSlot.BODY, explicitSlot));
}
return Stream.of(
new EquipmentSlot(equipment, EquipSlot.HELMET, explicitSlot),
new EquipmentSlot(equipment, EquipSlot.CHESTPLATE, explicitSlot),
Expand All @@ -96,7 +116,7 @@ protected Slot[] get(Event event, LivingEntity[] source) {

@Override
public boolean isSingle() {
return !isArmor && super.isSingle();
return isBody || (!isArmor && super.isSingle());
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ch/njol/skript/util/slot/EquipmentSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ public ItemStack get(final EntityEquipment e) {
public void set(final EntityEquipment e, final @Nullable ItemStack item) {
e.setBoots(item);
}
},

BODY() {
@Override
public @Nullable ItemStack get(EntityEquipment equipment) {
return equipment.getItem(org.bukkit.inventory.EquipmentSlot.BODY);
}

@Override
public void set(EntityEquipment equipment, @Nullable ItemStack item) {
equipment.setItem(org.bukkit.inventory.EquipmentSlot.BODY, item);
}
};

public final int slotNumber;
Expand Down
18 changes: 18 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprArmorSlot.sk
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ test "armour slot":
clear armour of event-entity
assert armour of event-entity does not contain dirt block, diamond chestplate, iron leggings and gold boots with "Failed to clear EquipmentSlots"
delete event-entity

test "body armor wolf" when running minecraft "1.20.5":
spawn wolf at spawn of world "world":
set {_entity} to event-entity
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

set body armor of {_entity} to wolf armor
assert body armor of {_entity} is wolf armor with "Body armor of entity is not wolf armor"
clear body armor of {_entity}
assert body armor of {_entity} is air with "Body armor of entity did not get cleared"
clear entity within {_entity}

test "invalid body armor":
loop a zombie, a skeleton, a zombie horse and a skeleton horse:
spawn loop-value at spawn of world "world":
assert (body armor of event-entity) is not set with "Entity body armor is accessible"
set body armor of event-entity to diamond armor
assert (body armor of event-entity) is not set with "Entity body armor is accessible"
clear event-entity
Loading