diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 5a85a3351..413d520af 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents; import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener; import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener; import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents; +import com.github.intellectualsites.plotsquared.bukkit.placeholders.PlaceholderFormatter; import com.github.intellectualsites.plotsquared.bukkit.placeholders.Placeholders; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager; @@ -31,6 +32,7 @@ import com.github.intellectualsites.plotsquared.configuration.ConfigurationSecti import com.github.intellectualsites.plotsquared.plot.IPlotMain; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.config.ChatFormatter; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; @@ -160,6 +162,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new Placeholders(this).register(); + if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { + ChatFormatter.formatters.add(new PlaceholderFormatter()); + } PlotSquared.log(Captions.PREFIX + "&6PlaceholderAPI found! Hook activated."); } else { PlotSquared.log(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated."); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index f59c2e29e..f897f89d3 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -187,7 +187,9 @@ public class BukkitPlayer extends PlotPlayer { return this.player.isPermissionSet(permission); } - @Override public void sendMessage(final String message) { + @Override public void sendMessage(String message) { + message = message.replace('\u2010', '%') + .replace('\u2020', '&').replace('\u2030', '&'); if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || ( System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) { setMeta("lastMessage", message); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/placeholders/PlaceholderFormatter.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/placeholders/PlaceholderFormatter.java new file mode 100644 index 000000000..f4844aecb --- /dev/null +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/placeholders/PlaceholderFormatter.java @@ -0,0 +1,23 @@ +package com.github.intellectualsites.plotsquared.bukkit.placeholders; + +import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; +import com.github.intellectualsites.plotsquared.plot.config.ChatFormatter; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.entity.Player; + +public class PlaceholderFormatter implements ChatFormatter { + + @Override public void format(final ChatContext context) { + final PlotPlayer recipient = context.getRecipient(); + if (recipient instanceof BukkitPlayer) { + if (context.isRawOutput()) { + context.setMessage(context.getMessage().replace('%', '\u2010')); + } else { + final Player player = ((BukkitPlayer) recipient).player; + context.setMessage(PlaceholderAPI.setPlaceholders(player, context.getMessage())); + } + } + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index 691daa93e..d09918d3d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -114,7 +114,7 @@ public abstract class Command { return this.id; } - public List getCommands(CommandCaller player) { + public List getCommands(PlotPlayer player) { List commands = new ArrayList<>(); for (Command cmd : this.allCommands) { if (cmd.canExecute(player, false)) { @@ -124,7 +124,7 @@ public abstract class Command { return commands; } - public List getCommands(CommandCategory category, CommandCaller player) { + public List getCommands(CommandCategory category, PlotPlayer player) { List commands = getCommands(player); if (category != null) { commands.removeIf(command -> command.category != category); @@ -347,7 +347,7 @@ public abstract class Command { return CompletableFuture.completedFuture(true); } - public boolean checkArgs(CommandCaller player, String[] args) { + public boolean checkArgs(PlotPlayer player, String[] args) { Argument[] reqArgs = getRequiredArguments(); if (reqArgs != null && reqArgs.length > 0) { boolean failed = args.length < reqArgs.length; @@ -440,7 +440,7 @@ public abstract class Command { return null; } - public boolean canExecute(CommandCaller player, boolean message) { + public boolean canExecute(PlotPlayer player, boolean message) { if (player == null) { return true; } @@ -595,7 +595,7 @@ public abstract class Command { this.args = args; } - public void perform(CommandCaller player) { + public void perform(PlotPlayer player) { if (player != null && message != null) { message.send(player, args); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index ce1c20a68..681c2dd33 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -21,6 +21,7 @@ import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGe import com.github.intellectualsites.plotsquared.plot.listener.WESubscriber; import com.github.intellectualsites.plotsquared.plot.logger.ILogger; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -311,7 +312,7 @@ import java.util.zip.ZipInputStream; } PlotSquared.log(Captions.PREFIX + Captions - .format(Captions.ENABLED.getTranslated(), IMP.getPluginName())); + .format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(), IMP.getPluginName())); } /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index 294e4668a..8f751a316 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -220,11 +220,11 @@ public class Auto extends SubCommand { return true; } if (!Permissions.hasPermission(player, - Captions.format(Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) + Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)); + Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)); return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java index c6acc1010..367cbdea7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java @@ -59,7 +59,7 @@ public class Claim extends SubCommand { } if (!Permissions .hasPermission(player, Captions - .format(Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) + .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { return sendMessage(player, Captions.NO_SCHEMATIC_PERMISSION, schematic); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index bfe3cc4c9..04d752155 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -41,7 +41,7 @@ public class FlagCmd extends SubCommand { key = key.toLowerCase(); value = value.toLowerCase(); String perm = Captions - .format(Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), value.toLowerCase()); if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { try { @@ -54,7 +54,7 @@ public class FlagCmd extends SubCommand { final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric; if (!result) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), value.toLowerCase())); } return result; @@ -67,12 +67,12 @@ public class FlagCmd extends SubCommand { Set parsedBlocks = blockListFlag.parseValue(value); for (final BlockType block : parsedBlocks) { final String permission = Captions - .format(Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), block.toString().toLowerCase()); final boolean result = Permissions.hasPermission(player, permission); if (!result) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), value.toLowerCase())); return false; } @@ -82,7 +82,7 @@ public class FlagCmd extends SubCommand { final boolean result = Permissions.hasPermission(player, perm); if (!result) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(), value.toLowerCase())); } return result; @@ -200,11 +200,11 @@ public class FlagCmd extends SubCommand { return false; } if (!Permissions.hasPermission(player, Captions - .format(Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), args[1].toLowerCase()))) { if (args.length != 3) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), + .format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(), args[1].toLowerCase())); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java index a3d8855ec..fc8fb6b50 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java @@ -33,9 +33,9 @@ import java.util.concurrent.CompletableFuture; case "add": case "check": if (!Permissions.hasPermission(player, - Captions.format(Captions.PERMISSION_GRANT.getTranslated(), arg0))) { + Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0))) { Captions.NO_PERMISSION.send(player, - Captions.format(Captions.PERMISSION_GRANT.getTranslated(), arg0)); + Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0)); return CompletableFuture.completedFuture(false); } if (args.length > 2) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java index 7949df513..d2f0e5a71 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -21,7 +20,7 @@ public class Help extends Command { super(parent, true); } - @Override public boolean canExecute(CommandCaller player, boolean message) { + @Override public boolean canExecute(PlotPlayer player, boolean message) { return true; } @@ -56,7 +55,7 @@ public class Help extends Command { return CompletableFuture.completedFuture(true); } - public CompletableFuture displayHelp(final CommandCaller player, final String catRaw, final int page) { + public CompletableFuture displayHelp(final PlotPlayer player, final String catRaw, final int page) { return CompletableFuture.supplyAsync(() -> { String cat = catRaw; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index 8230922c6..fefcea46e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -138,9 +138,9 @@ public class ListCmd extends SubCommand { } if (!Permissions .hasPermission(player, - Captions.format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { + Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); + Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); return false; } plots = new ArrayList<>(PlotSquared.get().getPlots(world)); @@ -163,9 +163,9 @@ public class ListCmd extends SubCommand { } if (!Permissions .hasPermission(player, - Captions.format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { + Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); + Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world)); return false; } plots = area == null ? new ArrayList() : new ArrayList<>(area.getPlots()); @@ -311,9 +311,9 @@ public class ListCmd extends SubCommand { } if (!Permissions .hasPermission(player, Captions - .format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0]))) { + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0]))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0])); + .format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0])); return false; } plots = new ArrayList<>(PlotSquared.get().getPlots(args[0])); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java index dd060c88e..c262d6018 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; @@ -283,7 +282,7 @@ public class MainCommand extends Command { return CompletableFuture.completedFuture(true); } - @Override public boolean canExecute(CommandCaller player, boolean message) { + @Override public boolean canExecute(PlotPlayer player, boolean message) { return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java index 438086b43..c633ff61e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java @@ -51,9 +51,9 @@ import java.util.stream.IntStream; for (String component : components) { if (component.equalsIgnoreCase(args[0])) { if (!Permissions.hasPermission(player, Captions - .format(Captions.PERMISSION_SET_COMPONENT.getTranslated(), component))) { + .format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), component))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions - .format(Captions.PERMISSION_SET_COMPONENT.getTranslated(), + .format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), component)); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java index 8ec4bee2c..cfb45fa95 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SetCommand.java @@ -19,9 +19,9 @@ public abstract class SetCommand extends SubCommand { if (!plot.hasOwner()) { if (!Permissions .hasPermission(player, - Captions.format(Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { + Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); + Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); MainUtil.sendMessage(player, Captions.PLOT_NOT_CLAIMED); return false; } @@ -29,9 +29,9 @@ public abstract class SetCommand extends SubCommand { if (!plot.isOwner(player.getUUID())) { if (!Permissions .hasPermission(player, - Captions.format(Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { + Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.format(Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); + Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId())); MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 000555a1b..77ead6ca6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -1,9 +1,9 @@ package com.github.intellectualsites.plotsquared.plot.config; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.io.File; @@ -11,8 +11,6 @@ import java.io.IOException; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.Set; /** @@ -655,32 +653,27 @@ public enum Captions { this(defaultString, true, category.toLowerCase()); } - public static String format(String message, Object... args) { - if (args.length == 0) { - return message; + public static String formatRaw(PlotPlayer recipient, String message, Object... args) { + final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, true); + for (final ChatFormatter chatFormatter : ChatFormatter.formatters) { + chatFormatter.format(chatContext); } - Map map = new LinkedHashMap<>(); - for (int i = args.length - 1; i >= 0; i--) { - String arg = "" + args[i]; - if (arg.isEmpty()) { - map.put("%s" + i, ""); - } else { - arg = Captions.color(arg); - map.put("%s" + i, arg); - } - if (i == 0) { - map.put("%s", arg); - } - } - message = StringMan.replaceFromMap(message, map); - return message; + return chatContext.getMessage(); } - public static String format(Captions caption, Object... args) { + public static String format(PlotPlayer recipient, String message, Object... args) { + final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, false); + for (final ChatFormatter chatFormatter : ChatFormatter.formatters) { + chatFormatter.format(chatContext); + } + return chatContext.getMessage(); + } + + public static String format(PlotPlayer recipient, Captions caption, Object... args) { if (caption.usePrefix() && caption.translatedString.length() > 0) { - return Captions.PREFIX.getTranslated() + format(caption.translatedString, args); + return Captions.PREFIX.getTranslated() + format(recipient, caption.translatedString, args); } else { - return format(caption.translatedString, args); + return format(recipient, caption.translatedString, args); } } @@ -794,12 +787,12 @@ public enum Captions { return this.category; } - public void send(CommandCaller caller, String... args) { + public void send(PlotPlayer caller, String... args) { send(caller, (Object[]) args); } - public void send(CommandCaller caller, Object... args) { - String msg = format(this, args); + public void send(PlotPlayer caller, Object... args) { + String msg = format(caller, this, args); if (caller == null) { PlotSquared.log(msg); } else { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ChatFormatter.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ChatFormatter.java new file mode 100644 index 000000000..e275e8a17 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ChatFormatter.java @@ -0,0 +1,27 @@ +package com.github.intellectualsites.plotsquared.plot.config; + +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +@FunctionalInterface public interface ChatFormatter { + + Collection formatters = new ArrayList<>(Collections.singletonList(new PlotSquaredChatFormatter())); + + void format(ChatContext context); + + @AllArgsConstructor final class ChatContext { + + @Getter private final PlotPlayer recipient; + @Getter @Setter private String message; + @Getter private final Object[] args; + @Getter private final boolean rawOutput; + + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/PlotSquaredChatFormatter.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/PlotSquaredChatFormatter.java new file mode 100644 index 000000000..714418f9c --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/PlotSquaredChatFormatter.java @@ -0,0 +1,35 @@ +package com.github.intellectualsites.plotsquared.plot.config; + +import com.github.intellectualsites.plotsquared.plot.util.StringMan; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class PlotSquaredChatFormatter implements ChatFormatter { + + @Override public void format(final ChatContext context) { + if (context.isRawOutput()) { + context.setMessage(context.getMessage().replace('&', '\u2020').replace('\u00A7', '\u2030')); + } + if (context.getArgs().length == 0) { + return; + } + final Map map = new LinkedHashMap<>(); + for (int i = context.getArgs().length - 1; i >= 0; i--) { + String arg = "" + context.getArgs()[i]; + if (arg.isEmpty()) { + map.put("%s" + i, ""); + } else { + if (!context.isRawOutput()) { + arg = Captions.color(arg); + } + map.put("%s" + i, arg); + } + if (i == 0) { + map.put("%s", arg); + } + } + context.setMessage(StringMan.replaceFromMap(context.getMessage(), map)); + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java index cd7237bc5..9eb51662e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java @@ -347,5 +347,7 @@ public class Settings extends Config { @Comment("Delete plots when a player is banned") public static boolean BAN_DELETER = false; @Comment({"Prevent possibly unsafe blocks from being used in plot components", "Can be bypassed with `/plot debugallowunsafe`"}) public static boolean PREVENT_UNSAFE = true; + @Comment("Allows PlaceholderAPI placeholders to be used in captions, flags, etc") + public static boolean EXTERNAL_PLACEHOLDERS = true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java index 443a93f5b..db7b2023f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java @@ -622,7 +622,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { if (getMeta("teleportOnLogin", true)) { teleport(location); sendMessage( - Captions.format(Captions.TELEPORTED_TO_PLOT.getTranslated()) + Captions.format(PlotPlayer.this, Captions.TELEPORTED_TO_PLOT.getTranslated()) + " (quitLoc) (" + plotX + "," + plotZ + ")"); } @@ -634,7 +634,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { if (getMeta("teleportOnLogin", true)) { if (plot.isLoaded()) { teleport(location); - sendMessage(Captions.format( + sendMessage(Captions.format(PlotPlayer.this, Captions.TELEPORTED_TO_PLOT.getTranslated()) + " (quitLoc-unloaded) (" + plotX + "," + plotZ + ")"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index 0187f67b4..fd4a9bb73 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -88,7 +88,7 @@ public abstract class EventUtil { .getArea() instanceof SinglePlotArea)) { TaskManager.runTask(() -> plot.teleportPlayer(player)); MainUtil.sendMessage(player, - Captions.format(Captions.TELEPORTED_TO_ROAD.getTranslated()) + " (on-login) " + "(" + plot.getId().x + ";" + plot + Captions.format(player, Captions.TELEPORTED_TO_ROAD.getTranslated()) + " (on-login) " + "(" + plot.getId().x + ";" + plot .getId().y + ")"); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java index 38db9b9f4..531f60c97 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/LegacyConverter.java @@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.configuration.ConfigurationSecti import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; import com.sk89q.worldedit.world.block.BlockState; import lombok.NonNull; @@ -82,7 +83,7 @@ import java.util.Map; final BlockBucket bucket = this.blockToBucket(block); this.setString(section, key, bucket); PlotSquared.log(Captions - .format(Captions.LEGACY_CONFIG_REPLACED.getTranslated(), block, bucket.toString())); + .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), block, bucket.toString())); } private void convertBlockList(@NonNull final ConfigurationSection section, @@ -91,7 +92,7 @@ import java.util.Map; final BlockBucket bucket = this.blockListToBucket(blocks); this.setString(section, key, bucket); PlotSquared.log(Captions - .format(Captions.LEGACY_CONFIG_REPLACED.getTranslated(), plotBlockArrayString(blocks), + .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), plotBlockArrayString(blocks), bucket.toString())); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index ea34c5dc9..f54fb5ff5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -1,6 +1,5 @@ package com.github.intellectualsites.plotsquared.plot.util; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.commands.Like; import com.github.intellectualsites.plotsquared.plot.config.Captions; @@ -620,14 +619,14 @@ public class MainUtil { * @param prefix If the message should be prefixed with the configured prefix * @return */ - public static boolean sendMessage(CommandCaller player, @NotNull String msg, boolean prefix) { + public static boolean sendMessage(PlotPlayer player, @NotNull String msg, boolean prefix) { if (!msg.isEmpty()) { if (player == null) { - String message = (prefix ? Captions.PREFIX.getTranslated() : "") + msg; + String message = Captions.format(null, (prefix ? Captions.PREFIX.getTranslated() : "") + msg); PlotSquared.log(message); } else { player.sendMessage( - (prefix ? Captions.PREFIX.getTranslated() : "") + Captions.color(msg)); + Captions.format(player, (prefix ? Captions.PREFIX.getTranslated() : "") + Captions.color(msg))); } } return true; @@ -640,7 +639,7 @@ public class MainUtil { * @param caption the message to send * @return boolean success */ - public static boolean sendMessage(CommandCaller player, Captions caption, String... args) { + public static boolean sendMessage(PlotPlayer player, Captions caption, String... args) { return sendMessage(player, caption, (Object[]) args); } @@ -651,13 +650,13 @@ public class MainUtil { * @param caption the message to send * @return boolean success */ - public static boolean sendMessage(final CommandCaller player, final Captions caption, + public static boolean sendMessage(final PlotPlayer player, final Captions caption, final Object... args) { if (caption.getTranslated().isEmpty()) { return true; } TaskManager.runTaskAsync(() -> { - String m = Captions.format(caption, args); + String m = Captions.format(player, caption, args); if (player == null) { PlotSquared.log(m); } else { @@ -790,8 +789,8 @@ public class MainUtil { } flags.append(prefix) .append(Captions - .format(Captions.PLOT_FLAG_LIST.getTranslated(), entry.getKey().getName(), - value)); + .format(player, Captions.PLOT_FLAG_LIST.getTranslated(), entry.getKey().getName(), + Captions.formatRaw(player, value.toString(), ""))); prefix = ", "; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java index c10d9507b..72fd362f1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java @@ -1,9 +1,9 @@ package com.github.intellectualsites.plotsquared.plot.util.helpmenu; import com.github.intellectualsites.plotsquared.commands.Command; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.commands.MainCommand; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import java.util.List; @@ -11,13 +11,13 @@ public class HelpMenu { private static final int PER_PAGE = 5; - private final CommandCaller commandCaller; + private final PlotPlayer commandCaller; private HelpPage page = new HelpPage(CommandCategory.INFO, 0, 0); private int maxPage; private CommandCategory commandCategory; private List commands; - public HelpMenu(CommandCaller commandCaller) { + public HelpMenu(PlotPlayer commandCaller) { this.commandCaller = commandCaller; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java index 5b165d32a..8a13afa8e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java @@ -1,8 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.util.helpmenu; -import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -21,7 +21,7 @@ public class HelpPage { .replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + ""); } - public void render(CommandCaller player) { + public void render(PlotPlayer player) { if (this.helpObjects.size() < 1) { MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0)"); } else { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b7c8c5dbf..f9eaab9f6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Feb 20 15:17:22 CET 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME