mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 06:06:45 +01:00
Allow all messages to be formatted by external formatters and add PAPI support
This commit is contained in:
parent
17e4bde720
commit
464f5e09ae
@ -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.");
|
||||
|
@ -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.<Long>getMeta("lastMessageTime") > 5000)) {
|
||||
setMeta("lastMessage", message);
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -114,7 +114,7 @@ public abstract class Command {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<Command> getCommands(CommandCaller player) {
|
||||
public List<Command> getCommands(PlotPlayer player) {
|
||||
List<Command> 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<Command> getCommands(CommandCategory category, CommandCaller player) {
|
||||
public List<Command> getCommands(CommandCategory category, PlotPlayer player) {
|
||||
List<Command> 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);
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<BlockType> 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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<Boolean> displayHelp(final CommandCaller player, final String catRaw, final int page) {
|
||||
public CompletableFuture<Boolean> displayHelp(final PlotPlayer player, final String catRaw, final int page) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
String cat = catRaw;
|
||||
|
||||
|
@ -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<Plot>() : 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]));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<String, String> 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 {
|
||||
|
@ -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<ChatFormatter> 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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<String, String> 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));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
+ ")");
|
||||
|
@ -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 + ")");
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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 = ", ";
|
||||
}
|
||||
}
|
||||
|
@ -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<Command> commands;
|
||||
|
||||
public HelpMenu(CommandCaller commandCaller) {
|
||||
public HelpMenu(PlotPlayer commandCaller) {
|
||||
this.commandCaller = commandCaller;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user