From c8a8806e7dd7d8d96225c4c0811d1098c1112ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 5 Jul 2020 13:41:40 +0200 Subject: [PATCH] Component progress. The plugin is **very** broken right now. --- Bukkit/build.gradle | 7 +- .../bukkit/player/BukkitPlayer.java | 27 ++++--- Core/build.gradle | 1 + .../com/plotsquared/core/PlotSquared.java | 8 -- .../core/command/CommandCaller.java | 12 +-- .../core/configuration/Caption.java | 36 +++------ .../core/configuration/Settings.java | 2 - .../configuration/caption/CaptionLoader.java | 2 +- .../configuration/caption/CaptionMap.java | 50 ++++++++++-- .../configuration/caption/KeyedCaption.java | 18 +++++ .../caption/LegacyCaptionMap.java | 77 ------------------- ...ableReplacement.java => LocaleHolder.java} | 46 +++-------- .../caption/LocalizedCaptionMap.java | 10 +-- .../caption/PerUserLocaleCaptionMap.java | 11 +-- .../caption/TranslatableCaption.java | 35 +++++---- .../plotsquared/core/player/PlotPlayer.java | 7 +- 16 files changed, 142 insertions(+), 207 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/configuration/caption/KeyedCaption.java delete mode 100644 Core/src/main/java/com/plotsquared/core/configuration/caption/LegacyCaptionMap.java rename Core/src/main/java/com/plotsquared/core/configuration/caption/{VariableReplacement.java => LocaleHolder.java} (54%) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index afd240034..835a1a121 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -14,6 +14,7 @@ repositories { maven { url = "https://ci.ender.zone/plugin/repository/everything/" } maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" } maven { url = "https://repo.wea-ondara.net/repository/public/" } + maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } mavenLocal() } @@ -35,7 +36,8 @@ dependencies { implementation("net.luckperms:api:5.1") implementation("net.ess3:EssentialsX:2.17.2") implementation("net.alpenblock:BungeePerms:4.0-dev-106") - implementation("net.kyori:adventure-text-platform-bukkit:4.0.0-SNAPSHOT") + implementation("net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT") + implementation('net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT') compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } } @@ -92,7 +94,8 @@ shadowJar { dependencies { include(dependency(":PlotSquared-Core")) include(dependency("io.papermc:paperlib:1.0.2")) - include(dependency("net.kyori:adventure-text-platform-bukkit:4.0.0-SNAPSHOT")) + include(dependency("net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT")) + include(dependency("net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT")) include(dependency("org.bstats:bstats-bukkit:1.7")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 94b77fd37..536fc328b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -26,24 +26,28 @@ package com.plotsquared.bukkit.player; import com.google.common.base.Charsets; +import com.google.common.base.Objects; +import com.plotsquared.bukkit.BukkitMain; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; -import com.plotsquared.core.configuration.caption.VariableReplacement; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.MathMan; -import com.plotsquared.core.util.StringMan; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import io.papermc.lib.PaperLib; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.Template; import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.WeatherType; @@ -67,6 +71,9 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL; public class BukkitPlayer extends PlotPlayer { + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + private static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitMain.getPlugin(BukkitMain.class)); + private static boolean CHECK_EFFECTIVE = true; public final Player player; private boolean offline; @@ -228,17 +235,13 @@ public class BukkitPlayer extends PlotPlayer { } @Override public void sendMessage(@NotNull final Caption caption, - @NotNull final VariableReplacement... replacements) { - - } - - @Deprecated @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); + @NotNull final Template... replacements) { + // TODO: Inject the prefix here + final Component component = MINI_MESSAGE.parse(caption.getComponent(this), replacements); + if (!Objects.equal(component, this.getMeta("lastMessage")) || System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000) { + setMeta("lastMessage", component); setMeta("lastMessageTime", System.currentTimeMillis()); - this.player.sendMessage(message); + BUKKIT_AUDIENCES.player(player).sendMessage(component); } } diff --git a/Core/build.gradle b/Core/build.gradle index e8a52b612..581e3e3d8 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -1,6 +1,7 @@ repositories { maven { url = "https://jitpack.io" } maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" } + maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } } def textVersion = "3.0.2" diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 3d7ff56c0..6d81c48ac 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -33,7 +33,6 @@ import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; -import com.plotsquared.core.configuration.caption.LegacyCaptionMap; import com.plotsquared.core.configuration.MemorySection; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; @@ -234,13 +233,6 @@ public class PlotSquared { String fileName = "messages_" + Settings.Enabled_Components.DEFAULT_LOCALE + ".json"; captionMap = CaptionLoader.loadSingle(Paths.get("lang", fileName)); } - if (Settings.Enabled_Components.LEGACY_MESSAGES) { - this.translationFile = MainUtil.getFile(this.IMP.getDirectory(), - Settings.Paths.TRANSLATIONS + File.separator + IMP.getPluginName() - + ".use_THIS.yml"); - Captions.load(this.translationFile); - captionMap = new LegacyCaptionMap(captionMap); - } this.captionMap = captionMap; // Setup plotAreaManager diff --git a/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java b/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java index 60565c0e1..1868556f3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java +++ b/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java @@ -26,26 +26,18 @@ package com.plotsquared.core.command; import com.plotsquared.core.configuration.Caption; -import com.plotsquared.core.configuration.caption.VariableReplacement; +import net.kyori.adventure.text.minimessage.Template; import org.jetbrains.annotations.NotNull; public interface CommandCaller { - /** - * Send the player a message. - * - * @param message the message to send - * @deprecated Use static captions instead - */ - @Deprecated void sendMessage(String message); - /** * Send a message to the command caller * * @param caption Caption to send * @param replacements Variable replacements */ - void sendMessage(@NotNull Caption caption, @NotNull VariableReplacement... replacements); + void sendMessage(@NotNull Caption caption, @NotNull Template... replacements); /** * Check the player's permissions. Will be cached if permission caching is enabled. diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Caption.java b/Core/src/main/java/com/plotsquared/core/configuration/Caption.java index a70d77dab..30d2d1b3d 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Caption.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Caption.java @@ -25,32 +25,20 @@ */ package com.plotsquared.core.configuration; -import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.player.PlotPlayer; -import com.plotsquared.core.util.StringMan; +import com.plotsquared.core.configuration.caption.LocaleHolder; +import org.jetbrains.annotations.NotNull; +/** + * Any message that can be sent to a player, the console, etc. + */ public interface Caption { - String getTranslated(); - - @Deprecated default String formatted() { - return StringMan.replaceFromMap(getTranslated(), Captions.replacements); - } - - default boolean send(PlotPlayer caller, String... args) { - return send(caller, (Object[]) args); - } - - default boolean send(PlotPlayer caller, Object... args) { - String msg = CaptionUtility.format(caller, this, args); - if (caller == null) { - PlotSquared.log(msg); - } else { - caller.sendMessage(msg); - } - return true; - } - - boolean usePrefix(); + /** + * Get the message that should be sent to the recipient + * + * @param localeHolder Locale holder + * @return Message + */ + @NotNull String getComponent(@NotNull LocaleHolder localeHolder); } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index c2e2c4f68..a5305e6e2 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -573,8 +573,6 @@ public class Settings extends Config { PERSISTENT_ROAD_REGEN = false; @Comment({"Enable the `/plot component` preset GUI", "Read more about components here: https://wiki.intellectualsites.com/en/plotsquared/installation/plot-components"}) public static boolean COMPONENT_PRESETS = true; - @Comment({"Use legacy messages (will be removed in future)", - "It is recommended to use the new message system"}) public static boolean LEGACY_MESSAGES = true; @Comment("Enable per user locale") public static boolean PER_USER_LOCALE = false; @Comment("The default locale") public static String DEFAULT_LOCALE = "en"; @Comment("Use UUID cache to complete usernames") diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java index 9850925c7..5b66d1f74 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java @@ -78,7 +78,7 @@ public final class CaptionLoader { JsonObject.class); Map captions = new HashMap<>(); for (Map.Entry entry : object.entrySet()) { - TranslatableCaption key = TranslatableCaption.of(entry.getKey()); + TranslatableCaption key = TranslatableCaption.keyed(entry.getKey()); captions.put(key, entry.getValue().getAsString()); } return new LocalizedCaptionMap(locale, captions); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java index ff54851f4..b0ebb3d9c 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java @@ -25,17 +25,57 @@ */ package com.plotsquared.core.configuration.caption; -import com.plotsquared.core.player.PlotPlayer; +import net.kyori.text.Component; +import org.jetbrains.annotations.NotNull; import java.util.Locale; +/** + * Map containing mappings between {@link TranslatableCaption captions} and + * {@link Component components} + */ public interface CaptionMap { - String getMessage(TranslatableCaption caption); + /** + * Get a message using the server locale + * + * @param caption Caption containing the caption key + * @return Component + * @throws NoSuchCaptionException if no caption with the given key exists + */ + @NotNull String getMessage(@NotNull TranslatableCaption caption) throws NoSuchCaptionException; - String getMessage(TranslatableCaption caption, PlotPlayer context); + /** + * Get a message using a specific locale + * + * @param caption Caption containing the caption key + * @param localeHolder Holder that determines the message locale + * @return Component + * @throws NoSuchCaptionException if no caption with the given key exists + */ + String getMessage(@NotNull TranslatableCaption caption, @NotNull LocaleHolder localeHolder) throws NoSuchCaptionException; - boolean supportsLocale(Locale locale); + /** + * Check if the map supports a given locale + * + * @param locale Locale + * @return True if the map supports the locale + */ + boolean supportsLocale(@NotNull Locale locale); + + /** + * Get the locale of the messages stored in the map + * + * @return Message locale + */ + @NotNull Locale getLocale(); + + class NoSuchCaptionException extends IllegalArgumentException { + + public NoSuchCaptionException(@NotNull final KeyedCaption caption) { + super(String.format("No caption with the key '%s' exists in the map", caption.getKey())); + } + + } - Locale getLocale(); } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/KeyedCaption.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/KeyedCaption.java new file mode 100644 index 000000000..9a2b78c8e --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/KeyedCaption.java @@ -0,0 +1,18 @@ +package com.plotsquared.core.configuration.caption; + +import com.plotsquared.core.configuration.Caption; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link com.plotsquared.core.configuration.Caption} that can be identified by a key + */ +public interface KeyedCaption extends Caption { + + /** + * Get the key that identifies this caption + * + * @return Caption key + */ + @NotNull String getKey(); + +} diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/LegacyCaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/LegacyCaptionMap.java deleted file mode 100644 index e7ecd7cd4..000000000 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/LegacyCaptionMap.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * _____ _ _ _____ _ - * | __ \| | | | / ____| | | - * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | - * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | - * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | - * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| - * | | - * |_| - * PlotSquared plot management system for Minecraft - * Copyright (C) 2020 IntellectualSites - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.plotsquared.core.configuration.caption; - -import com.plotsquared.core.configuration.Caption; -import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.player.PlotPlayer; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -@Deprecated -public class LegacyCaptionMap implements CaptionMap { - private final CaptionMap parent; - private final Map legacyMap; - - public LegacyCaptionMap(CaptionMap parent) { - this.parent = parent; - this.legacyMap = new HashMap<>(); - // add here custom mappings - } - - @Override - public String getMessage(TranslatableCaption caption) { - Caption legacy = this.legacyMap.computeIfAbsent(caption.getKey(), key -> { - String captionsName = key.substring(key.indexOf('.') + 1).toUpperCase(Locale.ROOT); - try { - return Captions.valueOf(captionsName); - } catch (IllegalArgumentException ignored) { - return null; - } - }); - if (legacy == null) { - return this.parent.getMessage(caption); - } - return legacy.getTranslated(); - } - - @Override - public String getMessage(TranslatableCaption caption, PlotPlayer context) { - return getMessage(caption); // Captions does not allow per player locale - } - - @Override - public boolean supportsLocale(Locale locale) { - return false; - } - - @Override - public Locale getLocale() { - return Locale.ROOT; - } -} diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/VariableReplacement.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocaleHolder.java similarity index 54% rename from Core/src/main/java/com/plotsquared/core/configuration/caption/VariableReplacement.java rename to Core/src/main/java/com/plotsquared/core/configuration/caption/LocaleHolder.java index 974acd5e1..29748531e 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/VariableReplacement.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocaleHolder.java @@ -25,55 +25,27 @@ */ package com.plotsquared.core.configuration.caption; -import lombok.EqualsAndHashCode; -import lombok.ToString; import org.jetbrains.annotations.NotNull; -import java.util.Objects; +import java.util.Locale; /** - * Key-value pair used as replacement of variables in {@link com.plotsquared.core.configuration.Caption captions} + * Any entity that has a locale */ -@ToString -@EqualsAndHashCode -public final class VariableReplacement { - - private final String key; - private final String value; - - private VariableReplacement(@NotNull final String key, @NotNull final String value) { - this.key = Objects.requireNonNull(key, "Key may not be null"); - this.value = Objects.requireNonNull(value, "Value may not be null"); - } +public interface LocaleHolder { /** - * Create a new variable replacement from a key-value pair + * Get the locale used by the holder * - * @param key Replacement key - * @param value Replacement value - * @return Replacement instance + * @return Locale */ - @NotNull public static VariableReplacement keyed(@NotNull final String key, - @NotNull final String value) { - return new VariableReplacement(key, value); - } + @NotNull Locale getLocale(); /** - * Get the replacement key + * Set the locale for the holder * - * @return Replacement key + * @param locale New locale */ - @NotNull public String getKey() { - return this.key; - } - - /** - * Get the replacement value - * - * @return Replacement value - */ - @NotNull public String getValue() { - return this.value; - } + void setLocale(@NotNull Locale locale); } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java index b9e25e2a1..56eeb8a13 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java @@ -25,7 +25,7 @@ */ package com.plotsquared.core.configuration.caption; -import com.plotsquared.core.player.PlotPlayer; +import org.jetbrains.annotations.NotNull; import java.util.Locale; import java.util.Map; @@ -40,19 +40,19 @@ public class LocalizedCaptionMap implements CaptionMap { this.captions = captions; } - @Override public String getMessage(TranslatableCaption caption) { + @Override @NotNull public String getMessage(@NotNull final TranslatableCaption caption) { return this.captions.get(caption); } - @Override public String getMessage(TranslatableCaption caption, PlotPlayer context) { + @Override @NotNull public String getMessage(@NotNull final TranslatableCaption caption, @NotNull final LocaleHolder localeHolder) { return getMessage(caption); // use the translation of this locale } - @Override public boolean supportsLocale(Locale locale) { + @Override public boolean supportsLocale(@NotNull final Locale locale) { return this.locale.equals(locale); } - @Override public Locale getLocale() { + @Override @NotNull public Locale getLocale() { return this.locale; } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/PerUserLocaleCaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/PerUserLocaleCaptionMap.java index c49d3863a..8fdacbd07 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/PerUserLocaleCaptionMap.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/PerUserLocaleCaptionMap.java @@ -25,7 +25,7 @@ */ package com.plotsquared.core.configuration.caption; -import com.plotsquared.core.player.PlotPlayer; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.Locale; @@ -40,13 +40,14 @@ public class PerUserLocaleCaptionMap extends LocalizedCaptionMap { this.localeMap = localeMap; } - @Override - public String getMessage(TranslatableCaption caption, PlotPlayer context) { - return this.localeMap.get(context.getLocale()).getMessage(caption); + @Override @NotNull public String getMessage(@NotNull final TranslatableCaption caption, + @NotNull final LocaleHolder localeHolder) throws NoSuchCaptionException { + return this.localeMap.get(localeHolder.getLocale()).getMessage(caption); } @Override - public boolean supportsLocale(Locale locale) { + public boolean supportsLocale(@NotNull final Locale locale) { return this.localeMap.containsKey(locale); } + } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java index ed8c90154..50521b271 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java @@ -26,31 +26,34 @@ package com.plotsquared.core.configuration.caption; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Caption; +import lombok.Getter; import org.jetbrains.annotations.NotNull; -public final class TranslatableCaption implements Caption { +import java.util.Locale; - @NotNull private final String key; +/** + * Caption that is user modifiable + */ +public final class TranslatableCaption implements KeyedCaption { - private TranslatableCaption(@NotNull String key) { + @Getter private final String key; + + private TranslatableCaption(@NotNull final String key) { this.key = key; } - public static TranslatableCaption of(@NotNull final String key) { - return new TranslatableCaption(key); + /** + * Get a new {@link TranslatableCaption} instance + * + * @param key Caption key + * @return Caption instance + */ + @NotNull public static TranslatableCaption keyed(@NotNull final String key) { + return new TranslatableCaption(key.toLowerCase(Locale.ENGLISH)); } - @Override public String getTranslated() { - return null; - } - - @Override public boolean usePrefix() { - return false; - } - - @NotNull public String getKey() { - return this.key; + @Override @NotNull public String getComponent(@NotNull final LocaleHolder localeHolder) { + return PlotSquared.get().getCaptionMap().getMessage(this, localeHolder); } } 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 20d3f16b9..964572d29 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -32,6 +32,7 @@ import com.plotsquared.core.command.RequiredType; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.LocaleHolder; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.location.Location; @@ -72,7 +73,7 @@ import java.util.stream.Collectors; /** * The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}. */ -public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer { +public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, LocaleHolder { public static final String META_LAST_PLOT = "lastplot"; public static final String META_LOCATION = "location"; @@ -739,14 +740,14 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer return this.getAttribute("debug"); } - @NotNull public Locale getLocale() { + @NotNull @Override public Locale getLocale() { if (this.locale == null) { this.locale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE); } return this.locale; } - public void setLocale(@NotNull final Locale locale) { + @Override public void setLocale(@NotNull final Locale locale) { if (!PlotSquared.get().getCaptionMap().supportsLocale(locale)) { this.locale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE); } else {