Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 450-new-settings-rewrite
Conflicts: src/main/java/fr/xephi/authme/AuthMe.java src/main/java/fr/xephi/authme/settings/Settings.java src/main/java/fr/xephi/authme/settings/custom/NewSetting.java
This commit is contained in:
@@ -5,17 +5,13 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalListeners;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -23,7 +19,6 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CacheDataSource implements DataSource {
|
||||
|
||||
private final DataSource source;
|
||||
private final ExecutorService exec;
|
||||
private final LoadingCache<String, Optional<PlayerAuth>> cachedAuths;
|
||||
|
||||
/**
|
||||
@@ -33,10 +28,9 @@ public class CacheDataSource implements DataSource {
|
||||
*/
|
||||
public CacheDataSource(DataSource src) {
|
||||
this.source = src;
|
||||
this.exec = Executors.newCachedThreadPool();
|
||||
cachedAuths = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(5, TimeUnit.MINUTES)
|
||||
.removalListener(RemovalListeners.asynchronous(new RemovalListener<String, Optional<PlayerAuth>>() {
|
||||
this.cachedAuths = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(8, TimeUnit.MINUTES)
|
||||
.removalListener(new RemovalListener<String, Optional<PlayerAuth>>() {
|
||||
@Override
|
||||
public void onRemoval(RemovalNotification<String, Optional<PlayerAuth>> removalNotification) {
|
||||
String name = removalNotification.getKey();
|
||||
@@ -44,7 +38,7 @@ public class CacheDataSource implements DataSource {
|
||||
cachedAuths.getUnchecked(name);
|
||||
}
|
||||
}
|
||||
}, exec))
|
||||
})
|
||||
.build(
|
||||
new CacheLoader<String, Optional<PlayerAuth>>() {
|
||||
public Optional<PlayerAuth> load(String key) {
|
||||
@@ -168,24 +162,13 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
try {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(8, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
source.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() { // unused method
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.reload();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
});
|
||||
source.reload();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,13 +197,8 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(final List<String> banned) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.purgeBanned(banned);
|
||||
cachedAuths.invalidateAll(banned);
|
||||
}
|
||||
});
|
||||
source.purgeBanned(banned);
|
||||
cachedAuths.invalidateAll(banned);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,33 +213,18 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public void setLogged(final String user) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
});
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(final String user) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
});
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeLogged() {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.purgeLogged();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
});
|
||||
source.purgeLogged();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,14 +233,9 @@ public class CacheDataSource implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(final String oldOne, final String newOne) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.updateName(oldOne, newOne);
|
||||
cachedAuths.invalidate(oldOne);
|
||||
}
|
||||
});
|
||||
public void updateName(final String oldOne, final String newOne) { // unused method
|
||||
source.updateName(oldOne, newOne);
|
||||
cachedAuths.invalidate(oldOne);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -257,8 +257,7 @@ public class MySQL implements DataSource {
|
||||
ResultSet rs = pst.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -276,8 +275,7 @@ public class MySQL implements DataSource {
|
||||
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -322,8 +320,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
return null;
|
||||
}
|
||||
return pAuth;
|
||||
@@ -525,8 +522,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -589,8 +585,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -623,8 +618,7 @@ public class MySQL implements DataSource {
|
||||
pst.setLong(1, until);
|
||||
result = pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -647,8 +641,7 @@ public class MySQL implements DataSource {
|
||||
st.executeUpdate();
|
||||
st.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -680,8 +673,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -702,8 +694,7 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -722,8 +713,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return countIp;
|
||||
}
|
||||
@@ -739,8 +729,7 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -750,9 +739,8 @@ public class MySQL implements DataSource {
|
||||
try {
|
||||
reloadArguments();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL configuration!");
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
ConsoleLogger.logException("Can't reconnect to MySQL database... " +
|
||||
"Please check your MySQL configuration! Encountered", ex);
|
||||
AuthMe.getInstance().stopOrUnload();
|
||||
}
|
||||
}
|
||||
@@ -778,8 +766,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -798,8 +785,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -818,8 +804,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return countEmail;
|
||||
}
|
||||
@@ -834,8 +819,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,8 +838,7 @@ public class MySQL implements DataSource {
|
||||
ResultSet rs = pst.executeQuery();
|
||||
isLogged = rs.next() && (rs.getInt(columnLogged) == 1);
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return isLogged;
|
||||
}
|
||||
@@ -870,8 +853,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,8 +867,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,9 +880,8 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(2, 1);
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -916,9 +896,8 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -931,9 +910,8 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, newOne);
|
||||
pst.setString(2, oldOne);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,9 +955,8 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return auths;
|
||||
}
|
||||
@@ -1021,11 +998,14 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return auths;
|
||||
}
|
||||
|
||||
private static void logSqlException(SQLException e) {
|
||||
ConsoleLogger.logException("Error during SQL operation:", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -170,8 +170,7 @@ public class SQLite implements DataSource {
|
||||
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
ConsoleLogger.logException("Error getting password:", ex);
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
|
||||
Reference in New Issue
Block a user