From f6aa06483565f8a87ca97b520ed2de1ca18fbcb3 Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 9 Jun 2016 12:43:04 +0200 Subject: [PATCH] Added localization messages (Fixes #20) --- bukkit/pom.xml | 2 +- .../games647/fastlogin/bukkit/BukkitCore.java | 20 +++++ .../fastlogin/bukkit/FastLoginBukkit.java | 6 +- .../bukkit/commands/CrackedCommand.java | 10 +-- .../bukkit/commands/PremiumCommand.java | 10 +-- .../bukkit/hooks/CrazyLoginHook.java | 2 +- .../bukkit/hooks/LoginSecurityHook.java | 8 +- .../fastlogin/bukkit/hooks/UltraAuthHook.java | 1 - .../bukkit/listener/BukkitJoinListener.java | 2 +- .../bukkit/listener/BungeeCordListener.java | 2 +- .../listener/ProtocolSupportListener.java | 3 +- .../packet/EncryptionPacketListener.java | 28 ++++--- .../bukkit/{ => tasks}/DelayedAuthHook.java | 3 +- .../bukkit/{ => tasks}/ForceLoginTask.java | 10 +-- bungee/pom.xml | 2 +- .../games647/fastlogin/bungee/BungeeCore.java | 44 +++++++++++ .../fastlogin/bungee/FastLoginBungee.java | 17 +--- .../bungee/tasks/AsyncToggleMessage.java | 23 +----- core/pom.xml | 2 +- .../fastlogin/core/FastLoginCore.java | 11 +++ .../core/importer/ElDziAuthImporter.java | 1 + core/src/main/resources/messages.yml | 79 ++++++++++++++++--- pom.xml | 2 +- universal/pom.xml | 2 +- 24 files changed, 206 insertions(+), 84 deletions(-) rename bukkit/src/main/java/com/github/games647/fastlogin/bukkit/{ => tasks}/DelayedAuthHook.java (96%) rename bukkit/src/main/java/com/github/games647/fastlogin/bukkit/{ => tasks}/ForceLoginTask.java (92%) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 6a0421b7..4e8120be 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.4 + 1.5 ../pom.xml diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java index 3304694d..51a7f9d1 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java @@ -7,6 +7,9 @@ import java.io.File; import java.util.concurrent.ThreadFactory; import java.util.logging.Logger; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.YamlConfiguration; + public class BukkitCore extends FastLoginCore { private final FastLoginBukkit plugin; @@ -34,4 +37,21 @@ public class BukkitCore extends FastLoginCore { .setDaemon(true) .build(); } + + @Override + public void loadMessages() { + plugin.saveResource("messages.yml", false); + + File messageFile = new File(plugin.getDataFolder(), "messages.yml"); + YamlConfiguration messageConfig = YamlConfiguration.loadConfiguration(messageFile); + for (String key : messageConfig.getKeys(false)) { + String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key)); + localeMessages.put(key, message); + } + } + + @Override + public void loadConfig() { + plugin.saveConfig(); + } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index b2f05eba..2096d213 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -1,5 +1,6 @@ package com.github.games647.fastlogin.bukkit; +import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook; import com.avaje.ebeaninternal.api.ClassUtil; import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.ProtocolLibrary; @@ -59,6 +60,9 @@ public class FastLoginBukkit extends JavaPlugin { @Override public void onEnable() { core.setMojangApiConnector(new MojangApiBukkit(core)); + + core.loadConfig(); + core.loadMessages(); try { if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) { @@ -69,8 +73,6 @@ public class FastLoginBukkit extends JavaPlugin { ex.printStackTrace(); } - saveDefaultConfig(); - if (getServer().getOnlineMode()) { //we need to require offline to prevent a session request for a offline player getLogger().severe("Server have to be in offline mode"); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java index fb675035..f479ed98 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java @@ -25,13 +25,13 @@ public class CrackedCommand implements CommandExecutor { if (args.length == 0) { if (!(sender instanceof Player)) { //console or command block - sender.sendMessage(ChatColor.DARK_RED + "Only players can remove themselves from the premium list"); + sender.sendMessage(plugin.getCore().getMessage("no-console")); return true; } if (plugin.isBungeeCord()) { notifiyBungeeCord(sender, sender.getName()); - sender.sendMessage(ChatColor.YELLOW + "Sending request..."); + sender.sendMessage(plugin.getCore().getMessage("wait-on-proxy")); } else { //todo: load async if it's not in the cache anymore final PlayerProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName()); @@ -53,18 +53,18 @@ public class CrackedCommand implements CommandExecutor { return true; } else { if (!sender.hasPermission(command.getPermission() + ".other")) { - sender.sendMessage(ChatColor.DARK_RED + "Not enough permissions"); + sender.sendMessage(plugin.getCore().getMessage("no-permission")); return true; } if (plugin.isBungeeCord()) { notifiyBungeeCord(sender, args[0]); - sender.sendMessage(ChatColor.YELLOW + "Sending request for player " + args[0] + "..."); + sender.sendMessage(plugin.getCore().getMessage("wait-on-proxy")); } else { //todo: load async if it's not in the cache anymore final PlayerProfile profile = plugin.getCore().getStorage().loadProfile(args[0]); if (profile == null) { - sender.sendMessage(ChatColor.DARK_RED + "Player not in the database"); + sender.sendMessage(plugin.getCore().getMessage("player-unknown")); return true; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java index e37df3b9..ac3fbd75 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java @@ -30,13 +30,13 @@ public class PremiumCommand implements CommandExecutor { if (args.length == 0) { if (!(sender instanceof Player)) { //console or command block - sender.sendMessage(ChatColor.DARK_RED + "Only players can add themselves as premium"); + sender.sendMessage(plugin.getCore().getMessage("no-console")); return true; } if (plugin.isBungeeCord()) { notifiyBungeeCord(sender, sender.getName()); - sender.sendMessage(ChatColor.YELLOW + "Sending request..."); + sender.sendMessage(plugin.getCore().getMessage("wait-on-proxy")); } else { // //todo: load async if it's not in the cache anymore final PlayerProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName()); @@ -59,18 +59,18 @@ public class PremiumCommand implements CommandExecutor { return true; } else { if (!sender.hasPermission(command.getPermission() + ".other")) { - sender.sendMessage(ChatColor.DARK_RED + "Not enough permissions"); + sender.sendMessage(plugin.getCore().getMessage("no-permission")); return true; } if (plugin.isBungeeCord()) { notifiyBungeeCord(sender, args[0]); - sender.sendMessage(ChatColor.YELLOW + "Sending request..."); + sender.sendMessage(plugin.getCore().getMessage("wait-on-proxy")); } else { //todo: load async if it's not in the cache anymore final PlayerProfile profile = plugin.getCore().getStorage().loadProfile(args[0]); if (profile == null) { - sender.sendMessage(ChatColor.DARK_RED + "Player not in the database"); + sender.sendMessage(plugin.getCore().getMessage("player-unknown")); return true; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java index c90de171..6529dcad 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java @@ -7,10 +7,10 @@ import de.st_ddt.crazylogin.data.LoginPlayerData; import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase; import de.st_ddt.crazylogin.listener.PlayerListener; import de.st_ddt.crazylogin.metadata.Authenticated; + import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; - import java.util.logging.Level; import org.bukkit.Bukkit; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java index 90ad55be..0ce7f5fa 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java @@ -5,14 +5,13 @@ import com.lenis0012.bukkit.ls.LoginSecurity; import com.lenis0012.bukkit.ls.data.DataManager; import java.net.InetAddress; - import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; -import org.bukkit.Bukkit; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** @@ -27,6 +26,11 @@ import org.bukkit.entity.Player; public class LoginSecurityHook implements BukkitAuthPlugin { protected final LoginSecurity securityPlugin = LoginSecurity.instance; +// protected final boolean newVersion; + + public LoginSecurityHook() { +// this.newVersion = ClassUtil.isPresent("com.lenis0012.bukkit.loginsecurity.session.action.LoginAction"); + } @Override public boolean forceLogin(final Player player) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java index 4b19350e..7011f1b3 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java @@ -6,7 +6,6 @@ import java.util.concurrent.Future; import java.util.logging.Level; import org.bukkit.Bukkit; - import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java index 1f3c8dff..6c3318ae 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java @@ -4,7 +4,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedSignedProperty; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; -import com.github.games647.fastlogin.bukkit.ForceLoginTask; +import com.github.games647.fastlogin.bukkit.tasks.ForceLoginTask; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java index af46e02b..e11ef442 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java @@ -1,7 +1,7 @@ package com.github.games647.fastlogin.bukkit.listener; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; -import com.github.games647.fastlogin.bukkit.ForceLoginTask; +import com.github.games647.fastlogin.bukkit.tasks.ForceLoginTask; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin; import com.google.common.base.Charsets; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtocolSupportListener.java index 6b697518..ba8bafd3 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtocolSupportListener.java @@ -89,7 +89,8 @@ public class ProtocolSupportListener implements Listener { } } - private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered, PlayerProfile playerProfile) { + private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered + , PlayerProfile playerProfile) { loginStartEvent.setOnlineMode(true); InetSocketAddress address = loginStartEvent.getAddress(); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/packet/EncryptionPacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/packet/EncryptionPacketListener.java index 2020786c..04669c1f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/packet/EncryptionPacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/packet/EncryptionPacketListener.java @@ -9,9 +9,9 @@ import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.EncryptionUtil; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; -import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -75,7 +75,7 @@ public class EncryptionPacketListener extends PacketAdapter { BukkitLoginSession session = plugin.getSessions().get(player.getAddress().toString()); if (session == null) { - disconnect(packetEvent, "Invalid request", Level.FINE + disconnect(packetEvent, plugin.getCore().getMessage("invalid-requst"), true , "Player {0} tried to send encryption response at invalid state", player.getAddress()); return; } @@ -106,7 +106,7 @@ public class EncryptionPacketListener extends PacketAdapter { receiveFakeStartPacket(username, player); } else { //user tried to fake a authentication - disconnect(packetEvent, "Invalid session", Level.FINE + disconnect(packetEvent, plugin.getCore().getMessage("invalid-session"), true , "Player {0} ({1}) tried to log in with an invalid session ServerId: {2}" , session.getUsername(), player.getAddress(), serverId); } @@ -137,9 +137,8 @@ public class EncryptionPacketListener extends PacketAdapter { //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L182 if (!Arrays.equals(requestVerify, EncryptionUtil.decryptData(privateKey, responseVerify))) { //check if the verify token are equal to the server sent one - disconnect(packetEvent, "Invalid token", Level.FINE - , "Player {0} ({1}) tried to login with an invalid verify token. " - + "Server: {2} Client: {3}" + disconnect(packetEvent, plugin.getCore().getMessage("invalid-verify-token"), true + , "Player {0} ({1}) tried to login with an invalid verify token. Server: {2} Client: {3}" , session.getUsername(), packetEvent.getPlayer().getAddress(), requestVerify, responseVerify); return false; } @@ -168,23 +167,28 @@ public class EncryptionPacketListener extends PacketAdapter { Object networkManager = getNetworkManager(player); //try to detect the method by parameters - Method encryptConnectionMethod = FuzzyReflection.fromObject(networkManager) - .getMethodByParameters("a", SecretKey.class); + Method encryptConnectionMethod = FuzzyReflection + .fromObject(networkManager).getMethodByParameters("a", SecretKey.class); //encrypt/decrypt following packets //the client expects this behaviour encryptConnectionMethod.invoke(networkManager, loginKey); } catch (ReflectiveOperationException ex) { - disconnect(packetEvent, "Error occurred", Level.SEVERE, "Couldn't enable encryption", ex); + disconnect(packetEvent, plugin.getCore().getMessage("error-kick"), false, "Couldn't enable encryption", ex); return false; } return true; } - private void disconnect(PacketEvent packetEvent, String kickReason, Level logLevel, String logMessage + private void disconnect(PacketEvent packetEvent, String kickReason, boolean debugLevel, String logMessage , Object... arguments) { - plugin.getLogger().log(logLevel, logMessage, arguments); + if (debugLevel) { + plugin.getLogger().log(Level.FINE, logMessage, arguments); + } else { + plugin.getLogger().log(Level.SEVERE, logMessage, arguments); + } + kickPlayer(packetEvent.getPlayer(), kickReason); //cancel the event in order to prevent the server receiving an invalid packet packetEvent.setCancelled(true); @@ -219,7 +223,7 @@ public class EncryptionPacketListener extends PacketAdapter { } catch (InvocationTargetException | IllegalAccessException ex) { plugin.getLogger().log(Level.WARNING, "Failed to fake a new start packet", ex); //cancel the event in order to prevent the server receiving an invalid packet - kickPlayer(from, "Error occured"); + kickPlayer(from, plugin.getCore().getMessage("error-kick")); } } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/DelayedAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java similarity index 96% rename from bukkit/src/main/java/com/github/games647/fastlogin/bukkit/DelayedAuthHook.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java index 373383cc..33ca0b0c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/DelayedAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java @@ -1,5 +1,6 @@ -package com.github.games647.fastlogin.bukkit; +package com.github.games647.fastlogin.bukkit.tasks; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.hooks.AuthMeHook; import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin; import com.github.games647.fastlogin.bukkit.hooks.CrazyLoginHook; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java similarity index 92% rename from bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java index c047299e..23ec60a5 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java @@ -1,5 +1,7 @@ -package com.github.games647.fastlogin.bukkit; +package com.github.games647.fastlogin.bukkit.tasks; +import com.github.games647.fastlogin.bukkit.BukkitLoginSession; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin; import com.github.games647.fastlogin.core.PlayerProfile; import com.github.games647.fastlogin.core.Storage; @@ -12,7 +14,6 @@ import java.util.concurrent.Future; import java.util.logging.Level; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; public class ForceLoginTask implements Runnable { @@ -85,15 +86,14 @@ public class ForceLoginTask implements Runnable { String generatedPassword = plugin.generateStringPassword(player); boolean success = authPlugin.forceRegister(player, generatedPassword); - player.sendMessage(ChatColor.DARK_GREEN + "Auto registered with password: " + generatedPassword); - player.sendMessage(ChatColor.DARK_GREEN + "You may want change it?"); + player.sendMessage(plugin.getCore().getMessage("auto-register").replace("%password", generatedPassword)); return success; } private boolean forceLogin(BukkitAuthPlugin authPlugin, Player player) { plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName()); boolean success = authPlugin.forceLogin(player); - player.sendMessage(ChatColor.DARK_GREEN + "Auto logged in"); + player.sendMessage(plugin.getCore().getMessage("auto-login")); return success; } diff --git a/bungee/pom.xml b/bungee/pom.xml index 026aa400..ae0f3591 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.4 + 1.5 ../pom.xml diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java index d0a8d83b..492d79aa 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java @@ -4,10 +4,18 @@ import com.github.games647.fastlogin.core.FastLoginCore; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.util.concurrent.ThreadFactory; +import java.util.logging.Level; import java.util.logging.Logger; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.scheduler.GroupedThreadFactory; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; public class BungeeCore extends FastLoginCore { @@ -36,4 +44,40 @@ public class BungeeCore extends FastLoginCore { .setDaemon(true) .setThreadFactory(new GroupedThreadFactory(plugin, pluginName)).build(); } + + @Override + public void loadMessages() { + try { + saveDefaultFile("messages.yml"); + + File messageFile = new File(getDataFolder(), "messages.yml"); + Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(messageFile); + for (String key : messageConfig.getKeys()) { + String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key)); + localeMessages.put(key, message); + } + } catch (IOException ex) { + getLogger().log(Level.SEVERE, "Failed to load messages", ex); + } + } + + @Override + public void loadConfig() { + if (!getDataFolder().exists()) { + getDataFolder().mkdir(); + } + + saveDefaultFile("config.yml"); + } + + private void saveDefaultFile(String fileName) { + File configFile = new File(getDataFolder(), fileName); + if (!configFile.exists()) { + try (InputStream in = plugin.getResourceAsStream(fileName)) { + Files.copy(in, configFile.toPath()); + } catch (IOException ioExc) { + getLogger().log(Level.SEVERE, "Error saving default " + fileName, ioExc); + } + } + } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index b28bb766..70b6c873 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -10,8 +10,6 @@ import com.google.common.cache.CacheBuilder; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; import java.util.Random; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -46,20 +44,11 @@ public class FastLoginBungee extends Plugin { public void onEnable() { loginCore.setMojangApiConnector(new MojangApiBungee(loginCore)); - if (!getDataFolder().exists()) { - getDataFolder().mkdir(); - } - - File configFile = new File(getDataFolder(), "config.yml"); - if (!configFile.exists()) { - try (InputStream in = getResourceAsStream("config.yml")) { - Files.copy(in, configFile.toPath()); - } catch (IOException ioExc) { - getLogger().log(Level.SEVERE, "Error saving default config", ioExc); - } - } + loginCore.loadConfig(); + loginCore.loadMessages(); try { + File configFile = new File(getDataFolder(), "config.yml"); configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); String driver = configuration.getString("driver"); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java index 9d817966..b18a0f3f 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncToggleMessage.java @@ -3,7 +3,6 @@ package com.github.games647.fastlogin.bungee.tasks; import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.core.PlayerProfile; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -34,39 +33,25 @@ public class AsyncToggleMessage implements Runnable { private void turnOffPremium() { PlayerProfile playerProfile = plugin.getCore().getStorage().loadProfile(targetPlayer); if (!playerProfile.isPremium()) { - if (fromPlayer.isConnected()) { - TextComponent textComponent = new TextComponent("You are not in the premium list"); - textComponent.setColor(ChatColor.DARK_RED); - fromPlayer.sendMessage(textComponent); - } - + fromPlayer.sendMessage(TextComponent.fromLegacyText(plugin.getCore().getMessage("not-premium"))); return; } playerProfile.setPremium(false); playerProfile.setUuid(null); plugin.getCore().getStorage().save(playerProfile); - TextComponent textComponent = new TextComponent("Removed to the list of premium players"); - textComponent.setColor(ChatColor.DARK_GREEN); - fromPlayer.sendMessage(textComponent); + fromPlayer.sendMessage(TextComponent.fromLegacyText(plugin.getCore().getMessage("remove-premium"))); } private void activatePremium() { PlayerProfile playerProfile = plugin.getCore().getStorage().loadProfile(targetPlayer); if (playerProfile.isPremium()) { - if (fromPlayer.isConnected()) { - TextComponent textComponent = new TextComponent("You are already on the premium list"); - textComponent.setColor(ChatColor.DARK_RED); - fromPlayer.sendMessage(textComponent); - } - + fromPlayer.sendMessage(TextComponent.fromLegacyText(plugin.getCore().getMessage("already-exists"))); return; } playerProfile.setPremium(true); plugin.getCore().getStorage().save(playerProfile); - TextComponent textComponent = new TextComponent("Added to the list of premium players"); - textComponent.setColor(ChatColor.DARK_GREEN); - fromPlayer.sendMessage(textComponent); + fromPlayer.sendMessage(TextComponent.fromLegacyText(plugin.getCore().getMessage("add-premium"))); } } diff --git a/core/pom.xml b/core/pom.xml index 0c6e7e84..cc0bddd2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.4 + 1.5 ../pom.xml diff --git a/core/src/main/java/com/github/games647/fastlogin/core/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/FastLoginCore.java index c3bb5884..64a77c15 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/FastLoginCore.java @@ -1,6 +1,8 @@ package com.github.games647.fastlogin.core; import java.io.File; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import java.util.concurrent.ThreadFactory; import java.util.logging.Level; @@ -16,6 +18,7 @@ public abstract class FastLoginCore { + "-" + withoutDashes.substring(20, 32)); } + protected final Map localeMessages = new HashMap<>(); private MojangApiConnector mojangApiConnector; private Storage storage; @@ -37,6 +40,14 @@ public abstract class FastLoginCore { public abstract ThreadFactory getThreadFactory(); + public String getMessage(String key) { + return localeMessages.get(key); + } + + public abstract void loadMessages(); + + public abstract void loadConfig(); + public boolean setupDatabase(String driver, String host, int port, String database, String user, String password) { storage = new Storage(this, driver, host, port, database, user, password); try { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java b/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java index 1d1de711..fd21f299 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/importer/ElDziAuthImporter.java @@ -3,6 +3,7 @@ package com.github.games647.fastlogin.core.importer; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; + import javax.sql.DataSource; public class ElDziAuthImporter extends Importer { diff --git a/core/src/main/resources/messages.yml b/core/src/main/resources/messages.yml index 34662b1f..6f3083b2 100644 --- a/core/src/main/resources/messages.yml +++ b/core/src/main/resources/messages.yml @@ -4,15 +4,76 @@ # # You can access the newest locale here: # https://github.com/games647/FastLogin/blob/master/core/src/main/resources/messages.yml +# +# You want to have language template? Visit the Github Wiki here: +# https://github.com/games647/FastLogin/wiki/English -# ========= Shared (BungeeCord an Bukkit) ============ - - - -# ========= Bukkit only ================================ - - - -# ========= Bungee only ================================ +# In order to split a message into seperate lines you could just make a new line, but keep the ' +# Example: +# bla: '&aFirst line +# Second line +# Third line' + +# If you want to disable a message, you can just set it to a empty value. +# In this case no message will be sent +# Example: +# bla: '' + +# ========= Shared (BungeeCord and Bukkit) ============ + +# Player activated premium logins in order to skip offline authentication +add-premium: '&2Added to the list of premium players' + +# Player is already set be a paid account +already-exists: '&4You are already on the premium list' + +# Player was changed to be cracked +remove-premium: '&2Removed from the list of premium players' + +# Player is already set to be cracked +not-premium: '&4You are not in the premium list' + +# Admin wanted to change the premium of a user that isn't known to the plugin +player-unknown: '&4Player not in the database' + +# ========= Bukkit/Spigot/PaperSpigot/TacoSpigot only ================================ + +# The user skipped the authentication, because it was a premium player +auto-login: '&2Auto logged in' + +# The user was auto registered on the first join. The user account will be registered to protect it from cracked players +# The password can be used if the mojang servers are down and you still want your premium users to login (PLANNED) +auto-register: '&2Auto registered with password: %password +You may want change it?' + +# Player is not able to toggle the premium state of other players +no-permission: '&4Not enough permissions' + +# Although the console can toggle the premium state, it's not possible for the console itself. +# Because the console is not a user. (obviously, isn't it?) +no-console: '&4You are not a player. You cannot toggle the premium state for YOURSELF as a console' + +# The user wants to toggle premium state, but BungeeCord support is enabled. This means the server have to communicate +# with the BungeeCord first which will establish a connection with the database server. +wait-on-proxy: '&6Sending request...' + +# When ProtocolLib is enabled and the plugin is unable to continue handling a login request after a requested premium +# authentication. In this state the client expects a success packet with a encrypted connection or disconnect packet. +# So we kick the player, if we cannot encrypt the connection. In other situation (example: premium name check), +# the player will be just authenticated as cracked +error-kick: '&4Error occured' + +# The server sents a verify token within the premium authentication reqest. If this doesn't match on response, +# it could be another client sending malicious packets +invalid-verify-token: '&4Invalid token' + +# The client sent no request join server request to the mojang servers which would proof that it's owner of that +# acciunt. Only modified clients would do this. +invalid-session: '&4Invalid session' + +# The client sent a malicous packet without a login request packet +invalid-requst: '&4Invalid request' + +# ========= Bungee/Waterfall only ================================ diff --git a/pom.xml b/pom.xml index 4379722c..3fcc6eb9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ pom FastLogin - 1.4 + 1.5 2015 https://www.spigotmc.org/resources/fastlogin.14153/ diff --git a/universal/pom.xml b/universal/pom.xml index 79c0552e..ddef93a2 100644 --- a/universal/pom.xml +++ b/universal/pom.xml @@ -5,7 +5,7 @@ com.github.games647 fastlogin - 1.4 + 1.5 ../pom.xml