From 4095baa08bead37cd07719148f583e9b55a7c670 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:53:45 +0200 Subject: [PATCH 01/12] init commit --- src/main/java/ch/njol/skript/effects/EffEquip.java | 3 ++- .../regressions/7140-leather horse armor unequipable.sk | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 8d818170062..3a096062cd7 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -99,7 +99,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye private static ItemType LEGGINGS; private static ItemType BOOTS; private static ItemType CARPET; - private static final ItemType HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR); + private static final ItemType HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, + Material.DIAMOND_HORSE_ARMOR); private static final ItemType SADDLE = new ItemType(Material.SADDLE); private static final ItemType CHEST = new ItemType(Material.CHEST); diff --git a/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk new file mode 100644 index 00000000000..ecb769e884e --- /dev/null +++ b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk @@ -0,0 +1,9 @@ +test "leather horse armor unequipable": + spawn horse at spawn of world "world": + set {_h} to entity + + equip {_h} with leather horse armor + + assert {_h} has leather horse armor with "horse doesn't have horse armor" + + delete entity within {_h} From 85c82035892c669f2f85d45d4db6b58165a3ffba Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:56:32 +0200 Subject: [PATCH 02/12] oops --- src/main/java/ch/njol/skript/effects/EffEquip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 3a096062cd7..3106199f9a7 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -100,7 +100,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye private static ItemType BOOTS; private static ItemType CARPET; private static final ItemType HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, - Material.DIAMOND_HORSE_ARMOR); + Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); private static final ItemType SADDLE = new ItemType(Material.SADDLE); private static final ItemType CHEST = new ItemType(Material.CHEST); From 752b8563d8069ab7fe623de5162cc780b43b1b3d Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:43:36 +0200 Subject: [PATCH 03/12] update --- .../java/ch/njol/skript/effects/EffEquip.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 3106199f9a7..064ed356e79 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -60,13 +60,22 @@ @Since("1.0, 2.7 (multiple entities, unequip)") public class EffEquip extends Effect { + private static ItemType HORSE_ARMOR; + static { + try { + HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, + Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); + } catch (NoSuchFieldError ex) { + HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, + Material.DIAMOND_HORSE_ARMOR); + } + Skript.registerEffect(EffEquip.class, "equip [%livingentities%] with %itemtypes%", "make %livingentities% wear %itemtypes%", "unequip %itemtypes% [from %livingentities%]", - "unequip %livingentities%'[s] (armor|equipment)" - ); + "unequip %livingentities%'[s] (armor|equipment)"); } @SuppressWarnings("NotNullFieldNotInitialized") @@ -99,8 +108,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye private static ItemType LEGGINGS; private static ItemType BOOTS; private static ItemType CARPET; - private static final ItemType HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, - Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); private static final ItemType SADDLE = new ItemType(Material.SADDLE); private static final ItemType CHEST = new ItemType(Material.CHEST); From a4082ece78cd0d3b248ccc05ae4d27facd104192 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:59:12 +0200 Subject: [PATCH 04/12] update ver --- .../tests/regressions/7140-leather horse armor unequipable.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk index ecb769e884e..35d1f1826cb 100644 --- a/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk +++ b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk @@ -1,4 +1,4 @@ -test "leather horse armor unequipable": +test "leather horse armor unequipable" when running minecraft "1.14": spawn horse at spawn of world "world": set {_h} to entity From 51f425228b0d17db6fec74539ad9ee26d7e41a99 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:45:46 +0200 Subject: [PATCH 05/12] fix paper --- .../java/ch/njol/skript/effects/EffEquip.java | 60 +++++++------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 064ed356e79..2bd553b240c 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -1,42 +1,14 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ package ch.njol.skript.effects; import ch.njol.skript.aliases.ItemData; import org.bukkit.Material; import org.bukkit.Tag; -import org.bukkit.entity.AbstractHorse; -import org.bukkit.entity.ChestedHorse; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Llama; -import org.bukkit.entity.Pig; -import org.bukkit.entity.Player; -import org.bukkit.entity.Steerable; +import org.bukkit.entity.*; import org.bukkit.event.Event; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.LlamaInventory; +import org.bukkit.inventory.*; import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; -import ch.njol.skript.aliases.Aliases; import ch.njol.skript.aliases.ItemType; import ch.njol.skript.bukkitutil.PlayerUtils; import ch.njol.skript.doc.Description; @@ -49,17 +21,23 @@ import ch.njol.util.Kleenean; @Name("Equip") -@Description("Equips or unequips an entity with some given armor. This will replace any armor that the entity is wearing.") +@Description( + "Equips or unequips an entity with some given armor. " + + "This will replace any armor that the entity is wearing." +) @Examples({ - "equip player with diamond helmet", - "equip player with all diamond armor", - "unequip diamond chestplate from player", - "unequip all armor from player", - "unequip player's armor" + "equip player with diamond helmet", + "equip player with all diamond armor", + "unequip diamond chestplate from player", + "unequip all armor from player", + "unequip player's armor" }) @Since("1.0, 2.7 (multiple entities, unequip)") public class EffEquip extends Effect { + private static final boolean SUPPORTS_SET_ARMOR = + Skript.methodExists(HorseInventory.class, "setArmor", ItemStack.class); + private static ItemType HORSE_ARMOR; static { @@ -198,10 +176,14 @@ protected void execute(Event event) { Inventory inv = ((AbstractHorse) entity).getInventory(); for (ItemType itemType : itemTypes) { for (ItemStack item : itemType.getAll()) { - if (SADDLE.isOfType(item)) { - inv.setItem(0, equip ? item : null); // Slot 0=saddle + if (SADDLE.isOfType(item) && entity instanceof Horse) { + ((Horse) entity).getInventory().setSaddle(equip ? item : null); } else if (HORSE_ARMOR.isOfType(item)) { - inv.setItem(1, equip ? item : null); // Slot 1=armor + if (SUPPORTS_SET_ARMOR) { + ((Horse) entity).getInventory().setArmor(equip ? item : null); + } else { + inv.setItem(1, equip ? item : null); + } } else if (CHEST.isOfType(item) && entity instanceof ChestedHorse) { ((ChestedHorse) entity).setCarryingChest(equip); } From efbf0cce419dd6a82de46a54e28a069f4fba4c24 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:49:46 +0200 Subject: [PATCH 06/12] hmm --- src/main/java/ch/njol/skript/effects/EffEquip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 2bd553b240c..7433c45d402 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -36,7 +36,7 @@ public class EffEquip extends Effect { private static final boolean SUPPORTS_SET_ARMOR = - Skript.methodExists(HorseInventory.class, "setArmor", ItemStack.class); + Skript.classExists("org.bukkit.inventory.ArmoredHorseInventory"); private static ItemType HORSE_ARMOR; From 4e9825028d51c1bab9e744192bfce81f248ca2ff Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:56:04 +0200 Subject: [PATCH 07/12] yeah ok --- .../java/ch/njol/skript/effects/EffEquip.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 7433c45d402..83f88f56701 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -1,14 +1,7 @@ package ch.njol.skript.effects; -import ch.njol.skript.aliases.ItemData; -import org.bukkit.Material; -import org.bukkit.Tag; -import org.bukkit.entity.*; -import org.bukkit.event.Event; -import org.bukkit.inventory.*; -import org.jetbrains.annotations.Nullable; - import ch.njol.skript.Skript; +import ch.njol.skript.aliases.ItemData; import ch.njol.skript.aliases.ItemType; import ch.njol.skript.bukkitutil.PlayerUtils; import ch.njol.skript.doc.Description; @@ -19,6 +12,15 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.entity.*; +import org.bukkit.event.Event; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.LlamaInventory; +import org.jetbrains.annotations.Nullable; @Name("Equip") @Description( @@ -35,9 +37,6 @@ @Since("1.0, 2.7 (multiple entities, unequip)") public class EffEquip extends Effect { - private static final boolean SUPPORTS_SET_ARMOR = - Skript.classExists("org.bukkit.inventory.ArmoredHorseInventory"); - private static ItemType HORSE_ARMOR; static { @@ -179,11 +178,7 @@ protected void execute(Event event) { if (SADDLE.isOfType(item) && entity instanceof Horse) { ((Horse) entity).getInventory().setSaddle(equip ? item : null); } else if (HORSE_ARMOR.isOfType(item)) { - if (SUPPORTS_SET_ARMOR) { - ((Horse) entity).getInventory().setArmor(equip ? item : null); - } else { - inv.setItem(1, equip ? item : null); - } + inv.setItem(1, equip ? item : null); } else if (CHEST.isOfType(item) && entity instanceof ChestedHorse) { ((ChestedHorse) entity).setCarryingChest(equip); } From c818c64ae078ad8619f844921bb3e6cc27d12df6 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:13:47 +0200 Subject: [PATCH 08/12] oops --- src/main/java/ch/njol/skript/effects/EffEquip.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 83f88f56701..6142efa422a 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -176,9 +176,9 @@ protected void execute(Event event) { for (ItemType itemType : itemTypes) { for (ItemStack item : itemType.getAll()) { if (SADDLE.isOfType(item) && entity instanceof Horse) { - ((Horse) entity).getInventory().setSaddle(equip ? item : null); + inv.setItem(0, equip ? item : null); // Slot 0=saddle } else if (HORSE_ARMOR.isOfType(item)) { - inv.setItem(1, equip ? item : null); + inv.setItem(1, equip ? item : null); // Slot 1=armor } else if (CHEST.isOfType(item) && entity instanceof ChestedHorse) { ((ChestedHorse) entity).setCarryingChest(equip); } From b90c57ec6e2ced3252da8829012453ea64628d4d Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:14:44 +0200 Subject: [PATCH 09/12] biggera oops --- src/main/java/ch/njol/skript/effects/EffEquip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 6142efa422a..5d253f14338 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -175,7 +175,7 @@ protected void execute(Event event) { Inventory inv = ((AbstractHorse) entity).getInventory(); for (ItemType itemType : itemTypes) { for (ItemStack item : itemType.getAll()) { - if (SADDLE.isOfType(item) && entity instanceof Horse) { + if (SADDLE.isOfType(item)) { inv.setItem(0, equip ? item : null); // Slot 0=saddle } else if (HORSE_ARMOR.isOfType(item)) { inv.setItem(1, equip ? item : null); // Slot 1=armor From 922e2af2c3e646dc7e55af9def4795e536e776bd Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:02:56 +0200 Subject: [PATCH 10/12] dont run tests on 1.20.6 --- .../tests/regressions/7140-leather horse armor unequipable.sk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk index 35d1f1826cb..fbfae46cc9f 100644 --- a/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk +++ b/src/test/skript/tests/regressions/7140-leather horse armor unequipable.sk @@ -1,4 +1,7 @@ test "leather horse armor unequipable" when running minecraft "1.14": + if minecraft version is "1.20.6": + stop # horse armor equipping is broken on Paper 1.20.6. see https://github.com/PaperMC/Paper/pull/11139 + spawn horse at spawn of world "world": set {_h} to entity From f1fbe8996971266421d3f03d974846b4b0e820ca Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sat, 12 Oct 2024 12:02:12 +0200 Subject: [PATCH 11/12] requested changes --- src/main/java/ch/njol/skript/effects/EffEquip.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 5d253f14338..01f57e21e23 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -37,13 +37,13 @@ @Since("1.0, 2.7 (multiple entities, unequip)") public class EffEquip extends Effect { - private static ItemType HORSE_ARMOR; + private static final ItemType HORSE_ARMOR; static { - try { + if (Skript.isRunningMinecraft(1, 14)) { HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); - } catch (NoSuchFieldError ex) { + } else { HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, Material.DIAMOND_HORSE_ARMOR); } @@ -52,7 +52,7 @@ public class EffEquip extends Effect { "equip [%livingentities%] with %itemtypes%", "make %livingentities% wear %itemtypes%", "unequip %itemtypes% [from %livingentities%]", - "unequip %livingentities%'[s] (armor|equipment)"); + "unequip %livingentities%'[s] (armo[u]r|equipment)"); } @SuppressWarnings("NotNullFieldNotInitialized") From d1c3d5f2a743d183bbecb7f5654e6a4c56911e5f Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:33:03 +0200 Subject: [PATCH 12/12] tabs --- src/main/java/ch/njol/skript/effects/EffEquip.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffEquip.java b/src/main/java/ch/njol/skript/effects/EffEquip.java index 01f57e21e23..74ca1572497 100644 --- a/src/main/java/ch/njol/skript/effects/EffEquip.java +++ b/src/main/java/ch/njol/skript/effects/EffEquip.java @@ -42,10 +42,10 @@ public class EffEquip extends Effect { static { if (Skript.isRunningMinecraft(1, 14)) { HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, - Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); + Material.DIAMOND_HORSE_ARMOR, Material.LEATHER_HORSE_ARMOR); } else { HORSE_ARMOR = new ItemType(Material.IRON_HORSE_ARMOR, Material.GOLDEN_HORSE_ARMOR, - Material.DIAMOND_HORSE_ARMOR); + Material.DIAMOND_HORSE_ARMOR); } Skript.registerEffect(EffEquip.class,