From 9cf5e010d0e37b361c4c34e1a4f5f2f5e64f4e64 Mon Sep 17 00:00:00 2001 From: Peashooter101 Date: Thu, 4 Jun 2026 10:16:22 -0500 Subject: [PATCH 01/19] Replace Maven pom.xml with Gradle multi-project build --- build.gradle | 23 ++++++++++ core/build.gradle | 12 ++++++ fabric/build.gradle | 18 ++++++++ gradle.properties | 8 ++++ paper/build.gradle | 20 +++++++++ pom.xml | 103 -------------------------------------------- settings.gradle | 9 ++++ 7 files changed, 90 insertions(+), 103 deletions(-) create mode 100644 build.gradle create mode 100644 core/build.gradle create mode 100644 fabric/build.gradle create mode 100644 gradle.properties create mode 100644 paper/build.gradle delete mode 100644 pom.xml create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..a416763 --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +allprojects { + group = 'simplexity' + version = '3.2.2' +} + +subprojects { + apply plugin: 'java' + + java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } + } + + repositories { + mavenCentral() + maven { url 'https://repo.papermc.io/repository/maven-public/' } + maven { url 'https://maven.fabricmc.net/' } + maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' } + maven { url 'https://oss.sonatype.org/content/groups/public/' } + maven { url 'https://maven.nucleoid.xyz/' } + } +} diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000..5c90673 --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'java-library' +} + +dependencies { + compileOnly "net.kyori:adventure-api:${adventureVersion}" + compileOnly "net.kyori:adventure-text-minimessage:${miniMessageVersion}" + compileOnly "org.slf4j:slf4j-api:${slf4jVersion}" + compileOnly "org.yaml.snakeyaml:snakeyaml:2.3" + api "com.zaxxer:HikariCP:${hikariVersion}" + compileOnly "org.jetbrains:annotations:24.0.0" +} diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..7eb5c35 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'fabric-loom' version '1.9.+' +} + +dependencies { + minecraft 'com.mojang:minecraft:1.21.5' + mappings loom.officialMojangMappings() + modImplementation "net.fabricmc:fabric-loader:${fabricLoaderVersion}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${fabricApiVersion}" + + implementation project(':core') + + include(modImplementation("net.kyori:adventure-platform-fabric:${adventureFabricVersion}")) + include(modImplementation("net.kyori:adventure-text-minimessage:${miniMessageVersion}")) + include(modImplementation("com.zaxxer:HikariCP:${hikariVersion}")) + include(modImplementation("org.yaml.snakeyaml:snakeyaml:2.3")) + include(modImplementation("org.xerial:sqlite-jdbc:3.47.+")) +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..b9cf3c7 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,8 @@ +adventureVersion=4.17.0 +miniMessageVersion=4.17.0 +hikariVersion=6.3.0 +slf4jVersion=2.0.16 +paperVersion=1.21.5-R0.1-SNAPSHOT +fabricLoaderVersion=0.16.9 +fabricApiVersion=0.119.2+1.21.5 +adventureFabricVersion=6.2.0 diff --git a/paper/build.gradle b/paper/build.gradle new file mode 100644 index 0000000..dbfa696 --- /dev/null +++ b/paper/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'io.papermc.paperweight.userdev' version '2.0.0-beta.17' + id 'com.github.johnrengelman.shadow' version '8.1.1' +} + +dependencies { + paperweight.paperDevBundle("${paperVersion}") + implementation project(':core') + compileOnly "me.clip:placeholderapi:2.11.5" + compileOnly "io.github.miniplaceholders:miniplaceholders-api:3.2.0" +} + +shadowJar { + relocate 'com.zaxxer.hikari', 'simplexity.simplenicks.shaded.hikari' + manifest { + attributes 'paperweight-mappings-namespace': 'mojang' + } +} + +assemble.dependsOn reobfJar diff --git a/pom.xml b/pom.xml deleted file mode 100644 index aa43fb2..0000000 --- a/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - 4.0.0 - - simplexity - SimpleNicks - 3.2.2 - jar - - SimpleNicks - - - 21 - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 21 - 21 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - - - - mojang - - - - - - - - - - - src/main/resources - true - - - - - - - papermc-repo - https://repo.papermc.io/repository/maven-public/ - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - placeholderapi - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - - io.papermc.paper - paper-api - 1.21.5-R0.1-SNAPSHOT - provided - - - me.clip - placeholderapi - 2.11.5 - provided - - - com.zaxxer - HikariCP - 6.3.0 - - - io.github.miniplaceholders - miniplaceholders-api - 3.2.0 - provided - - - diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..5f3ca94 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { url 'https://maven.fabricmc.net/' } + gradlePluginPortal() + } +} + +rootProject.name = 'SimpleNicks' +include 'core', 'paper', 'fabric' From 6239c1b02bc8bb7941b252e68f92000ce9fece82 Mon Sep 17 00:00:00 2001 From: Peashooter101 Date: Thu, 4 Jun 2026 10:18:27 -0500 Subject: [PATCH 02/19] Add core platform interfaces and SimpleNicksCore --- .../simplenicks/SimpleNicksCore.java | 75 ++++++++++ .../simplenicks/platform/ConfigProvider.java | 74 ++++++++++ .../simplenicks/platform/PlatformAdapter.java | 133 ++++++++++++++++++ .../simplenicks/platform/PlayerInfo.java | 18 +++ .../simplenicks/platform/SenderContext.java | 56 ++++++++ 5 files changed, 356 insertions(+) create mode 100644 core/src/main/java/simplexity/simplenicks/SimpleNicksCore.java create mode 100644 core/src/main/java/simplexity/simplenicks/platform/ConfigProvider.java create mode 100644 core/src/main/java/simplexity/simplenicks/platform/PlatformAdapter.java create mode 100644 core/src/main/java/simplexity/simplenicks/platform/PlayerInfo.java create mode 100644 core/src/main/java/simplexity/simplenicks/platform/SenderContext.java diff --git a/core/src/main/java/simplexity/simplenicks/SimpleNicksCore.java b/core/src/main/java/simplexity/simplenicks/SimpleNicksCore.java new file mode 100644 index 0000000..d9ad9f4 --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/SimpleNicksCore.java @@ -0,0 +1,75 @@ +package simplexity.simplenicks; + +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.jetbrains.annotations.NotNull; +import simplexity.simplenicks.platform.PlatformAdapter; + +/** + * Central singleton for the SimpleNicks core. + *

+ * Initialized by the platform entry point (e.g. {@code SimpleNicks} on Paper, + * {@code SimpleNicksFabric} on Fabric) before any core class is used. + * All core classes access the platform through {@link #get()}. + *

+ */ +public final class SimpleNicksCore { + + private static SimpleNicksCore instance; + + private final PlatformAdapter platform; + private final MiniMessage miniMessage; + + private SimpleNicksCore(@NotNull PlatformAdapter platform) { + this.platform = platform; + this.miniMessage = platform.getMiniMessage(); + } + + /** + * Initializes the core with the given platform adapter. + * Must be called before any core class accesses {@link #get()}. + * + * @param platform the platform-specific adapter + */ + public static void initialize(@NotNull PlatformAdapter platform) { + instance = new SimpleNicksCore(platform); + } + + /** + * Returns the active core instance. + * + * @return the core singleton + * @throws IllegalStateException if {@link #initialize(PlatformAdapter)} has not been called + */ + @NotNull + public static SimpleNicksCore get() { + if (instance == null) throw new IllegalStateException("SimpleNicksCore has not been initialized"); + return instance; + } + + /** + * Tears down the core instance. Called during plugin/mod shutdown. + */ + public static void shutdown() { + instance = null; + } + + /** + * Returns the platform adapter for this environment. + * + * @return the platform adapter + */ + @NotNull + public PlatformAdapter platform() { + return platform; + } + + /** + * Returns the configured {@link MiniMessage} instance. + * + * @return the MiniMessage instance + */ + @NotNull + public MiniMessage miniMessage() { + return miniMessage; + } +} diff --git a/core/src/main/java/simplexity/simplenicks/platform/ConfigProvider.java b/core/src/main/java/simplexity/simplenicks/platform/ConfigProvider.java new file mode 100644 index 0000000..728b17d --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/platform/ConfigProvider.java @@ -0,0 +1,74 @@ +package simplexity.simplenicks.platform; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Abstracts YAML file reading and writing so that core config/locale handlers + * do not depend on platform-specific config APIs (e.g. Bukkit {@code FileConfiguration}). + */ +public interface ConfigProvider { + + /** + * Reloads values from the backing file. + */ + void reload(); + + /** + * Returns the string value at {@code key}, or {@code defaultValue} if absent. + * + * @param key the config key + * @param defaultValue fallback value + * @return the string value, or {@code defaultValue} + */ + @Nullable + String getString(@NotNull String key, @Nullable String defaultValue); + + /** + * Returns the int value at {@code key}, or {@code defaultValue} if absent or not an int. + * + * @param key the config key + * @param defaultValue fallback value + * @return the int value, or {@code defaultValue} + */ + int getInt(@NotNull String key, int defaultValue); + + /** + * Returns the boolean value at {@code key}, or {@code defaultValue} if absent. + * + * @param key the config key + * @param defaultValue fallback value + * @return the boolean value, or {@code defaultValue} + */ + boolean getBoolean(@NotNull String key, boolean defaultValue); + + /** + * Returns the long value at {@code key}, or {@code defaultValue} if absent. + * + * @param key the config key + * @param defaultValue fallback value + * @return the long value, or {@code defaultValue} + */ + long getLong(@NotNull String key, long defaultValue); + + /** + * Sets a value in the backing store. Does not persist until {@link #save()} is called. + * + * @param key the config key + * @param value the value to set + */ + void set(@NotNull String key, @Nullable Object value); + + /** + * Persists the current state of the backing store to disk. + */ + void save(); + + /** + * Returns whether the given key exists in the backing store. + * + * @param key the config key + * @return {@code true} if the key is present + */ + boolean contains(@NotNull String key); +} diff --git a/core/src/main/java/simplexity/simplenicks/platform/PlatformAdapter.java b/core/src/main/java/simplexity/simplenicks/platform/PlatformAdapter.java new file mode 100644 index 0000000..d31f293 --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/platform/PlatformAdapter.java @@ -0,0 +1,133 @@ +package simplexity.simplenicks.platform; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; + +import java.nio.file.Path; +import java.util.Collection; +import java.util.Optional; +import java.util.UUID; + +/** + * Abstracts all platform-specific operations (scheduling, player access, display names, permissions). + *

+ * Each platform (Paper, Fabric) provides its own implementation. Core logic accesses the + * platform exclusively through this interface via {@link simplexity.simplenicks.SimpleNicksCore}. + *

+ */ +public interface PlatformAdapter { + + /** + * Runs a task on a background thread. + * + * @param task the task to run asynchronously + */ + void runAsync(@NotNull Runnable task); + + /** + * Runs a task on the main server thread. + * + * @param task the task to run synchronously + */ + void runSync(@NotNull Runnable task); + + /** + * Returns whether a player is currently online. + * + * @param uuid the player's UUID + * @return {@code true} if the player is online + */ + boolean isPlayerOnline(@NotNull UUID uuid); + + /** + * Returns the username of a player if they are currently online. + * + * @param uuid the player's UUID + * @return the username, or empty if offline + */ + @NotNull + Optional getPlayerUsername(@NotNull UUID uuid); + + /** + * Returns the UUIDs of all currently online players. + * + * @return collection of online player UUIDs + */ + @NotNull + Collection getOnlinePlayers(); + + /** + * Sets the display name shown in chat and above the player's head. + * + * @param uuid the player's UUID + * @param displayName the Adventure component to display + */ + void setDisplayName(@NotNull UUID uuid, @NotNull Component displayName); + + /** + * Sets the name shown in the tab list. + * + * @param uuid the player's UUID + * @param tablistName the Adventure component to display + */ + void setTablistName(@NotNull UUID uuid, @NotNull Component tablistName); + + /** + * Clears the player's display name, reverting to their username. + * + * @param uuid the player's UUID + */ + void clearDisplayName(@NotNull UUID uuid); + + /** + * Checks whether the given player has a permission node. + * + * @param uuid the player's UUID + * @param permission the permission node string + * @return {@code true} if the player has the permission + */ + boolean hasPermission(@NotNull UUID uuid, @NotNull String permission); + + /** + * Returns the plugin's data directory (where config and database files are stored). + * + * @return the data directory path + */ + @NotNull + Path getDataDirectory(); + + /** + * Returns the plugin logger. + * + * @return SLF4J logger instance + */ + @NotNull + Logger getLogger(); + + /** + * Returns the configured {@link MiniMessage} instance with all permitted color and format + * tag resolvers registered. + * + * @return the MiniMessage instance + */ + @NotNull + MiniMessage getMiniMessage(); + + /** + * Returns the {@link ConfigProvider} for {@code config.yml}. + * + * @return config provider + */ + @NotNull + ConfigProvider getConfigProvider(); + + /** + * Returns the {@link ConfigProvider} for {@code locale.yml}. + * + * @return locale provider + */ + @NotNull + ConfigProvider getLocaleProvider(); +} diff --git a/core/src/main/java/simplexity/simplenicks/platform/PlayerInfo.java b/core/src/main/java/simplexity/simplenicks/platform/PlayerInfo.java new file mode 100644 index 0000000..9f2cd21 --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/platform/PlayerInfo.java @@ -0,0 +1,18 @@ +package simplexity.simplenicks.platform; + +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + +/** + * Immutable snapshot of a player's identity and last login time. + *

+ * Replaces {@code OfflinePlayer} in core logic so that player data can be + * resolved purely from the database without platform API calls. + *

+ * + * @param uuid the player's UUID + * @param username the player's last known username + * @param lastLoginMillis epoch milliseconds of the player's last login, or {@code -1} if unknown + */ +public record PlayerInfo(@NotNull UUID uuid, @NotNull String username, long lastLoginMillis) {} diff --git a/core/src/main/java/simplexity/simplenicks/platform/SenderContext.java b/core/src/main/java/simplexity/simplenicks/platform/SenderContext.java new file mode 100644 index 0000000..b01dd8b --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/platform/SenderContext.java @@ -0,0 +1,56 @@ +package simplexity.simplenicks.platform; + +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; +import java.util.UUID; + +/** + * Platform-agnostic abstraction for a command sender (player or console). + *

+ * Paper wraps {@code CommandSender}; Fabric wraps {@code CommandSourceStack}. + * Core logic uses this interface instead of platform types for permission checks + * and message delivery. + *

+ */ +public interface SenderContext { + + /** + * Checks whether this sender has the given permission node. + * + * @param permission the permission node string + * @return {@code true} if the sender has the permission + */ + boolean hasPermission(@NotNull String permission); + + /** + * Returns the UUID of this sender if they are a player, otherwise empty. + * + * @return the player's UUID, or empty for the console + */ + @NotNull + Optional getUuid(); + + /** + * Sends an Adventure component message to this sender. + * + * @param message the component to send + */ + void sendMessage(@NotNull Component message); + + /** + * Returns whether this sender is a player (as opposed to the console or a command block). + * + * @return {@code true} if the sender is a player + */ + boolean isPlayer(); + + /** + * Returns a display-friendly name for this sender (player name or "[Console]"). + * + * @return the sender's display name + */ + @NotNull + String getDisplayName(); +} From 114ad6f291147306a419f058ea1bc61a21b7c41f Mon Sep 17 00:00:00 2001 From: Peashooter101 Date: Thu, 4 Jun 2026 10:23:07 -0500 Subject: [PATCH 03/19] Add core data classes, util enums, and config handlers --- .../simplenicks/config/ConfigHandler.java | 150 ++++++++++++++++++ .../simplenicks/config/LocaleHandler.java | 44 +++++ .../simplenicks/config/LocaleMessage.java | 109 +++++++++++++ .../simplenicks/config/MessageUtils.java | 87 ++++++++++ .../simplenicks/saving/Nickname.java | 40 +++++ .../simplenicks/saving/NicknameRecord.java | 7 + .../simplexity/simplenicks/util/ColorTag.java | 37 +++++ .../simplenicks/util/FormatTag.java | 41 +++++ .../simplenicks/util/NickPermission.java | 44 +++++ 9 files changed, 559 insertions(+) create mode 100644 core/src/main/java/simplexity/simplenicks/config/ConfigHandler.java create mode 100644 core/src/main/java/simplexity/simplenicks/config/LocaleHandler.java create mode 100644 core/src/main/java/simplexity/simplenicks/config/LocaleMessage.java create mode 100644 core/src/main/java/simplexity/simplenicks/config/MessageUtils.java create mode 100644 core/src/main/java/simplexity/simplenicks/saving/Nickname.java create mode 100644 core/src/main/java/simplexity/simplenicks/saving/NicknameRecord.java create mode 100644 core/src/main/java/simplexity/simplenicks/util/ColorTag.java create mode 100644 core/src/main/java/simplexity/simplenicks/util/FormatTag.java create mode 100644 core/src/main/java/simplexity/simplenicks/util/NickPermission.java diff --git a/core/src/main/java/simplexity/simplenicks/config/ConfigHandler.java b/core/src/main/java/simplexity/simplenicks/config/ConfigHandler.java new file mode 100644 index 0000000..cd2927b --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/config/ConfigHandler.java @@ -0,0 +1,150 @@ +package simplexity.simplenicks.config; + +import org.slf4j.Logger; +import simplexity.simplenicks.SimpleNicksCore; +import simplexity.simplenicks.platform.ConfigProvider; + +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +public class ConfigHandler { + + private static ConfigHandler instance; + + private Pattern regex; + private boolean mySql, tablistNick, usernameProtection, onlineNickProtection, offlineNickProtection, debugMode, + nickRequiresPermission, colorRequiresPermission, formatRequiresPermission, whoRequiresPermission; + private int maxLength, maxSaves; + private static final int MILLI_PER_DAY = 86_400_000; + private String regexString, nickPrefix, mySqlIp, mySqlName, mySqlUsername, mySqlPassword; + private long usernameProtectionTime, offlineNickProtectionTime = 0; + + private ConfigHandler() { + } + + public static ConfigHandler getInstance() { + if (instance != null) return instance; + instance = new ConfigHandler(); + return instance; + } + + private static Logger logger() { + return SimpleNicksCore.get().platform().getLogger(); + } + + public void reloadConfig() { + ConfigProvider config = SimpleNicksCore.get().platform().getConfigProvider(); + config.reload(); + LocaleHandler.getInstance().reloadLocale(); + try { + String regexSetting = config.getString("nickname-regex", "[A-Za-z0-9_]+"); + regexString = regexSetting; + regex = Pattern.compile(regexSetting); + } catch (PatternSyntaxException e) { + logger().error(LocaleMessage.ERROR_INVALID_CONFIG_REGEX.getMessage(), e); + } + debugMode = config.getBoolean("debug-mode", false); + mySql = config.getBoolean("mysql.enabled", false); + nickRequiresPermission = config.getBoolean("require-permission.nick", true); + colorRequiresPermission = config.getBoolean("require-permission.color", true); + formatRequiresPermission = config.getBoolean("require-permission.format", true); + whoRequiresPermission = config.getBoolean("require-permission.who", false); + mySqlIp = config.getString("mysql.ip", "localhost:3306"); + mySqlName = config.getString("mysql.name", "simplenicks"); + mySqlUsername = config.getString("mysql.username", "username1"); + mySqlPassword = config.getString("mysql.password", "badpassword!"); + maxLength = config.getInt("max-nickname-length", 25); + maxSaves = config.getInt("max-saves", 5); + tablistNick = config.getBoolean("tablist-nick", false); + usernameProtection = config.getBoolean("nickname-protection.username.enabled", true); + usernameProtectionTime = config.getLong("nickname-protection.username.expires", 30) * MILLI_PER_DAY; + nickPrefix = config.getString("nickname-prefix", ""); + onlineNickProtection = config.getBoolean("nickname-protection.online.enabled", false); + offlineNickProtection = config.getBoolean("nickname-protection.offline.enabled", false); + offlineNickProtectionTime = config.getLong("nickname-protection.offline.expires", 30) * MILLI_PER_DAY; + } + + public Pattern getRegex() { + return regex; + } + + public String getRegexString() { + return regexString; + } + + public int getMaxLength() { + return maxLength; + } + + public int getMaxSaves() { + return maxSaves; + } + + public boolean shouldNickTablist() { + return tablistNick; + } + + public long getUsernameProtectionTime() { + return usernameProtectionTime; + } + + public boolean isMySql() { + return mySql; + } + + public String getMySqlIp() { + return mySqlIp; + } + + public String getMySqlName() { + return mySqlName; + } + + public String getMySqlUsername() { + return mySqlUsername; + } + + public String getMySqlPassword() { + return mySqlPassword; + } + + public long getOfflineNickProtectionTime() { + return offlineNickProtectionTime; + } + + public boolean shouldOnlineNicksBeProtected() { + return onlineNickProtection; + } + + public boolean shouldOfflineNicksBeProtected() { + return offlineNickProtection; + } + + public boolean isDebugMode() { + return debugMode; + } + + public boolean isNickRequiresPermission() { + return nickRequiresPermission; + } + + public boolean isColorRequiresPermission() { + return colorRequiresPermission; + } + + public boolean isFormatRequiresPermission() { + return formatRequiresPermission; + } + + public boolean isWhoRequiresPermission() { + return whoRequiresPermission; + } + + public boolean isUsernameProtection() { + return usernameProtection; + } + + public String getNickPrefix() { + return nickPrefix; + } +} diff --git a/core/src/main/java/simplexity/simplenicks/config/LocaleHandler.java b/core/src/main/java/simplexity/simplenicks/config/LocaleHandler.java new file mode 100644 index 0000000..05608a6 --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/config/LocaleHandler.java @@ -0,0 +1,44 @@ +package simplexity.simplenicks.config; + +import simplexity.simplenicks.SimpleNicksCore; +import simplexity.simplenicks.platform.ConfigProvider; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +@SuppressWarnings("CallToPrintStackTrace") +public class LocaleHandler { + + private static LocaleHandler instance; + + private LocaleHandler() { + } + + public static LocaleHandler getInstance() { + if (instance == null) { + instance = new LocaleHandler(); + } + return instance; + } + + public void reloadLocale() { + ConfigProvider locale = SimpleNicksCore.get().platform().getLocaleProvider(); + locale.reload(); + populateLocale(locale); + locale.save(); + } + + private void populateLocale(ConfigProvider locale) { + Set missing = new HashSet<>(Arrays.asList(LocaleMessage.values())); + for (LocaleMessage localeMessage : LocaleMessage.values()) { + if (locale.contains(localeMessage.getPath())) { + localeMessage.setMessage(locale.getString(localeMessage.getPath(), localeMessage.getMessage())); + missing.remove(localeMessage); + } + } + for (LocaleMessage localeMessage : missing) { + locale.set(localeMessage.getPath(), localeMessage.getMessage()); + } + } +} diff --git a/core/src/main/java/simplexity/simplenicks/config/LocaleMessage.java b/core/src/main/java/simplexity/simplenicks/config/LocaleMessage.java new file mode 100644 index 0000000..e469d8b --- /dev/null +++ b/core/src/main/java/simplexity/simplenicks/config/LocaleMessage.java @@ -0,0 +1,109 @@ +package simplexity.simplenicks.config; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public enum LocaleMessage { + HELP_HEADER("plugin.help.header", "========== SimpleNicks Help =========="), + HELP_SET("plugin.help.set", "/nick set (nickname) - Set your nickname"), + HELP_RESET("plugin.help.reset", "/nick reset - Reset your nickname"), + HELP_SAVE("plugin.help.save", "/nick save [nickname] - Save a nickname for later"), + HELP_DELETE("plugin.help.delete", "/nick delete (nickname) - Delete a saved nickname"), + HELP_WHO("plugin.help.who", "/nick who (nickname) - Find who is using a nickname"), + HELP_ADMIN_SET("plugin.help.admin.set", "/nick admin set (username) (nickname) - Set another player's nickname"), + HELP_ADMIN_RESET("plugin.help.admin.reset", "/nick admin reset (username) - Reset another player's nickname"), + HELP_ADMIN_DELETE("plugin.help.admin.delete", "/nick admin delete (username) (nickname) - Delete a saved nickname from a player"), + HELP_ADMIN_LOOKUP("plugin.help.admin.lookup", "/nick admin lookup (username) - Look up a player's nickname info"), + HELP_RELOAD("plugin.help.reload", "/nick reload - Reload the plugin configuration"), + SHOWN_HELP("plugin.user-shown-help", " has been shown the help screen"), + CONFIG_RELOADED("plugin.config-reloaded", "SimpleNicks config and locale reloaded"), + SERVER_DISPLAY_NAME("plugin.server-display-name", "[Server]"), + + // Basic Functionality + SET_SELF("nick.set.self", "Changed your nickname to !"), + SET_TARGET("nick.set.target", "Changed 's nickname to "), + SET_BY_INITIATOR("nick.set.by-initiator", " changed your nickname to !"), + RESET_SELF("nick.reset.self", "Reset your nickname!"), + RESET_TARGET("nick.reset.target", "Reset 's nickname."), + RESET_BY_INITIATOR("nick.reset.by-initiator", "Your nickname was reset by "), + SAVE_NICK("nick.save.self", "Success! The nickname has been saved for future use"), + DELETE_SELF("nick.delete.self", "The nickname has been successfully removed from your saved names"), + DELETED_TARGET("nick.delete.target", "You have successfully deleted from 's saved nicknames"), + DELETED_BY_INITIATOR("nick.delete.by-initiator", "The nickname has been deleted from your saved nicknames by "), + WHO_HEADER("nick.who.header", "Users with the name : "), + WHO_INFO("nick.who.info", "\n- - Last Seen: