diff --git a/README.md b/README.md index 79a91b7..610483e 100644 --- a/README.md +++ b/README.md @@ -17,21 +17,23 @@ won't be changed unless the player passes all world protection checks. ## Commands -| Command | Arguments | Description | -|--------------|----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| /setSignLine | \ \ \ ... | Sets the text of the sign line (1-4) to the given input. Then right-click the sign to update. | -| /viewSign | \[raw true/false] \[placeholders true/false] | Allows the player to view the full contents and details of the looked at sign. If "raw" is true, formatting codes are displayed. If placeholders is true, stored placeholders are displayed. | -| /copySign | | Allows the player to copy the sign they are currently looking at to another sign, including placeholders, formatting codes, dye and waxed state. | +| Command | Arguments | Description | +|--------------|----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| /setSignLine | \ \ \ ... | Sets the text of the sign line (1-4) to the given input. Then right-click the sign to update. | +| /viewSign | \[raw true/false] \[placeholders true/false] | Shows the full contents and details of the sign you are currently looking at. If "raw" is true, formatting codes are displayed. If placeholders is true, stored placeholders are displayed. | +| /copySign | | Copies the sign you are currently looking at to another sign, including placeholders, formatting codes, dye and waxed state. | +| /unWaxSign | | Removes the wax from the sign you are currently looking at. | ## Permissions -| Permission | Description | -|------------------------------------|---------------------------------------------------------------------------------------------------------------| -| placeholdersigns.* | Gives all permissions. | -| placeholdersigns.edit | Allows unrestricted use of the /setSignLine command. | -| placeholdersigns.edit.use | Allows use of the /setSignLine command. | -| placeholdersigns.edit.bypass-waxed | Allows use of the /setSignLine command on a waxed sign. | -| placeholdersigns.placeholder | Allows a player to make signs containing placeholders. Without this, placeholders are treated as normal text. | -| placeholdersigns.copy | Allows unrestricted use of the /copySign command. | -| placeholdersigns.copy.use | Allows use of the /copySign command. | -| placeholdersigns.copy.bypass-waxed | Allows pasting a sign copied with /copySign onto a waxed sign. | \ No newline at end of file +| Permission | Description | +|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| +| placeholdersigns.* | Gives all permissions. | +| placeholdersigns.edit | Allows unrestricted use of the /setSignLine command. | +| placeholdersigns.edit.use | Allows use of the /setSignLine command. | +| placeholdersigns.edit.bypass-waxed | Allows use of the /setSignLine command on a waxed sign. | +| placeholdersigns.placeholder | Allows a player to make signs containing placeholders. Without this, placeholders are treated as normal text for all commands, and when editing sign text. | +| placeholdersigns.copy | Allows unrestricted use of the /copySign command. | +| placeholdersigns.copy.use | Allows use of the /copySign command. | +| placeholdersigns.copy.bypass-waxed | Allows pasting a sign copied with /copySign onto a waxed sign. | +| placeholdersigns.unwax | Allows use of the /unWaxSign command | \ No newline at end of file diff --git a/src/main/java/net/knarcraft/placeholdersigns/PlaceholderSigns.java b/src/main/java/net/knarcraft/placeholdersigns/PlaceholderSigns.java index 3300f62..ced1a05 100644 --- a/src/main/java/net/knarcraft/placeholdersigns/PlaceholderSigns.java +++ b/src/main/java/net/knarcraft/placeholdersigns/PlaceholderSigns.java @@ -5,6 +5,7 @@ import net.knarcraft.knarlib.formatting.Translator; import net.knarcraft.knarlib.property.ColorConversion; import net.knarcraft.placeholdersigns.command.CopySignCommand; import net.knarcraft.placeholdersigns.command.EditSignCommand; +import net.knarcraft.placeholdersigns.command.UnWaxSignCommand; import net.knarcraft.placeholdersigns.command.ViewSignCommand; import net.knarcraft.placeholdersigns.config.PlaceholderSignMessage; import net.knarcraft.placeholdersigns.handler.PlaceholderSignHandler; @@ -95,6 +96,7 @@ public final class PlaceholderSigns extends JavaPlugin { registerCommand("setSignLine", new EditSignCommand()); registerCommand("viewSign", new ViewSignCommand()); registerCommand("copySign", new CopySignCommand()); + registerCommand("unWaxSign", new UnWaxSignCommand()); } @Override diff --git a/src/main/java/net/knarcraft/placeholdersigns/command/UnWaxSignCommand.java b/src/main/java/net/knarcraft/placeholdersigns/command/UnWaxSignCommand.java new file mode 100644 index 0000000..ff1b606 --- /dev/null +++ b/src/main/java/net/knarcraft/placeholdersigns/command/UnWaxSignCommand.java @@ -0,0 +1,52 @@ +package net.knarcraft.placeholdersigns.command; + +import net.knarcraft.knarlib.formatting.StringFormatter; +import net.knarcraft.placeholdersigns.PlaceholderSigns; +import net.knarcraft.placeholdersigns.config.PlaceholderSignMessage; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/** + * A command for removing the wax on a sign + */ +public class UnWaxSignCommand implements TabExecutor { + + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, + @NotNull String[] strings) { + StringFormatter stringFormatter = PlaceholderSigns.getInstance().getStringFormatter(); + if (!(commandSender instanceof Player player)) { + stringFormatter.displayErrorMessage(commandSender, PlaceholderSignMessage.ERROR_PLAYER_ONLY); + return false; + } + + Block targetBlock = player.getTargetBlockExact(7); + if (targetBlock == null || !(targetBlock.getState() instanceof Sign sign)) { + stringFormatter.displayErrorMessage(commandSender, PlaceholderSignMessage.ERROR_NOT_LOOKING_AT_SIGN); + return false; + } + + sign.setWaxed(false); + sign.update(); + + stringFormatter.displaySuccessMessage(commandSender, PlaceholderSignMessage.SUCCESS_SIGN_UN_WAXED); + return true; + } + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, + @NotNull String[] strings) { + return new ArrayList<>(); + } + +} diff --git a/src/main/java/net/knarcraft/placeholdersigns/command/ViewSignCommand.java b/src/main/java/net/knarcraft/placeholdersigns/command/ViewSignCommand.java index aee0663..38c9d2d 100644 --- a/src/main/java/net/knarcraft/placeholdersigns/command/ViewSignCommand.java +++ b/src/main/java/net/knarcraft/placeholdersigns/command/ViewSignCommand.java @@ -85,8 +85,8 @@ public class ViewSignCommand implements TabExecutor { /** * Prints the current contents of a sign to a player * - * @param sign

