From 5b137ff87b1f7560722e0a462bb36fa67d79e2f5 Mon Sep 17 00:00:00 2001 From: PseudoKnight Date: Sat, 15 Jun 2024 16:39:48 -0700 Subject: [PATCH] Add support for Minecraft 1.21 Attribute modifiers' optional "name" and "uuid" keys have been replaced with a namespaced key under "id". Old attribute modifiers will use the UUID to generate a namespaced key. --- pom.xml | 2 +- .../laytonsmith/abstraction/Convertor.java | 4 ++ .../abstraction/MCAttributeModifier.java | 1 + .../abstraction/blocks/MCMaterial.java | 7 ++- .../abstraction/bukkit/BukkitConvertor.java | 18 ++++++ .../bukkit/BukkitMCAttributeModifier.java | 6 ++ .../laytonsmith/abstraction/enums/MCArt.java | 41 +++++++++++-- .../abstraction/enums/MCAttribute.java | 11 +++- .../abstraction/enums/MCDamageCause.java | 4 ++ .../abstraction/enums/MCPatternShape.java | 2 + .../abstraction/enums/MCSound.java | 10 +++- .../abstraction/enums/MCSpawnReason.java | 1 + .../abstraction/enums/MCTreeType.java | 1 + .../abstraction/enums/MCVersion.java | 2 + .../events/MCLightningStrikeEvent.java | 1 + .../com/laytonsmith/core/ObjectGenerator.java | 57 ++++++++++++------- .../core/functions/MobManagement.java | 54 ++++++++++++------ .../com/laytonsmith/tools/Interpreter.java | 12 +++- src/main/resources/docs/Compatibility | 7 ++- src/main/resources/docs/Upgrade_Guide | 15 +++-- src/main/resources/functionDocs/entity_spec | 2 +- src/main/resources/functionDocs/get_itemmeta | 2 +- .../com/laytonsmith/testing/StaticTest.java | 10 ++++ 23 files changed, 216 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index ea37863258..31bf370e43 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ org.spigotmc spigot-api - 1.20.6-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT io.papermc.paper diff --git a/src/main/java/com/laytonsmith/abstraction/Convertor.java b/src/main/java/com/laytonsmith/abstraction/Convertor.java index 7200b0bcce..ef0b2a3ec4 100644 --- a/src/main/java/com/laytonsmith/abstraction/Convertor.java +++ b/src/main/java/com/laytonsmith/abstraction/Convertor.java @@ -45,6 +45,10 @@ public interface Convertor { MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, String name, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot); + MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot); + + MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot); + void Startup(CommandHelperPlugin chp); MCMaterial[] GetMaterialValues(); diff --git a/src/main/java/com/laytonsmith/abstraction/MCAttributeModifier.java b/src/main/java/com/laytonsmith/abstraction/MCAttributeModifier.java index 17d05b5c9a..35f6d78c73 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCAttributeModifier.java +++ b/src/main/java/com/laytonsmith/abstraction/MCAttributeModifier.java @@ -8,6 +8,7 @@ import java.util.UUID; public interface MCAttributeModifier extends AbstractionObject { + MCNamespacedKey getKey(); String getAttributeName(); MCAttribute getAttribute(); MCEquipmentSlot getEquipmentSlot(); diff --git a/src/main/java/com/laytonsmith/abstraction/blocks/MCMaterial.java b/src/main/java/com/laytonsmith/abstraction/blocks/MCMaterial.java index ad9d5e1472..9df45cf3ce 100644 --- a/src/main/java/com/laytonsmith/abstraction/blocks/MCMaterial.java +++ b/src/main/java/com/laytonsmith/abstraction/blocks/MCMaterial.java @@ -1667,7 +1667,12 @@ public enum MCVanillaMaterial { GUSTER_POTTERY_SHERD(MCVersion.MC1_20_6), SCRAPE_POTTERY_SHERD(MCVersion.MC1_20_6), VAULT(MCVersion.MC1_20_6), - WIND_CHARGE(MCVersion.MC1_20_6); + WIND_CHARGE(MCVersion.MC1_20_6), + + // 1.21 additions + MUSIC_DISC_CREATOR(MCVersion.MC1_21), + MUSIC_DISC_CREATOR_MUSIC_BOX(MCVersion.MC1_21), + MUSIC_DISC_PRECIPICE(MCVersion.MC1_21); private final MCVersion since; private final MCVersion until; diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java index 8b648cd147..7c513bbeea 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java @@ -149,6 +149,7 @@ import org.bukkit.inventory.BlastingRecipe; import org.bukkit.inventory.CampfireRecipe; import org.bukkit.inventory.ComplexRecipe; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.InventoryHolder; @@ -321,6 +322,23 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, Strin return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod); } + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot) { + EquipmentSlot es = BukkitMCEquipmentSlot.getConvertor().getConcreteEnum(slot); + AttributeModifier mod = new AttributeModifier((NamespacedKey) key.getHandle(), amt, + BukkitMCAttributeModifier.Operation.getConvertor().getConcreteEnum(op), + es == null ? EquipmentSlotGroup.ANY : es.getGroup()); + return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod); + } + + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) { + AttributeModifier mod = new AttributeModifier((NamespacedKey) key.getHandle(), amt, + BukkitMCAttributeModifier.Operation.getConvertor().getConcreteEnum(op), + EquipmentSlotGroup.getByName(slot.name())); + return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod); + } + @Override public MCMetadataValue GetMetadataValue(Object value, MCPlugin plugin) { return new BukkitMCMetadataValue(new FixedMetadataValue(((BukkitMCPlugin) plugin).getHandle(), value)); diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCAttributeModifier.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCAttributeModifier.java index 4110580a50..a4579c43d3 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCAttributeModifier.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCAttributeModifier.java @@ -2,6 +2,7 @@ import com.laytonsmith.abstraction.Implementation; import com.laytonsmith.abstraction.MCAttributeModifier; +import com.laytonsmith.abstraction.MCNamespacedKey; import com.laytonsmith.abstraction.enums.EnumConvertor; import com.laytonsmith.abstraction.enums.MCAttribute; import com.laytonsmith.abstraction.enums.MCEquipmentSlot; @@ -31,6 +32,11 @@ public Object getHandle() { return am; } + @Override + public MCNamespacedKey getKey() { + return new BukkitMCNamespacedKey(am.getKey()); + } + @Override public String getAttributeName() { return am.getName(); diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCArt.java b/src/main/java/com/laytonsmith/abstraction/enums/MCArt.java index 100cefb018..fce75ff9d7 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCArt.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCArt.java @@ -4,6 +4,7 @@ @MEnum("com.commandhelper.Art") public enum MCArt { + // 1x1 KEBAB, AZTEC, ALBAN, @@ -11,27 +12,55 @@ public enum MCArt { BOMB, PLANT, WASTELAND, + MEDITATIVE, + // 2x1 POOL, COURBET, SEA, SUNSET, CREEBET, + // 1x2 WANDERER, GRAHAM, + PRAIRIE_RIDE, + // 2x2 MATCH, BUST, STAGE, VOID, SKULL_AND_ROSES, WITHER, + BAROQUE, + HUMBLE, + EARTH, + WIND, + WATER, + FIRE, + // 4x2 FIGHTERS, + CHANGING, + FINDING, + LOWMIST, + PASSAGE, + // 3x3 + BOUQUET, + CAVEBIRD, + COTAN, + ENDBOSS, + FERN, + OWLEMONS, + SUNFLOWERS, + TIDES, + // 4x3 + SKELETON, + DONKEY_KONG, + // 3x4 + BACKYARD, + POND, + // 4x4 POINTER, PIGSCENE, BURNING_SKULL, - SKELETON, - DONKEY_KONG, - EARTH, - WIND, - WATER, - FIRE + ORB, + UNPACKED, } diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCAttribute.java b/src/main/java/com/laytonsmith/abstraction/enums/MCAttribute.java index 79d137d312..9c735559bc 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCAttribute.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCAttribute.java @@ -9,6 +9,8 @@ public enum MCAttribute { GENERIC_ATTACK_DAMAGE, GENERIC_ATTACK_KNOCKBACK, GENERIC_ATTACK_SPEED, + GENERIC_BURNING_TIME, + GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE, GENERIC_FALL_DAMAGE_MULTIPLIER, GENERIC_FLYING_SPEED, GENERIC_FOLLOW_RANGE, @@ -18,13 +20,20 @@ public enum MCAttribute { GENERIC_LUCK, GENERIC_MAX_ABSORPTION, GENERIC_MAX_HEALTH, + GENERIC_MOVEMENT_EFFICIENCY, GENERIC_MOVEMENT_SPEED, + GENERIC_OXYGEN_BONUS, GENERIC_SAFE_FALL_DISTANCE, GENERIC_SCALE, GENERIC_STEP_HEIGHT, - HORSE_JUMP_STRENGTH, // changed to GENERIC_JUMP_STRENGTH + GENERIC_WATER_MOVEMENT_EFFICIENCY, + HORSE_JUMP_STRENGTH, // changed to GENERIC_JUMP_STRENGTH in 1.20.6 PLAYER_BLOCK_BREAK_SPEED, PLAYER_BLOCK_INTERACTION_RANGE, PLAYER_ENTITY_INTERACTION_RANGE, + PLAYER_MINING_EFFICIENCY, + PLAYER_SNEAKING_SPEED, + PLAYER_SUBMERGED_MINING_SPEED, + PLAYER_SWEEPING_DAMAGE_RATIO, ZOMBIE_SPAWN_REINFORCEMENTS } diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCDamageCause.java b/src/main/java/com/laytonsmith/abstraction/enums/MCDamageCause.java index cee1eb3d19..154cc0a49a 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCDamageCause.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCDamageCause.java @@ -97,6 +97,10 @@ public enum MCDamageCause { * Damage caused when an entity steps on MAGMA. */ HOT_FLOOR, + /** + * Damage caused when an entity is on top a campfire. + */ + CAMPFIRE, /** * Damage caused when an entity is colliding with too many entities due to the maxEntityCramming game rule. */ diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCPatternShape.java b/src/main/java/com/laytonsmith/abstraction/enums/MCPatternShape.java index b87e896086..edb707f65f 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCPatternShape.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCPatternShape.java @@ -15,10 +15,12 @@ public enum MCPatternShape { DIAGONAL_LEFT_MIRROR, DIAGONAL_RIGHT, DIAGONAL_RIGHT_MIRROR, + FLOW, FLOWER, GLOBE, GRADIENT, GRADIENT_UP, + GUSTER, HALF_HORIZONTAL, HALF_HORIZONTAL_MIRROR, HALF_VERTICAL, diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCSound.java b/src/main/java/com/laytonsmith/abstraction/enums/MCSound.java index c8ace504d9..afdda10928 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCSound.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCSound.java @@ -1650,7 +1650,8 @@ public enum MCVanillaSound { BLOCK_HEAVY_CORE_PLACE(MCVersion.MC1_20_6), BLOCK_HEAVY_CORE_STEP(MCVersion.MC1_20_6), BLOCK_TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM(MCVersion.MC1_20_6), - BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED(MCVersion.MC1_20_6), + BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED(MCVersion.MC1_20_6, MCVersion.MC1_20_6), + BLOCK_TRIAL_SPAWNER_AMBIENT_OMINOUS(MCVersion.MC1_21), // changed from BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED BLOCK_TRIAL_SPAWNER_CHARGE_ACTIVATE(MCVersion.MC1_20_6), BLOCK_TRIAL_SPAWNER_SPAWN_ITEM(MCVersion.MC1_20_6), BLOCK_TRIAL_SPAWNER_SPAWN_ITEM_BEGIN(MCVersion.MC1_20_6), @@ -1707,6 +1708,13 @@ public enum MCVanillaSound { ITEM_WOLF_ARMOR_DAMAGE(MCVersion.MC1_20_6), ITEM_WOLF_ARMOR_REPAIR(MCVersion.MC1_20_6), + // 1.21 additions + BLOCK_TRIAL_SPAWNER_OMINOUS_ACTIVATE(MCVersion.MC1_21), + BLOCK_VAULT_REJECT_REWARDED_PLAYER(MCVersion.MC1_21), + MUSIC_DISC_CREATOR(MCVersion.MC1_21), + MUSIC_DISC_CREATOR_MUSIC_BOX(MCVersion.MC1_21), + MUSIC_DISC_PRECIPICE(MCVersion.MC1_21), + UNKNOWN(MCVersion.NEVER); private final MCVersion since; diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCSpawnReason.java b/src/main/java/com/laytonsmith/abstraction/enums/MCSpawnReason.java index 80665d6d0b..4fd7aeb38c 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCSpawnReason.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCSpawnReason.java @@ -54,4 +54,5 @@ public enum MCSpawnReason { SPELL, METAMORPHOSIS, DUPLICATION, + ENCHANTMENT, } diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCTreeType.java b/src/main/java/com/laytonsmith/abstraction/enums/MCTreeType.java index 18f65a9f04..11b6ec7695 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCTreeType.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCTreeType.java @@ -19,6 +19,7 @@ public enum MCTreeType { DARK_OAK, COCOA_TREE, MEGA_REDWOOD, + MEGA_PINE, TALL_BIRCH, CHORUS_PLANT, CRIMSON_FUNGUS, diff --git a/src/main/java/com/laytonsmith/abstraction/enums/MCVersion.java b/src/main/java/com/laytonsmith/abstraction/enums/MCVersion.java index 9a08f501ad..ee5fcbda2a 100644 --- a/src/main/java/com/laytonsmith/abstraction/enums/MCVersion.java +++ b/src/main/java/com/laytonsmith/abstraction/enums/MCVersion.java @@ -71,6 +71,8 @@ public enum MCVersion implements Version { MC1_20_4, MC1_20_6, MC1_20_X, + MC1_21, + MC1_21_X, MC1_X, MC2_X, MCX_X, diff --git a/src/main/java/com/laytonsmith/abstraction/events/MCLightningStrikeEvent.java b/src/main/java/com/laytonsmith/abstraction/events/MCLightningStrikeEvent.java index 49b42c2c74..5dbc28dcd0 100644 --- a/src/main/java/com/laytonsmith/abstraction/events/MCLightningStrikeEvent.java +++ b/src/main/java/com/laytonsmith/abstraction/events/MCLightningStrikeEvent.java @@ -11,6 +11,7 @@ public interface MCLightningStrikeEvent extends MCWeatherEvent { enum Cause { COMMAND, CUSTOM, + ENCHANTMENT, SPAWNER, TRIDENT, TRAP, diff --git a/src/main/java/com/laytonsmith/core/ObjectGenerator.java b/src/main/java/com/laytonsmith/core/ObjectGenerator.java index 1932ee66c0..c09ce82b33 100644 --- a/src/main/java/com/laytonsmith/core/ObjectGenerator.java +++ b/src/main/java/com/laytonsmith/core/ObjectGenerator.java @@ -1736,10 +1736,16 @@ public Map enchants(CArray enchantArray, Target t) { public CArray attributeModifier(MCAttributeModifier m, Target t) { CArray modifier = CArray.GetAssociativeArray(t); + + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) { + modifier.set("id", m.getKey().toString()); + } else { + modifier.set("name", m.getAttributeName()); + modifier.set("uuid", m.getUniqueId().toString()); + } + modifier.set("attribute", m.getAttribute().name()); - modifier.set("name", m.getAttributeName()); modifier.set("operation", m.getOperation().name()); - modifier.set("uuid", m.getUniqueId().toString()); modifier.set("amount", new CDouble(m.getAmount(), t), t); Mixed slot = CNull.NULL; @@ -1767,8 +1773,10 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) { MCAttribute attribute; MCAttributeModifier.Operation operation; double amount; + MCNamespacedKey id = null; UUID uuid = null; String name = ""; + MCEquipmentSlotGroup slotGroup = null; MCEquipmentSlot slot = null; try { @@ -1785,15 +1793,18 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) { amount = ArgumentValidation.getDouble(m.get("amount", t), t); - if(m.containsKey("name")) { - name = m.get("name", t).val(); - } - - if(m.containsKey("uuid")) { - try { - uuid = UUID.fromString(m.get("uuid", t).val()); - } catch (IllegalArgumentException ex) { - throw new CREFormatException("Invalid UUID format: " + m.get("uuid", t), t); + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21) && m.containsKey("id")) { + id = StaticLayer.GetConvertor().GetNamespacedKey(m.get("id", t).val()); + } else { + if(m.containsKey("name")) { + name = m.get("name", t).val(); + } + if(m.containsKey("uuid")) { + try { + uuid = UUID.fromString(m.get("uuid", t).val()); + } catch (IllegalArgumentException ex) { + throw new CREFormatException("Invalid UUID format: " + m.get("uuid", t), t); + } } } @@ -1801,7 +1812,6 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) { Mixed s = m.get("slot", t); if(!(s instanceof CNull)) { if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_6)) { - MCEquipmentSlotGroup slotGroup = null; if(s.val().equals("ANY")) { slotGroup = MCEquipmentSlotGroup.ANY; } else if(s.val().equals("HAND")) { @@ -1809,19 +1819,26 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) { } else if(s.val().equals("ARMOR")) { slotGroup = MCEquipmentSlotGroup.ARMOR; } - if(slotGroup != null) { - return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation, - slotGroup); - } } - try { - slot = MCEquipmentSlot.valueOf(s.val()); - } catch (IllegalArgumentException ex) { - throw new CREFormatException("Invalid equipment slot name: " + m.get("slot", t), t); + if(slotGroup == null) { + try { + slot = MCEquipmentSlot.valueOf(s.val()); + } catch (IllegalArgumentException ex) { + throw new CREFormatException("Invalid equipment slot name: " + m.get("slot", t), t); + } } } } + if(slotGroup != null) { + if(id != null) { + return StaticLayer.GetConvertor().GetAttributeModifier(attribute, id, amount, operation, slotGroup); + } + return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation, slotGroup); + } + if(id != null) { + return StaticLayer.GetConvertor().GetAttributeModifier(attribute, id, amount, operation, slot); + } return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation, slot); } diff --git a/src/main/java/com/laytonsmith/core/functions/MobManagement.java b/src/main/java/com/laytonsmith/core/functions/MobManagement.java index c37f26e1ba..637fc233dc 100644 --- a/src/main/java/com/laytonsmith/core/functions/MobManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/MobManagement.java @@ -3,6 +3,7 @@ import com.laytonsmith.PureUtilities.Common.StringUtils; import com.laytonsmith.PureUtilities.Version; import com.laytonsmith.abstraction.MCAttributeModifier; +import com.laytonsmith.abstraction.MCNamespacedKey; import com.laytonsmith.abstraction.blocks.MCMaterial; import com.laytonsmith.abstraction.MCAnimalTamer; import com.laytonsmith.abstraction.MCEntity; @@ -20,6 +21,7 @@ import com.laytonsmith.abstraction.enums.MCAttribute; import com.laytonsmith.abstraction.enums.MCEquipmentSlot; import com.laytonsmith.abstraction.enums.MCPotionEffectType; +import com.laytonsmith.abstraction.enums.MCVersion; import com.laytonsmith.annotations.api; import com.laytonsmith.core.ArgumentValidation; import com.laytonsmith.core.MSLog; @@ -1954,9 +1956,8 @@ public Integer[] numArgs() { @Override public String docs() { - return "void {entityUUID, modifier | entityUUID, attribute, id} Removes an attribute modifier from an" - + " entity. A modifier array can be provided, or both an attribute name and either the UUID or" - + " name (if it's unique) for the modifier can be provided as the identifier."; + return "void {entityUUID, modifier | entityUUID, attribute, id} Removes an attribute modifier from an entity." + + " Can provide either a modifier array or just the attribute and namespaced id of the modifier."; } @Override @@ -1989,20 +1990,41 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi throw new CREFormatException("Invalid attribute name: " + args[1].val(), t); } List modifiers = e.getAttributeModifiers(attribute); - String name = args[2].val(); - UUID id = null; - if(name.length() == 36 || name.length() == 32) { - try { - id = UUID.fromString(name); - } catch (IllegalArgumentException ex) { - // not UUID + String id = args[2].val(); + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) { + MCNamespacedKey key = null; + if(id.length() == 36) { + try { + UUID.fromString(id); + key = StaticLayer.GetConvertor().GetNamespacedKey("minecraft:" + id); + } catch (IllegalArgumentException ex) { + // not legacy UUID + } } - } - for(MCAttributeModifier m : modifiers) { - if(id != null && m.getUniqueId().compareTo(id) == 0 - || id == null && name.equals(m.getAttributeName())) { - modifier = m; - break; + if(key == null) { + key = StaticLayer.GetConvertor().GetNamespacedKey(id); + } + for(MCAttributeModifier m : modifiers) { + if(m.getKey().equals(key)) { + modifier = m; + break; + } + } + } else { + UUID uuid = null; + if(id.length() == 36) { + try { + uuid = UUID.fromString(id); + } catch (IllegalArgumentException ex) { + // not UUID + } + } + for(MCAttributeModifier m : modifiers) { + if(uuid != null && m.getUniqueId().compareTo(uuid) == 0 + || uuid == null && id.equals(m.getAttributeName())) { + modifier = m; + break; + } } } if(modifier == null) { diff --git a/src/main/java/com/laytonsmith/tools/Interpreter.java b/src/main/java/com/laytonsmith/tools/Interpreter.java index 56ce4851b5..c6fd0a5289 100644 --- a/src/main/java/com/laytonsmith/tools/Interpreter.java +++ b/src/main/java/com/laytonsmith/tools/Interpreter.java @@ -702,7 +702,7 @@ public static String reverseHTML(String input) { * @param args * @throws ConfigCompileException * @throws IOException - * @throws cConfigCompileGroupException + * @throws ConfigCompileGroupException */ public void execute(String script, List args) throws ConfigCompileException, IOException, ConfigCompileGroupException { execute(script, args, null); @@ -1177,6 +1177,16 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, Strin throw new UnsupportedOperationException("This method is not supported from a shell."); } + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot) { + throw new UnsupportedOperationException("This method is not supported from a shell."); + } + + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) { + throw new UnsupportedOperationException("This method is not supported from a shell."); + } + @Override public void Startup(CommandHelperPlugin chp) { diff --git a/src/main/resources/docs/Compatibility b/src/main/resources/docs/Compatibility index c092bf2f96..0fa9d0e50f 100644 --- a/src/main/resources/docs/Compatibility +++ b/src/main/resources/docs/Compatibility @@ -3,7 +3,7 @@ In general, the compatibility requirements, if not listed, are the same as the p The minimum requirements for the current builds are: * Java 16 -* Spigot or Paper 1.16.5 - 1.20.4 (when used as a plugin) +* Spigot or Paper 1.16.5 - 1.21 (when used as a plugin) CommandHelper may still be backwards and forward compatible to a large degree. Many of the advanced features that normally have hard dependencies on certain versions of external dependencies have been configured to "soft" fail. @@ -18,6 +18,11 @@ Regardless, only the most current builds are officially supported. ! scope="col" width="60%" | Milestone ! scope="col" width="21%" | Compatibility |- +| 3.3.5 build-478 +| +| Added support for Spigot 1.21 +| Spigot 1.16.5 - 1.21 +|- | 3.3.5 build-467 | [https://github.com/EngineHub/CommandHelper/commit/84f1af4764fa93fc4809696969fdbce2112ec4ac 84f1af4] | Added support for Spigot 1.20.6 diff --git a/src/main/resources/docs/Upgrade_Guide b/src/main/resources/docs/Upgrade_Guide index 5cd250e27b..4d1a339b31 100644 --- a/src/main/resources/docs/Upgrade_Guide +++ b/src/main/resources/docs/Upgrade_Guide @@ -3,10 +3,17 @@ Below is a reverse chronological guide to help you with the most notable of thes Where possible, any value changes are converted for backwards compatibility with saved data, but any script that checks output for equality will need to be updated. ---- +== Minecraft 1.21 == +* Attribute modifiers' optional "name" and "uuid" keys have been replaced with a namespaced key under "id". +Old attribute modifiers will use the UUID to generate a namespaced key. + +---- + == Minecraft 1.20.5 == * SCUTE item has been renamed to TURTLE_SCUTE * In potion item meta, the potion array under the "base" key was replaced by a "potiontype" string * In enchantment item meta, the arrays under the "enchants" key have had the "etype" key removed +* HORSE_JUMP_STRENGTH attribute was changed to GENERIC_JUMP_STRENGTH ---- @@ -110,7 +117,7 @@ Two paintings just had a space added to them: BURNING_SKULL and DONKEY_KONG. === Item/Block String Format Deprecated === The "0:0" format is no longer guaranteed to be accurate, so it's deprecated wherever it's used. In most cases you will be warned on compile time if you use these anywhere. If not, you will be warned in the log at runtime, but the -item/block will be attempted to be converted. Notably, get|set_block_at() has been deprecated for get|set_block(). If +item/block will be attempted to be converted. Notably, get|set_block_at() have been replaced with get|set_block(). If you need to read or write block data, the get|set_blockdata_string() functions are available until further functionality is added. These use the same format as vanilla block commands. @@ -125,7 +132,8 @@ use item arrays instead of the string formats. === CommandBlock Changes === In addition the vanilla changes to commands, they no longer automatically process vanilla selectors for plugin commands. -You will have to implement selectors yourself if you need this behavior. +You will have to implement selectors yourself if you need this behavior. If upgrading to 3.3.5, you can use the +select_entites() function. === Event Removals === The event tab_complete_chat is removed because clients no longer send these to the server. The event @@ -136,8 +144,7 @@ player_login. Pre-1.9 sound names are all removed and some post 1.9 sounds have been updated to reflect 1.13. However, these will no longer cause play_sound() to throw an exception. Instead, it will warn in the log and continue running. play_named_sound() always behaved like this, but did so silently. play_sound() will now simply warn you if the sound -didn't play because the name is incorrect. You can refer the Minecraft wiki or the Spigot documentation for the complete -list. You can also use reflect_pull('enum', 'Sound') to get the list in a script. +didn't play because the name is incorrect. === Event Data Changes === The following events' prefilters, event data, and/or mutable data were updated: piston_retract, piston_extend, diff --git a/src/main/resources/functionDocs/entity_spec b/src/main/resources/functionDocs/entity_spec index 38899213f6..deb33fa885 100644 --- a/src/main/resources/functionDocs/entity_spec +++ b/src/main/resources/functionDocs/entity_spec @@ -24,7 +24,7 @@ This particle array must contain a "particle" key, and supports the keys "block" | ARROW | * %KEY_ARROW_CRITICAL%: If this arrow is critical. (boolean) -* %KEY_ARROW_KNOCKBACK%: The knockback strength. (int) +* %KEY_ARROW_KNOCKBACK%: The knockback strength. (int) (before MC 1.21) * %KEY_ARROW_DAMAGE%: The amount of damage. (double) * %KEY_ARROW_PIERCE_LEVEL%: The remaining times that this arrow can pierce through an entity. (int from 0 and 127) * %KEY_ARROW_PICKUP%: Whether picking up this arrow is ALLOWED, DISALLOWED, or CREATIVE_ONLY. diff --git a/src/main/resources/functionDocs/get_itemmeta b/src/main/resources/functionDocs/get_itemmeta index 67b0905c59..1e7912aaa9 100644 --- a/src/main/resources/functionDocs/get_itemmeta +++ b/src/main/resources/functionDocs/get_itemmeta @@ -16,7 +16,7 @@ Some Minecraft NBT is not yet supported in item meta, and should be documented b * '''model''' : (int) Represents vanilla's CustomModelData tag for use with resource packs. * '''flags''' : (array) A list of flags used to hide meta in the item tooltip: ''%ITEM_FLAGS%''. * '''repair''' : (int) The cost to repair or combine this item in an anvil. -* '''modifiers''' : (array) An array of attribute modifier arrays, each with keys: '''"attribute"''', '''"operation"''', '''"amount"''' (double), '''"uuid"''' (optional), '''"name"''' (optional), and '''"slot"''' (optional). Possible attributes: ''%ATTRIBUTES%''. Possible operations: ''%OPERATIONS%''. Possible slots are ''%SLOTS%'' or one of the slot groups ''%SLOTGROUPS%''. +* '''modifiers''' : (array) An array of attribute modifier arrays, each with keys: '''"attribute"''', '''"operation"''', '''"amount"''' (double), '''"id"''' (optional), and '''"slot"''' (optional). Possible attributes: %ATTRIBUTES%. Possible operations: %OPERATIONS%. Possible slots are %SLOTS% or one of the slot groups %SLOTGROUPS%. An item can only have one modifier with the same id. * '''tags''' : (array) An associative array of custom tags used by plugins (or null). A tag's key is namespaced (e.g. "commandhelper:mytag") and the value is an associative array containing the '''"type"''' and '''"value"''' of the tag. Possible types: ''%TAG_TYPES%''. The "CanPlaceOn" tag for blocks and "CanDestroy" tag for tools are not yet supported. |- diff --git a/src/test/java/com/laytonsmith/testing/StaticTest.java b/src/test/java/com/laytonsmith/testing/StaticTest.java index 0710f2ff0f..4f266dc6df 100644 --- a/src/test/java/com/laytonsmith/testing/StaticTest.java +++ b/src/test/java/com/laytonsmith/testing/StaticTest.java @@ -735,6 +735,16 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, Strin throw new UnsupportedOperationException(); } + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot) { + throw new UnsupportedOperationException(); + } + + @Override + public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) { + throw new UnsupportedOperationException(); + } + @Override public int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) { //This needs fixing later