Messages can now be customized more easily
This commit is contained in:
@@ -141,7 +141,7 @@ public class AdminCommand implements CommandExecutor {
|
||||
}
|
||||
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(newConfigFile);
|
||||
Settings.reloadConfigOptions(newConfig);
|
||||
m.reLoad();
|
||||
m.reloadMessages();
|
||||
plugin.database.close();
|
||||
plugin.setupDatabase();
|
||||
m.send(sender, "reload");
|
||||
|
||||
@@ -428,17 +428,17 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.isKickNonRegisteredEnabled && !Settings.antiBotInAction){
|
||||
if (Settings.isKickNonRegisteredEnabled && !Settings.antiBotInAction) {
|
||||
if (!plugin.database.isAuthAvailable(name)) {
|
||||
event.setKickMessage(m.send("reg_only")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.antiBotInAction){
|
||||
|
||||
if (Settings.antiBotInAction) {
|
||||
if (!plugin.database.isAuthAvailable(name)) {
|
||||
event.setKickMessage("AntiBot service in action! Non registered players can't connect until the bot attack stops!"); //Need to add string to messages
|
||||
event.setKickMessage("AntiBot service in action! You actually need to be registered!");
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
@@ -658,31 +658,40 @@ public class AuthMePlayerListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getPlayer() == null)
|
||||
return;
|
||||
Player player = (Player) event.getPlayer();
|
||||
final Player player = (Player) event.getPlayer();
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
if (Utils.getInstance().isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getCitizensCommunicator().isNPC(player))
|
||||
return;
|
||||
|
||||
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.database.isAuthAvailable(name)) {
|
||||
if (!Settings.isForcedRegistrationEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
player.closeInventory();
|
||||
|
||||
/*
|
||||
* @note little hack cause InventoryOpenEvent cannot be cancelled for
|
||||
* real, cause no packet is send to server by client for the main inv
|
||||
*/
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.closeInventory();
|
||||
;
|
||||
}
|
||||
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
|
||||
@@ -12,13 +12,15 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
public class Messages extends CustomConfiguration {
|
||||
|
||||
private static Messages singleton = null;
|
||||
private String lang = "en";
|
||||
|
||||
public Messages(File file) {
|
||||
public Messages(File file, String lang) {
|
||||
super(file);
|
||||
loadDefaults(file);
|
||||
loadFile();
|
||||
saveDefaults(file);
|
||||
singleton = this;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +34,7 @@ public class Messages extends CustomConfiguration {
|
||||
InputStream stream = AuthMe.getInstance().getResource(file.getName());
|
||||
if (stream == null)
|
||||
return;
|
||||
|
||||
|
||||
setDefaults(YamlConfiguration.loadConfiguration(stream));
|
||||
}
|
||||
|
||||
@@ -67,12 +69,14 @@ public class Messages extends CustomConfiguration {
|
||||
}
|
||||
|
||||
private void loadFile() {
|
||||
this.load();
|
||||
this.save();
|
||||
load();
|
||||
save();
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, String msg) {
|
||||
String loc = (String) this.get(msg);
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang))
|
||||
singleton.reloadMessages();
|
||||
String loc = (String) singleton.get(msg);
|
||||
if (loc == null) {
|
||||
loc = "Error with Translation files, please contact the admin for verify or update translation";
|
||||
ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml !");
|
||||
@@ -83,13 +87,14 @@ public class Messages extends CustomConfiguration {
|
||||
}
|
||||
|
||||
public String[] send(String msg) {
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang))
|
||||
singleton.reloadMessages();
|
||||
String s = null;
|
||||
try {
|
||||
s = (String) this.get(msg);
|
||||
s = (String) singleton.get(msg);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (s == null)
|
||||
{
|
||||
if (s == null) {
|
||||
ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml !");
|
||||
String[] loc = new String[1];
|
||||
loc[0] = "Error with " + msg + " translation; Please contact the admin for verify or update translation files";
|
||||
@@ -109,9 +114,13 @@ public class Messages extends CustomConfiguration {
|
||||
|
||||
public static Messages getInstance() {
|
||||
if (singleton == null) {
|
||||
singleton = new Messages(new File(Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml"));
|
||||
singleton = new Messages(new File(Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void reloadMessages() {
|
||||
singleton = new Messages(new File(Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import fr.xephi.authme.security.HashAlgorithm;
|
||||
|
||||
public final class Settings extends YamlConfiguration {
|
||||
|
||||
//This is not an option!
|
||||
public static Boolean antiBotInAction = false;
|
||||
// This is not an option!
|
||||
public static Boolean antiBotInAction = false;
|
||||
|
||||
public static String PLUGIN_FOLDER = "." + File.separator + "plugins" + File.separator + "AuthMe";
|
||||
public static final String CACHE_FOLDER = Settings.PLUGIN_FOLDER + File.separator + "cache";
|
||||
@@ -62,17 +62,17 @@ public final class Settings extends YamlConfiguration {
|
||||
isResetInventoryIfCreative, isCachingEnabled,
|
||||
isKickOnWrongPasswordEnabled, getEnablePasswordVerifier,
|
||||
protectInventoryBeforeLogInEnabled, isBackupActivated,
|
||||
isBackupOnStart, isBackupOnStop, isStopEnabled,
|
||||
reloadSupport, rakamakUseIp, noConsoleSpam, removePassword,
|
||||
displayOtherAccounts, useCaptcha, emailRegistration, multiverse,
|
||||
chestshop, bungee, banUnsafeIp, doubleEmailCheck,
|
||||
sessionExpireOnIpChange, disableSocialSpy, forceOnlyAfterLogin,
|
||||
useEssentialsMotd, usePurge, purgePlayerDat, purgeEssentialsFile,
|
||||
supportOldPassword, purgeLimitedCreative, purgeAntiXray,
|
||||
purgePermissions, enableProtection, enableAntiBot, recallEmail,
|
||||
useWelcomeMessage, broadcastWelcomeMessage, forceRegKick,
|
||||
forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport,
|
||||
applyBlindEffect, customAttributes, generateImage;
|
||||
isBackupOnStart, isBackupOnStop, isStopEnabled, reloadSupport,
|
||||
rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts,
|
||||
useCaptcha, emailRegistration, multiverse, chestshop, bungee,
|
||||
banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange,
|
||||
disableSocialSpy, forceOnlyAfterLogin, useEssentialsMotd, usePurge,
|
||||
purgePlayerDat, purgeEssentialsFile, supportOldPassword,
|
||||
purgeLimitedCreative, purgeAntiXray, purgePermissions,
|
||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
||||
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
||||
checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect,
|
||||
customAttributes, generateImage;
|
||||
|
||||
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
|
||||
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
|
||||
@@ -127,7 +127,7 @@ public final class Settings extends YamlConfiguration {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void loadVariables() {
|
||||
messagesLanguage = checkLang(configFile.getString("settings.messagesLanguage", "en"));
|
||||
messagesLanguage = checkLang(configFile.getString("settings.messagesLanguage", "en").toLowerCase());
|
||||
isPermissionCheckEnabled = configFile.getBoolean("permission.EnablePermissionCheck", false);
|
||||
isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true);
|
||||
isRegistrationEnabled = configFile.getBoolean("settings.registration.enabled", true);
|
||||
@@ -603,22 +603,20 @@ public final class Settings extends YamlConfiguration {
|
||||
}
|
||||
|
||||
public static String checkLang(String lang) {
|
||||
for (messagesLang language : messagesLang.values()) {
|
||||
if (lang.toLowerCase().contains(language.toString())) {
|
||||
ConsoleLogger.info("Set Language: " + lang);
|
||||
return lang;
|
||||
}
|
||||
if (new File(MESSAGE_FILE + "_" + lang + ".yml").exists()) {
|
||||
ConsoleLogger.info("Set Language to: " + lang);
|
||||
return lang;
|
||||
}
|
||||
ConsoleLogger.info("Set Default Language: En ");
|
||||
ConsoleLogger.info("Language file not found for " + lang + ", set to default language: en !");
|
||||
return "en";
|
||||
}
|
||||
|
||||
public static void switchAntiBotMod(boolean mode) {
|
||||
if (mode){
|
||||
if (mode) {
|
||||
isKickNonRegisteredEnabled = true;
|
||||
antiBotInAction = true;
|
||||
}else{
|
||||
isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false);
|
||||
} else {
|
||||
isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false);
|
||||
antiBotInAction = false;
|
||||
}
|
||||
}
|
||||
@@ -684,31 +682,4 @@ public final class Settings extends YamlConfiguration {
|
||||
}
|
||||
return correct;
|
||||
}
|
||||
|
||||
public enum messagesLang {
|
||||
en,
|
||||
de,
|
||||
br,
|
||||
cz,
|
||||
pl,
|
||||
fr,
|
||||
uk,
|
||||
ru,
|
||||
hu,
|
||||
sk,
|
||||
es,
|
||||
fi,
|
||||
zhtw,
|
||||
zhhk,
|
||||
zhcn,
|
||||
lt,
|
||||
it,
|
||||
ko,
|
||||
pt,
|
||||
nl,
|
||||
gl,
|
||||
bg,
|
||||
eu,
|
||||
tr
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user