diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntitySize.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntitySize.java index 6c58c4fab9..fddcb22826 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntitySize.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntitySize.java @@ -13,7 +13,7 @@ public class EntitySize extends EntityProperty { // <--[property] // @object EntityTag // @name size - // @input ElementTag + // @input ElementTag(Number) // @description // Controls the size of an entity. // Cube-type (slime, magma cube, sulfur cube) mob sizes are between 1 and 127. diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SignCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SignCommand.java index 2904ef64ce..9a73e9271f 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SignCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SignCommand.java @@ -6,18 +6,14 @@ import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizen.objects.properties.material.MaterialDirectional; import com.denizenscript.denizen.utilities.Utilities; -import com.denizenscript.denizencore.exceptions.InvalidArgumentsException; -import com.denizenscript.denizencore.objects.Argument; -import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException; import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; -import com.denizenscript.denizencore.utilities.debugging.Debug; +import com.denizenscript.denizencore.scripts.commands.generator.*; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; +import org.bukkit.Tag; +import org.bukkit.block.*; public class SignCommand extends AbstractCommand { @@ -25,14 +21,15 @@ public class SignCommand extends AbstractCommand { public SignCommand() { setName("sign"); - setSyntax("sign (type:{automatic}/sign_post/wall_sign) (material:) [|...] [] (direction:north/east/south/west)"); + setSyntax("sign (type:{automatic}/sign_post/wall_sign/hanging) (material:) [|...] [] (direction:north/east/south/west)"); setRequiredArguments(1, 5); isProcedural = false; + autoCompile(); } // <--[command] // @Name Sign - // @Syntax sign (type:{automatic}/sign_post/wall_sign) (material:) [|...] [] (direction:north/east/south/west) + // @Syntax sign (type:{automatic}/sign_post/wall_sign/hanging) (material:) [|...] [] (direction:north/east/south/west) // @Required 1 // @Maximum 5 // @Short Modifies a sign. @@ -41,6 +38,8 @@ public SignCommand() { // @Description // Modifies a sign that replaces the text shown on it. If no sign is at the location, it replaces the location with the modified sign. // + // Text lines 1-4 will show on the front of the sign, and lines 5-8 will show on the back (requires MC 1.20+). + // // Specify 'automatic' as a type to use whatever sign type and direction is already placed there. // If there is not already a sign there, defaults to a sign_post. // @@ -59,6 +58,10 @@ public SignCommand() { // - sign "Hello|this is|some|text" // // @Usage + // Use to edit some text on the front and back of an existing sign. + // - sign "Hi!|This is|the|front.|This|is|the|back." + // + // @Usage // Use to show the time on a sign and ensure that it points north. // - sign "I point|North.|System Time<&co>|" <[location]> direction:north // @@ -73,101 +76,23 @@ public void addCustomTabCompletions(TabCompletionsBuilder tab) { tab.addNotesOfType(LocationTag.class); } - private enum Type {AUTOMATIC, SIGN_POST, WALL_SIGN} - - @Override - public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry) { - if (!scriptEntry.hasObject("type") - && arg.matchesEnum(Type.class)) { - scriptEntry.addObject("type", arg.asElement()); - } - else if (!scriptEntry.hasObject("location") - && arg.matchesArgumentType(LocationTag.class)) { - scriptEntry.addObject("location", arg.asType(LocationTag.class).setPrefix("location")); - } - else if (!scriptEntry.hasObject("direction") - && arg.matchesPrefix("direction", "dir")) { - scriptEntry.addObject("direction", arg.asElement()); - } - else if (!scriptEntry.hasObject("material") - && arg.matchesPrefix("material") - && arg.matchesArgumentType(MaterialTag.class)) { - scriptEntry.addObject("material", arg.asType(MaterialTag.class)); - } - else if (!scriptEntry.hasObject("text")) { - scriptEntry.addObject("text", arg.asType(ListTag.class)); - } - else { - arg.reportUnhandled(); - } - } - if (!scriptEntry.hasObject("location")) { - throw new InvalidArgumentsException("Must specify a Sign location!"); - } - if (!scriptEntry.hasObject("text")) { - throw new InvalidArgumentsException("Must specify sign text!"); - } - scriptEntry.defaultObject("type", new ElementTag(Type.AUTOMATIC)); - } - - public void setWallSign(Block sign, BlockFace bf, MaterialTag material) { - sign.setType(material == null ? Material.OAK_WALL_SIGN : material.getMaterial(), false); - MaterialTag signMaterial = new MaterialTag(sign); - MaterialDirectional.getFrom(signMaterial).setFacing(bf); - sign.setBlockData(signMaterial.getModernData()); - } - - public static boolean isStandingSign(Material material) { - switch (material) { - case CRIMSON_SIGN: - case WARPED_SIGN: - case ACACIA_SIGN: - case BIRCH_SIGN: - case DARK_OAK_SIGN: - case JUNGLE_SIGN: - case OAK_SIGN: - case SPRUCE_SIGN: - return true; - default: - return false; - } - } + public enum Type {AUTOMATIC, SIGN_POST, WALL_SIGN, HANGING} - public static boolean isWallSign(Material material) { - switch (material) { - case CRIMSON_WALL_SIGN: - case WARPED_WALL_SIGN: - case ACACIA_WALL_SIGN: - case BIRCH_WALL_SIGN: - case DARK_OAK_WALL_SIGN: - case JUNGLE_WALL_SIGN: - case OAK_WALL_SIGN: - case SPRUCE_WALL_SIGN: - return true; - default: - return false; + public static void autoExecute(ScriptEntry scriptEntry, + @ArgName("type") @ArgPrefixed @ArgDefaultText("automatic") Type type, + @ArgName("material") @ArgPrefixed @ArgDefaultNull MaterialTag material, + @ArgName("text") @ArgLinear @ArgDefaultNull ListTag text, + @ArgName("location") @ArgLinear @ArgDefaultNull LocationTag location, + @ArgName("direction") @ArgPrefixed @ArgDefaultNull String direction) { + if (location == null) { + throw new InvalidArgumentsRuntimeException("Must specify a Sign location!"); } - } - - public static boolean isAnySign(Material material) { - return isStandingSign(material) || isWallSign(material); - } - - @Override - public void execute(final ScriptEntry scriptEntry) { - String direction = scriptEntry.hasObject("direction") ? ((ElementTag) scriptEntry.getObject("direction")).asString() : null; - ElementTag typeElement = scriptEntry.getElement("type"); - ListTag text = scriptEntry.getObjectTag("text"); - LocationTag location = scriptEntry.getObjectTag("location"); - MaterialTag material = scriptEntry.getObjectTag("material"); - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), typeElement, location, db("direction", direction), material, text); + if (text == null) { + throw new InvalidArgumentsRuntimeException("Must specify sign text!"); } - Type type = Type.valueOf(typeElement.asString().toUpperCase()); Block sign = location.getBlock(); if (type != Type.AUTOMATIC || !isAnySign(sign.getType())) { - if (type == Type.WALL_SIGN) { + if (type == Type.WALL_SIGN || (SIGN_SIDES_SUPPORTED && type == Type.HANGING)) { BlockFace bf; if (direction != null) { bf = Utilities.chooseSignRotation(direction); @@ -175,7 +100,12 @@ public void execute(final ScriptEntry scriptEntry) { else { bf = Utilities.chooseSignRotation(sign); } - setWallSign(sign, bf, material); + if (type == Type.WALL_SIGN) { + setWallSign(sign, bf, material); + } + else { + setHangingSign(sign, bf, material); + } } else { sign.setType(material == null ? Material.OAK_SIGN : material.getMaterial(), false); @@ -194,6 +124,54 @@ else if (!isAnySign(sign.getType())) { } } BlockState signState = sign.getState(); - Utilities.setSignLines((Sign) signState, text.toArray(new String[4])); + Utilities.setSignLines((Sign) signState, text.toArray(new String[8])); + } + + public static void setWallSign(Block sign, BlockFace bf, MaterialTag material) { + sign.setType(material == null ? Material.OAK_WALL_SIGN : material.getMaterial(), false); + MaterialTag signMaterial = new MaterialTag(sign); + MaterialDirectional.getFrom(signMaterial).setFacing(bf); + sign.setBlockData(signMaterial.getModernData()); + } + + public static void setHangingSign(Block sign, BlockFace bf, MaterialTag material) { + sign.setType(material == null ? Material.OAK_HANGING_SIGN : material.getMaterial(), false); + MaterialTag signMaterial = new MaterialTag(sign); + MaterialDirectional.getFrom(signMaterial).setFacing(bf); + sign.setBlockData(signMaterial.getModernData()); + } + + public static boolean isStandingSign(Material material) { + for (Material signType : Tag.STANDING_SIGNS.getValues()) { + if (signType == material) { + return true; + } + } + return false; + } + + public static boolean isWallSign(Material material) { + for (Material signType : Tag.WALL_SIGNS.getValues()) { + if (signType == material) { + return true; + } + } + return false; + } + + public static boolean isHangingSign(Material material) { + if (!SIGN_SIDES_SUPPORTED) { + return false; + } + for (Material signType : Tag.CEILING_HANGING_SIGNS.getValues()) { + if (signType == material) { + return true; + } + } + return false; + } + + public static boolean isAnySign(Material material) { + return isStandingSign(material) || isWallSign(material) || isHangingSign(material); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java index 7f3923bcea..2cec02d2b3 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/Utilities.java @@ -379,6 +379,11 @@ public static void setSignLines(Sign sign, String[] lines) { for (int n = 0; n < 4; n++) { PaperAPITools.instance.setSignLine(sign, n, lines[n]); } + if (SignCommand.SIGN_SIDES_SUPPORTED) { + for (int n = 4; n < 8; n++) { + PaperAPITools.instance.setSignBackLine(sign, n, lines[n]); + } + } sign.update(); }