Adds a command for un-waxing a sign
All checks were successful
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-04-28 11:22:18 +02:00
parent 66c45e00e2
commit 14f9fa8833
8 changed files with 95 additions and 24 deletions

View File

@ -18,20 +18,22 @@ won't be changed unless the player passes all world protection checks.
## Commands
| Command | Arguments | Description |
|--------------|----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|--------------|----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| /setSignLine | \<line> \<text> \<text> ... | 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. |
| /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.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 |

View File

@ -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

View File

@ -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<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] strings) {
return new ArrayList<>();
}
}

View File

@ -161,9 +161,11 @@ public class ViewSignCommand implements TabExecutor {
}
Map<Integer, String> placeholders = placeholderSign.placeholders().get(side);
if (placeholders != null) {
for (Map.Entry<Integer, String> entry : placeholders.entrySet()) {
lines[entry.getKey()] = entry.getValue();
}
}
return getSignText(lines, raw);
}

View File

@ -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

View File

@ -18,6 +18,9 @@ commands:
usage: /<command>
permission: placeholdersigns.copy.use
description: Copies all sign information from one sign to another
unWaxSign:
usage: /<command>
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
@ -58,3 +62,6 @@ permissions:
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

View File

@ -18,3 +18,4 @@ en:
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"
SUCCESS_SIGN_UN_WAXED: "&7The sign was successfully un-waxed"