diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java b/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java index 0b6d741ced..c533f2cd20 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java @@ -28,6 +28,7 @@ import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.*; import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -104,7 +105,18 @@ public String getPlayerListName(Player player) { public String[] getSignLines(Sign sign) { String[] output = new String[4]; int i = 0; - for (Component component : sign.lines()) { + List list = NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) ? sign.getSide(Side.FRONT).lines() : sign.lines(); + for (Component component : list) { + output[i++] = PaperModule.stringifyComponent(component); + } + return output; + } + + @Override + public String[] getBackSignLines(Sign sign) { + String[] output = new String[4]; + int i = 0; + for (Component component : sign.getSide(Side.BACK).lines()) { output[i++] = PaperModule.stringifyComponent(component); } return output; @@ -112,7 +124,17 @@ public String[] getSignLines(Sign sign) { @Override public void setSignLine(Sign sign, int line, String text) { - sign.line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK)); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + sign.getSide(Side.FRONT).line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK)); + } + else { + sign.line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK)); + } + } + + @Override + public void setBackSignLine(Sign sign, int line, String text) { + sign.getSide(Side.BACK).line(line, PaperModule.parseFormattedText(text == null ? "" : text, ChatColor.BLACK)); } @Override diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java index 35501f2d69..f816467c85 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java @@ -40,6 +40,7 @@ import org.bukkit.block.banner.PatternType; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; +import org.bukkit.block.sign.Side; import org.bukkit.block.structure.Mirror; import org.bukkit.block.structure.StructureRotation; import org.bukkit.block.structure.UsageMode; @@ -1249,14 +1250,14 @@ public static void register() { // @group world // @description // Returns a list of lines on a sign. + // For MC 1.20+, this returns the contents on the front of the sign. + // To get the contents of the back, see <@link tag LocationTag.sign_contents_back>. // --> tagProcessor.registerTag(ListTag.class, "sign_contents", (attribute, object) -> { - if (object.getBlockStateForTag(attribute) instanceof Sign) { - return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines(((Sign) object.getBlockStateForTag(attribute))))); - } - else { - return null; + if (object.getBlockStateForTag(attribute) instanceof Sign sign) { + return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines(sign))); } + return null; }); // <--[tag] @@ -4156,14 +4157,15 @@ else if (material.hasModernData() && material.getModernData() instanceof org.buk // @group world // @description // Returns whether the location is a Sign block that is glowing. + // For MC 1.20+, this returns the glowing status of the front of the sign. + // To get the glowing state of the back, see <@link tag LocationTag.sign_glowing_back>. // --> tagProcessor.registerTag(ElementTag.class, "sign_glowing", (attribute, object) -> { - BlockState state = object.getBlockStateForTag(attribute); - if (!(state instanceof Sign)) { + if (!(object.getBlockStateForTag(attribute) instanceof Sign sign)) { attribute.echoError("Location is not a valid Sign block."); return null; } - return new ElementTag(((Sign) state).isGlowingText()); + return new ElementTag(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) ? sign.getSide(Side.FRONT).isGlowingText() : sign.isGlowingText()); }); // <--[tag] @@ -4173,15 +4175,16 @@ else if (material.hasModernData() && material.getModernData() instanceof org.buk // @group world // @description // Returns the name of the glow-color of the sign at the location. + // For MC 1.20+, this returns the color on the front of the sign. + // To get the color of the back, see <@link tag LocationTag.sign_glow_color_back>. // See also <@link tag LocationTag.sign_glowing> // --> tagProcessor.registerTag(ElementTag.class, "sign_glow_color", (attribute, object) -> { - BlockState state = object.getBlockStateForTag(attribute); - if (!(state instanceof Sign)) { + if (!(object.getBlockStateForTag(attribute) instanceof Sign sign)) { attribute.echoError("Location is not a valid Sign block."); return null; } - return new ElementTag(((Sign) state).getColor()); + return new ElementTag(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) ? sign.getSide(Side.FRONT).getColor() : sign.getColor()); }); // <--[tag] @@ -4568,6 +4571,131 @@ else if (material.hasModernData() && material.getModernData() instanceof org.buk } crafter.update(); }); + + // <--[tag] + // @attribute + // @returns ListTag + // @mechanism LocationTag.sign_contents_back + // @group world + // @description + // Returns the contents on the back of a sign block. + // For the contents on the front, see <@link tag LocationTag.sign_contents>. + // --> + tagProcessor.registerTag(ListTag.class, "sign_contents_back", (attribute, object) -> { + if (object.getBlockStateForTag(attribute) instanceof Sign sign) { + return new ListTag(Arrays.asList(PaperAPITools.instance.getBackSignLines(sign)), true); + } + return null; + }); + + // <--[mechanism] + // @object LocationTag + // @name sign_contents_back + // @input ListTag + // @description + // Sets the contents on the back of a sign block. + // To set the contents of the front, see <@link mechanism LocationTag.sign_contents>. + // @tags + // + // --> + tagProcessor.registerMechanism("sign_contents_back", false, ListTag.class, (object, mechanism, input) -> { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("Mechanism 'LocationTag.sign_contents_back' is only valid for Sign blocks."); + return; + } + for (int i = 0; i < 4; i++) { + PaperAPITools.instance.setBackSignLine(sign, i, ""); + } + CoreUtilities.fixNewLinesToListSeparation(input); + if (input.size() > 4) { + mechanism.echoError("Sign can only hold four lines!"); + } + for (int i = 0; i < input.size(); i++) { + PaperAPITools.instance.setBackSignLine(sign, i, input.get(i)); + } + sign.update(); + }); + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @mechanism LocationTag.sign_glowing_back + // @group world + // @description + // Returns whether the back of a Sign block at this location is glowing. + // To get the glowing state of the front, see <@link tag LocationTag.sign_glowing>. + // --> + tagProcessor.registerTag(ElementTag.class, "sign_glowing_back", (attribute, object) -> { + if (!(object.getBlockStateForTag(attribute) instanceof Sign sign)) { + attribute.echoError("Location is not a valid Sign block."); + return null; + } + return new ElementTag(sign.getSide(Side.BACK).isGlowingText()); + }); + + // <--[mechanism] + // @object LocationTag + // @name sign_glowing_back + // @input ElementTag(Boolean) + // @description + // Changes whether the back of the sign at the location is glowing. + // To set the glowing state of the front, see <@link mechanism LocationTag.sign_glowing>. + // @tags + // + // + // --> + tagProcessor.registerMechanism("sign_glowing_back", false, ElementTag.class, (object, mechanism, input) -> { + if (mechanism.requireBoolean()) { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("'sign_glowing_back' mechanism can only be called on Sign blocks."); + return; + } + sign.getSide(Side.BACK).setGlowingText(input.asBoolean()); + sign.update(); + } + }); + + // <--[tag] + // @attribute + // @returns ElementTag + // @mechanism LocationTag.sign_glow_color_back + // @group world + // @description + // Returns the name of the glow-color on the back of the sign at the location. + // To get the color of the front, see <@link tag LocationTag.sign_glow_color>. + // See also <@link tag LocationTag.sign_glowing_back>. + // --> + tagProcessor.registerTag(ElementTag.class, "sign_glow_color_back", (attribute, object) -> { + if (!(object.getBlockStateForTag(attribute) instanceof Sign sign)) { + attribute.echoError("Location is not a valid Sign block."); + return null; + } + return new ElementTag(sign.getSide(Side.BACK).getColor()); + }); + + // <--[mechanism] + // @object LocationTag + // @name sign_glow_color_back + // @input ElementTag + // @description + // Changes the glow color on the back of a sign. + // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. + // If a sign is not glowing, this is equivalent to applying a chat color to the sign. + // Use <@link mechanism LocationTag.sign_glowing> to toggle whether the front of the sign is glowing. + // @tags + // + // + // --> + tagProcessor.registerMechanism("sign_glow_color_back", false, ElementTag.class, (object, mechanism, input) -> { + if (mechanism.requireEnum(DyeColor.class)) { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("'sign_glow_color_back' mechanism can only be called on Sign blocks."); + return; + } + sign.getSide(Side.BACK).setColor(input.asEnum(DyeColor.class)); + sign.update(); + } + }); } // <--[mechanism] @@ -4635,6 +4763,94 @@ else if (mechanism.requireObject(EntityTag.class)) { mechanism.echoError("The 'LocationTag.page' mechanism can only be called on a lectern block."); } }); + + // <--[mechanism] + // @object LocationTag + // @name sign_contents + // @input ListTag + // @description + // Sets the contents of a sign block. + // For MC 1.20+, this sets the contents on the front of the sign. + // To set the contents of the back, see <@link mechanism LocationTag.sign_contents_back>. + // @tags + // + // --> + tagProcessor.registerMechanism("sign_contents", false, ListTag.class, (object, mechanism, value) -> { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("Mechanism 'LocationTag.sign_contents' is only valid for Sign blocks."); + return; + } + for (int i = 0; i < 4; i++) { + PaperAPITools.instance.setSignLine(sign, i, ""); + } + CoreUtilities.fixNewLinesToListSeparation(value); + if (value.size() > 4) { + mechanism.echoError("Sign can only hold four lines!"); + } + for (int i = 0; i < value.size(); i++) { + PaperAPITools.instance.setSignLine(sign, i, value.get(i)); + } + sign.update(); + }); + + // <--[mechanism] + // @object LocationTag + // @name sign_glowing + // @input ElementTag(Boolean) + // @description + // Changes whether the sign at the location is glowing. + // For MC 1.20+, this sets the glowing status on the front of the sign. + // To set the glowing status of the back, see <@link mechanism LocationTag.sign_glowing_back>. + // @tags + // + // + // --> + tagProcessor.registerMechanism("sign_glowing", false, ElementTag.class, (object, mechanism, input) -> { + if (mechanism.requireBoolean()) { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("'sign_glowing' mechanism can only be called on Sign blocks."); + return; + } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + sign.getSide(Side.FRONT).setGlowingText(input.asBoolean()); + } + else { + sign.setGlowingText(input.asBoolean()); + } + sign.update(); + } + }); + + // <--[mechanism] + // @object LocationTag + // @name sign_glow_color + // @input ElementTag + // @description + // Changes the glow color of a sign. + // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. + // If a sign is not glowing, this is equivalent to applying a chat color to the sign. + // Use <@link mechanism LocationTag.sign_glowing> to toggle whether the sign is glowing. + // For MC 1.20+, this sets the color on the front of the sign. + // To set the color of the back, see <@link mechanism LocationTag.sign_glow_color_back>. + // @tags + // + // + // --> + tagProcessor.registerMechanism("sign_glow_color", false, ElementTag.class, (object, mechanism, input) -> { + if (mechanism.requireEnum(DyeColor.class)) { + if (!(object.getBlockState() instanceof Sign sign)) { + mechanism.echoError("'sign_glow_color' mechanism can only be called on Sign blocks."); + return; + } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + sign.getSide(Side.FRONT).setColor(input.asEnum(DyeColor.class)); + } + else { + sign.setColor(mechanism.getValue().asEnum(DyeColor.class)); + } + sign.update(); + } + }); } public static final ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); @@ -4830,33 +5046,6 @@ public void adjust(Mechanism mechanism) { state.update(); } - // <--[mechanism] - // @object LocationTag - // @name sign_contents - // @input ListTag - // @description - // Sets the contents of a sign block. - // @tags - // - // --> - if (mechanism.matches("sign_contents") && getBlockState() instanceof Sign) { - Sign state = (Sign) getBlockState(); - for (int i = 0; i < 4; i++) { - PaperAPITools.instance.setSignLine(state, i, ""); - } - ListTag list = mechanism.valueAsType(ListTag.class); - CoreUtilities.fixNewLinesToListSeparation(list); - if (list.size() > 4) { - mechanism.echoError("Sign can only hold four lines!"); - } - else { - for (int i = 0; i < list.size(); i++) { - PaperAPITools.instance.setSignLine(state, i, list.get(i)); - } - } - state.update(); - } - // <--[mechanism] // @object LocationTag // @name skull_skin @@ -5503,53 +5692,6 @@ else if (state instanceof Dropper) { } } - // <--[mechanism] - // @object LocationTag - // @name sign_glowing - // @input ElementTag(Boolean) - // @description - // Changes whether the sign at the location is glowing. - // @tags - // - // - // --> - if (mechanism.matches("sign_glowing") && mechanism.requireBoolean()) { - BlockState state = getBlockState(); - if (!(state instanceof Sign)) { - mechanism.echoError("'sign_glowing' mechanism can only be called on Sign blocks."); - } - else { - Sign sign = (Sign) state; - sign.setGlowingText(mechanism.getValue().asBoolean()); - sign.update(); - } - } - - // <--[mechanism] - // @object LocationTag - // @name sign_glow_color - // @input ElementTag - // @description - // Changes the glow color of a sign. - // For the list of possible colors, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/DyeColor.html>. - // If a sign is not glowing, this is equivalent to applying a chat color to the sign. - // Use <@link mechanism LocationTag.sign_glowing> to toggle whether the sign is glowing. - // @tags - // - // - // --> - if (mechanism.matches("sign_glow_color") && mechanism.requireEnum(DyeColor.class)) { - BlockState state = getBlockState(); - if (!(state instanceof Sign)) { - mechanism.echoError("'sign_glow_color' mechanism can only be called on Sign blocks."); - } - else { - Sign sign = (Sign) state; - sign.setColor(mechanism.getValue().asEnum(DyeColor.class)); - sign.update(); - } - } - // <--[mechanism] // @object LocationTag // @name structure_block_data diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java index 477c8bb129..3f3158ea99 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java @@ -260,6 +260,7 @@ public static void registerMainProperties() { PropertyParser.registerProperty(ItemScript.class, ItemTag.class); PropertyParser.registerProperty(ItemSignContents.class, ItemTag.class); // Special case handling in ItemComponentsPatch if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + PropertyParser.registerProperty(ItemSignContentsBack.class, ItemTag.class); PropertyParser.registerProperty(ItemSignIsWaxed.class, ItemTag.class); // Special case handling in ItemComponentsPatch } registerItemProperty(ItemSkullskin.class, "profile"); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContents.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContents.java index 9774eccaf2..ce90750742 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContents.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContents.java @@ -1,84 +1,55 @@ package com.denizenscript.denizen.objects.properties.item; import com.denizenscript.denizen.utilities.PaperAPITools; -import com.denizenscript.denizencore.utilities.debugging.Debug; import com.denizenscript.denizen.objects.ItemTag; import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ListTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.tags.Attribute; import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.block.Sign; import org.bukkit.inventory.meta.BlockStateMeta; import java.util.Arrays; -public class ItemSignContents implements Property { +public class ItemSignContents extends ItemProperty { - public static boolean describes(ObjectTag item) { - return item instanceof ItemTag - && ((ItemTag) item).getItemMeta() instanceof BlockStateMeta - && ((BlockStateMeta) ((ItemTag) item).getItemMeta()).getBlockState() instanceof Sign; - } - - public static ItemSignContents getFrom(ObjectTag _item) { - if (!describes(_item)) { - return null; - } - else { - return new ItemSignContents((ItemTag) _item); - } - } + // <--[property] + // @object ItemTag + // @name sign_contents + // @input ListTag + // @description + // Controls the contents of a sign item. + // For MC 1.20+, this is the contents on the front of the sign. + // For the back of the sign, see <@link property ItemTag.sign_contents_back>. + // --> - public static final String[] handledTags = new String[] { - "sign_contents" - }; - - public static final String[] handledMechs = new String[] { - "sign_contents" - }; - - public ListTag getSignContents() { - return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines((Sign) ((BlockStateMeta) item.getItemMeta()).getBlockState())), true); + public static boolean describes(ItemTag item) { + return item.getItemMeta() instanceof BlockStateMeta blockStateMeta + && blockStateMeta.getBlockState() instanceof Sign; } - public ItemSignContents(ItemTag _item) { - item = _item; + @Override + public ListTag getPropertyValue() { + return new ListTag(Arrays.asList(PaperAPITools.instance.getSignLines((Sign) ((BlockStateMeta) getItemMeta()).getBlockState())), true); } - ItemTag item; - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - if (attribute == null) { - return null; + public void setPropertyValue(ListTag value, Mechanism mechanism) { + BlockStateMeta bsm = ((BlockStateMeta) getItemMeta()); + Sign sign = (Sign) bsm.getBlockState(); + for (int i = 0; i < 4; i++) { + PaperAPITools.instance.setSignLine(sign, i, ""); } - - // <--[tag] - // @attribute - // @returns ListTag - // @mechanism ItemTag.sign_contents - // @group properties - // @description - // Returns a list of lines on a sign item. - // --> - if (attribute.startsWith("sign_contents")) { - return getSignContents().getObjectAttribute(attribute.fulfill(1)); + CoreUtilities.fixNewLinesToListSeparation(value); + if (value.size() > 4) { + mechanism.echoError("Sign can only hold four lines!"); } - - return null; - } - - @Override - public String getPropertyString() { - for (String line : getSignContents()) { - if (line.length() > 0) { - return getSignContents().identify(); + else { + for (int i = 0; i < value.size(); i++) { + PaperAPITools.instance.setSignLine(sign, i, value.get(i)); } } - return null; + bsm.setBlockState(sign); + getItemStack().setItemMeta(bsm); } @Override @@ -86,36 +57,7 @@ public String getPropertyId() { return "sign_contents"; } - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object ItemTag - // @name sign_contents - // @input ListTag - // @description - // Sets the contents of a sign item. - // @tags - // - // --> - if (mechanism.matches("sign_contents")) { - BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta()); - Sign sign = (Sign) bsm.getBlockState(); - for (int i = 0; i < 4; i++) { - PaperAPITools.instance.setSignLine(sign, i, ""); - } - ListTag list = mechanism.valueAsType(ListTag.class); - CoreUtilities.fixNewLinesToListSeparation(list); - if (list.size() > 4) { - Debug.echoError("Sign can only hold four lines!"); - } - else { - for (int i = 0; i < list.size(); i++) { - PaperAPITools.instance.setSignLine(sign, i, list.get(i)); - } - } - bsm.setBlockState(sign); - item.setItemMeta(bsm); - } + public static void register() { + autoRegister("sign_contents", ItemSignContents.class, ListTag.class, false); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContentsBack.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContentsBack.java new file mode 100644 index 0000000000..ccb3039b3e --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemSignContentsBack.java @@ -0,0 +1,59 @@ +package com.denizenscript.denizen.objects.properties.item; + +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizen.utilities.PaperAPITools; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.core.ListTag; +import org.bukkit.block.Sign; +import org.bukkit.inventory.meta.BlockStateMeta; + +import java.util.Arrays; + +public class ItemSignContentsBack extends ItemProperty { + + // <--[property] + // @object ItemTag + // @name sign_contents_back + // @input ListTag + // @description + // Controls the contents of a sign item. + // For the front of the sign, see <@link property ItemTag.sign_contents>. + // --> + + public static boolean describes(ItemTag item) { + return item.getItemMeta() instanceof BlockStateMeta blockStateMeta + && blockStateMeta.getBlockState() instanceof Sign; + } + + @Override + public ListTag getPropertyValue() { + Sign sign = (((Sign) ((BlockStateMeta) getItemMeta()).getBlockState())); + return new ListTag(Arrays.asList(PaperAPITools.instance.getBackSignLines(sign)), true); + } + + @Override + public void setPropertyValue(ListTag value, Mechanism mechanism) { + BlockStateMeta meta = ((BlockStateMeta) getItemMeta()); + Sign sign = (Sign) meta.getBlockState(); + for (int i = 0; i < 4; i++) { + PaperAPITools.instance.setBackSignLine(sign, i, ""); + } + if (value.size() > 4) { + mechanism.echoError("Sign can only hold four lines!"); + } + for (int i = 0; i < value.size(); i++) { + PaperAPITools.instance.setBackSignLine(sign, i, value.get(i)); + } + meta.setBlockState(sign); + getItemStack().setItemMeta(meta); + } + + @Override + public String getPropertyId() { + return "sign_contents_back"; + } + + public static void register() { + autoRegister("sign_contents_back", ItemSignContentsBack.class, ListTag.class, false); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CopyBlockCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CopyBlockCommand.java index 05e42edccb..b043cb90f4 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CopyBlockCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CopyBlockCommand.java @@ -1,5 +1,7 @@ package com.denizenscript.denizen.scripts.commands.world; +import com.denizenscript.denizen.nms.NMSHandler; +import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.utilities.PaperAPITools; import com.denizenscript.denizen.utilities.blocks.FullBlockData; import com.denizenscript.denizencore.utilities.debugging.Debug; @@ -12,6 +14,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.*; +import org.bukkit.block.sign.Side; import org.bukkit.inventory.InventoryHolder; import java.util.ArrayList; @@ -110,6 +113,11 @@ else if (sourceState instanceof Sign) { for (String line : ((Sign) sourceState).getLines()) { PaperAPITools.instance.setSignLine(((Sign) updateState), n++, line); } + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + for (String line : ((Sign) sourceState).getSide(Side.BACK).getLines()) { + PaperAPITools.instance.setBackSignLine(((Sign) updateState), n++, line); + } + } } else if (sourceState instanceof Skull) { ((Skull) updateState).setSkullType(((Skull) sourceState).getSkullType()); diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java index 6f6877e768..140debd218 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java @@ -12,6 +12,7 @@ import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.*; import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -85,11 +86,27 @@ public String getPlayerListName(Player player) { } public String[] getSignLines(Sign sign) { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + return sign.getSide(Side.FRONT).getLines(); + } return sign.getLines(); } + public String[] getBackSignLines(Sign sign) { + return sign.getSide(Side.BACK).getLines(); + } + public void setSignLine(Sign sign, int line, String text) { - sign.setLine(line, text == null ? "" : text); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { + sign.getSide(Side.FRONT).setLine(line, text == null ? "" : text); + } + else { + sign.setLine(line, text == null ? "" : text); + } + } + + public void setBackSignLine(Sign sign, int line, String text) { + sign.getSide(Side.BACK).setLine(line, text == null ? "" : text); } public void sendResourcePack(Player player, String url, String hash, boolean forced, String prompt) { @@ -237,7 +254,7 @@ public void setMaterialTags(Material type, Set tags) { public void addLink(ServerLinks links, String display, URI uri) { links.addLink(display, uri); } - + public double[] getRecentTps() { return NMSHandler.instance.getRecentTps(); }