Adds a command for un-waxing a sign
All checks were successful
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good
All checks were successful
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good
This commit is contained in:
@@ -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
|
||||
|
@@ -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<>();
|
||||
}
|
||||
|
||||
}
|
@@ -85,8 +85,8 @@ public class ViewSignCommand implements TabExecutor {
|
||||
/**
|
||||
* Prints the current contents of a sign to a player
|
||||
*
|
||||
* @param sign <p>The sign to print</p>
|
||||
* @param player <p>The player to display the contents to</p>
|
||||
* @param sign <p>The sign to print</p>
|
||||
* @param player <p>The player to display the contents to</p>
|
||||
*/
|
||||
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<Integer, String> placeholders = placeholderSign.placeholders().get(side);
|
||||
for (Map.Entry<Integer, String> entry : placeholders.entrySet()) {
|
||||
lines[entry.getKey()] = entry.getValue();
|
||||
if (placeholders != null) {
|
||||
for (Map.Entry<Integer, String> entry : placeholders.entrySet()) {
|
||||
lines[entry.getKey()] = entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return getSignText(lines, raw);
|
||||
|
@@ -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
|
||||
|
@@ -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 <p>The sign that's changed</p>
|
||||
* @param signSide <p>The side of the sign to get lines from</p>
|
||||
* @param side <p>The side that's processed</p>
|
||||
* @param sign <p>The sign that's changed</p>
|
||||
* @param signSide <p>The side of the sign to get lines from</p>
|
||||
* @param side <p>The side that's processed</p>
|
||||
* @param placeholderSign <p>The placeholder sign corresponding to the sign, if any</p>
|
||||
* @param player <p>The player attempting to paste the sign</p>
|
||||
* @param player <p>The player attempting to paste the sign</p>
|
||||
* @return <p>The final lines, or null if the event was cancelled</p>
|
||||
*/
|
||||
@Nullable
|
||||
|
Reference in New Issue
Block a user