-
-
Notifications
You must be signed in to change notification settings - Fork 114
Adds item_model, max_durability, max_stack_size, and rarity item components.
#2734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
0e03c46
3b843b5
7041ca6
af3e6b8
20a1c76
da0349d
aeba5f6
90ccdd2
83cf3cb
4ebc675
2e0b4fe
ce49c3a
4323e7d
eb4b36a
fe6a2aa
555b249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,26 @@ | ||
| package com.denizenscript.denizen.paper.properties; | ||
|
|
||
| import com.denizenscript.denizen.nms.NMSHandler; | ||
| import com.denizenscript.denizen.nms.NMSVersion; | ||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
|
|
||
| public class PaperItemExtensions { | ||
|
|
||
| public static void register() { | ||
|
|
||
| // <--[tag] | ||
| // @attribute <ItemTag.rarity> | ||
| // @returns ElementTag | ||
| // @group paper | ||
| // @Plugin Paper | ||
| // @description | ||
| // Returns the rarity of an item, as "common", "uncommon", "rare", or "epic". | ||
| // --> | ||
| ItemTag.tagProcessor.registerTag(ElementTag.class, "rarity", (attribute, item) -> { | ||
| return new ElementTag(item.getItemStack().getRarity()); | ||
| }); | ||
| if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_19)) { | ||
| // <--[tag] | ||
| // @attribute <ItemTag.rarity> | ||
| // @returns ElementTag | ||
| // @group paper | ||
| // @Plugin Paper | ||
| // @description | ||
| // Returns the rarity of an item, as "common", "uncommon", "rare", or "epic". | ||
| // --> | ||
| ItemTag.tagProcessor.registerTag(ElementTag.class, "rarity", (attribute, item) -> { | ||
| return new ElementTag(item.getItemStack().getRarity()); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ public static ItemDurability getFrom(ObjectTag _item) { | |
| } | ||
|
|
||
| public static final String[] handledTags = new String[] { | ||
| "durability", "max_durability" | ||
| "durability" | ||
| }; | ||
|
|
||
| public static final String[] handledMechs = new String[] { | ||
|
|
@@ -58,19 +58,6 @@ public ObjectTag getObjectAttribute(Attribute attribute) { | |
| .getObjectAttribute(attribute.fulfill(1)); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <ItemTag.max_durability> | ||
| // @returns ElementTag(Number) | ||
| // @group properties | ||
| // @description | ||
| // Returns the maximum durability (number of uses) of this item. | ||
| // For use with <@link tag ItemTag.durability> and <@link mechanism ItemTag.durability>. | ||
| // --> | ||
| if (attribute.startsWith("max_durability")) { | ||
| return new ElementTag(item.getMaterial().getMaterial().getMaxDurability()) | ||
| .getObjectAttribute(attribute.fulfill(1)); | ||
| } | ||
|
Comment on lines
69
to
72
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this properly backsupported? from what I can see it's completely removed from here and the new property is 1.20+ |
||
|
|
||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -101,7 +88,6 @@ public void adjust(Mechanism mechanism) { | |
| // Changes the durability of damageable items. | ||
| // @tags | ||
| // <ItemTag.durability> | ||
| // <ItemTag.max_durability> | ||
| // <ItemTag.repairable> | ||
| // --> | ||
| if (mechanism.matches("durability") && mechanism.requireInteger()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 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 org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
| import org.bukkit.inventory.meta.components.FoodComponent; | ||
|
|
||
| public class ItemFood extends ItemProperty<MapTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name food | ||
| // @input MapTag | ||
| // @description | ||
| // Controls the food properties of the item. | ||
| // A food item has the 'nutrition', 'saturation', and 'can_always_eat' properties. | ||
| // The 'nutrition' is the amount of hunger points the food restores. | ||
| // The 'saturation' is the amount of saturation points the food restores. | ||
| // The 'can_always_eat' is a boolean indicating if the food can be eaten even when the player is not hungry. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public MapTag getPropertyValue() { | ||
| if (getItemMeta().hasFood()) { | ||
| FoodComponent food = getItemMeta().getFood(); | ||
| MapTag map = new MapTag(); | ||
| map.putObject("nutrition", new ElementTag(food.getNutrition())); | ||
| map.putObject("saturation", new ElementTag(food.getSaturation())); | ||
| map.putObject("can_always_eat", new ElementTag(food.canAlwaysEat())); | ||
| return map; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(MapTag element, Mechanism mechanism) { | ||
|
||
| FoodComponent food = getItemMeta().getFood(); | ||
|
||
| editMeta(ItemMeta.class, meta -> { | ||
| if (element.getElement("nutrition") != null) { | ||
| food.setNutrition(element.getElement("nutrition").asInt()); | ||
| } | ||
| if (element.getElement("saturation") != null) { | ||
| food.setSaturation(element.getElement("saturation").asFloat()); | ||
| } | ||
| if (element.getElement("can_always_eat") != null) { | ||
| food.setCanAlwaysEat(element.getElement("can_always_eat").asBoolean()); | ||
| } | ||
| meta.setFood(food); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "food"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("food", ItemFood.class, MapTag.class, false); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 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 org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.Damageable; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemMaxDurability extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name max_durability | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum durability of an item. | ||
|
||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR | ||
| && item.getItemMeta() instanceof Damageable; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta() instanceof Damageable damageable | ||
| && damageable.hasMaxDamage()) { | ||
|
||
| damageable.getMaxDamage(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
|
||
| if (meta instanceof Damageable damageable) { | ||
| damageable.setMaxDamage(element.asInt()); | ||
|
||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "max_durability"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("max_durability", ItemMaxDurability.class, ElementTag.class, false); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 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 org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemMaxStackSize extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name max_stack_size | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum stack size of the item. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta().hasMaxStackSize()) { | ||
| return new ElementTag(getItemMeta().getMaxStackSize()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> meta.setMaxStackSize(element.asInt())); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "max_stack_size"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("max_stack_size", ItemMaxDurability.class, ElementTag.class, false); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| 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 org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemModel extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name item_model | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the item model of the item in namespaced key format. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta().hasItemModel()) { | ||
| return new ElementTag(Utilities.namespacedKeyToString(getItemMeta().getItemModel())); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> meta.setItemModel(Utilities.parseNamespacedKey(element.toString()))); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "item_model"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("item_model", ItemModel.class, ElementTag.class, false); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.denizenscript.denizen.objects.properties.item; | ||
|
|
||
| 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 org.bukkit.Material; | ||
| import org.bukkit.inventory.meta.ItemMeta; | ||
|
|
||
| public class ItemRarity extends ItemProperty<ElementTag> { | ||
|
|
||
| // <--[property] | ||
| // @object ItemTag | ||
| // @name rarity | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the rarity of the item. | ||
| // Valid rarities are: 'COMMON', 'UNCOMMON', 'RARE', and 'EPIC'. | ||
| // --> | ||
|
|
||
| public static boolean describes(ItemTag item) { | ||
| return item.getBukkitMaterial() != Material.AIR; | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta().hasRarity()) { | ||
| return Utilities.enumlikeToElement(getItemMeta().getRarity()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| if (mechanism.requireEnum(org.bukkit.inventory.ItemRarity.class)) { | ||
| editMeta(ItemMeta.class, meta -> meta.setRarity(element.asEnum(org.bukkit.inventory.ItemRarity.class))); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "rarity"; | ||
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("rarity", ItemRarity.class, ElementTag.class, false); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta is double-registered, should just be excluded from a legacy copy