diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 146cdeeab..0b88ca931 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -194,16 +194,6 @@ public class PlotSquared { this.captionMaps = new HashMap<>(); - // Setup localization - CaptionMap captionMap; - if (Settings.Enabled_Components.PER_USER_LOCALE) { - captionMap = CaptionLoader.loadAll(Paths.get("lang")); - } else { - String fileName = "messages_" + Settings.Enabled_Components.DEFAULT_LOCALE + ".json"; - captionMap = CaptionLoader.loadSingle(Paths.get("lang", fileName)); - } - - this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap); this.worldedit = WorldEdit.getInstance(); // Create Event utility class @@ -236,6 +226,18 @@ public class PlotSquared { } } + public void loadCaptionMap() throws IOException { + // Setup localization + CaptionMap captionMap; + if (Settings.Enabled_Components.PER_USER_LOCALE) { + captionMap = CaptionLoader.loadAll(Paths.get("lang")); + } else { + String fileName = "messages_" + Settings.Enabled_Components.DEFAULT_LOCALE + ".json"; + captionMap = CaptionLoader.loadSingle(Paths.get("lang", fileName)); + } + this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap); + } + /** * Get the platform specific {@link PlotAreaManager} instance * diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 72ca92da2..f480a41f8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; @@ -58,6 +59,7 @@ import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; +import com.plotsquared.core.util.task.RunnableVal3; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -584,14 +586,18 @@ public class Area extends SubCommand { percent = claimed == 0 ? 0 : 100d * claimed / Integer.MAX_VALUE; region = "N/A"; } - String value = - "&r$1NAME: " + name + "\n$1Type: $2" + area.getType() + "\n$1Terrain: $2" + area - .getTerrain() + "\n$1Usage: $2" + String.format("%.2f", percent) + '%' - + "\n$1Claimed: $2" + claimed + "\n$1Clusters: $2" + clusters - + "\n$1Region: $2" + region + "\n$1Generator: $2" + generator; - MainUtil.sendMessage(player, - Captions.PLOT_INFO_HEADER.getTranslated() + '\n' + value + '\n' - + Captions.PLOT_INFO_FOOTER.getTranslated(), false); + Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player)); + Template nameTemplate = Template.of("name", name); + Template typeTemplate = Template.of("type", area.getType().name()); + Template terrainTemplate = Template.of("terrain", area.getTerrain().name()); + Template usageTemplate = Template.of("usage", String.format("%.2f", percent)); + Template claimedTemplate = Template.of("name", String.valueOf(claimed)); + Template clustersTemplate = Template.of("name", String.valueOf(clusters)); + Template regionTemplate = Template.of("name", region); + Template generatorTemplate = Template.of("name", generator); + Template footerTemplate = Template.of("name", TranslatableCaption.of("info.plot_info_footer").getComponent(player)); + player.sendMessage(TranslatableCaption.of("info.area_format"), headerTemplate, nameTemplate, typeTemplate, terrainTemplate, + usageTemplate, claimedTemplate, clustersTemplate, regionTemplate, generatorTemplate, footerTemplate); return true; } case "l": @@ -621,8 +627,8 @@ public class Area extends SubCommand { } final List areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas())); paginate(player, areas, 8, page, - new RunnableVal3() { - @Override public void run(Integer i, PlotArea area, PlotMessage message) { + new RunnableVal3() { + @Override public void run(Integer i, PlotArea area, Caption message) { String name; double percent; int claimed = area.getPlotCount(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index a99d0072f..0eac92bf0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -28,6 +28,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; @@ -759,13 +760,13 @@ public class Cluster extends SubCommand { String size = (cluster.getP2().getX() - cluster.getP1().getX() + 1) + "x" + ( cluster.getP2().getY() - cluster.getP1().getY() + 1); String rights = cluster.isAdded(player.getUUID()) + ""; - String message = Captions.CLUSTER_INFO.getTranslated(); - message = message.replaceAll("%id%", id); - message = message.replaceAll("%owner%", owner); - message = message.replaceAll("%name%", name); - message = message.replaceAll("%size%", size); - message = message.replaceAll("%rights%", rights); - player.sendMessage(StaticCaption.of(message)); + Caption message = TranslatableCaption.of("cluster.cluster_info"); + Template idTemplate = Template.of("id", id); + Template ownerTemplate = Template.of("owner", owner); + Template nameTemplate = Template.of("name", name); + Template sizeTemplate = Template.of("size", size); + Template rightsTemplate = Template.of("rights", rights); + player.sendMessage(message, idTemplate, ownerTemplate, nameTemplate, sizeTemplate, rightsTemplate); } }); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 731329db6..1611d6cd0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -217,6 +217,7 @@ public class DatabaseCommand extends SubCommand { break; default: player.sendMessage(StaticCaption.of("/plot database [sqlite/mysql]")); + return false; } try { SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener, this.worldConfiguration); diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 4b034e9a4..7aa250d6b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -42,6 +42,7 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; @@ -60,6 +61,7 @@ public class Merge extends SubCommand { public static final String[] values = new String[] {"north", "east", "south", "west"}; public static final String[] aliases = new String[] {"n", "e", "s", "w"}; + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); private final EventDispatcher eventDispatcher; private final EconHandler econHandler; @@ -283,8 +285,9 @@ public class Merge extends SubCommand { player.sendMessage(TranslatableCaption.of("merge.success_merge")); }; if (!force && hasConfirmation(player)) { - CmdConfirm.addPending(accepter, Captions.MERGE_REQUEST_CONFIRM.getTranslated() - .replaceAll("%s", player.getName()), run); + CmdConfirm.addPending(accepter, MINI_MESSAGE.serialize(MINI_MESSAGE + .parse(TranslatableCaption.of("merge.merge_request_confirm").getComponent(player), Template.of("player", player.getName()))), + run); } else { run.run(); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Reload.java b/Core/src/main/java/com/plotsquared/core/command/Reload.java index 8945a0808..bfb461897 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Reload.java +++ b/Core/src/main/java/com/plotsquared/core/command/Reload.java @@ -68,7 +68,7 @@ public class Reload extends SubCommand { // The following won't affect world generation, as that has to be // loaded during startup unfortunately. PlotSquared.get().setupConfigs(); - Captions.load(PlotSquared.get().translationFile); + PlotSquared.get().loadCaptionMap(); this.plotAreaManager.forEachPlotArea(area -> { ConfigurationSection worldSection = this.worldConfiguration .getConfigurationSection("worlds." + area.getWorldName()); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java index 528bf5e27..2942ed56e 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/Templates.java @@ -26,6 +26,7 @@ package com.plotsquared.core.configuration.caption; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.util.PlayerManager; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; @@ -67,7 +68,7 @@ public final class Templates { * @return Generated template */ @Nonnull public static Template of(@Nonnull final String key, @Nonnull final UUID uuid) { - final String username = MainUtil.getName(uuid); + final String username = PlayerManager.getName(uuid); return Template.of(key, username); } diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 8c2c80965..21d4e880f 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -28,11 +28,13 @@ package com.plotsquared.core.listener; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; @@ -159,7 +161,7 @@ public class PlotListener { final String greeting = plot.getFlag(GreetingFlag.class); if (!greeting.isEmpty()) { - plot.format(greeting, player, false).thenAcceptAsync(player::sendMessage); + plot.format(StaticCaption.of(greeting), player, false).thenAcceptAsync(player::sendMessage); } if (plot.getFlag(NotifyEnterFlag.class)) { @@ -270,8 +272,8 @@ public class PlotListener { CommentManager.sendTitle(player, plot); if (titles && !player.getAttribute("disabletitles")) { - if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty() - || !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) { + if (!TranslatableCaption.of("titles.title_entered_plot").getComponent(ConsolePlayer.getConsole()).isEmpty() + || !TranslatableCaption.of("titles.title_entered_plot_sub").getComponent(ConsolePlayer.getConsole()).isEmpty()) { TaskManager.runTaskLaterAsync(() -> { Plot lastPlot = null; try (final MetaDataAccess lastPlotAccess = @@ -346,7 +348,7 @@ public class PlotListener { final String farewell = plot.getFlag(FarewellFlag.class); if (!farewell.isEmpty()) { - plot.format(farewell, player, false).thenAcceptAsync(player::sendMessage); + plot.format(StaticCaption.of(farewell), player, false).thenAcceptAsync(player::sendMessage); } if (plot.getFlag(NotifyLeaveFlag.class)) { diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 3b7c9e7d8..e93c336f9 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -70,6 +70,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.title.Title; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -866,6 +867,11 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, } } + // Redefine from PermissionHolder as it's required from CommandCaller + @Override public boolean hasPermission(@NotNull String permission) { + return hasPermission(null, permission); + } + boolean hasPersistentMeta(String key) { return this.metaMap.containsKey(key); } @@ -884,7 +890,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, } @Override public void setLocale(@Nonnull final Locale locale) { - if (!PlotSquared.get().getCaptionMap().supportsLocale(locale)) { + if (!PlotSquared.get().getCaptionMap(TranslatableCaption.DEFAULT_NAMESPACE).supportsLocale(locale)) { this.locale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE); } else { this.locale = locale; diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 59a725b60..b9594414d 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -142,13 +142,12 @@ public class Plot { private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName()); private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); - - private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); - static { FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); } + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + private static Set connected_cache; private static Set regions_cache; @@ -1893,6 +1892,7 @@ public class Plot { return true; } + /** * Register a plot and create it in the database
* - The plot will not be created if the owner is null
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index a7e8c72f4..14abb33b8 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -29,12 +29,13 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.plotsquared.core.collection.QuadMap; -import com.plotsquared.core.configuration.caption.CaptionUtility; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.CaptionUtility; +import com.plotsquared.core.configuration.caption.LocaleHolder; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.generator.GridPlotWorld; @@ -43,6 +44,7 @@ import com.plotsquared.core.inject.annotations.WorldConfig; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; +import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; @@ -51,6 +53,7 @@ import com.plotsquared.core.plot.flag.FlagParseException; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.plot.flag.types.DoubleFlag; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.EconHandler; @@ -65,11 +68,15 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -89,6 +96,11 @@ import java.util.function.Consumer; public abstract class PlotArea { private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotArea.class.getSimpleName()); + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); + static { + FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); + } protected final ConcurrentHashMap plots = new ConcurrentHashMap<>(); @Nonnull private final String worldName; @@ -369,20 +381,10 @@ public abstract class PlotArea { } this.getFlagContainer().addAll(parseFlags(flags)); - StringBuilder flagBuilder = new StringBuilder(); + Component flagsComponent = null; Collection> flagCollection = this.getFlagContainer().getFlagMap().values(); - if (flagCollection.isEmpty()) { - flagBuilder.append(TranslatableCaption.of("info.none")); - } else { - String prefix = " "; - for (final PlotFlag flag : flagCollection) { - Object value = flag.toString(); - flagBuilder.append(prefix).append(CaptionUtility - .format(null, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(), - CaptionUtility.formatRaw(null, value.toString(), ""))); - prefix = ", "; - } - } + flagsComponent = getFlagsComponent(flagsComponent, flagCollection); + ConsolePlayer.getConsole().sendMessage(StaticCaption.of("[P2] - area flags: "), Template.of("flags", flagsComponent)); this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); @@ -404,25 +406,39 @@ public abstract class PlotArea { } this.getRoadFlagContainer().addAll(parseFlags(roadflags)); - StringBuilder roadFlagBuilder = new StringBuilder(); - Collection> roadFlagCollection = this.getFlagContainer().getFlagMap().values(); - if (roadFlagCollection.isEmpty()) { - roadFlagBuilder.append(TranslatableCaption.of("info.none")); + Component roadFlagsComponent = null; + Collection> roadFlagCollection = this.getRoadFlagContainer().getFlagMap().values(); + roadFlagsComponent = getFlagsComponent(roadFlagsComponent, roadFlagCollection); + ConsolePlayer.getConsole().sendMessage(StaticCaption.of("[P2] - road flags: "), Template.of("flags", roadFlagsComponent)); + + loadConfiguration(config); + } + + private Component getFlagsComponent(Component flagsComponent, Collection> flagCollection) { + if (flagCollection.isEmpty()) { + flagsComponent = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(LocaleHolder.console())); } else { - roadFlags = true; String prefix = " "; - for (final PlotFlag flag : roadFlagCollection) { - Object value = flag.toString(); - roadFlagBuilder.append(prefix).append(CaptionUtility - .format(null, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(), - CaptionUtility.formatRaw(null, value.toString(), ""))); + for (final PlotFlag flag : flagCollection) { + Object value; + if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { + value = FLAG_DECIMAL_FORMAT.format(flag.getValue()); + } else { + value = flag.toString(); + } + Component snip = MINI_MESSAGE.parse(prefix + CaptionUtility + .format(ConsolePlayer.getConsole(), TranslatableCaption.of("info.plot_flag_list").getComponent(LocaleHolder.console())), + Template.of("flag", flag.getName()), + Template.of("value", CaptionUtility.formatRaw(ConsolePlayer.getConsole(), value.toString()))); + if (flagsComponent != null) { + flagsComponent.append(snip); + } else { + flagsComponent = snip; + } prefix = ", "; } } - - logger.info("[P2] - road flags: {}", roadFlagBuilder.toString()); - - loadConfiguration(config); + return flagsComponent; } public abstract void loadConfiguration(ConfigurationSection config); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BooleanFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BooleanFlag.java index 1221c70e8..ef651a10f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BooleanFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BooleanFlag.java @@ -59,7 +59,7 @@ public abstract class BooleanFlag> extends PlotFl * * @param description Flag description */ - protected BooleanFlag(final Captions description) { + protected BooleanFlag(final Caption description) { this(false, description); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java index 60395d491..524f40969 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java @@ -37,7 +37,7 @@ import java.util.List; public abstract class ListFlag, F>> extends PlotFlag, F> { - public ListFlag(final List valueList, final Captions category, final Caption description) { + public ListFlag(final List valueList, final Caption category, final Caption description) { super(Collections.unmodifiableList(valueList), category, description); } diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index 36950be18..188b1ef6f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -30,9 +30,13 @@ import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; +import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.uuid.UUIDMapping; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -54,6 +58,8 @@ import java.util.function.BiConsumer; */ public abstract class PlayerManager

, T> { + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + private final Map playerMap = new HashMap<>(); private final Object playerLock = new Object(); @@ -116,11 +122,11 @@ public abstract class PlayerManager

, T> { final List users = new LinkedList<>(); for (final UUID uuid : uuids) { if (uuid == null) { - users.add(Captions.NONE.getTranslated()); + users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.none").getComponent(ConsolePlayer.getConsole()))); } else if (DBFunc.EVERYONE.equals(uuid)) { - users.add(Captions.EVERYONE.getTranslated()); + users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.everyone").getComponent(ConsolePlayer.getConsole()))); } else if (DBFunc.SERVER.equals(uuid)) { - users.add(Captions.SERVER.getTranslated()); + users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.console").getComponent(ConsolePlayer.getConsole()))); } else { players.add(uuid); } @@ -135,13 +141,13 @@ public abstract class PlayerManager

, T> { e.printStackTrace(); } - String c = Captions.PLOT_USER_LIST.getTranslated(); - StringBuilder list = new StringBuilder(); + String c = TranslatableCaption.of("info.plot_user_list").getComponent(ConsolePlayer.getConsole()); + Component list = MINI_MESSAGE.deserialize(""); for (int x = 0; x < users.size(); x++) { if (x + 1 == uuids.size()) { - list.append(c.replace("%user%", users.get(x)).replace(",", "")); + list.append(MINI_MESSAGE.parse(c, Template.of("user", users.get(x)))); } else { - list.append(c.replace("%user%", users.get(x))); + list.append(MINI_MESSAGE.parse(c + ", ", Template.of("user", users.get(x)))); } } return list.toString(); diff --git a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java index 803633a33..42926b8f5 100644 --- a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java +++ b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java @@ -26,11 +26,11 @@ package com.plotsquared.core.util.helpmenu; import com.plotsquared.core.command.CommandCategory; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.StringMan; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import java.util.ArrayList; @@ -38,27 +38,29 @@ import java.util.List; public class HelpPage { + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); private final List helpObjects; - private final String header; + private final Template catTemplate; + private final Template curTemplate; + private final Template maxTemplate; public HelpPage(CommandCategory category, int currentPage, int maxPages) { this.helpObjects = new ArrayList<>(); - this.header = Captions.HELP_PAGE_HEADER.getTranslated() - .replace("%category%", category == null ? "ALL" : category.toString()) - .replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + ""); + this.catTemplate = Template.of("category", category == null ? "ALL" : category.name()); + this.curTemplate = Template.of("current", String.valueOf(currentPage + 1)); + this.maxTemplate = Template.of("max", String.valueOf(maxPages + 1)); } public void render(PlotPlayer player) { if (this.helpObjects.size() < 1) { - player.sendMessage( - TranslatableCaption.of("invalid.not_valid_number"), - Template.of("value", "(0)") - ); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"), Template.of("value", "(0)")); } else { - String message = - Captions.HELP_HEADER.getTranslated() + "\n" + this.header + "\n" + StringMan - .join(this.helpObjects, "\n") + "\n" + Captions.HELP_FOOTER.getTranslated(); - player.sendMessage(StaticCaption.of(message)); + Template header = Template.of("header", TranslatableCaption.of("help.help_header").getComponent(player)); + Template page_header = Template.of("page_header", + MINI_MESSAGE.parse(TranslatableCaption.of("help.help_page_header").getComponent(player), catTemplate, curTemplate, maxTemplate)); + Template help_objects = Template.of("help_objects", StringMan.join(this.helpObjects, "\n")); + Template footer = Template.of("footer", TranslatableCaption.of("help.help_footer").getComponent(player)); + player.sendMessage(StaticCaption.of("

\n\n\n