Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.GlowSquid;

public class EntityDarkDuration implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof GlowSquid;
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof GlowSquid;
}

public static EntityDarkDuration getFrom(ObjectTag entity) {
Expand All @@ -23,10 +24,6 @@ public static EntityDarkDuration getFrom(ObjectTag entity) {
}
}

public static final String[] handledTags = new String[] {
"dark_duration"
};

public static final String[] handledMechs = new String[] {
"dark_duration"
};
Expand All @@ -39,20 +36,19 @@ private EntityDarkDuration(EntityTag ent) {

@Override
public String getPropertyString() {
return new DurationTag((long) ((GlowSquid) entity.getBukkitEntity()).getDarkTicksRemaining()).identify();
return new DurationTag((long) getGlowSquid().getDarkTicksRemaining()).identify();
}

@Override
public String getPropertyId() {
return "dark_duration";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public GlowSquid getGlowSquid() {
return (GlowSquid) entity.getBukkitEntity();
}

if (attribute == null) {
return null;
}
public static void registerTags() {

// <--[tag]
// @attribute <EntityTag.dark_duration>
Expand All @@ -62,12 +58,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the duration remaining before a glow squid starts glowing.
// -->
if (attribute.startsWith("dark_duration")) {
return new DurationTag((long) ((GlowSquid) entity.getBukkitEntity()).getDarkTicksRemaining())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
PropertyParser.<EntityDarkDuration, DurationTag>registerTag(DurationTag.class, "dark_duration", (attribute, object) -> {
return new DurationTag((long) object.getGlowSquid().getDarkTicksRemaining());
});
}

@Override
Expand All @@ -83,7 +76,7 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.dark_duration>
// -->
if (mechanism.matches("dark_duration") && mechanism.requireObject(DurationTag.class)) {
((GlowSquid) entity.getBukkitEntity()).setDarkTicksRemaining(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
getGlowSquid().setDarkTicksRemaining(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Fireball;

public class EntityDirection implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Fireball;
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof Fireball;
}

public static EntityDirection getFrom(ObjectTag entity) {
Expand All @@ -23,10 +24,6 @@ public static EntityDirection getFrom(ObjectTag entity) {
}
}

public static final String[] handledTags = new String[] {
"direction"
};

public static final String[] handledMechs = new String[] {
"direction"
};
Expand All @@ -39,20 +36,19 @@ private EntityDirection(EntityTag ent) {

@Override
public String getPropertyString() {
return new LocationTag(((Fireball) entity.getBukkitEntity()).getDirection()).identify();
return new LocationTag(getFireball().getDirection()).identify();
}

@Override
public String getPropertyId() {
return "direction";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public Fireball getFireball() {
return (Fireball) entity.getBukkitEntity();
}

if (attribute == null) {
return null;
}
public static void registerTags() {

// <--[tag]
// @attribute <EntityTag.direction>
Expand All @@ -62,12 +58,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// Returns the movement/acceleration direction of a fireball entity, as a LocationTag vector.
// -->
if (attribute.startsWith("direction")) {
return new LocationTag(((Fireball) entity.getBukkitEntity()).getDirection())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
PropertyParser.<EntityDirection, LocationTag>registerTag(LocationTag.class, "direction", (attribute, object) -> {
return new LocationTag(object.getFireball().getDirection());
});
}

@Override
Expand All @@ -83,7 +76,7 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.direction>
// -->
if (mechanism.matches("direction") && mechanism.requireObject(LocationTag.class)) {
((Fireball) entity.getBukkitEntity()).setDirection(mechanism.valueAsType(LocationTag.class).toVector());
getFireball().setDirection(mechanism.valueAsType(LocationTag.class).toVector());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ArmorStand;
import org.bukkit.inventory.EquipmentSlot;

import java.util.*;

public class EntityDisabledSlots implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntityType() == EntityType.ARMOR_STAND;
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof ArmorStand;
}

public static EntityDisabledSlots getFrom(ObjectTag entity) {
Expand All @@ -29,10 +30,6 @@ public static EntityDisabledSlots getFrom(ObjectTag entity) {
}
}

public static final String[] handledTags = new String[] {
"disabled_slots"
};

public static final String[] handledMechs = new String[] {
"disabled_slots_raw", "disabled_slots"
};
Expand Down Expand Up @@ -79,26 +76,7 @@ public String getPropertyId() {
return "disabled_slots";
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}

// <--[tag]
// @attribute <EntityTag.disabled_slots.raw>
// @returns ElementTag(Number)
// @mechanism EntityTag.disabled_slots_raw
// @group properties
// @description
// If the entity is an armor stand, returns its raw disabled slots value.
// See <@link url https://minecraft.fandom.com/wiki/Armor_Stand/ED>
// -->
if (attribute.startsWith("disabled_slots.raw")) {
return new ElementTag(CustomNBT.getCustomIntNBT(dentity.getBukkitEntity(), CustomNBT.KEY_DISABLED_SLOTS))
.getObjectAttribute(attribute.fulfill(2));
}
public static void registerTags() {

// <--[tag]
// @attribute <EntityTag.disabled_slots>
Expand All @@ -108,11 +86,24 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @description
// If the entity is an armor stand, returns a list of its disabled slots in the form slot/action|...
// -->
if (attribute.startsWith("disabled_slots")) {
return getDisabledSlots().getObjectAttribute(attribute.fulfill(1));
}
PropertyParser.<EntityDisabledSlots, ObjectTag>registerTag(ObjectTag.class, "disabled_slots", (attribute, object) -> {

// <--[tag]
// @attribute <EntityTag.disabled_slots.raw>
// @returns ElementTag(Number)
// @mechanism EntityTag.disabled_slots_raw
// @group properties
// @description
// If the entity is an armor stand, returns its raw disabled slots value.
// See <@link url https://minecraft.fandom.com/wiki/Armor_Stand/ED>
// -->
if (attribute.startsWith("raw", 2)) {
attribute.fulfill(1);
return new ElementTag(CustomNBT.getCustomIntNBT(object.dentity.getBukkitEntity(), CustomNBT.KEY_DISABLED_SLOTS));
}

return null;
return object.getDisabledSlots();
});
}

@Override
Expand Down Expand Up @@ -161,22 +152,17 @@ public void adjust(Mechanism mechanism) {
for (String string : list) {
String[] split = string.toUpperCase().split("/", 2);

EquipmentSlot slot;
EquipmentSlot slot = new ElementTag(split[0]).asEnum(EquipmentSlot.class);
Action action = null;

try {
slot = EquipmentSlot.valueOf(split[0]);
}
catch (IllegalArgumentException e) {
if (slot == null) {
mechanism.echoError("Invalid equipment slot specified: " + split[0]);
continue;
}

if (split.length == 2) {
try {
action = Action.valueOf(split[1]);
}
catch (IllegalArgumentException e) {
action = new ElementTag(split[1]).asEnum(Action.class);
if (action == null) {
mechanism.echoError("Invalid action specified: " + split[1]);
continue;
}
Expand Down