mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-11 06:38:00 +02:00
extract language if available.
This commit is contained in:
parent
670caaea4b
commit
981da0a0f3
@ -127,9 +127,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Setup the Logger
|
||||
authmeLogger.setParent(this.getLogger());
|
||||
|
||||
// Setup otherAccounts file
|
||||
otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
// Load settings and custom configurations
|
||||
// TODO: new configuration style (more files)
|
||||
try {
|
||||
@ -139,6 +136,10 @@ public class AuthMe extends JavaPlugin {
|
||||
this.getServer().shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup otherAccounts file
|
||||
otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
// Configuration Security Warnings
|
||||
if (!Settings.isForceSingleSessionEnabled) {
|
||||
ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
|
||||
|
@ -114,34 +114,7 @@ public class AdminCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
File newConfigFile = new File("plugins" + File.separator + "AuthMe", "config.yml");
|
||||
if (!newConfigFile.exists()) {
|
||||
InputStream fis = getClass().getResourceAsStream("" + File.separator + "config.yml");
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(newConfigFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int i = 0;
|
||||
|
||||
while ((i = fis.read(buf)) != -1) {
|
||||
fos.write(buf, 0, i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Failed to load config from JAR");
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(newConfigFile);
|
||||
Settings.reloadConfigOptions(newConfig);
|
||||
plugin.getSettings().reload();
|
||||
m.reloadMessages();
|
||||
plugin.database.close();
|
||||
|
||||
|
@ -1,21 +1,15 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FlatFile implements DataSource {
|
||||
|
||||
/*
|
||||
@ -32,7 +26,7 @@ public class FlatFile implements DataSource {
|
||||
private File source;
|
||||
|
||||
public FlatFile() {
|
||||
source = new File(Settings.AUTH_FILE);
|
||||
source = Settings.AUTH_FILE;
|
||||
try {
|
||||
source.createNewFile();
|
||||
} catch (IOException e) {
|
||||
@ -41,9 +35,10 @@ public class FlatFile implements DataSource {
|
||||
ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN...");
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled)
|
||||
if (!Settings.isStopEnabled) {
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
return;
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +103,7 @@ public class FlatFile implements DataSource {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line = "";
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args[0].equals(auth.getNickname())) {
|
||||
@ -167,7 +162,7 @@ public class FlatFile implements DataSource {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line = "";
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||
@ -226,7 +221,7 @@ public class FlatFile implements DataSource {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line = "";
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||
|
@ -52,6 +52,10 @@ public class CustomConfiguration extends YamlConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public boolean loadResource(File file) {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import java.io.File;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import java.io.File;
|
||||
|
||||
public class Messages extends CustomConfiguration {
|
||||
|
||||
@ -23,11 +23,10 @@ public class Messages extends CustomConfiguration {
|
||||
/**
|
||||
* Loads a file from the plugin jar and sets as default
|
||||
*
|
||||
* @param file
|
||||
* The filename to open
|
||||
* @param file The filename to open
|
||||
*/
|
||||
public final void loadDefaults(File file) {
|
||||
if(file.isFile()){
|
||||
if (file.isFile()) {
|
||||
setDefaults(YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
}
|
||||
@ -48,7 +47,7 @@ public class Messages extends CustomConfiguration {
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
*
|
||||
* <p>
|
||||
* If defaults and configuration are empty, saves blank file.
|
||||
*
|
||||
* @return True if saved successfully
|
||||
@ -73,7 +72,7 @@ public class Messages extends CustomConfiguration {
|
||||
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 !");
|
||||
ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + getConfigFile() + " !");
|
||||
}
|
||||
for (String l : loc.split("&n")) {
|
||||
sender.sendMessage(l.replace("&", "\u00a7"));
|
||||
@ -81,15 +80,12 @@ public class Messages extends CustomConfiguration {
|
||||
}
|
||||
|
||||
public String[] send(String msg) {
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang))
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) {
|
||||
singleton.reloadMessages();
|
||||
String s = null;
|
||||
try {
|
||||
s = (String) singleton.get(msg);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
String s = (String) singleton.get(msg);
|
||||
if (s == null) {
|
||||
ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml !");
|
||||
ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + getConfigFile() + " !");
|
||||
String[] loc = new String[1];
|
||||
loc[0] = "Error with " + msg + " translation; Please contact the admin for verify or update translation files";
|
||||
return (loc);
|
||||
@ -108,13 +104,13 @@ public class Messages extends CustomConfiguration {
|
||||
|
||||
public static Messages getInstance() {
|
||||
if (singleton == null) {
|
||||
singleton = new Messages(new File(Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
singleton = new Messages(new File(Settings.MESSAGE_DIR, "messages_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void reloadMessages() {
|
||||
singleton = new Messages(new File(Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
singleton = new Messages(new File(Settings.MESSAGE_DIR, "messages_" + Settings.messagesLanguage + ".yml"), Settings.messagesLanguage);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +1,28 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public final class Settings extends YamlConfiguration {
|
||||
|
||||
// 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";
|
||||
public static final String AUTH_FILE = Settings.PLUGIN_FOLDER + File.separator + "auths.db";
|
||||
public static final String MESSAGE_FILE = Settings.PLUGIN_FOLDER + File.separator + "messages" + File.separator + "messages";
|
||||
public static final String SETTINGS_FILE = Settings.PLUGIN_FOLDER + File.separator + "config.yml";
|
||||
public static final File PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
|
||||
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
|
||||
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
|
||||
public static final File MESSAGE_DIR = new File(PLUGIN_FOLDER, "messages");
|
||||
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
||||
public static List<String> allowCommands = null;
|
||||
public static List<String> getJoinPermissions = null;
|
||||
public static List<String> getUnrestrictedName = null;
|
||||
@ -43,7 +36,6 @@ public final class Settings extends YamlConfiguration {
|
||||
public static List<String> forceRegisterCommands = null;
|
||||
public static List<String> forceRegisterCommandsAsConsole = null;
|
||||
private AuthMe plugin;
|
||||
private final File file;
|
||||
public static DataSourceType getDataSource;
|
||||
public static HashAlgorithm getPasswordHash;
|
||||
public static Boolean useLogging = false;
|
||||
@ -100,7 +92,7 @@ public final class Settings extends YamlConfiguration {
|
||||
protected static YamlConfiguration configFile;
|
||||
|
||||
public Settings(AuthMe plugin) {
|
||||
this.file = new File(plugin.getDataFolder(), "config.yml");
|
||||
configFile = (YamlConfiguration) plugin.getConfig();
|
||||
this.plugin = plugin;
|
||||
boolean exist = exists();
|
||||
if (exist) {
|
||||
@ -109,8 +101,6 @@ public final class Settings extends YamlConfiguration {
|
||||
plugin.saveDefaultConfig();
|
||||
load();
|
||||
}
|
||||
configFile = (YamlConfiguration) plugin.getConfig();
|
||||
PLUGIN_FOLDER = plugin.getDataFolder().toString();
|
||||
loadConfigOptions(exist);
|
||||
}
|
||||
|
||||
@ -519,14 +509,10 @@ public final class Settings extends YamlConfiguration {
|
||||
;
|
||||
}
|
||||
}
|
||||
if (namefound == false) {
|
||||
if (!namefound) {
|
||||
return true;
|
||||
} else {
|
||||
if (trueonce == true) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return trueonce;
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,7 +523,7 @@ public final class Settings extends YamlConfiguration {
|
||||
*/
|
||||
public final boolean load() {
|
||||
try {
|
||||
load(file);
|
||||
load(SETTINGS_FILE);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
@ -545,8 +531,9 @@ public final class Settings extends YamlConfiguration {
|
||||
}
|
||||
|
||||
public final void reload() {
|
||||
if (!exists())
|
||||
if (!exists()) {
|
||||
plugin.saveDefaultConfig();
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
@ -557,7 +544,7 @@ public final class Settings extends YamlConfiguration {
|
||||
*/
|
||||
public final boolean save() {
|
||||
try {
|
||||
save(file);
|
||||
save(SETTINGS_FILE);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
@ -570,12 +557,12 @@ public final class Settings extends YamlConfiguration {
|
||||
* @return True if configuration exists on disk
|
||||
*/
|
||||
public final boolean exists() {
|
||||
return file.exists();
|
||||
return SETTINGS_FILE.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
*
|
||||
* <p>
|
||||
* If defaults and configuration are empty, saves blank file.
|
||||
*
|
||||
* @return True if saved successfully
|
||||
@ -602,14 +589,15 @@ public final class Settings extends YamlConfiguration {
|
||||
* @return false When all defaults aren't present in config
|
||||
*/
|
||||
public boolean checkDefaults() {
|
||||
if (getDefaults() == null) {
|
||||
return true;
|
||||
}
|
||||
return getKeys(true).containsAll(getDefaults().getKeys(true));
|
||||
return getDefaults() == null || getKeys(true).containsAll(getDefaults().getKeys(true));
|
||||
}
|
||||
|
||||
public static String checkLang(String lang) {
|
||||
if (new File(MESSAGE_FILE + "_" + lang + ".yml").exists()) {
|
||||
if (new File(MESSAGE_DIR, "messages_" + lang + ".yml").exists()) {
|
||||
ConsoleLogger.info("Set Language to: " + lang);
|
||||
return lang;
|
||||
}
|
||||
if (AuthMe.class.getResourceAsStream("/messages/messages_" + lang + ".yml") != null) {
|
||||
ConsoleLogger.info("Set Language to: " + lang);
|
||||
return lang;
|
||||
}
|
||||
@ -629,7 +617,7 @@ public final class Settings extends YamlConfiguration {
|
||||
|
||||
private static void getWelcomeMessage() {
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
welcomeMsg = new ArrayList<String>();
|
||||
welcomeMsg = new ArrayList<>();
|
||||
if (!useWelcomeMessage) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user