The sign to print

- * @param player

The player to display the contents to

+ * @param sign

The sign to print

+ * @param player

The player to display the contents to

*/ private void printSign(@NotNull Sign sign, @NotNull Player player, boolean showRawText, boolean showPlaceholders) { Location location = sign.getLocation(); @@ -161,8 +161,10 @@ public class ViewSignCommand implements TabExecutor { } Map placeholders = placeholderSign.placeholders().get(side); - for (Map.Entry entry : placeholders.entrySet()) { - lines[entry.getKey()] = entry.getValue(); + if (placeholders != null) { + for (Map.Entry entry : placeholders.entrySet()) { + lines[entry.getKey()] = entry.getValue(); + } } return getSignText(lines, raw); diff --git a/src/main/java/net/knarcraft/placeholdersigns/config/PlaceholderSignMessage.java b/src/main/java/net/knarcraft/placeholdersigns/config/PlaceholderSignMessage.java index 870db98..4365b20 100644 --- a/src/main/java/net/knarcraft/placeholdersigns/config/PlaceholderSignMessage.java +++ b/src/main/java/net/knarcraft/placeholdersigns/config/PlaceholderSignMessage.java @@ -62,6 +62,11 @@ public enum PlaceholderSignMessage implements TranslatableMessage { * The message displayed when a protection plugin cancels the sign change event */ ERROR_CANCELLED_BY_PROTECTION, + + /** + * The message displayed when a sign has been successfully un-waxed + */ + SUCCESS_SIGN_UN_WAXED, ; @Override diff --git a/src/main/java/net/knarcraft/placeholdersigns/listener/SignClickListener.java b/src/main/java/net/knarcraft/placeholdersigns/listener/SignClickListener.java index 545648a..c3018dc 100644 --- a/src/main/java/net/knarcraft/placeholdersigns/listener/SignClickListener.java +++ b/src/main/java/net/knarcraft/placeholdersigns/listener/SignClickListener.java @@ -130,11 +130,11 @@ public class SignClickListener implements Listener { /** * Gets the final lines from a sign side, after inserting placeholders and running a sign change event * - * @param sign

The sign that's changed

- * @param signSide

The side of the sign to get lines from

- * @param side

The side that's processed

+ * @param sign

The sign that's changed

+ * @param signSide

The side of the sign to get lines from

+ * @param side

The side that's processed

* @param placeholderSign

The placeholder sign corresponding to the sign, if any

- * @param player

The player attempting to paste the sign

+ * @param player

The player attempting to paste the sign

* @return

The final lines, or null if the event was cancelled

*/ @Nullable diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1509941..6d49f74 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -18,6 +18,9 @@ commands: usage: / permission: placeholdersigns.copy.use description: Copies all sign information from one sign to another + unWaxSign: + usage: / + permission: placeholdersigns.unwax permissions: placeholdersigns.*: @@ -27,6 +30,7 @@ permissions: - placeholdersigns.placeholder - placeholdersigns.view - placeholdersigns.copy + - placeholdersigns.unwax default: op placeholdersigns.edit: description: Allows a player to use the /editSign command without restriction @@ -57,4 +61,7 @@ permissions: default: false placeholdersigns.copy.bypass-waxed: description: Allows a player to use the /copySign command and paste onto a waxed sign + default: false + placeholdersigns.unwax: + description: Allows a player to remove the wax from a sign default: false \ No newline at end of file diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 7d5eff5..61c8c9f 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -17,4 +17,5 @@ en: ERROR_NOT_LOOKING_AT_SIGN: "You are not currently looking at a sign" SUCCESS_CLICK_SIGN_TO_PASTE: "&7Click the sign you want to paste onto" SUCCESS_SIGN_PASTED: "&7Sign pasted!" - ERROR_CANCELLED_BY_PROTECTION: "A protection plugin blocked the sign change" \ No newline at end of file + ERROR_CANCELLED_BY_PROTECTION: "A protection plugin blocked the sign change" + SUCCESS_SIGN_UN_WAXED: "&7The sign was successfully un-waxed" \ No newline at end of file