mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-30 14:13:35 +01:00
Enhance mainclass
This commit is contained in:
parent
e85d8acc24
commit
7458224ada
@ -71,7 +71,7 @@ public class AuthMe extends JavaPlugin {
|
||||
public Essentials ess;
|
||||
public Location essentialsSpawn;
|
||||
public MultiverseCore multiverse = null;
|
||||
public LookupService ls = null;
|
||||
public LookupService lookupService = null;
|
||||
public CitizensCommunicator citizens;
|
||||
public boolean isCitizensActive = false;
|
||||
public boolean CombatTag = false;
|
||||
@ -79,10 +79,10 @@ public class AuthMe extends JavaPlugin {
|
||||
public boolean BungeeCord = false;
|
||||
public boolean antibotMod = false;
|
||||
public boolean delayedAntiBot = true;
|
||||
public ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<String, BukkitTask>();
|
||||
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 ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
||||
public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
|
||||
public ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>();
|
||||
public ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>();
|
||||
protected static String vgUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||
|
||||
public static AuthMe getInstance() {
|
||||
@ -264,8 +264,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Reload support hook
|
||||
if (Settings.reloadSupport) {
|
||||
try {
|
||||
int playersOnline = Utils.getOnlinePlayers().length;
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
if (database != null) {
|
||||
if (playersOnline < 1) {
|
||||
database.purgeLogged();
|
||||
@ -279,8 +278,6 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
// Register events
|
||||
@ -318,7 +315,7 @@ public class AuthMe extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Save player data
|
||||
Player[] players = Utils.getOnlinePlayers();
|
||||
Collection<? extends Player> players = Utils.getOnlinePlayers();
|
||||
if (players != null) {
|
||||
for (Player player : players) {
|
||||
this.savePlayer(player);
|
||||
@ -361,7 +358,7 @@ public class AuthMe extends JavaPlugin {
|
||||
// Initialize and setup the database
|
||||
public void setupDatabase() throws ClassNotFoundException, PoolInitializationException, SQLException {
|
||||
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
||||
int accounts = 0;
|
||||
int accounts;
|
||||
switch (Settings.getDataSource) {
|
||||
case FILE:
|
||||
database = new FlatFile();
|
||||
@ -391,11 +388,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
||||
Converter converter = new ForceFlatToSqlite(database, this);
|
||||
try {
|
||||
Thread t = new Thread(converter);
|
||||
t.start();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
getServer().getScheduler().runTaskAsynchronously(this, converter);
|
||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !");
|
||||
ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart");
|
||||
}
|
||||
@ -431,9 +424,8 @@ public class AuthMe extends JavaPlugin {
|
||||
// Check the version of the ChestShop plugin
|
||||
public void checkChestShop() {
|
||||
if (Settings.legacyChestShop && server.getPluginManager().isPluginEnabled("ChestShop")) {
|
||||
try {
|
||||
String rawver = com.Acrobot.ChestShop.ChestShop.getVersion();
|
||||
double version = 0;
|
||||
double version;
|
||||
try {
|
||||
version = Double.valueOf(rawver.split(" ")[0]);
|
||||
} catch (NumberFormatException nfe) {
|
||||
@ -452,8 +444,6 @@ public class AuthMe extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
legacyChestShop = true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else {
|
||||
legacyChestShop = false;
|
||||
}
|
||||
@ -462,7 +452,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Check PerWorldInventories version
|
||||
public void checkPerWorldInventories() {
|
||||
if (server.getPluginManager().isPluginEnabled("PerWorldInventories")) {
|
||||
try {
|
||||
double version = 0;
|
||||
String ver = server.getPluginManager().getPlugin("PerWorldInventories").getDescription().getVersion();
|
||||
try {
|
||||
@ -470,14 +459,12 @@ public class AuthMe extends JavaPlugin {
|
||||
} catch (NumberFormatException nfe) {
|
||||
try {
|
||||
version = Double.valueOf(ver.split("t")[0]);
|
||||
} catch (NumberFormatException nfee) {
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
}
|
||||
if (version < 1.57) {
|
||||
ConsoleLogger.showError("Please Update your PerWorldInventories version! INVENTORY WIPE may occur!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -554,7 +541,6 @@ public class AuthMe extends JavaPlugin {
|
||||
if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String name = player.getName().toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) {
|
||||
final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName(), player.getName());
|
||||
@ -580,8 +566,6 @@ public class AuthMe extends JavaPlugin {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
player.saveData();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
// Select the player to kick when a vip player join the server when full
|
||||
@ -686,8 +670,12 @@ public class AuthMe extends JavaPlugin {
|
||||
public void downloadGeoIp() {
|
||||
ConsoleLogger.info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com");
|
||||
File file = new File(getDataFolder(), "GeoIP.dat");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
if (file.exists()) {
|
||||
if (lookupService == null) {
|
||||
lookupService = new LookupService(file);
|
||||
}
|
||||
} else {
|
||||
String url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz";
|
||||
URL downloadUrl = new URL(url);
|
||||
URLConnection conn = downloadUrl.openConnection();
|
||||
@ -706,35 +694,26 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
output.close();
|
||||
input.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Need to review the code below!
|
||||
|
||||
public String getCountryCode(String ip) {
|
||||
try {
|
||||
if (ls == null)
|
||||
ls = new LookupService(new File(getDataFolder(), "GeoIP.dat"));
|
||||
String code = ls.getCountry(ip).getCode();
|
||||
if (code != null && !code.isEmpty())
|
||||
return code;
|
||||
} catch (Exception e) {
|
||||
if (lookupService != null) {
|
||||
return lookupService.getCountry(ip).getCode();
|
||||
}
|
||||
return null;
|
||||
return "--";
|
||||
}
|
||||
|
||||
public String getCountryName(String ip) {
|
||||
try {
|
||||
if (ls == null)
|
||||
ls = new LookupService(new File(getDataFolder(), "GeoIP.dat"));
|
||||
String code = ls.getCountry(ip).getName();
|
||||
if (code != null && !code.isEmpty())
|
||||
return code;
|
||||
} catch (Exception e) {
|
||||
if (lookupService != null) {
|
||||
return lookupService.getCountry(ip).getName();
|
||||
}
|
||||
return null;
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public void switchAntiBotMod(boolean mode) {
|
||||
@ -765,8 +744,7 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
|
||||
public String replaceAllInfos(String message, Player player) {
|
||||
try {
|
||||
int playersOnline = Utils.getOnlinePlayers().length;
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
message = message.replace("&", "\u00a7");
|
||||
message = message.replace("{PLAYER}", player.getName());
|
||||
message = message.replace("{ONLINE}", "" + playersOnline);
|
||||
@ -777,8 +755,6 @@ public class AuthMe extends JavaPlugin {
|
||||
message = message.replace("{SERVER}", this.getServer().getServerName());
|
||||
message = message.replace("{VERSION}", this.getServer().getBukkitVersion());
|
||||
message = message.replace("{COUNTRY}", this.getCountryName(getIP(player)));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -831,7 +807,7 @@ public class AuthMe extends JavaPlugin {
|
||||
if (inputLine != null && !inputLine.isEmpty() && !inputLine.equalsIgnoreCase("error") && !inputLine.contains("error")) {
|
||||
realIP = inputLine;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return realIP;
|
||||
}
|
||||
|
@ -11,21 +11,32 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static boolean getOnlinePlayersIsCollection;
|
||||
private String currentGroup;
|
||||
private static Utils singleton;
|
||||
private static Method getOnlinePlayers;
|
||||
public final AuthMe plugin;
|
||||
|
||||
public Utils(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Method m = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
||||
getOnlinePlayersIsCollection = m.getReturnType() == Collection.class;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroup(Player player, groupType group) {
|
||||
setGroup(player.getName(), group);
|
||||
}
|
||||
@ -182,19 +193,21 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Player[] getOnlinePlayers() {
|
||||
Player[] players;
|
||||
public static Collection<? extends Player> getOnlinePlayers() {
|
||||
if (getOnlinePlayersIsCollection) {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
try {
|
||||
Method m = Bukkit.class.getMethod("getOnlinePlayers");
|
||||
if (m.getReturnType() == Collection.class) {
|
||||
players = (Player[]) ((Collection<?>) m.invoke(null)).toArray();
|
||||
} else {
|
||||
players = ((Player[]) m.invoke(null));
|
||||
if (getOnlinePlayers == null) {
|
||||
getOnlinePlayers = Bukkit.class.getMethod("getOnlinePlayers");
|
||||
}
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
|
||||
// can never happen
|
||||
players = null;
|
||||
Object obj = getOnlinePlayers.invoke(null);
|
||||
if (obj instanceof Collection) {
|
||||
return (Collection) obj;
|
||||
}
|
||||
return players;
|
||||
return Arrays.asList((Player[]) obj);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
int playersOnline = Utils.getOnlinePlayers().length;
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
if (playersOnline > plugin.getServer().getMaxPlayers()) {
|
||||
event.allow();
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user