diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAI.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAI.java index 972403f6b9..18f0231576 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAI.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAI.java @@ -1,10 +1,21 @@ package com.denizenscript.denizen.objects.properties.entity; import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class EntityAI extends EntityProperty { +public class EntityAI extends EntityProperty { + + // <--[property] + // @object EntityTag + // @name has_ai + // @input ElementTag(Boolean) + // @description + // Controls whether this entity will use the default Minecraft AI to roam and look around. + // This tends to have implications for other vanilla functionality, including gravity. + // This generally shouldn't be used with NPCs. NPCs do not have vanilla AI, regardless of what this tag returns. + // Other programmatic methods of blocking AI might also not be accounted for by this tag. + // --> public static boolean describes(EntityTag entity) { return entity.isLivingEntityType(); @@ -15,42 +26,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getLivingEntity().hasAI()); } + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + getLivingEntity().setAI(param.asBoolean()); + } + } + @Override public String getPropertyId() { return "has_ai"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism EntityTag.has_ai - // @group attributes - // @description - // Returns whether the entity uses the default Minecraft AI to roam and look around. - // This tends to have implications for other vanilla functionality, including gravity. - // This generally shouldn't be used with NPCs. NPCs do not have vanilla AI, regardless of what this tag returns. - // Other programmatic methods of blocking AI might also not be accounted for by this tag. - // --> - PropertyParser.registerTag(EntityAI.class, ElementTag.class, "has_ai", (attribute, prop) -> { - return new ElementTag(prop.getLivingEntity().hasAI()); - }); - - // <--[mechanism] - // @object EntityTag - // @name has_ai - // @input ElementTag(Boolean) - // @description - // Sets whether this entity will use the default Minecraft AI to roam and look around. - // This tends to have implications for other vanilla functionality, including gravity. - // @tags - // - // --> - PropertyParser.registerMechanism(EntityAI.class, ElementTag.class, "has_ai", (prop, mechanism, param) -> { - if (mechanism.requireBoolean()) { - prop.getLivingEntity().setAI(param.asBoolean()); - } - }, "toggle_ai"); + autoRegister("has_ai", EntityAI.class, ElementTag.class, false, "toggle_ai"); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAge.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAge.java index f39c01d69e..eb9b98078b 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAge.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAge.java @@ -3,6 +3,7 @@ import com.denizenscript.denizen.objects.EntityTag; import com.denizenscript.denizen.utilities.BukkitImplDeprecations; import com.denizenscript.denizencore.objects.ArgumentHelper; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.objects.properties.PropertyParser; @@ -11,7 +12,19 @@ import org.bukkit.entity.Ageable; import org.bukkit.entity.Breedable; -public class EntityAge extends EntityProperty { +public class EntityAge extends EntityProperty { + + // <--[property] + // @object EntityTag + // @name age + // @input ElementTag + // @description + // Controls the entity's age. + // Age moves 1 towards zero each tick. + // A newly spawned baby is -24000, a standard adult is 0, an adult that just bred is 6000. + // For the mechanism, inputs can be 'baby', 'adult', or a valid age number. + // Also available: <@link mechanism EntityTag.age_locked> and <@link tag EntityTag.is_baby> + // --> public static boolean describes(EntityTag entity) { return entity.getBukkitEntity() instanceof Ageable; @@ -26,6 +39,38 @@ public ElementTag getPropertyValue() { return new ElementTag(as(Ageable.class).getAge()); } + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + ListTag listHack = param.asType(ListTag.class, mechanism.context); + if (listHack.isEmpty()) { + mechanism.echoError("Missing value for 'age' mechanism!"); + return; + } + String input = CoreUtilities.toLowerCase(listHack.get(0)); + switch (input) { + case "baby" -> setAge(-24000); + case "adult" -> setAge(0); + default -> { + if (!ArgumentHelper.matchesInteger(input)) { + mechanism.echoError("Invalid age '" + input + "': must be 'baby', 'adult', or a valid age number."); + return; + } + setAge(new ElementTag(input).asInt()); + } + } + if (listHack.size() > 1) { + BukkitImplDeprecations.oldAgeLockedControls.warn(mechanism.context); + if (!(getEntity() instanceof Breedable breedable)) { + return; + } + switch (CoreUtilities.toLowerCase(listHack.get(1))) { + case "locked" -> breedable.setAgeLock(true); + case "unlocked" -> breedable.setAgeLock(false); + default -> mechanism.echoError("Invalid lock state '" + listHack.get(1) + "': must be 'locked' or 'unlocked'."); + } + } + } + @Override public String getPropertyId() { return "age"; @@ -41,6 +86,7 @@ public void setAge(int age) { } public static void register() { + autoRegister("age", EntityAge.class, ElementTag.class, false); // <--[tag] // @attribute @@ -53,62 +99,5 @@ public static void register() { PropertyParser.registerTag(EntityAge.class, ElementTag.class, "is_baby", (attribute, prop) -> { return new ElementTag(!prop.as(Ageable.class).isAdult()); }); - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism EntityTag.age - // @group properties - // @description - // If the entity is ageable, returns the entity's age. - // Age moves 1 towards zero each tick. - // A newly spawned baby is -24000, a standard adult is 0, an adult that just bred is 6000. - // --> - PropertyParser.registerTag(EntityAge.class, ElementTag.class, "age", (attribute, prop) -> { - return new ElementTag(prop.as(Ageable.class).getAge()); - }); - - // <--[mechanism] - // @object EntityTag - // @name age - // @input ElementTag - // @description - // Sets the entity's age. - // Inputs can be 'baby', 'adult', or a valid age number. - // A newly spawned baby is -24000, a standard adult is 0, an adult that just bred is 6000. - // Also available: <@link mechanism EntityTag.age_locked>. - // @tags - // - // - // --> - PropertyParser.registerMechanism(EntityAge.class, ListTag.class, "age", (prop, mechanism, param) -> { - if (param.isEmpty()) { - mechanism.echoError("Missing value for 'age' mechanism!"); - return; - } - String input = CoreUtilities.toLowerCase(param.get(0)); - switch (input) { - case "baby" -> prop.setAge(-24000); - case "adult" -> prop.setAge(0); - default -> { - if (!ArgumentHelper.matchesInteger(input)) { - mechanism.echoError("Invalid age '" + input + "': must be 'baby', 'adult', or a valid age number."); - return; - } - prop.setAge(new ElementTag(input).asInt()); - } - } - if (param.size() > 1) { - BukkitImplDeprecations.oldAgeLockedControls.warn(mechanism.context); - if (!(prop.getEntity() instanceof Breedable breedable)) { - return; - } - switch (CoreUtilities.toLowerCase(param.get(1))) { - case "locked" -> breedable.setAgeLock(true); - case "unlocked" -> breedable.setAgeLock(false); - default -> mechanism.echoError("Invalid lock state '" + param.get(1) + "': must be 'locked' or 'unlocked'."); - } - } - }); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAgeLocked.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAgeLocked.java index 9a1beeb753..e8f76d7843 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAgeLocked.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAgeLocked.java @@ -1,20 +1,45 @@ package com.denizenscript.denizen.objects.properties.entity; import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import net.citizensnpcs.trait.Age; import org.bukkit.entity.Breedable; -public class EntityAgeLocked extends EntityProperty { +public class EntityAgeLocked extends EntityProperty { + + // <--[property] + // @object EntityTag + // @name age_locked + // @input ElementTag(Boolean) + // @description + // Controls whether the entity is locked into its current age. + // --> public static boolean describes(EntityTag entity) { return entity.getBukkitEntity() instanceof Breedable; } + @Override + public boolean isDefaultValue(ElementTag val) { + return !val.asBoolean(); + } + @Override public ElementTag getPropertyValue() { - return as(Breedable.class).getAgeLock() ? new ElementTag(true) : null; + return new ElementTag(as(Breedable.class).getAgeLock()); + } + + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + if (object.isCitizensNPC()) { + object.getDenizenNPC().getCitizen().getOrAddTrait(Age.class).setLocked(param.asBoolean()); + } + else { + as(Breedable.class).setAgeLock(param.asBoolean()); + } + } } @Override @@ -23,6 +48,7 @@ public String getPropertyId() { } public static void register() { + autoRegister("age_locked", EntityAgeLocked.class, ElementTag.class, false, "is_age_locked", "age_lock"); // <--[tag] // @attribute @@ -33,18 +59,6 @@ public static void register() { // Deprecated in favor of <@link tag EntityTag.age_locked>. // --> - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism EntityTag.age_locked - // @group properties - // @description - // Returns whether the entity is locked into its current age. - // --> - PropertyParser.registerTag(EntityAgeLocked.class, ElementTag.class, "age_locked", (attribute, prop) -> { - return new ElementTag(prop.as(Breedable.class).getAgeLock()); - }, "is_age_locked"); - // <--[mechanism] // @object EntityTag // @name age_lock @@ -53,25 +67,5 @@ public static void register() { // @description // Deprecated in favor of <@link mechanism EntityTag.age_locked>. // --> - - // <--[mechanism] - // @object EntityTag - // @name age_locked - // @input ElementTag(Boolean) - // @description - // Sets whether the entity is locked into its current age. - // @tags - // - // --> - PropertyParser.registerMechanism(EntityAgeLocked.class, ElementTag.class, "age_locked", (prop, mechanism, input) -> { - if (mechanism.requireBoolean()) { - if (prop.object.isCitizensNPC()) { - prop.object.getDenizenNPC().getCitizen().getOrAddTrait(Age.class).setLocked(input.asBoolean()); - } - else { - prop.as(Breedable.class).setAgeLock(input.asBoolean()); - } - } - }, "age_lock"); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAggressive.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAggressive.java index c7d83b3b97..58b74045ef 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAggressive.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAggressive.java @@ -2,11 +2,19 @@ import com.denizenscript.denizen.nms.NMSHandler; import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.entity.Mob; -public class EntityAggressive extends EntityProperty { +public class EntityAggressive extends EntityProperty { + + // <--[property] + // @object EntityTag + // @name aggressive + // @input ElementTag(Boolean) + // @description + // Controls whether the entity is currently aggressive. + // --> public static boolean describes(EntityTag entity) { return entity.getBukkitEntity() instanceof Mob; @@ -14,7 +22,14 @@ public static boolean describes(EntityTag entity) { @Override public ElementTag getPropertyValue() { - return new ElementTag(NMSHandler.entityHelper.isAggressive(getMob())); + return new ElementTag(NMSHandler.entityHelper.isAggressive(as(Mob.class))); + } + + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + NMSHandler.entityHelper.setAggressive(as(Mob.class), param.asBoolean()); + } } @Override @@ -23,36 +38,6 @@ public String getPropertyId() { } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism EntityTag.aggressive - // @group properties - // @description - // Returns whether the entity is currently aggressive. - // --> - PropertyParser.registerTag(EntityAggressive.class, ElementTag.class, "aggressive", (attribute, prop) -> { - return new ElementTag(NMSHandler.entityHelper.isAggressive(prop.getMob())); - }); - - // <--[mechanism] - // @object EntityTag - // @name aggressive - // @input ElementTag(Boolean) - // @description - // Sets whether the entity is currently aggressive. - // @tags - // - // --> - PropertyParser.registerMechanism(EntityAggressive.class, ElementTag.class, "aggressive", (prop, mechanism, input) -> { - if (mechanism.requireBoolean()) { - NMSHandler.entityHelper.setAggressive(prop.getMob(), input.asBoolean()); - } - }); - } - - public Mob getMob() { - return (Mob) getEntity(); + autoRegister("aggressive", EntityAggressive.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityProperty.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityProperty.java index b55b7c9990..cc25e9f2e5 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityProperty.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityProperty.java @@ -1,12 +1,13 @@ package com.denizenscript.denizen.objects.properties.entity; import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; -public abstract class EntityProperty extends ObjectProperty { +public abstract class EntityProperty extends ObjectProperty { public EntityProperty() { } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityStepHeight.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityStepHeight.java index 6b398a83d5..d58a90e77e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityStepHeight.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityStepHeight.java @@ -1,56 +1,46 @@ package com.denizenscript.denizen.objects.properties.entity; import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.objects.EntityTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class EntityStepHeight extends EntityProperty { +public class EntityStepHeight extends EntityProperty { + + // <--[property] + // @object EntityTag + // @name step_height + // @input ElementTag(Decimal) + // @description + // Sets the entity's step height, which controls how many blocks can it walk over. + // As this is based on an internal value, it has some edge-cases, for example: + // - most (but not all) living entities can still step over 1 block tall things as usual, even if this is set to 0. + // - this doesn't apply to vehicles when the player is controlling them. + // Note that this also applies to things like getting pushed. + // --> + + public static boolean describes(EntityTag entity) { + return true; + } @Override public ElementTag getPropertyValue() { return new ElementTag(NMSHandler.entityHelper.getStepHeight(getEntity())); } + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + if (mechanism.requireFloat()) { + NMSHandler.entityHelper.setStepHeight(getEntity(), param.asFloat()); + } + } + @Override public String getPropertyId() { return "step_height"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Decimal) - // @mechanism EntityTag.step_height - // @group properties - // @description - // Returns the entity's step height, which controls how many blocks can it walk over. - // As this is based on an internal value, it has some edge-cases, for example: - // - most (but not all) living entities can still step over 1 block tall things as usual, even if this is set to 0. - // - this doesn't apply to vehicles when the player is controlling them. - // Note that this also applies to things like getting pushed. - // --> - PropertyParser.registerTag(EntityStepHeight.class, ElementTag.class, "step_height", (attribute, prop) -> { - return prop.getPropertyValue(); - }); - - // <--[mechanism] - // @object EntityTag - // @name step_height - // @input ElementTag(Decimal) - // @description - // Sets the entity's step height, which controls how many blocks can it walk over. - // As this is based on an internal value, it has some edge-cases, for example: - // - most (but not all) living entities can still step over 1 block tall things as usual, even if this is set to 0. - // - this doesn't apply to vehicles when the player is controlling them. - // Note that this also applies to things like getting pushed. - // @tags - // - // --> - PropertyParser.registerMechanism(EntityStepHeight.class, ElementTag.class, "step_height", (prop, mechanism, input) -> { - if (mechanism.requireFloat()) { - NMSHandler.entityHelper.setStepHeight(prop.getEntity(), input.asFloat()); - } - }); + autoRegister("step_height", EntityStepHeight.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryContents.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryContents.java index 943611b9af..49f262aa36 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryContents.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryContents.java @@ -2,6 +2,7 @@ import com.denizenscript.denizen.objects.InventoryTag; import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.objects.core.MapTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; @@ -10,7 +11,7 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -public class InventoryContents extends ObjectProperty { +public class InventoryContents extends ObjectProperty { public static boolean describes(InventoryTag inventory) { return true; @@ -28,6 +29,13 @@ public ListTag getPropertyValue() { return contents; } + @Override + public void setPropertyValue(ListTag list, Mechanism mechanism) { + if (object.isGeneric() || !mechanism.isProperty) { + object.setContents(list, mechanism.context); + } + } + @Override public String getPropertyId() { return "contents"; @@ -187,9 +195,7 @@ public static void register() { // ].simple> // --> PropertyParser.registerMechanism(InventoryContents.class, ListTag.class, "contents", (prop, mechanism, param) -> { - if (prop.object.isGeneric() || !mechanism.isProperty) { - prop.object.setContents(param, mechanism.context); - } + prop.setPropertyValue(param, mechanism); }); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryHolder.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryHolder.java index af54b18304..fbb710ac56 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryHolder.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryHolder.java @@ -1,13 +1,14 @@ package com.denizenscript.denizen.objects.properties.inventory; import com.denizenscript.denizen.objects.*; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ScriptTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.event.inventory.InventoryType; -public class InventoryHolder extends ObjectProperty { +public class InventoryHolder extends ObjectProperty { public static boolean describes(InventoryTag inventory) { return true; @@ -24,6 +25,11 @@ public ObjectTag getPropertyValue() { } } + @Override + public void setPropertyValue(ObjectTag param, Mechanism mechanism) { + throw new UnsupportedOperationException(); + } + @Override public String getPropertyId() { return "holder"; diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventorySize.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventorySize.java index 9e33c54147..e5f077d672 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventorySize.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventorySize.java @@ -1,13 +1,22 @@ package com.denizenscript.denizen.objects.properties.inventory; import com.denizenscript.denizen.objects.InventoryTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.event.inventory.InventoryType; -public class InventorySize extends ObjectProperty { +public class InventorySize extends ObjectProperty { + + // <--[property] + // @object InventoryTag + // @name size + // @input ElementTag(Number) + // @description + // Controls the size of the inventory. + // Note that the mechanism can only be set for "generic" chest inventories. + // --> public static boolean describes(ObjectTag inventory) { return true; @@ -24,12 +33,24 @@ public void setSize(int size) { object.setSize(size); } + @Override + public boolean isDefaultValue(ElementTag size) { + return !(getSize() > 0 && (object.getIdType().equals("generic") || object.getIdType().equals("script")) && object.getInventoryType() == InventoryType.CHEST); + } + @Override public ElementTag getPropertyValue() { - if (getSize() > 0 && (object.getIdType().equals("generic") || object.getIdType().equals("script")) && object.getInventoryType() == InventoryType.CHEST) { - return new ElementTag(getSize()); + return new ElementTag(getSize()); + } + + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + if (object.getIdType().equals("generic") || object.getIdType().equals("script")) { + setSize(param.asInt()); + } + else { + mechanism.echoError("Inventories of type '" + object.getIdType() + "' cannot have their size changed!"); } - return null; } @Override @@ -38,35 +59,6 @@ public String getPropertyId() { } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @group properties - // @mechanism InventoryTag.size - // @description - // Return the number of slots in the inventory. - // --> - PropertyParser.registerTag(InventorySize.class, ElementTag.class, "size", (attribute, inventory) -> { - return new ElementTag(inventory.getSize()); - }); - - // <--[mechanism] - // @object InventoryTag - // @name size - // @input ElementTag(Number) - // @description - // Sets the size of the inventory. (Only works for "generic" chest inventories.) - // @tags - // - // --> - PropertyParser.registerMechanism(InventorySize.class, ElementTag.class, "size", (prop, mechanism, param) -> { - if (prop.object.getIdType().equals("generic") || prop.object.getIdType().equals("script")) { - prop.setSize(param.asInt()); - } - else { - mechanism.echoError("Inventories of type '" + prop.object.getIdType() + "' cannot have their size changed!"); - } - }); + autoRegister("size", InventorySize.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTitle.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTitle.java index cdcc851b58..630468b6cb 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTitle.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTitle.java @@ -3,95 +3,83 @@ import com.denizenscript.denizen.objects.InventoryTag; import com.denizenscript.denizen.scripts.containers.core.InventoryScriptHelper; import com.denizenscript.denizen.utilities.PaperAPITools; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; -public class InventoryTitle extends ObjectProperty { +public class InventoryTitle extends ObjectProperty { + + // <--[property] + // @object InventoryTag + // @name title + // @input ElementTag + // @description + // Controls the title of the inventory. + // Note that the mechanism can only be set for "generic" inventories. + // --> public static boolean describes(InventoryTag inventory) { return true; } @Override - public ElementTag getPropertyValue() { - // Only show a property string for titles that can actually change - if (object.isGeneric() || object.isSaving) { - return new ElementTag(getTitle()); - } - return null; + public boolean isDefaultValue(ElementTag title) { + return !object.isGeneric() && !object.isSaving; } @Override - public String getPropertyId() { - return "title"; - } - - public String getTitle() { + public ElementTag getPropertyValue() { if (object.getInventory() != null) { String title = PaperAPITools.instance.getTitle(object.getInventory()); if (title != null) { if (!title.startsWith("container.")) { - return title; + return new ElementTag(title, true); } } } return null; } - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @group properties - // @mechanism InventoryTag.title - // @description - // Returns the title of the inventory. - // --> - PropertyParser.registerTag(InventoryTitle.class, ElementTag.class, "title", (attribute, inventory) -> { - return new ElementTag(inventory.getTitle(), true); - }); - // <--[mechanism] - // @object InventoryTag - // @name title - // @input ElementTag - // @description - // Sets the title of the inventory. (Only works for "generic" inventories.) - // @tags - // - // --> - PropertyParser.registerMechanism(InventoryTitle.class, ElementTag.class, "title", (prop, mechanism, param) -> { - InventoryTag inventory = prop.object; - if (!inventory.isGeneric() && !inventory.isUnique()) { - mechanism.echoError("Cannot set a title on a non-generic inventory."); - return; - } - String title = param.asString(); - if (InventoryScriptHelper.isPersonalSpecialInv(inventory.getInventory())) { - inventory.customTitle = title; - return; - } - if (inventory.getInventory() != null && PaperAPITools.instance.getTitle(inventory.getInventory()).equals(title)) { - return; - } - inventory.uniquifier = null; - if (inventory.getInventory() == null) { - inventory.setInventory(PaperAPITools.instance.createInventory(null, InventoryTag.maxSlots, title)); - InventoryTag.trackTemporaryInventory(inventory); - return; - } - ItemStack[] contents = inventory.getContents(); - if (inventory.getInventory().getType() == InventoryType.CHEST) { - inventory.setInventory(PaperAPITools.instance.createInventory(null, inventory.getSize(), title)); - } - else { - inventory.setInventory(PaperAPITools.instance.createInventory(null, inventory.getInventory().getType(), title)); - } - inventory.setContents(contents); + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + InventoryTag inventory = object; + if (!inventory.isGeneric() && !inventory.isUnique()) { + mechanism.echoError("Cannot set a title on a non-generic inventory."); + return; + } + String title = param.asString(); + if (InventoryScriptHelper.isPersonalSpecialInv(inventory.getInventory())) { + inventory.customTitle = title; + return; + } + if (inventory.getInventory() != null && PaperAPITools.instance.getTitle(inventory.getInventory()).equals(title)) { + return; + } + inventory.uniquifier = null; + if (inventory.getInventory() == null) { + inventory.setInventory(PaperAPITools.instance.createInventory(null, InventoryTag.maxSlots, title)); InventoryTag.trackTemporaryInventory(inventory); - }); + return; + } + ItemStack[] contents = inventory.getContents(); + if (inventory.getInventory().getType() == InventoryType.CHEST) { + inventory.setInventory(PaperAPITools.instance.createInventory(null, inventory.getSize(), title)); + } + else { + inventory.setInventory(PaperAPITools.instance.createInventory(null, inventory.getInventory().getType(), title)); + } + inventory.setContents(contents); + InventoryTag.trackTemporaryInventory(inventory); + } + + @Override + public String getPropertyId() { + return "title"; + } + + public static void register() { + autoRegister("title", InventoryTitle.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTrades.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTrades.java index 1e789cf6f9..9c6ee7a7a0 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTrades.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryTrades.java @@ -2,35 +2,35 @@ import com.denizenscript.denizen.objects.InventoryTag; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.inventory.MerchantInventory; import org.bukkit.inventory.MerchantRecipe; import java.util.ArrayList; -public class InventoryTrades extends ObjectProperty { +public class InventoryTrades extends ObjectProperty { + + // <--[property] + // @object InventoryTag + // @name trades + // @input ListTag(TradeTag) + // @description + // Controls the trade recipe list for a merchant inventory. + // --> public static boolean describes(InventoryTag inventory) { return inventory.getInventory() instanceof MerchantInventory; } @Override - public ListTag getPropertyValue() { - ListTag recipes = getTradeRecipes(); - if (recipes.isEmpty()) { - return null; - } - return recipes; + public boolean isDefaultValue(ListTag list) { + return list.isEmpty(); } @Override - public String getPropertyId() { - return "trades"; - } - - public ListTag getTradeRecipes() { + public ListTag getPropertyValue() { ArrayList recipes = new ArrayList<>(); for (MerchantRecipe recipe : ((MerchantInventory) object.getInventory()).getMerchant().getRecipes()) { recipes.add(new TradeTag(recipe).duplicate()); @@ -38,35 +38,21 @@ public ListTag getTradeRecipes() { return new ListTag(recipes); } - public static void register() { + @Override + public void setPropertyValue(ListTag list, Mechanism mechanism) { + ArrayList recipes = new ArrayList<>(); + for (TradeTag recipe : list.filter(TradeTag.class, mechanism.context)) { + recipes.add(recipe.getRecipe()); + } + ((MerchantInventory) object.getInventory()).getMerchant().setRecipes(recipes); + } - // <--[tag] - // @attribute - // @returns ListTag(TradeTag) - // @group properties - // @mechanism InventoryTag.trades - // @description - // Return the list of recipes from a merchant inventory. - // --> - PropertyParser.registerTag(InventoryTrades.class, ListTag.class, "trades", (attribute, inventory) -> { - return inventory.getTradeRecipes(); - }); + @Override + public String getPropertyId() { + return "trades"; + } - // <--[mechanism] - // @object InventoryTag - // @name trades - // @input ListTag(TradeTag) - // @description - // Sets the trade recipe list for a merchant inventory. - // @tags - // - // --> - PropertyParser.registerMechanism(InventoryTrades.class, ListTag.class, "trades", (prop, mechanism, param) -> { - ArrayList recipes = new ArrayList<>(); - for (TradeTag recipe : param.filter(TradeTag.class, mechanism.context)) { - recipes.add(recipe.getRecipe()); - } - ((MerchantInventory) prop.object.getInventory()).getMerchant().setRecipes(recipes); - }); + public static void register() { + autoRegister("trades", InventoryTrades.class, ListTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryUniquifier.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryUniquifier.java index e06b6db4bf..a00fb6cb8f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryUniquifier.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/inventory/InventoryUniquifier.java @@ -1,10 +1,11 @@ package com.denizenscript.denizen.objects.properties.inventory; import com.denizenscript.denizen.objects.InventoryTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; -public class InventoryUniquifier extends ObjectProperty { +public class InventoryUniquifier extends ObjectProperty { public static boolean describes(InventoryTag inventory) { return inventory.isGeneric(); @@ -18,6 +19,11 @@ public ElementTag getPropertyValue() { return new ElementTag(object.uniquifier); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + throw new UnsupportedOperationException(); + } + @Override public String getPropertyId() { return "uniquifier"; diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemArmorPose.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemArmorPose.java index 4034432fb7..cf458d15da 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemArmorPose.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemArmorPose.java @@ -7,7 +7,6 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.MapTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -15,40 +14,23 @@ import java.util.ArrayList; import java.util.List; -public class ItemArmorPose extends ItemProperty { +public class ItemArmorPose extends ItemProperty { + + // <--[property] + // @object ItemTag + // @name armor_pose + // @input MapTag + // @description + // Controls the pose of this armor stand item. + // Allowed keys: head, body, left_arm, right_arm, left_leg, right_leg + // --> public static boolean describes(ItemTag item) { return item.getBukkitMaterial() == Material.ARMOR_STAND; } @Override - public String getPropertyString() { - MapTag result = getPoseMap(); - if (result == null) { - return null; - } - return result.toString(); - } - - @Override - public String getPropertyId() { - return "armor_pose"; - } - - public static void procPart(CompoundTag pose, String nmsName, String denizenName, MapTag result) { - List list = pose.getList(nmsName); - if (list == null || list.size() != 3) { - return; - } - Tag x = list.get(0), y = list.get(1), z = list.get(2); - if (!(x instanceof FloatTag) || !(y instanceof FloatTag) || !(z instanceof FloatTag)) { - return; - } - String combined = x.getValue() + "," + y.getValue() + "," + z.getValue(); - result.putObject(denizenName, new ElementTag(combined)); - } - - public MapTag getPoseMap() { + public MapTag getPropertyValue() { CompoundTag compoundTag = NMSHandler.itemHelper.getNbtData(getItemStack()); if (compoundTag == null) { return null; @@ -72,80 +54,77 @@ public MapTag getPoseMap() { return result; } - public static void register() { - - // <--[tag] - // @attribute - // @returns MapTag - // @group properties - // @mechanism ItemTag.armor_pose - // @description - // Returns the pose of this armor stand item, if any. - // Map has keys: head, body, left_arm, right_arm, left_leg, right_leg - // --> - PropertyParser.registerTag(ItemArmorPose.class, MapTag.class, "armor_pose", (attribute, prop) -> { - return prop.getPoseMap(); - }); - - // <--[mechanism] - // @object ItemTag - // @name armor_pose - // @input MapTag - // @description - // Sets the pose of this armor stand item. - // Allowed keys: head, body, left_arm, right_arm, left_leg, right_leg - // @tags - // - // --> - PropertyParser.registerMechanism(ItemArmorPose.class, MapTag.class, "armor_pose", (prop, mechanism, param) -> { - CompoundTag compoundTag = NMSHandler.itemHelper.getNbtData(prop.getItemStack()); - Tag entPart, posePart; - if (mechanism.hasValue()) { - if (compoundTag == null) { - compoundTag = new CompoundTagBuilder().build(); - } - entPart = compoundTag.getValue().get("EntityTag"); - if (!(entPart instanceof CompoundTag)) { - entPart = new CompoundTagBuilder().build(); - } - CompoundTagBuilder poseBuilder = new CompoundTagBuilder(); - procMechKey(mechanism, poseBuilder, "Head", "head", param); - procMechKey(mechanism, poseBuilder, "Body", "body", param); - procMechKey(mechanism, poseBuilder, "LeftArm", "left_arm", param); - procMechKey(mechanism, poseBuilder, "RightArm", "right_arm", param); - procMechKey(mechanism, poseBuilder, "LeftLeg", "left_leg", param); - procMechKey(mechanism, poseBuilder, "RightLeg", "right_leg", param); - CompoundTag pose = poseBuilder.build(); - if (pose.getValue().isEmpty()) { - entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build(); - } - else { - entPart = ((CompoundTag) entPart).createBuilder().put("Pose", pose).build(); - } + @Override + public void setPropertyValue(MapTag param, Mechanism mechanism) { + CompoundTag compoundTag = NMSHandler.itemHelper.getNbtData(getItemStack()); + Tag entPart, posePart; + if (mechanism.hasValue()) { + if (compoundTag == null) { + compoundTag = new CompoundTagBuilder().build(); } - else { - if (compoundTag == null) { - return; - } - entPart = compoundTag.getValue().get("EntityTag"); - if (!(entPart instanceof CompoundTag)) { - return; - } - posePart = ((CompoundTag) entPart).getValue().get("Pose"); - if (!(posePart instanceof CompoundTag)) { - return; - } - entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build(); + entPart = compoundTag.getValue().get("EntityTag"); + if (!(entPart instanceof CompoundTag)) { + entPart = new CompoundTagBuilder().build(); } - if (((CompoundTag) entPart).getValue().isEmpty()) { - compoundTag = compoundTag.createBuilder().remove("EntityTag").build(); + CompoundTagBuilder poseBuilder = new CompoundTagBuilder(); + procMechKey(mechanism, poseBuilder, "Head", "head", param); + procMechKey(mechanism, poseBuilder, "Body", "body", param); + procMechKey(mechanism, poseBuilder, "LeftArm", "left_arm", param); + procMechKey(mechanism, poseBuilder, "RightArm", "right_arm", param); + procMechKey(mechanism, poseBuilder, "LeftLeg", "left_leg", param); + procMechKey(mechanism, poseBuilder, "RightLeg", "right_leg", param); + CompoundTag pose = poseBuilder.build(); + if (pose.getValue().isEmpty()) { + entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build(); } else { - compoundTag = compoundTag.createBuilder().put("EntityTag", entPart).build(); + entPart = ((CompoundTag) entPart).createBuilder().put("Pose", pose).build(); + } + } + else { + if (compoundTag == null) { + return; + } + entPart = compoundTag.getValue().get("EntityTag"); + if (!(entPart instanceof CompoundTag)) { + return; } - ItemStack result = NMSHandler.itemHelper.setNbtData(prop.getItemStack(), compoundTag); - prop.setItemStack(result); - }); + posePart = ((CompoundTag) entPart).getValue().get("Pose"); + if (!(posePart instanceof CompoundTag)) { + return; + } + entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build(); + } + if (((CompoundTag) entPart).getValue().isEmpty()) { + compoundTag = compoundTag.createBuilder().remove("EntityTag").build(); + } + else { + compoundTag = compoundTag.createBuilder().put("EntityTag", entPart).build(); + } + ItemStack result = NMSHandler.itemHelper.setNbtData(getItemStack(), compoundTag); + setItemStack(result); + } + + @Override + public String getPropertyId() { + return "armor_pose"; + } + + public static void procPart(CompoundTag pose, String nmsName, String denizenName, MapTag result) { + List list = pose.getList(nmsName); + if (list == null || list.size() != 3) { + return; + } + Tag x = list.get(0), y = list.get(1), z = list.get(2); + if (!(x instanceof FloatTag) || !(y instanceof FloatTag) || !(z instanceof FloatTag)) { + return; + } + String combined = x.getValue() + "," + y.getValue() + "," + z.getValue(); + result.putObject(denizenName, new ElementTag(combined)); + } + + public static void register() { + autoRegister("armor_pose", ItemArmorPose.class, MapTag.class, false); } public static void procMechKey(Mechanism mech, CompoundTagBuilder pose, String nmsName, String denizenName, MapTag input) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemAttributeModifiers.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemAttributeModifiers.java index 7364b67eb9..b721b178e7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemAttributeModifiers.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemAttributeModifiers.java @@ -4,6 +4,7 @@ import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.objects.properties.entity.EntityAttributeModifiers; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; @@ -22,27 +23,30 @@ import java.util.Map; import java.util.UUID; -public class ItemAttributeModifiers extends ItemProperty { +public class ItemAttributeModifiers extends ItemProperty { + + // <--[property] + // @object ItemTag + // @name attribute_modifiers + // @input MapTag + // @description + // Controls the attribute modifiers of an item, with key as the attribute name and value as a list of modifiers, + // where each modifier is a MapTag containing keys 'name', 'amount', 'slot', 'operation', and 'id'. + // For use as a mechanism, this is a SET operation, meaning pre-existing modifiers are removed. + // For format details, refer to <@link language attribute modifiers>. + // --> public static boolean describes(ItemTag item) { return true; } @Override - public String getPropertyString() { - MapTag map = getAttributeModifiers(); - if (map.map.isEmpty()) { - return null; - } - return map.savable(); + public boolean isDefaultValue(MapTag map) { + return map.map.isEmpty(); } @Override - public String getPropertyId() { - return "attribute_modifiers"; - } - - public MapTag getAttributeModifiers() { + public MapTag getPropertyValue() { ItemMeta meta = getItemMeta(); if (meta == null) { return null; @@ -51,6 +55,25 @@ public MapTag getAttributeModifiers() { return getAttributeModifiersFor(metaMap); } + @Override + public void setPropertyValue(MapTag param, Mechanism mechanism) { + Multimap metaMap = LinkedHashMultimap.create(); + for (Map.Entry mapEntry : param.map.entrySet()) { + org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase()); + for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) { + metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue)); + } + } + ItemMeta meta = getItemMeta(); + meta.setAttributeModifiers(metaMap); + setItemMeta(meta); + } + + @Override + public String getPropertyId() { + return "attribute_modifiers"; + } + public static MapTag getAttributeModifiersFor(Multimap metaMap) { MapTag map = new MapTag(); if (metaMap == null) { @@ -71,21 +94,7 @@ public static MapTag getAttributeModifiersFor(Multimap - // @returns MapTag - // @group properties - // @mechanism ItemTag.attribute_modifiers - // @description - // Returns a map of all attribute modifiers on the item, with key as the attribute name and value as a list of modifiers, - // where each modifier is a MapTag containing keys 'name', 'amount', 'slot', 'operation', and 'id'. - // This is formatted in a way that can be sent back into the 'attribute_modifiers' mechanism. - // See also <@link language attribute modifiers>. - // --> - PropertyParser.registerTag(ItemAttributeModifiers.class, MapTag.class, "attribute_modifiers", (attribute, prop) -> { - return prop.getAttributeModifiers(); - }); + autoRegister("attribute_modifiers", ItemAttributeModifiers.class, MapTag.class, false); // <--[tag] // @attribute ]> @@ -108,30 +117,6 @@ public static void register() { return getAttributeModifiersFor(prop.getMaterial().getDefaultAttributeModifiers(slot)); }); - // <--[mechanism] - // @object ItemTag - // @name attribute_modifiers - // @input MapTag - // @description - // Sets the attribute modifiers of an item. - // This is a SET operation, meaning pre-existing modifiers are removed. - // For input format details, refer to <@link language attribute modifiers>. - // @tags - // - // --> - PropertyParser.registerMechanism(ItemAttributeModifiers.class, MapTag.class, "attribute_modifiers", (prop, mechanism, param) -> { - Multimap metaMap = LinkedHashMultimap.create(); - for (Map.Entry mapEntry : param.map.entrySet()) { - org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase()); - for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) { - metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue)); - } - } - ItemMeta meta = prop.getItemMeta(); - meta.setAttributeModifiers(metaMap); - prop.setItemMeta(meta); - }); - // <--[mechanism] // @object ItemTag // @name add_attribute_modifiers diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemBaseColor.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemBaseColor.java index 798b5b19bf..24bce734c7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemBaseColor.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemBaseColor.java @@ -1,9 +1,9 @@ package com.denizenscript.denizen.objects.properties.item; import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.MapTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.tags.TagContext; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -12,21 +12,37 @@ import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.ItemMeta; -public class ItemBaseColor extends ItemProperty { +public class ItemBaseColor extends ItemProperty { + + // <--[property] + // @object ItemTag + // @name base_color + // @input ElementTag + // @description + // Controls the base color of a shield. + // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. + // Give no input with a shield to remove the base color (and any patterns). + // Tag returns null if there is no base color or patterns. + // --> public static boolean describes(ItemTag item) { return item.getBukkitMaterial() == Material.SHIELD; } @Override - public String getPropertyString() { + public ElementTag getPropertyValue() { DyeColor baseColor = getBaseColor(); if (baseColor != null) { - return baseColor.name(); + return new ElementTag(baseColor.name()); } return null; } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + setBaseColor(mechanism.hasValue() ? val.asEnum(DyeColor.class) : null, mechanism.context); + } + @Override public String getPropertyId() { return "base_color"; @@ -70,37 +86,6 @@ public void setBaseColor(DyeColor color, TagContext context) { } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @group properties - // @mechanism ItemTag.base_color - // @description - // Gets the name of the base color of a shield. - // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. - // --> - PropertyParser.registerTag(ItemBaseColor.class, ElementTag.class, "base_color", (attribute, prop) -> { - DyeColor baseColor = prop.getBaseColor(); - if (baseColor == null) { - return null; - } - return new ElementTag(baseColor); - }); - - // <--[mechanism] - // @object ItemTag - // @name base_color - // @input ElementTag - // @description - // Changes the base color of a shield. - // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. - // Give no input with a shield to remove the base color (and any patterns). - // @tags - // - // --> - PropertyParser.registerMechanism(ItemBaseColor.class, ElementTag.class, "base_color", (prop, mechanism, param) -> { - prop.setBaseColor(mechanism.hasValue() ? DyeColor.valueOf(param.asString().toUpperCase()) : null, mechanism.context); - }); + autoRegister("base_color", ItemBaseColor.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemInstrument.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemInstrument.java index c7f2b3216b..75a6999ae0 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemInstrument.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemInstrument.java @@ -2,13 +2,29 @@ import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.utilities.Utilities; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.Material; import org.bukkit.MusicInstrument; import org.bukkit.inventory.meta.MusicInstrumentMeta; -public class ItemInstrument extends ItemProperty { +public class ItemInstrument extends ItemProperty { + + // <--[property] + // @object ItemTag + // @name instrument + // @input ElementTag + // @description + // Sets the instrument of a goat horn. + // For a list of possible instruments, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MusicInstrument.html>. + // @example + // # This can narrate: "This horn has the ponder_goat_horn instrument!" + // - narrate "This horn has the instrument!" + // @example + // # Forces the player's held item to play seek_goat_horn instead of whatever it played before. + // # Would break if the player isn't holding a goat horn. + // - inventory adjust slot:hand instrument:seek_goat_horn + // --> public static boolean describes(ItemTag item) { return item.getBukkitMaterial() == Material.GOAT_HORN; @@ -23,6 +39,16 @@ public ElementTag getPropertyValue() { return null; } + @Override + public void setPropertyValue(ElementTag param, Mechanism mechanism) { + MusicInstrument instrument = MusicInstrument.getByKey(Utilities.parseNamespacedKey(param.asString())); + if (instrument == null) { + mechanism.echoError("Invalid horn instrument: '" + param.asString() + "'! Instrument names should be like this: 'seek_goat_horn'."); + return; + } + setMusicInstrument(MusicInstrument.getByKey(Utilities.parseNamespacedKey(param.asString()))); + } + @Override public String getPropertyId() { return "instrument"; @@ -40,46 +66,6 @@ public void setMusicInstrument(MusicInstrument instrument) { } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @group properties - // @mechanism ItemTag.instrument - // @description - // Returns the instrument of a goat horn. - // For a list of possible instruments, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MusicInstrument.html>. - // @example - // # This can narrate: "This horn has the ponder_goat_horn instrument!" - // - narrate "This horn has the instrument!" - // --> - PropertyParser.registerTag(ItemInstrument.class, ElementTag.class, "instrument", (attribute, prop) -> { - MusicInstrument musicInstrument = prop.getMusicInstrument(); - if (musicInstrument == null) { - return null; - } - return new ElementTag(Utilities.namespacedKeyToString(musicInstrument.getKey())); - }); - - // <--[mechanism] - // @object ItemTag - // @name instrument - // @input ElementTag - // @description - // Sets the instrument of a goat horn. - // For a list of possible instruments, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/MusicInstrument.html>. - // @tags - // - // @example - // - inventory adjust slot:hand instrument:seek_goat_horn - // --> - PropertyParser.registerMechanism(ItemInstrument.class, ElementTag.class, "instrument", (prop, mechanism, param) -> { - MusicInstrument instrument = MusicInstrument.getByKey(Utilities.parseNamespacedKey(param.asString())); - if (instrument == null) { - mechanism.echoError("Invalid horn instrument: '" + param.asString() + "'! Instrument names should be like this: 'seek_goat_horn'."); - return; - } - prop.setMusicInstrument(MusicInstrument.getByKey(Utilities.parseNamespacedKey(param.asString()))); - }); + autoRegister("instrument", ItemInstrument.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemProperty.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemProperty.java index 0e8dee1a9c..3c3b248d94 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemProperty.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemProperty.java @@ -2,12 +2,13 @@ import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -public abstract class ItemProperty extends ObjectProperty { +public abstract class ItemProperty extends ObjectProperty { public MaterialTag getMaterialTag() { return object.getMaterial(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java index 77bb4db7d5..f4e4891c99 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAge.java @@ -2,6 +2,7 @@ import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.exceptions.Unreachable; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.block.data.Ageable; @@ -9,7 +10,16 @@ import org.bukkit.block.data.type.Sapling; import org.bukkit.block.data.type.TurtleEgg; -public class MaterialAge extends MaterialProperty { +public class MaterialAge extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name age + // @input ElementTag(Number) + // @description + // Controls an ageable material's current age. This includes plant growth. + // See also <@link tag MaterialTag.maximum_age>. + // --> public static boolean describes(MaterialTag material) { BlockData data = material.getModernData(); @@ -25,6 +35,28 @@ public ElementTag getPropertyValue() { return new ElementTag(getCurrent()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (!mechanism.requireInteger()) { + return; + } + int age = val.asInt(); + if (age < 0 || age > getMax()) { + mechanism.echoError("Age value '" + age + "' is not valid. Must be between 0 and " + getMax() + " for material '" + object.name() + "'."); + return; + } + BlockData data = getBlockData(); + if (data instanceof TurtleEgg turtle) { + turtle.setHatch(age); + } + else if (data instanceof Sapling sapling) { + sapling.setStage(age); + } + else if (data instanceof Ageable ageable) { + ageable.setAge(age); + } + } + @Override public String getPropertyId() { return "age"; @@ -43,48 +75,7 @@ public static void register() { return new ElementTag(prop.getMax()); }, "maximum_plant_growth"); - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism MaterialTag.age - // @group properties - // @description - // Returns the current age for an ageable material. This includes plant growth. - // --> - PropertyParser.registerStaticTag(MaterialAge.class, ElementTag.class, "age", (attribute, prop) -> { - return new ElementTag(prop.getCurrent()); - }, "plant_growth"); - - // <--[mechanism] - // @object MaterialTag - // @name age - // @input ElementTag(Number) - // @description - // Sets an ageable material's current age. This includes plant growth. - // @tags - // - // - // --> - PropertyParser.registerMechanism(MaterialAge.class, ElementTag.class, "age", (prop, mechanism, param) -> { - if (!mechanism.requireInteger()) { - return; - } - int age = param.asInt(); - if (age < 0 || age > prop.getMax()) { - mechanism.echoError("Age value '" + age + "' is not valid. Must be between 0 and " + prop.getMax() + " for material '" + prop.object.name() + "'."); - return; - } - BlockData data = prop.getBlockData(); - if (data instanceof TurtleEgg turtle) { - turtle.setHatch(age); - } - else if (data instanceof Sapling sapling) { - sapling.setStage(age); - } - else if (data instanceof Ageable ageable) { - ageable.setAge(age); - } - }, "plant_growth"); + autoRegister("age", MaterialAge.class, ElementTag.class, true, "plant_growth"); } public int getCurrent() { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java index 33d42d9ce9..29d22ed9dc 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialAttached.java @@ -4,15 +4,30 @@ import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.exceptions.Unreachable; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.block.data.Attachable; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Hangable; import org.bukkit.block.data.type.Gate; import org.bukkit.block.data.type.Lantern; -public class MaterialAttached extends MaterialProperty { +public class MaterialAttached extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name attached + // @input ElementTag(Boolean) + // @description + // Controls whether a material is attached. + // For a lantern, this sets whether it is hanging from the ceiling. + // For a gate, this sets whether it is lowered to attach to a wall block. + // For a mangrove_propagule, this sets whether it is hanging from the block above it. + // For a tripwire, this sets whether a tripwire hook or string forms a complete tripwire circuit and is ready to trigger. + // Updating the property on a tripwire hook will change the texture to indicate a connected string, but will not have any effect when used on the tripwire string itself. + // It may however still be used to check whether the string forms a circuit. + // For hanging signs, this affects signs hanging below a block and changes whether the chains are vertical (false) or diagonal (true). + // --> public static boolean describes(MaterialTag material) { BlockData data = material.getModernData(); @@ -25,65 +40,34 @@ public ElementTag getPropertyValue() { return new ElementTag(isAttached()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (!mechanism.requireBoolean()) { + return; + } + boolean attach = val.asBoolean(); + BlockData data = getBlockData(); + if (data instanceof Gate gate) { + gate.setInWall(attach); + } + else if (data instanceof Lantern lantern) { // TODO: remove once 1.19 is the minimum - Lantern extends Hangable + lantern.setHanging(attach); + } + else if (data instanceof Attachable attachable) { + attachable.setAttached(attach); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof Hangable hangable) { + hangable.setHanging(attach); + } + } + @Override public String getPropertyId() { return "attached"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism MaterialTag.attached - // @group properties - // @description - // Returns whether a material is attached. - // For a lantern, this returns whether it is hanging from the ceiling. - // For a gate, this returns whether it is lowered to attach to a wall block. - // For a mangrove_propagule, this returns whether it is hanging from the block above it. - // For a tripwire, this returns whether a tripwire hook or string forms a complete tripwire circuit and is ready to trigger. - // For a hanging sign, this returns whether it is hanging from the block above it. - // --> - PropertyParser.registerStaticTag(MaterialAttached.class, ElementTag.class, "attached", (attribute, prop) -> { - return new ElementTag(prop.isAttached()); - }, "attached_to_wall"); - - // <--[mechanism] - // @object MaterialTag - // @name attached - // @input ElementTag(Boolean) - // @description - // Sets whether a material is attached. - // For a lantern, this sets whether it is hanging from the ceiling. - // For a gate, this sets whether it is lowered to attach to a wall block. - // For a mangrove_propagule, this sets whether it is hanging from the block above it. - // For a tripwire, this sets whether a tripwire hook or string forms a complete tripwire circuit and is ready to trigger. - // Updating the property on a tripwire hook will change the texture to indicate a connected string, but will not have any effect when used on the tripwire string itself. - // It may however still be used to check whether the string forms a circuit. - // For hanging signs, this affects signs hanging below a block and changes whether the chains are vertical (false) or diagonal (true). - // @tags - // - // --> - PropertyParser.registerMechanism(MaterialAttached.class, ElementTag.class, "attached", (prop, mechanism, param) -> { - if (!mechanism.requireBoolean()) { - return; - } - boolean attach = param.asBoolean(); - BlockData data = prop.getBlockData(); - if (data instanceof Gate gate) { - gate.setInWall(attach); - } - else if (data instanceof Lantern lantern) { // TODO: remove once 1.19 is the minimum - Lantern extends Hangable - lantern.setHanging(attach); - } - else if (data instanceof Attachable attachable) { - attachable.setAttached(attach); - } - else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && data instanceof Hangable hangable) { - hangable.setHanging(attach); - } - }, "attached_to_wall"); + autoRegister("attached", MaterialAttached.class, ElementTag.class, true, "attached_to_wall"); } public boolean isAttached() { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBlockType.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBlockType.java index cc4ee68d4b..f49ef71bfc 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBlockType.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialBlockType.java @@ -2,13 +2,27 @@ import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.exceptions.Unreachable; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.*; -public class MaterialBlockType extends MaterialProperty { +public class MaterialBlockType extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name type + // @input ElementTag + // @description + // Controls the current type of the block. + // For slabs, input is TOP, BOTTOM, or DOUBLE. + // For piston_heads, input is NORMAL or STICKY. + // For campfires, input is NORMAL or SIGNAL. + // For pointed dripstone, input is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE. + // For cave vines, input is NORMAL or BERRIES. + // For scaffolding, input is NORMAL or BOTTOM. + // --> public static boolean describes(MaterialTag material) { BlockData data = material.getModernData(); @@ -21,67 +35,36 @@ public ElementTag getPropertyValue() { return new ElementTag(getType()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + BlockData data = getBlockData(); + if (data instanceof Slab slab && mechanism.requireEnum(Slab.Type.class)) { + slab.setType(val.asEnum(Slab.Type.class)); + } + else if (data instanceof TechnicalPiston piston && mechanism.requireEnum(TechnicalPiston.Type.class)) { + piston.setType(val.asEnum(TechnicalPiston.Type.class)); + } + else if (data instanceof Campfire campfire) { + campfire.setSignalFire(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "signal")); + } + else if (data instanceof PointedDripstone dripstone && mechanism.requireEnum(PointedDripstone.Thickness.class)) { + dripstone.setThickness(val.asEnum(PointedDripstone.Thickness.class)); + } + else if (data instanceof CaveVinesPlant vines) { + vines.setBerries(CoreUtilities.equalsIgnoreCase(val.asString(), "berries")); + } + else if (data instanceof Scaffolding scaffolding) { + scaffolding.setBottom(CoreUtilities.equalsIgnoreCase(val.asString(), "bottom")); + } + } + @Override public String getPropertyId() { return "type"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @mechanism MaterialTag.type - // @group properties - // @description - // Returns the current type of the block. - // For slabs, output is TOP, BOTTOM, or DOUBLE. - // For piston_heads, output is NORMAL or STICKY. - // For campfires, output is NORMAL or SIGNAL. - // For pointed dripstone, output is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE. - // For cave vines, output is NORMAL or BERRIES. - // For scaffolding, output is NORMAL or BOTTOM. - // --> - PropertyParser.registerStaticTag(MaterialBlockType.class, ElementTag.class, "type", (attribute, prop) -> { - return new ElementTag(prop.getPropertyString()); - }, "slab_type"); - - // <--[mechanism] - // @object MaterialTag - // @name type - // @input ElementTag - // @description - // Sets the current type of the block. - // For slabs, input is TOP, BOTTOM, or DOUBLE. - // For piston_heads, input is NORMAL or STICKY. - // For campfires, input is NORMAL or SIGNAL. - // For pointed dripstone, input is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE. - // For cave vines, input is NORMAL or BERRIES. - // For scaffolding, input is NORMAL or BOTTOM. - // @tags - // - // --> - PropertyParser.registerMechanism(MaterialBlockType.class, ElementTag.class, "type", (prop, mechanism, param) -> { - BlockData data = prop.getBlockData(); - if (data instanceof Slab slab && mechanism.requireEnum(Slab.Type.class)) { - slab.setType(mechanism.value.asElement().asEnum(Slab.Type.class)); - } - else if (data instanceof TechnicalPiston piston && mechanism.requireEnum(TechnicalPiston.Type.class)) { - piston.setType(mechanism.value.asElement().asEnum(TechnicalPiston.Type.class)); - } - else if (data instanceof Campfire campfire) { - campfire.setSignalFire(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "signal")); - } - else if (data instanceof PointedDripstone dripstone && mechanism.requireEnum(PointedDripstone.Thickness.class)) { - dripstone.setThickness(mechanism.value.asElement().asEnum(PointedDripstone.Thickness.class)); - } - else if (data instanceof CaveVinesPlant vines) { - vines.setBerries(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "berries")); - } - else if (data instanceof Scaffolding scaffolding) { - scaffolding.setBottom(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "bottom")); - } - }); + autoRegister("type", MaterialBlockType.class, ElementTag.class, true, "slab_type"); } public String getType() { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialProperty.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialProperty.java index d3aca85086..4cbb516800 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialProperty.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialProperty.java @@ -1,10 +1,11 @@ package com.denizenscript.denizen.objects.properties.material; import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; import org.bukkit.block.data.BlockData; -public abstract class MaterialProperty extends ObjectProperty { +public abstract class MaterialProperty extends ObjectProperty { public MaterialProperty() { } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeDemand.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeDemand.java index 4b42e5f914..be0e54da96 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeDemand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeDemand.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeDemand extends TradeProperty { +public class TradeDemand extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name demand + // @input ElementTag(Number) + // @description + // Sets the demand level of the trade. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,36 +23,18 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getDemand()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getRecipe().setDemand(mechanism.getValue().asInt()); + } + } + public String getPropertyId() { return "demand"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism TradeTag.demand - // @description - // Returns the demand level of the trade. - // --> - PropertyParser.registerTag(TradeDemand.class, ElementTag.class, "demand", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getDemand()); - }); - - // <--[mechanism] - // @object TradeTag - // @name demand - // @input ElementTag(Number) - // @description - // Sets the demand level of the trade. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeDemand.class, ElementTag.class, "demand", (prop, mechanism, param) -> { - if (mechanism.requireInteger()) { - prop.getRecipe().setDemand(mechanism.getValue().asInt()); - } - }); + autoRegister("demand", TradeDemand.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeHasXp.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeHasXp.java index f59482bcfe..16849c1bf0 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeHasXp.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeHasXp.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeHasXp extends TradeProperty { +public class TradeHasXp extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name has_xp + // @input ElementTag(Boolean) + // @description + // Sets whether this trade will reward XP upon successful trading. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().hasExperienceReward()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + getRecipe().setExperienceReward(mechanism.getValue().asBoolean()); + } + } + @Override public String getPropertyId() { return "has_xp"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @mechanism TradeTag.has_xp - // @description - // Returns whether the trade has an experience reward. - // --> - PropertyParser.registerTag(TradeHasXp.class, ElementTag.class, "has_xp", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().hasExperienceReward()); - }); - - // <--[mechanism] - // @object TradeTag - // @name has_xp - // @input ElementTag(Boolean) - // @description - // Sets whether this trade will reward XP upon successful trading. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeHasXp.class, ElementTag.class, "has_xp", (prop, mechanism, param) -> { - if (mechanism.requireBoolean()) { - prop.getRecipe().setExperienceReward(mechanism.getValue().asBoolean()); - } - }); + autoRegister("has_xp", TradeHasXp.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeInputs.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeInputs.java index d15061ccbf..64b5cbde52 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeInputs.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeInputs.java @@ -2,14 +2,23 @@ import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ListTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; -public class TradeInputs extends TradeProperty { +public class TradeInputs extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name inputs + // @input ListTag(ItemTag) + // @description + // Controls the items required to make a successful trade. Use an empty input to make the trade impossible. + // NOTE: If more than two items are specified, then only the first two items will be used. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -20,6 +29,24 @@ public ListTag getPropertyValue() { return getIngredientsList(); } + @Override + public void setPropertyValue(ListTag inList, Mechanism mechanism) { + List ingredients = new ArrayList<>(); + List list = inList.filter(ItemTag.class, mechanism.context); + if (!mechanism.hasValue() || list.isEmpty()) { + getRecipe().setIngredients(ingredients); + return; + } + for (ItemTag item : list) { + ingredients.add(item.getItemStack()); + } + if (ingredients.size() > 2) { + mechanism.echoError("Trade recipe input was given " + list.size() + " items. Only using the first two items!"); + ingredients = ingredients.subList(0, 2); + } + getRecipe().setIngredients(ingredients); + } + @Override public String getPropertyId() { return "inputs"; @@ -34,43 +61,6 @@ public ListTag getIngredientsList() { } public static void register() { - - // <--[tag] - // @attribute - // @returns ListTag(ItemTag) - // @mechanism TradeTag.inputs - // @description - // Returns the list of items required to make the trade. - // --> - PropertyParser.registerTag(TradeInputs.class, ListTag.class, "inputs", (attribute, prop) -> { - return prop.getIngredientsList(); - }); - - // <--[mechanism] - // @object TradeTag - // @name inputs - // @input ListTag(ItemTag) - // @description - // Sets the items required to make a successful trade. Use an empty input to make the trade impossible. - // NOTE: If more than two items are specified, then only the first two items will be used. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeInputs.class, ListTag.class, "inputs", (prop, mechanism, inList) -> { - List ingredients = new ArrayList<>(); - List list = inList.filter(ItemTag.class, mechanism.context); - if (!mechanism.hasValue() || list.isEmpty()) { - prop.getRecipe().setIngredients(ingredients); - return; - } - for (ItemTag item : list) { - ingredients.add(item.getItemStack()); - } - if (ingredients.size() > 2) { - mechanism.echoError("Trade recipe input was given " + list.size() + " items. Only using the first two items!"); - ingredients = ingredients.subList(0, 2); - } - prop.getRecipe().setIngredients(ingredients); - }); + autoRegister("inputs", TradeInputs.class, ListTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeMaxUses.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeMaxUses.java index 5f2190de72..ee63c45fb6 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeMaxUses.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeMaxUses.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeMaxUses extends TradeProperty { +public class TradeMaxUses extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name max_uses + // @input ElementTag(Number) + // @description + // Sets the maximum amount of times that the trade can be used. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getMaxUses()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getRecipe().setMaxUses(mechanism.getValue().asInt()); + } + } + @Override public String getPropertyId() { return "max_uses"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism TradeTag.max_uses - // @description - // Returns the maximum amount of times that the trade can be used. - // --> - PropertyParser.registerTag(TradeMaxUses.class, ElementTag.class, "max_uses", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getMaxUses()); - }); - - // <--[mechanism] - // @object TradeTag - // @name max_uses - // @input ElementTag(Number) - // @description - // Sets the maximum amount of times that the trade can be used. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeMaxUses.class, ElementTag.class, "max_uses", (prop, mechanism, param) -> { - if (mechanism.requireInteger()) { - prop.getRecipe().setMaxUses(mechanism.getValue().asInt()); - } - }); + autoRegister("max_uses", TradeMaxUses.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradePriceMultiplier.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradePriceMultiplier.java index f6c029a903..a0059b3fbe 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradePriceMultiplier.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradePriceMultiplier.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradePriceMultiplier extends TradeProperty { +public class TradePriceMultiplier extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name price_multiplier + // @input ElementTag(Decimal) + // @description + // Controls the price multiplier for this trade. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getPriceMultiplier()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireFloat()) { + getRecipe().setPriceMultiplier(mechanism.getValue().asFloat()); + } + } + @Override public String getPropertyId() { return "price_multiplier"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Decimal) - // @mechanism TradeTag.price_multiplier - // @description - // Returns the price multiplier for this trade. - // --> - PropertyParser.registerTag(TradePriceMultiplier.class, ElementTag.class, "price_multiplier", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getPriceMultiplier()); - }); - - // <--[mechanism] - // @object TradeTag - // @name price_multiplier - // @input ElementTag(Decimal) - // @description - // Sets the price multiplier for this trade. - // @tags - // - // --> - PropertyParser.registerMechanism(TradePriceMultiplier.class, ElementTag.class, "price_multiplier", (prop, mechanism, param) -> { - if (mechanism.requireFloat()) { - prop.getRecipe().setPriceMultiplier(mechanism.getValue().asFloat()); - } - }); + autoRegister("price_multiplier", TradePriceMultiplier.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeProperty.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeProperty.java index 3580abcdef..3c3642ac0f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeProperty.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeProperty.java @@ -1,10 +1,11 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.properties.ObjectProperty; import org.bukkit.inventory.MerchantRecipe; -public abstract class TradeProperty extends ObjectProperty { +public abstract class TradeProperty extends ObjectProperty { public MerchantRecipe getRecipe() { return object.getRecipe(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeResult.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeResult.java index eab3706f91..b30ec99ff8 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeResult.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeResult.java @@ -2,9 +2,17 @@ import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizen.objects.TradeTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; +import com.denizenscript.denizencore.objects.Mechanism; -public class TradeResult extends TradeProperty { +public class TradeResult extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name result + // @input ItemTag + // @description + // Controls what the trade will give the player. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,35 +23,17 @@ public ItemTag getPropertyValue() { return new ItemTag(getRecipe().getResult()); } + @Override + public void setPropertyValue(ItemTag item, Mechanism mechanism) { + object.setRecipe(TradeTag.duplicateRecipe(item.getItemStack(), getRecipe())); + } + @Override public String getPropertyId() { return "result"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ItemTag - // @mechanism TradeTag.result - // @description - // Returns what the trade will give the player. - // --> - PropertyParser.registerTag(TradeResult.class, ItemTag.class, "result", (attribute, prop) -> { - return new ItemTag(prop.getRecipe().getResult()); - }); - - // <--[mechanism] - // @object TradeTag - // @name result - // @input ItemTag - // @description - // Sets what the trade will give the player. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeResult.class, ItemTag.class, "result", (prop, mechanism, item) -> { - prop.object.setRecipe(TradeTag.duplicateRecipe(item.getItemStack(), prop.getRecipe())); - }); + autoRegister("result", TradeResult.class, ItemTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeSpecialPrice.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeSpecialPrice.java index b4f7658d3d..c0f6b91b2f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeSpecialPrice.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeSpecialPrice.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeSpecialPrice extends TradeProperty { +public class TradeSpecialPrice extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name special_price + // @input ElementTag(Number) + // @description + // Sets the special price for this trade. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getSpecialPrice()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getRecipe().setSpecialPrice(mechanism.getValue().asInt()); + } + } + @Override public String getPropertyId() { return "special_price"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism TradeTag.special_price - // @description - // Returns the special price for this trade. - // --> - PropertyParser.registerTag(TradeSpecialPrice.class, ElementTag.class, "special_price", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getSpecialPrice()); - }); - - // <--[mechanism] - // @object TradeTag - // @name special_price - // @input ElementTag(Number) - // @description - // Sets the special price for this trade. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeSpecialPrice.class, ElementTag.class, "special_price", (prop, mechanism, param) -> { - if (mechanism.requireInteger()) { - prop.getRecipe().setSpecialPrice(mechanism.getValue().asInt()); - } - }); + autoRegister("special_price", TradeSpecialPrice.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeUses.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeUses.java index 18f29050fd..b748650b31 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeUses.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeUses.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeUses extends TradeProperty { +public class TradeUses extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name uses + // @input ElementTag(Number) + // @description + // Controls the amount of times the trade has been used. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getUses()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getRecipe().setUses(mechanism.getValue().asInt()); + } + } + @Override public String getPropertyId() { return "uses"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism TradeTag.uses - // @description - // Returns how many times the trade has been used. - // --> - PropertyParser.registerTag(TradeUses.class, ElementTag.class, "uses", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getUses()); - }); - - // <--[mechanism] - // @object TradeTag - // @name uses - // @input ElementTag(Number) - // @description - // Sets the amount of times the trade has been used. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeUses.class, ElementTag.class, "uses", (prop, mechanism, param) -> { - if (mechanism.requireInteger()) { - prop.getRecipe().setUses(mechanism.getValue().asInt()); - } - }); + autoRegister("uses", TradeUses.class, ElementTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeVillagerXP.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeVillagerXP.java index 2c4aabfb3f..c08f8a1903 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeVillagerXP.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeVillagerXP.java @@ -1,10 +1,18 @@ package com.denizenscript.denizen.objects.properties.trade; import com.denizenscript.denizen.objects.TradeTag; +import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.PropertyParser; -public class TradeVillagerXP extends TradeProperty { +public class TradeVillagerXP extends TradeProperty { + + // <--[property] + // @object TradeTag + // @name villager_xp + // @input ElementTag(Number) + // @description + // Controls the amount of experience a villager gains from this trade. + // --> public static boolean describes(TradeTag recipe) { return true; @@ -15,37 +23,19 @@ public ElementTag getPropertyValue() { return new ElementTag(getRecipe().getVillagerExperience()); } + @Override + public void setPropertyValue(ElementTag val, Mechanism mechanism) { + if (mechanism.requireInteger()) { + getRecipe().setVillagerExperience(mechanism.getValue().asInt()); + } + } + @Override public String getPropertyId() { return "villager_xp"; } public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag(Number) - // @mechanism TradeTag.villager_xp - // @description - // Returns the amount of experience a villager gains from this trade. - // --> - PropertyParser.registerTag(TradeVillagerXP.class, ElementTag.class, "villager_xp", (attribute, prop) -> { - return new ElementTag(prop.getRecipe().getVillagerExperience()); - }); - - // <--[mechanism] - // @object TradeTag - // @name villager_xp - // @input ElementTag(Number) - // @description - // Sets the amount of experience a villager gains from this trade. - // @tags - // - // --> - PropertyParser.registerMechanism(TradeVillagerXP.class, ElementTag.class, "villager_xp", (prop, mechanism, param) -> { - if (mechanism.requireInteger()) { - prop.getRecipe().setVillagerExperience(mechanism.getValue().asInt()); - } - }); + autoRegister("villager_xp", TradeVillagerXP.class, ElementTag.class, false); } }