Merge pull request #31 from Xephi/master

Up
This commit is contained in:
Gabriele C. 2015-08-20 20:40:51 +02:00
commit 9957cfe570
2 changed files with 38 additions and 33 deletions

View File

@ -121,6 +121,7 @@ public class MySQL implements DataSource {
config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("autoReconnect", true); config.addDataSourceProperty("autoReconnect", true);
config.setMaxLifetime(12000);
config.setInitializationFailFast(false); config.setInitializationFailFast(false);
ds = new HikariDataSource(config); ds = new HikariDataSource(config);
ConsoleLogger.info("Connection pool ready"); ConsoleLogger.info("Connection pool ready");
@ -196,7 +197,7 @@ public class MySQL implements DataSource {
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
return rs.next(); return rs.next();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -246,7 +247,7 @@ public class MySQL implements DataSource {
} else { } else {
return null; return null;
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} finally { } finally {
@ -456,7 +457,7 @@ public class MySQL implements DataSource {
if (rs != null && !rs.isClosed()) if (rs != null && !rs.isClosed())
rs.close(); rs.close();
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -501,7 +502,7 @@ public class MySQL implements DataSource {
if (rs != null && !rs.isClosed()) if (rs != null && !rs.isClosed())
rs.close(); rs.close();
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -523,7 +524,7 @@ public class MySQL implements DataSource {
pst.setString(3, auth.getRealName()); pst.setString(3, auth.getRealName());
pst.setString(4, auth.getNickname()); pst.setString(4, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -542,7 +543,7 @@ public class MySQL implements DataSource {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
return pst.executeUpdate(); return pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -570,7 +571,7 @@ public class MySQL implements DataSource {
pst.setLong(1, until); pst.setLong(1, until);
pst.executeUpdate(); pst.executeUpdate();
return list; return list;
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>(); return new ArrayList<String>();
} finally { } finally {
@ -606,7 +607,7 @@ public class MySQL implements DataSource {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -629,7 +630,7 @@ public class MySQL implements DataSource {
pst.setString(4, auth.getWorld()); pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname()); pst.setString(5, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -654,7 +655,7 @@ public class MySQL implements DataSource {
countIp++; countIp++;
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -674,7 +675,7 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -697,7 +698,7 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getSalt()); pst.setString(1, auth.getSalt());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -732,7 +733,7 @@ public class MySQL implements DataSource {
if (st != null) { if (st != null) {
try { try {
st.close(); st.close();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@ -742,7 +743,7 @@ public class MySQL implements DataSource {
if (rs != null) { if (rs != null) {
try { try {
rs.close(); rs.close();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@ -752,7 +753,7 @@ public class MySQL implements DataSource {
if (con != null) { if (con != null) {
try { try {
con.close(); con.close();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@ -773,7 +774,7 @@ public class MySQL implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>(); return new ArrayList<String>();
} finally { } finally {
@ -798,7 +799,7 @@ public class MySQL implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>(); return new ArrayList<String>();
} finally { } finally {
@ -823,7 +824,7 @@ public class MySQL implements DataSource {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(columnName));
} }
return countEmail; return countEmail;
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>(); return new ArrayList<String>();
} finally { } finally {
@ -844,7 +845,7 @@ public class MySQL implements DataSource {
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -890,7 +891,7 @@ public class MySQL implements DataSource {
while (con == null) while (con == null)
try { try {
con = ds.getConnection(); con = ds.getConnection();
} catch (SQLException e) { } catch (Exception e) {
try { try {
reconnect(false); reconnect(false);
con = ds.getConnection(); con = ds.getConnection();
@ -914,6 +915,7 @@ public class MySQL implements DataSource {
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("autoReconnect", true); config.addDataSourceProperty("autoReconnect", true);
config.setInitializationFailFast(false); config.setInitializationFailFast(false);
config.setMaxLifetime(12000);
config.setPoolName("AuthMeMYSQLPool"); config.setPoolName("AuthMeMYSQLPool");
ds = new HikariDataSource(config); ds = new HikariDataSource(config);
if (!reload) if (!reload)
@ -937,7 +939,7 @@ public class MySQL implements DataSource {
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) if (rs.next())
return (rs.getInt(columnLogged) == 1); return (rs.getInt(columnLogged) == 1);
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -958,7 +960,7 @@ public class MySQL implements DataSource {
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} finally { } finally {
@ -979,7 +981,7 @@ public class MySQL implements DataSource {
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} finally { } finally {
@ -999,7 +1001,7 @@ public class MySQL implements DataSource {
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} finally { } finally {
@ -1022,7 +1024,7 @@ public class MySQL implements DataSource {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
result = rs.getInt(1); result = rs.getInt(1);
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return result; return result;
} finally { } finally {
@ -1042,7 +1044,7 @@ public class MySQL implements DataSource {
pst.setString(1, newone); pst.setString(1, newone);
pst.setString(2, oldone); pst.setString(2, oldone);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} finally { } finally {
@ -1092,7 +1094,7 @@ public class MySQL implements DataSource {
if (pAuth != null) if (pAuth != null)
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@ -1143,7 +1145,7 @@ public class MySQL implements DataSource {
if (pAuth != null) if (pAuth != null)
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {

View File

@ -21,7 +21,7 @@ public class AsyncronousQuit {
protected AuthMe plugin; protected AuthMe plugin;
protected DataSource database; protected DataSource database;
protected Player p; protected Player player;
protected Utils utils = Utils.getInstance(); protected Utils utils = Utils.getInstance();
private String name; private String name;
private ItemStack[] armor = null; private ItemStack[] armor = null;
@ -33,7 +33,7 @@ public class AsyncronousQuit {
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database, public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
boolean isKick) { boolean isKick) {
this.p = p; this.player = p;
this.plugin = plugin; this.plugin = plugin;
this.database = database; this.database = database;
this.name = p.getName().toLowerCase(); this.name = p.getName().toLowerCase();
@ -41,7 +41,8 @@ public class AsyncronousQuit {
} }
public void process() { public void process() {
final Player player = p; if (player == null)
return;
if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
return; return;
} }
@ -64,7 +65,8 @@ public class AsyncronousQuit {
inv = limbo.getInventory(); inv = limbo.getInventory();
armor = limbo.getArmour(); armor = limbo.getArmour();
} }
utils.addNormal(player, limbo.getGroup()); if (limbo.getGroup() != null && !limbo.getGroup().equals(""))
utils.addNormal(player, limbo.getGroup());
needToChange = true; needToChange = true;
isOp = limbo.getOperator(); isOp = limbo.getOperator();
isFlying = limbo.isFlying(); isFlying = limbo.isFlying();
@ -94,6 +96,7 @@ public class AsyncronousQuit {
database.setUnlogged(name); database.setUnlogged(name);
} }
AuthMePlayerListener.gameMode.remove(name); AuthMePlayerListener.gameMode.remove(name);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange)); final Player p = player;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange));
} }
} }