Skip to content

Commit

Permalink
Fix #26 - Prevent parsing of placeholders with /svs info
Browse files Browse the repository at this point in the history
  • Loading branch information
EpiCanard committed Dec 15, 2020
1 parent 4b6ba16 commit 7a56ab8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 4
10 changes: 10 additions & 0 deletions src/main/java/de/czymm/serversigns/ServerSignsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ public void serverCommand(String command) {
this.getServer().dispatchCommand(getServer().getConsoleSender(), command);
}

public void sendBasic(CommandSender sender, String message) {
if (message.isEmpty()) return;
sender.sendMessage((config.getMessagePrefix().isEmpty() ? "" : ChatColor.DARK_GREEN + config.getMessagePrefix() + " ") + ChatColor.YELLOW + config.getMessageColour() + MessageFormatter.toColor(message));
}

public void sendBasic(CommandSender to, Collection<String> messages) {
for (String str : messages)
sendBasic(to, str);
}

public void send(CommandSender sender, String message) {
if (message.isEmpty()) return;
sender.sendMessage((config.getMessagePrefix().isEmpty() ? "" : ChatColor.DARK_GREEN + config.getMessagePrefix() + " ") + ChatColor.YELLOW + config.getMessageColour() + messageFormatter.format(sender, message));
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/de/czymm/serversigns/listeners/AdminListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void handleAdminInteract(Location clicked, CommandSender recipient, UUID
}

if (!sign.getPermissionMessage().isEmpty())
plugin.send(recipient, "&6No Perm Message: &e" + sign.getPermissionMessage());
plugin.sendBasic(recipient, "&6No Perm Message: &e" + sign.getPermissionMessage());

if (sign.getPrice() != 0)
plugin.send(recipient, "&6Price: &e" + sign.getPrice());
Expand All @@ -307,7 +307,7 @@ public void handleAdminInteract(Location clicked, CommandSender recipient, UUID
plugin.send(recipient, "&6Xp Cost: &e" + sign.getXP());

if (sign.isConfirmation())
plugin.send(recipient, "&6Confirmation: &etrue" + (sign.getConfirmationMessage().isEmpty() ? "" : ", &6Message: &e" + sign.getConfirmationMessage()));
plugin.sendBasic(recipient, "&6Confirmation: &etrue" + (sign.getConfirmationMessage().isEmpty() ? "" : ", &6Message: &e" + sign.getConfirmationMessage()));

if (sign.getCooldown() != 0)
plugin.send(recipient, "&6Cooldown: &e" + TimeUtils.getTimeSpan(sign.getCooldown() * 1000, TimeUtils.TimeUnit.SECONDS, TimeUtils.TimeUnit.YEARS, true, false));
Expand All @@ -328,7 +328,7 @@ public void handleAdminInteract(Location clicked, CommandSender recipient, UUID
if (!sign.getPriceItems().isEmpty()) {
plugin.send(recipient, "&6Price Items: ");
for (ItemStack stack : sign.getPriceItems()) {
plugin.send(recipient, ItemUtils.getDescription(stack, plugin.config.getMessageColour()));
plugin.sendBasic(recipient, ItemUtils.getDescription(stack, plugin.config.getMessageColour()));
}

plugin.send(recipient, "&6Price Item Criteria: &a&oTrue &c&oFalse");
Expand Down Expand Up @@ -366,12 +366,12 @@ public void handleAdminInteract(Location clicked, CommandSender recipient, UUID
}

if (!sign.getInputOptions().isEmpty()) {
plugin.send(recipient, "&6'Option Menus' (Q+As): ");
plugin.sendBasic(recipient, "&6'Option Menus' (Q+As): ");
for (PlayerInputOptions options : sign.getInputOptions()) {
plugin.send(recipient, "&bID: " + options.getName());
plugin.send(recipient, " &9" + options.getQuestion());
plugin.sendBasic(recipient, "&bID: " + options.getName());
plugin.sendBasic(recipient, " &9" + options.getQuestion());
for (int k = 0; k < options.getAnswersLength(); k++) {
plugin.send(recipient, " &3" + options.getAnswerLabel(k) + " - " + options.getAnswerDescription(k));
plugin.sendBasic(recipient, " &3" + options.getAnswerLabel(k) + " - " + options.getAnswerDescription(k));
}
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ public void handleAdminInteract(Location clicked, CommandSender recipient, UUID
}
builder.append("&7").append(line.getInteractValue() == 0 ? "both " : line.getInteractValue() == 1 ? "left " : "right ");
builder.append("&f").append(line.getUnformattedCommand());
plugin.send(recipient, builder.toString().trim());
plugin.sendBasic(recipient, builder.toString().trim());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ private boolean canAffordPriceItem(Player player, ServerSign sign) {
if (sign.shouldDisplayInternalMessages()) {
plugin.send(player, Message.NOT_ENOUGH_ITEMS);
for (ItemStack required : leftover) {
plugin.send(player, ItemUtils.getDescription(required, plugin.config.getMessageColour()));
plugin.sendBasic(player, ItemUtils.getDescription(required, plugin.config.getMessageColour()));
}
}
return false;
Expand Down Expand Up @@ -676,4 +676,4 @@ private List<TaskManagerTask> removePermissions(UUID player, long timestamp, Lis
}
return tasks;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public class BasicMessageFormatter extends MessageFormatter {
*/
@Override
public String format(final CommandSender player, final String message) {
return this.toColor(message);
return MessageFormatter.toColor(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public abstract class MessageFormatter {

protected String toColor(final String message) {
public static String toColor(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public class PlaceholderMessageFormatter extends MessageFormatter {
*/
@Override
public String format(final CommandSender player, final String message) {
return PlaceholderAPI.setPlaceholders((Player)player, this.toColor(message));
return PlaceholderAPI.setPlaceholders((Player)player, MessageFormatter.toColor(message));
}
}

0 comments on commit 7a56ab8

Please sign in to comment.