mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
Change how PlayersLogs work - Change how reload work
This commit is contained in:
parent
36632bbb58
commit
63a90abec1
@ -12,8 +12,6 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
@ -80,7 +78,6 @@ public class AuthMe extends JavaPlugin {
|
||||
public DataSource database = null;
|
||||
private Settings settings;
|
||||
private Messages m;
|
||||
public PlayersLogs pllog;
|
||||
public OtherAccounts otherAccounts;
|
||||
public static Server server;
|
||||
public static Logger authmeLogger = Logger.getLogger("AuthMe");
|
||||
@ -97,9 +94,9 @@ public class AuthMe extends JavaPlugin {
|
||||
public Essentials ess;
|
||||
public API api;
|
||||
public Management management;
|
||||
public HashMap<String, Integer> captcha = new HashMap<String, Integer>();
|
||||
public HashMap<String, String> cap = new HashMap<String, String>();
|
||||
public HashMap<String, String> realIp = new HashMap<String, String>();
|
||||
public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<String, Integer>();
|
||||
public ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<String, String>();
|
||||
public ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<String, String>();
|
||||
public MultiverseCore multiverse = null;
|
||||
public Location essentialsSpawn;
|
||||
public LookupService ls = null;
|
||||
@ -151,8 +148,6 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
m = Messages.getInstance();
|
||||
|
||||
pllog = PlayersLogs.getInstance();
|
||||
|
||||
otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
server = getServer();
|
||||
@ -246,9 +241,10 @@ public class AuthMe extends JavaPlugin {
|
||||
ConsoleLogger.showError("BECAREFUL !!! By disabling ForceSingleSession, your server protection is set to LOW");
|
||||
}
|
||||
|
||||
PlayersLogs.getInstance();
|
||||
|
||||
if (Settings.reloadSupport)
|
||||
try {
|
||||
onReload();
|
||||
int playersOnline = 0;
|
||||
try {
|
||||
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class)
|
||||
@ -261,7 +257,7 @@ public class AuthMe extends JavaPlugin {
|
||||
database.purgeLogged();
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
}
|
||||
} else PlayersLogs.getInstance().loadPlayers();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
@ -432,27 +428,6 @@ public class AuthMe extends JavaPlugin {
|
||||
ConsoleLogger.info("Authme " + this.getDescription().getVersion() + " disabled");
|
||||
}
|
||||
|
||||
private void onReload() {
|
||||
try {
|
||||
if (Bukkit.getServer().getOnlinePlayers() != null) {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (database.isLogged(player.getName().toLowerCase())) {
|
||||
String name = player.getName().toLowerCase();
|
||||
PlayerAuth pAuth = database.getAuth(name);
|
||||
if (pAuth == null)
|
||||
break;
|
||||
PlayerAuth auth = new PlayerAuth(name, pAuth.getHash(), pAuth.getIp(), new Date().getTime(), pAuth.getEmail());
|
||||
database.updateSession(auth);
|
||||
PlayerCache.getInstance().addPlayer(auth);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static AuthMe getInstance() {
|
||||
return authme;
|
||||
}
|
||||
|
@ -43,4 +43,8 @@ public class PlayerCache {
|
||||
return cache.size();
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, PlayerAuth> getCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ 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.PlayersLogs;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
@ -648,17 +649,17 @@ public class FlatFile implements DataSource {
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
return PlayersLogs.getInstance().players.contains(user.toLowerCase());
|
||||
return PlayerCache.getInstance().isAuthenticated(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
PlayersLogs.getInstance().addPlayer(user.toLowerCase());
|
||||
PlayersLogs.getInstance().savePlayerLogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
PlayersLogs.getInstance().removePlayer(user.toLowerCase());
|
||||
PlayersLogs.getInstance().savePlayerLogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,6 +12,7 @@ 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.datasource.MiniConnectionPoolManager.TimeoutException;
|
||||
import fr.xephi.authme.settings.PlayersLogs;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@ -74,8 +75,8 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void connect() throws ClassNotFoundException,
|
||||
SQLException {
|
||||
private synchronized void connect()
|
||||
throws ClassNotFoundException, SQLException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
ConsoleLogger.info("SQLite driver loaded");
|
||||
this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||
@ -508,17 +509,17 @@ public class SQLite implements DataSource {
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
return PlayersLogs.getInstance().players.contains(user.toLowerCase());
|
||||
return PlayerCache.getInstance().isAuthenticated(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
PlayersLogs.getInstance().addPlayer(user.toLowerCase());
|
||||
PlayersLogs.getInstance().savePlayerLogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
PlayersLogs.getInstance().removePlayer(user.toLowerCase());
|
||||
PlayersLogs.getInstance().savePlayerLogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,6 +12,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.PlayersLogs;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class AsyncronousRegister {
|
||||
@ -64,9 +65,7 @@ public class AsyncronousRegister {
|
||||
|
||||
else if (database.isAuthAvailable(name)) {
|
||||
m.send(player, "user_regged");
|
||||
if (plugin.pllog.getStringList("players").contains(name)) {
|
||||
plugin.pllog.getStringList("players").remove(name);
|
||||
}
|
||||
PlayersLogs.getInstance().savePlayerLogs();
|
||||
allowRegister = false;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import fr.xephi.authme.events.AuthMeTeleportEvent;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.events.RegisterTeleportEvent;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.PlayersLogs;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
@ -71,7 +72,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
try {
|
||||
plugin.pllog.removePlayer(name);
|
||||
PlayersLogs.getInstance().save();
|
||||
if (player.isInsideVehicle())
|
||||
player.getVehicle().eject();
|
||||
} catch (NullPointerException npe) {
|
||||
|
@ -2,8 +2,14 @@ package fr.xephi.authme.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
@ -11,19 +17,27 @@ import java.util.List;
|
||||
public class PlayersLogs extends CustomConfiguration {
|
||||
|
||||
private static PlayersLogs pllog = null;
|
||||
public List<String> players;
|
||||
|
||||
public PlayersLogs() {
|
||||
super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "players.yml"));
|
||||
pllog = this;
|
||||
load();
|
||||
save();
|
||||
players = this.getStringList("players");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
set("players", new ArrayList<String>());
|
||||
save();
|
||||
public void loadPlayers() {
|
||||
DataSource database = AuthMe.getInstance().database;
|
||||
List<String> list = this.getStringList("players");
|
||||
if (list == null || list.isEmpty())
|
||||
return;
|
||||
for (String s : list) {
|
||||
PlayerAuth auth = database.getAuth(s);
|
||||
if (auth == null)
|
||||
continue;
|
||||
auth.setLastLogin(new Date().getTime());
|
||||
database.updateSession(auth);
|
||||
PlayerCache.getInstance().addPlayer(auth);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayersLogs getInstance() {
|
||||
@ -33,21 +47,18 @@ public class PlayersLogs extends CustomConfiguration {
|
||||
return pllog;
|
||||
}
|
||||
|
||||
public void addPlayer(String user) {
|
||||
players = this.getStringList("players");
|
||||
if (!players.contains(user.toLowerCase())) {
|
||||
players.add(user.toLowerCase());
|
||||
set("players", players);
|
||||
save();
|
||||
public void savePlayerLogs() {
|
||||
List<String> players = new ArrayList<String>();
|
||||
for (String s : PlayerCache.getInstance().getCache().keySet()) {
|
||||
players.add(s);
|
||||
}
|
||||
this.set("players", players);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void removePlayer(String user) {
|
||||
players = this.getStringList("players");
|
||||
if (players.contains(user.toLowerCase())) {
|
||||
players.remove(user.toLowerCase());
|
||||
set("players", players);
|
||||
save();
|
||||
}
|
||||
public void clear() {
|
||||
this.set("players", new ArrayList<String>());
|
||||
this.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user