Encoding depend on OS

This commit is contained in:
Xephi59 2015-07-18 16:52:14 +02:00
parent b60daae936
commit 663c4a48d1
3 changed files with 25 additions and 22 deletions

View File

@ -111,6 +111,14 @@ public class AuthMe extends JavaPlugin {
return settings;
}
public DataSource getAuthMeDatabase() {
return database;
}
public void setAuthMeDatabase(DataSource database) {
this.database = database;
}
@Override
public void onEnable() {
authme = this;

View File

@ -407,6 +407,9 @@ public class AuthMePlayerListener implements Listener {
return;
}
if (player.isBanned())
return;
if (Settings.enablePasspartu && !Settings.countriesBlacklist.isEmpty()) {
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
if (((code == null) || (Settings.countriesBlacklist.contains(code) && !isAuthAvailable)) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
@ -432,12 +435,6 @@ public class AuthMePlayerListener implements Listener {
}
}
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
event.setKickMessage(m.send("same_nick")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
}
// Check if forceSingleSession is set to true, so kick player that has
// joined with same nick of online player
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
@ -463,13 +460,12 @@ public class AuthMePlayerListener implements Listener {
String regex = Settings.getNickRegex;
if (name.length() > max || name.length() < min) {
event.setKickMessage(m.send("name_len")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
}
try {
if (!player.getName().matches(regex) || name.equals("Player")) {
if (!player.getName().matches(regex) || name.equalsIgnoreCase("Player")) {
try {
event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
@ -511,8 +507,6 @@ public class AuthMePlayerListener implements Listener {
}
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL)
return;
if (player.isBanned())
return;
if (!plugin.authmePermissible(player, "authme.vip")) {
event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL);

View File

@ -10,13 +10,12 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.nio.charset.StandardCharsets;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import fr.xephi.authme.ConsoleLogger;
public class CustomConfiguration extends YamlConfiguration {
@ -32,12 +31,12 @@ public class CustomConfiguration extends YamlConfiguration {
try {
super.load(configFile);
} catch (FileNotFoundException e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not find " + configFile.getName() + ", creating new one...");
ConsoleLogger.showError("Could not find " + configFile.getName() + ", creating new one...");
reLoad();
} catch (IOException e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not load " + configFile.getName(), e);
ConsoleLogger.showError("Could not load " + configFile.getName());
} catch (InvalidConfigurationException e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, configFile.getName() + " is no valid configuration file", e);
ConsoleLogger.showError(configFile.getName() + " is no valid configuration file");
}
}
@ -55,7 +54,7 @@ public class CustomConfiguration extends YamlConfiguration {
try {
super.save(configFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + configFile.getName(), ex);
ConsoleLogger.showError("Could not save config to " + configFile.getName());
}
}
@ -63,19 +62,21 @@ public class CustomConfiguration extends YamlConfiguration {
boolean out = true;
if (!file.exists()) {
try {
String charset = System.getProperty("file.encoding");
String newline = System.getProperty("line.separator");
InputStream fis = getClass().getResourceAsStream("/" + file.getName());
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8").newDecoder()));
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8));
String str;
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8").newEncoder()));
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset));
while ((str = reader.readLine()) != null) {
writer.append(str).append("\r\n");
writer.append(str).append(newline);
}
writer.flush();
writer.close();
reader.close();
fis.close();
} catch (Exception e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Failed to load config from JAR");
ConsoleLogger.showError("Failed to load config from JAR");
out = false;
}
}