Some minor automatic fixes and changes

This commit is contained in:
Tim Visée 2015-11-23 21:43:40 +01:00
parent 1cdf49f7e1
commit f15eaae67f
5 changed files with 283 additions and 273 deletions

View File

@ -878,8 +878,8 @@ public class AuthMe extends JavaPlugin {
ip = realIp.get(name); ip = realIp.get(name);
} }
if (Settings.checkVeryGames) if (Settings.checkVeryGames)
if (getVeryGamesIP(player) != null) if (getVeryGamesIp(player) != null)
ip = getVeryGamesIP(player); ip = getVeryGamesIp(player);
return ip; return ip;
} }
@ -908,11 +908,12 @@ public class AuthMe extends JavaPlugin {
/** /**
* Gets a player's real IP through VeryGames method. * Gets a player's real IP through VeryGames method.
* *
* @param player the player to process * @param player The player to process.
* @return the real IP of the player *
* @return The real IP of the player.
*/ */
@Deprecated @Deprecated
public String getVeryGamesIP(Player player) { public String getVeryGamesIp(Player player) {
String realIP = player.getAddress().getAddress().getHostAddress(); String realIP = player.getAddress().getAddress().getHostAddress();
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%"; String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()).replace("%PORT%", "" + player.getAddress().getPort()); sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()).replace("%PORT%", "" + player.getAddress().getPort());

View File

@ -30,8 +30,8 @@ public class ConsoleFilter implements Filter {
return true; return true;
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register ")) if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
return true; return true;
String playername = record.getMessage().split(" ")[0]; String playerName = record.getMessage().split(" ")[0];
record.setMessage(playername + " issued an AuthMe command!"); record.setMessage(playerName + " issued an AuthMe command!");
return true; return true;
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
return true; return true;

View File

@ -1,261 +1,269 @@
package fr.xephi.authme; package fr.xephi.authme;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
/** /**
*/ */
public class DataManager { public class DataManager {
public AuthMe plugin; public AuthMe plugin;
/** /**
* Constructor for DataManager. * Constructor for DataManager.
* *
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public DataManager(AuthMe plugin) { public DataManager(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public void run() { public void run() {
} }
/** /**
* Method getOfflinePlayer. * Method getOfflinePlayer.
* *
* @param name String * @param name String
* @return OfflinePlayer * @return OfflinePlayer
*/ */
public synchronized OfflinePlayer getOfflinePlayer(final String name) { public synchronized OfflinePlayer getOfflinePlayer(final String name) {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() { Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
public synchronized OfflinePlayer call() throws Exception { public synchronized OfflinePlayer call() throws Exception {
OfflinePlayer result = null; OfflinePlayer result = null;
try { try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) for (OfflinePlayer op : Bukkit.getOfflinePlayers())
if (op.getName().equalsIgnoreCase(name)) { if (op.getName().equalsIgnoreCase(name)) {
result = op; result = op;
break; break;
} }
} catch (Exception e) { } catch (Exception ignored) {
} }
return result; return result;
} }
}); });
try { try {
return result.get(); return result.get();
} catch (Exception e) { } catch (Exception e) {
return (null); return (null);
} finally { } finally {
executor.shutdown(); executor.shutdown();
} }
} }
/** /**
* Method purgeAntiXray. * Method purgeAntiXray.
* *
* @param cleared List<String> * @param cleared List<String>
*/ */
public synchronized void purgeAntiXray(List<String> cleared) { public synchronized void purgeAntiXray(List<String> cleared) {
int i = 0; int i = 0;
for (String name : cleared) { for (String name : cleared) {
try { try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null) if (player == null)
continue; continue;
String playerName = player.getName(); String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName); File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
if (playerFile.exists()) { if (playerFile.exists()) {
playerFile.delete(); //noinspection ResultOfMethodCallIgnored
i++; playerFile.delete();
} i++;
} catch (Exception e) { }
} } catch (Exception ignored) {
} }
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files"); }
} ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
}
/**
* Method purgeLimitedCreative. /**
* * Method purgeLimitedCreative.
* @param cleared List<String> *
*/ * @param cleared List<String>
public synchronized void purgeLimitedCreative(List<String> cleared) { */
int i = 0; public synchronized void purgeLimitedCreative(List<String> cleared) {
for (String name : cleared) { int i = 0;
try { for (String name : cleared) {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); try {
if (player == null) org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
continue; if (player == null)
String playerName = player.getName(); continue;
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml"); String playerName = player.getName();
if (playerFile.exists()) { File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
playerFile.delete(); if (playerFile.exists()) {
i++; //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml"); i++;
if (playerFile.exists()) { }
playerFile.delete(); playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
i++; if (playerFile.exists()) {
} //noinspection ResultOfMethodCallIgnored
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml"); playerFile.delete();
if (playerFile.exists()) { i++;
playerFile.delete(); }
i++; playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
} if (playerFile.exists()) {
} catch (Exception e) { //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
} i++;
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files"); }
} } catch (Exception ignored) {
}
/** }
* Method purgeDat. ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
* }
* @param cleared List<String>
*/ /**
public synchronized void purgeDat(List<String> cleared) { * Method purgeDat.
int i = 0; *
for (String name : cleared) { * @param cleared List<String>
try { */
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); public synchronized void purgeDat(List<String> cleared) {
if (player == null) { int i = 0;
continue; for (String name : cleared) {
} try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
try { if (player == null) {
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); continue;
playerFile.delete(); }
i++;
} catch (Exception ignore) { try {
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat"); File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
if (playerFile.exists()) { //noinspection ResultOfMethodCallIgnored
playerFile.delete(); playerFile.delete();
i++; i++;
} } catch (Exception ignore) {
} File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
} catch (Exception ignore) { if (playerFile.exists()) {
} //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); i++;
} }
}
/** } catch (Exception ignore) {
* Method purgeEssentials. }
* }
* @param cleared List<String> ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
*/ }
@SuppressWarnings("deprecation")
public void purgeEssentials(List<String> cleared) { /**
int i = 0; * Method purgeEssentials.
for (String name : cleared) { *
try { * @param cleared List<String>
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml"); */
playerFile.delete(); @SuppressWarnings("deprecation")
i++; public void purgeEssentials(List<String> cleared) {
} catch (Exception e) { int i = 0;
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); for (String name : cleared) {
if (playerFile.exists()) { try {
playerFile.delete(); File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
i++; //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
} i++;
} } catch (Exception e) {
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
} if (playerFile.exists()) {
//noinspection ResultOfMethodCallIgnored
// TODO: What is this method for? Is it correct? playerFile.delete();
i++;
/** }
* @param cleared Cleared players. }
*/ }
public synchronized void purgePermissions(List<String> cleared) { ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
// Get the permissions manager, and make sure it's valid }
PermissionsManager permsMan = this.plugin.getPermissionsManager();
if (permsMan == null) // TODO: What is this method for? Is it correct?
ConsoleLogger.showError("Unable to access permissions manager instance!");
assert permsMan != null; /**
* @param cleared Cleared players.
int i = 0; */
for (String name : cleared) { public synchronized void purgePermissions(List<String> cleared) {
try { // Get the permissions manager, and make sure it's valid
permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase())); PermissionsManager permsMan = this.plugin.getPermissionsManager();
i++; if (permsMan == null)
} catch (Exception e) { ConsoleLogger.showError("Unable to access permissions manager instance!");
} assert permsMan != null;
}
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions"); int i = 0;
for (String name : cleared) {
/*int i = 0; try {
for (String name : cleared) { permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase()));
try { i++;
OfflinePlayer p = this.getOfflinePlayer(name); } catch (Exception ignored) {
for (String group : permission.getPlayerGroups((Player) p)) { }
permission.playerRemoveGroup(null, p, group); }
} ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions");
i++;
} catch (Exception e) { /*int i = 0;
} for (String name : cleared) {
} try {
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/ OfflinePlayer p = this.getOfflinePlayer(name);
} for (String group : permission.getPlayerGroups((Player) p)) {
permission.playerRemoveGroup(null, p, group);
/** }
* Method isOnline. i++;
* } catch (Exception e) {
* @param player Player }
* @param name String }
* @return boolean ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/
*/ }
public boolean isOnline(Player player, final String name) {
if (player.isOnline()) /**
return true; * Method isOnline.
ExecutorService executor = Executors.newSingleThreadExecutor(); *
Future<Boolean> result = executor.submit(new Callable<Boolean>() { * @param player Player
* @param name String
@Override * @return boolean
public synchronized Boolean call() throws Exception { */
for (OfflinePlayer op : Utils.getOnlinePlayers()) public boolean isOnline(Player player, final String name) {
if (op.getName().equalsIgnoreCase(name)) { if (player.isOnline())
return true; return true;
} ExecutorService executor = Executors.newSingleThreadExecutor();
return false; Future<Boolean> result = executor.submit(new Callable<Boolean>() {
}
}); @Override
try { public synchronized Boolean call() throws Exception {
return result.get(); for (OfflinePlayer op : Utils.getOnlinePlayers())
} catch (Exception e) { if (op.getName().equalsIgnoreCase(name)) {
return false; return true;
} finally { }
executor.shutdown(); return false;
} }
} });
try {
/** return result.get();
* Method getOnlinePlayerLower. } catch (Exception e) {
* return false;
* @param name String } finally {
* @return Player executor.shutdown();
*/ }
public Player getOnlinePlayerLower(String name) { }
name = name.toLowerCase();
for (Player player : Utils.getOnlinePlayers()) { /**
if (player.getName().equalsIgnoreCase(name)) * Method getOnlinePlayerLower.
return player; *
} * @param name String
return null; * @return Player
} */
} public Player getOnlinePlayerLower(String name) {
name = name.toLowerCase();
for (Player player : Utils.getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(name))
return player;
}
return null;
}
}

