Merge pull request #6 from Xephi/master

Encoding depend on OS
This commit is contained in:
Gabriele C. 2015-07-18 17:02:18 +02:00
commit aae94a29b8
3 changed files with 25 additions and 22 deletions

View File

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

View File

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

View File

@ -10,13 +10,12 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import fr.xephi.authme.ConsoleLogger;
public class CustomConfiguration extends YamlConfiguration { public class CustomConfiguration extends YamlConfiguration {
@ -32,12 +31,12 @@ public class CustomConfiguration extends YamlConfiguration {
try { try {
super.load(configFile); super.load(configFile);
} catch (FileNotFoundException e) { } 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(); reLoad();
} catch (IOException e) { } 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) { } 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 { try {
super.save(configFile); super.save(configFile);
} catch (IOException ex) { } 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; boolean out = true;
if (!file.exists()) { if (!file.exists()) {
try { try {
String charset = System.getProperty("file.encoding");
String newline = System.getProperty("line.separator");
InputStream fis = getClass().getResourceAsStream("/" + file.getName()); 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; 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) { while ((str = reader.readLine()) != null) {
writer.append(str).append("\r\n"); writer.append(str).append(newline);
} }
writer.flush(); writer.flush();
writer.close(); writer.close();
reader.close(); reader.close();
fis.close(); fis.close();
} catch (Exception e) { } 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; out = false;
} }
} }