Intial i18n messages support
Send different languages of messages based on player's client setting
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Player utilities.
|
||||
*/
|
||||
@@ -36,4 +39,30 @@ public final class PlayerUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale that player uses.
|
||||
*
|
||||
* @param sender The player
|
||||
*/
|
||||
public static String getLocale(CommandSender sender) {
|
||||
String locale = null;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (Utils.majorVersion >= 12) {
|
||||
locale = player.getLocale();
|
||||
} else {
|
||||
try {
|
||||
Method spigotMethod = player.getClass().getMethod("spigot");
|
||||
Object spigot = spigotMethod.invoke(player);
|
||||
|
||||
Method spigotGetLocaleMethod = spigot.getClass().getMethod("getLocale");
|
||||
locale = (String) spigotGetLocaleMethod.invoke(spigot);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@@ -107,4 +108,12 @@ public final class Utils {
|
||||
public static boolean isEmailEmpty(String email) {
|
||||
return StringUtils.isBlank(email) || "your@email.com".equalsIgnoreCase(email);
|
||||
}
|
||||
|
||||
private final static String[] serverVersion = Bukkit.getServer().getBukkitVersion()
|
||||
.substring(0, Bukkit.getServer().getBukkitVersion().indexOf("-"))
|
||||
.split("\\.");
|
||||
|
||||
private final static int mcFirstVersion = Integer.parseInt(serverVersion[0]);
|
||||
public final static int majorVersion = Integer.parseInt(serverVersion[1]);
|
||||
public final static int minorVersion = Integer.parseInt(serverVersion[2]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user