View File

@ -154,7 +154,7 @@ public class PerformBackup {
*/ */
private boolean checkWindows(String windowsPath) { private boolean checkWindows(String windowsPath) {
String isWin = System.getProperty("os.name").toLowerCase(); String isWin = System.getProperty("os.name").toLowerCase();
if (isWin.indexOf("win") >= 0) { if (isWin.contains("win")) {
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) { if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
return true; return true;
} else { } else {

View File

@ -34,15 +34,15 @@ public class SendMailSSL {
* @param newPass String * @param newPass String
*/ */
public void main(final PlayerAuth auth, final String newPass) { public void main(final PlayerAuth auth, final String newPass) {
String sendername; String senderName;
if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) { if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) {
sendername = Settings.getmailAccount; senderName = Settings.getmailAccount;
} else { } else {
sendername = Settings.getmailSenderName; senderName = Settings.getmailSenderName;
} }
final String sender = sendername; final String sender = senderName;
final int port = Settings.getMailPort; final int port = Settings.getMailPort;
final String acc = Settings.getmailAccount; final String acc = Settings.getmailAccount;
final String subject = Settings.getMailSubject; final String subject = Settings.getMailSubject;
@ -90,6 +90,7 @@ public class SendMailSSL {
ConsoleLogger.showError("Fail to send a mail to " + mail); ConsoleLogger.showError("Fail to send a mail to " + mail);
} }
if (file != null) if (file != null)
//noinspection ResultOfMethodCallIgnored
file.delete(); file.delete();
} catch (Exception e) { } catch (Exception e) {