Merge pull request #42 from DNx5/master

cleanup & improvements
This commit is contained in:
Gabriele C. 2015-09-08 20:49:29 +02:00
commit 0180b2210c
9 changed files with 169 additions and 244 deletions

View File

@ -80,7 +80,7 @@ import net.milkbowl.vault.permission.Permission;
public class AuthMe extends JavaPlugin { public class AuthMe extends JavaPlugin {
public DataSource database = null; public DataSource database;
private Settings settings; private Settings settings;
private Messages m; private Messages m;
public OtherAccounts otherAccounts; public OtherAccounts otherAccounts;
@ -178,9 +178,7 @@ public class AuthMe extends JavaPlugin {
try { try {
Class.forName("org.apache.logging.log4j.core.Filter"); Class.forName("org.apache.logging.log4j.core.Filter");
setLog4JFilter(); setLog4JFilter();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | NoClassDefFoundError e) {
ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled");
} catch (NoClassDefFoundError e) {
ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled"); ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled");
} }
} }
@ -219,13 +217,8 @@ public class AuthMe extends JavaPlugin {
try { try {
setupDatabase(); setupDatabase();
} catch (ClassNotFoundException nfe) { } catch (ClassNotFoundException | SQLException | PoolInitializationException ex) {
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!"); ConsoleLogger.writeStackTrace(ex);
return;
} catch (SQLException sqle) {
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!");
return;
} catch (PoolInitializationException pie) {
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!"); ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!");
return; return;
} }
@ -275,25 +268,18 @@ public class AuthMe extends JavaPlugin {
if (Settings.reloadSupport) { if (Settings.reloadSupport) {
try { try {
int playersOnline = 0; int playersOnline = Utils.getOnlinePlayers().length;
try { if (database != null) {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) if (playersOnline < 1) {
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size();
else playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length;
} catch (Exception ex) {
}
if (playersOnline < 1) {
try {
database.purgeLogged(); database.purgeLogged();
} catch (NullPointerException npe) { } else {
} for (PlayerAuth auth : database.getLoggedPlayers()) {
} else { if (auth == null)
for (PlayerAuth auth : database.getLoggedPlayers()) { continue;
if (auth == null) auth.setLastLogin(new Date().getTime());
continue; database.updateSession(auth);
auth.setLastLogin(new Date().getTime()); PlayerCache.getInstance().addPlayer(auth);
database.updateSession(auth); }
PlayerCache.getInstance().addPlayer(auth);
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -400,38 +386,27 @@ public class AuthMe extends JavaPlugin {
multiverse = null; multiverse = null;
return; return;
} }
if (this.getServer().getPluginManager().getPlugin("Multiverse-Core") != null && this.getServer().getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { if (this.getServer().getPluginManager().isPluginEnabled("Multiverse-Core")) {
try { try {
multiverse = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core"); multiverse = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
ConsoleLogger.info("Hooked correctly with Multiverse-Core"); ConsoleLogger.info("Hooked correctly with Multiverse-Core");
} catch (NullPointerException npe) { } catch (Exception | NoClassDefFoundError ignored) {
multiverse = null;
} catch (ClassCastException cce) {
multiverse = null;
} catch (NoClassDefFoundError ncdfe) {
multiverse = null;
} }
} else {
multiverse = null;
} }
} }
public void checkEssentials() { public void checkEssentials() {
if (this.getServer().getPluginManager().getPlugin("Essentials") != null && this.getServer().getPluginManager().getPlugin("Essentials").isEnabled()) { if (this.getServer().getPluginManager().isPluginEnabled("Essentials")) {
try { try {
ess = (Essentials) this.getServer().getPluginManager().getPlugin("Essentials"); ess = (Essentials) this.getServer().getPluginManager().getPlugin("Essentials");
ConsoleLogger.info("Hooked correctly with Essentials"); ConsoleLogger.info("Hooked correctly with Essentials");
} catch (NullPointerException npe) { } catch (Exception | NoClassDefFoundError e) {
ess = null;
} catch (ClassCastException cce) {
ess = null;
} catch (NoClassDefFoundError ncdfe) {
ess = null; ess = null;
} }
} else { } else {
ess = null; ess = null;
} }
if (this.getServer().getPluginManager().getPlugin("EssentialsSpawn") != null && this.getServer().getPluginManager().getPlugin("EssentialsSpawn").isEnabled()) { if (this.getServer().getPluginManager().isPluginEnabled("EssentialsSpawn")) {
try { try {
essentialsSpawn = new EssSpawn().getLocation(); essentialsSpawn = new EssSpawn().getLocation();
ConsoleLogger.info("Hooked correctly with EssentialsSpawn"); ConsoleLogger.info("Hooked correctly with EssentialsSpawn");
@ -445,42 +420,24 @@ public class AuthMe extends JavaPlugin {
} }
public void checkCombatTag() { public void checkCombatTag() {
if (this.getServer().getPluginManager().getPlugin("CombatTag") != null && this.getServer().getPluginManager().getPlugin("CombatTag").isEnabled()) { this.CombatTag = this.getServer().getPluginManager().isPluginEnabled("CombatTag");
this.CombatTag = true;
} else {
this.CombatTag = false;
}
} }
public void checkCitizens() { public void checkCitizens() {
if (this.getServer().getPluginManager().getPlugin("Citizens") != null && this.getServer().getPluginManager().getPlugin("Citizens").isEnabled()) this.isCitizensActive = this.getServer().getPluginManager().isPluginEnabled("Citizens");
this.isCitizensActive = true;
else this.isCitizensActive = false;
} }
@Override @Override
public void onDisable() { public void onDisable() {
int playersOnline = 0; Player[] players = Utils.getOnlinePlayers();
try { if (players != null) {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) for (Player player : players) {
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size();
else playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length;
} catch (NoSuchMethodException ex) {
} // can never happen
catch (InvocationTargetException ex) {
} // can also never happen
catch (IllegalAccessException ex) {
} // can still never happen
if (playersOnline != 0)
for (Player player : Bukkit.getOnlinePlayers()) {
this.savePlayer(player); this.savePlayer(player);
} }
}
if (database != null) { if (database != null) {
try { database.close();
database.close();
} catch (Exception e) {
}
} }
if (Settings.isBackupActivated && Settings.isBackupOnStop) { if (Settings.isBackupActivated && Settings.isBackupOnStop) {
@ -497,11 +454,8 @@ public class AuthMe extends JavaPlugin {
} }
public void savePlayer(Player player) { public void savePlayer(Player player) {
try { if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) {
if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return;
return;
}
} catch (Exception e) {
} }
try { try {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -511,7 +465,7 @@ public class AuthMe extends JavaPlugin {
} }
if (LimboCache.getInstance().hasLimboPlayer(name)) { if (LimboCache.getInstance().hasLimboPlayer(name)) {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (Settings.protectInventoryBeforeLogInEnabled.booleanValue()) { if (Settings.protectInventoryBeforeLogInEnabled) {
player.getInventory().setArmorContents(limbo.getArmour()); player.getInventory().setArmorContents(limbo.getArmour());
player.getInventory().setContents(limbo.getInventory()); player.getInventory().setContents(limbo.getInventory());
} }
@ -730,18 +684,8 @@ public class AuthMe extends JavaPlugin {
} }
public String replaceAllInfos(String message, Player player) { public String replaceAllInfos(String message, Player player) {
int playersOnline = 0;
try {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class)
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size();
else playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length;
} catch (NoSuchMethodException ex) {
} // can never happen
catch (InvocationTargetException ex) {
} // can also never happen
catch (IllegalAccessException ex) {
} // can still never happen
try { try {
int playersOnline = Utils.getOnlinePlayers().length;
message = message.replace("&", "\u00a7"); message = message.replace("&", "\u00a7");
message = message.replace("{PLAYER}", player.getName()); message = message.replace("{PLAYER}", player.getName());
message = message.replace("{ONLINE}", "" + playersOnline); message = message.replace("{ONLINE}", "" + playersOnline);
@ -776,9 +720,7 @@ public class AuthMe extends JavaPlugin {
if (ip.equalsIgnoreCase(getIP(player)) && database.isLogged(player.getName().toLowerCase()) && !player.getName().equalsIgnoreCase(name)) if (ip.equalsIgnoreCase(getIP(player)) && database.isLogged(player.getName().toLowerCase()) && !player.getName().equalsIgnoreCase(name))
count++; count++;
} }
if (count >= Settings.getMaxLoginPerIp) return count >= Settings.getMaxLoginPerIp;
return true;
return false;
} }
public boolean hasJoinedIp(String name, String ip) { public boolean hasJoinedIp(String name, String ip) {
@ -787,14 +729,12 @@ public class AuthMe extends JavaPlugin {
if (ip.equalsIgnoreCase(getIP(player)) && !player.getName().equalsIgnoreCase(name)) if (ip.equalsIgnoreCase(getIP(player)) && !player.getName().equalsIgnoreCase(name))
count++; count++;
} }
if (count >= Settings.getMaxJoinPerIp) return count >= Settings.getMaxJoinPerIp;
return true;
return false;
} }
/** /**
* Get Player real IP through VeryGames method * Get Player real IP through VeryGames method
* *
* @param player * @param player
* player * player
*/ */

View File

@ -1,5 +1,6 @@
package fr.xephi.authme; package fr.xephi.authme;
import com.google.common.base.Throwables;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -59,4 +60,7 @@ public class ConsoleLogger {
} }
} }
public static void writeStackTrace(Exception ex){
writeLog(Throwables.getStackTraceAsString(ex));
}
} }

View File

@ -1,18 +1,19 @@
package fr.xephi.authme; package fr.xephi.authme;
import java.io.File; import fr.xephi.authme.cache.limbo.LimboCache;
import java.util.Iterator; import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import fr.xephi.authme.cache.limbo.LimboCache; import java.io.File;
import fr.xephi.authme.cache.limbo.LimboPlayer; import java.lang.reflect.InvocationTargetException;
import fr.xephi.authme.events.AuthMeTeleportEvent; import java.util.Collection;
import fr.xephi.authme.settings.Settings; import java.util.Iterator;
public class Utils { public class Utils {
@ -130,7 +131,7 @@ public class Utils {
} }
public void packCoords(double x, double y, double z, String w, public void packCoords(double x, double y, double z, String w,
final Player pl) { final Player pl) {
World theWorld; World theWorld;
if (w.equals("unavailableworld")) { if (w.equals("unavailableworld")) {
theWorld = pl.getWorld(); theWorld = pl.getWorld();
@ -171,13 +172,13 @@ public class Utils {
NOTLOGGEDIN, NOTLOGGEDIN,
LOGGEDIN LOGGEDIN
} }
public static void purgeDirectory(File file){ public static void purgeDirectory(File file) {
String files[] = file.list(); String files[] = file.list();
if (files != null && files.length != 0){ if (files != null && files.length != 0) {
for (String temp : files) { for (String temp : files) {
File fileDelete = new File(file, temp); File fileDelete = new File(file, temp);
if (fileDelete.isDirectory()){ if (fileDelete.isDirectory()) {
purgeDirectory(fileDelete); purgeDirectory(fileDelete);
fileDelete.delete(); fileDelete.delete();
} else { } else {
@ -186,4 +187,18 @@ public class Utils {
} }
} }
} }
public static Player[] getOnlinePlayers() {
Player[] players = null;
try {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) {
players = (Player[]) ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).toArray();
} else {
players = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null));
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
// can never happen
}
return players;
}
} }

View File

@ -70,9 +70,7 @@ public class NewAPI {
* @return true if player is a npc * @return true if player is a npc
*/ */
public boolean isNPC(Player player) { public boolean isNPC(Player player) {
if (plugin.getCitizensCommunicator().isNPC(player)) return plugin.getCitizensCommunicator().isNPC(player) || CombatTagComunicator.isNPC(player);
return true;
return CombatTagComunicator.isNPC(player);
} }
/** /**
@ -89,8 +87,7 @@ public class NewAPI {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
if (auth != null) { if (auth != null) {
Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
return loc;
} else { } else {
return null; return null;
} }
@ -152,10 +149,7 @@ public class NewAPI {
return false; return false;
} }
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com"); PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com");
if (!plugin.database.saveAuth(auth)) { return plugin.database.saveAuth(auth);
return false;
}
return true;
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
return false; return false;
} }

View File

@ -2,11 +2,7 @@ package fr.xephi.authme.cache.backup;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -44,9 +40,7 @@ public class FileCache {
return; return;
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase();
} catch (Error e) {
path = player.getName().toLowerCase(); path = player.getName().toLowerCase();
} }
File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache");
@ -109,22 +103,19 @@ public class FileCache {
if (Settings.customAttributes) { if (Settings.customAttributes) {
try { try {
Attributes attributes = new Attributes(item); Attributes attributes = new Attributes(item);
if (attributes != null) { Iterator<Attribute> iter = attributes.values().iterator();
Iterator<Attribute> iter = attributes.values().iterator(); Attribute a = null;
Attribute a = null; while (iter.hasNext()) {
while (iter.hasNext()) { Attribute b = iter.next();
Attribute b = iter.next(); if (a != null && a == b)
if (a != null && a == b) break;
break; a = b;
a = b; if (a != null) {
if (a != null) { if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null)
if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null) writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString());
writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString());
}
} }
} }
} catch (Exception e) { } catch (Exception | Error e) {
} catch (Error e) {
} }
} }
} else { } else {
@ -172,14 +163,13 @@ public class FileCache {
if (Settings.customAttributes) { if (Settings.customAttributes) {
try { try {
Attributes attributes = new Attributes(item); Attributes attributes = new Attributes(item);
if (attributes != null) while (attributes.values().iterator().hasNext()) {
while (attributes.values().iterator().hasNext()) { Attribute a = attributes.values().iterator().next();
Attribute a = attributes.values().iterator().next(); if (a != null) {
if (a != null) { if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null && a.getAttributeType().getMinecraftId() != null)
if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null && a.getAttributeType().getMinecraftId() != null) writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString());
writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString());
}
} }
}
} catch (Exception e) { } catch (Exception e) {
} }
} }
@ -197,9 +187,7 @@ public class FileCache {
String path = ""; String path = "";
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase();
} catch (Error e) {
path = player.getName().toLowerCase(); path = player.getName().toLowerCase();
} }
try { try {
@ -232,13 +220,9 @@ public class FileCache {
final String[] playerInfo = line.split(";"); final String[] playerInfo = line.split(";");
group = playerInfo[0]; group = playerInfo[0];
if (Integer.parseInt(playerInfo[1]) == 1) { op = Integer.parseInt(playerInfo[1]) == 1;
op = true;
} else op = false;
if (playerInfo.length > 2) { if (playerInfo.length > 2) {
if (Integer.parseInt(playerInfo[2]) == 1) flying = Integer.parseInt(playerInfo[2]) == 1;
flying = true;
else flying = false;
} }
continue; continue;
@ -275,9 +259,7 @@ public class FileCache {
} }
if (!lores.isEmpty()) { if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>(); List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) { Collections.addAll(loreList, lores.split("%newline%"));
loreList.add(s);
}
meta.setLore(loreList); meta.setLore(loreList);
} }
if (meta != null) if (meta != null)
@ -296,9 +278,7 @@ public class FileCache {
meta.setDisplayName(name); meta.setDisplayName(name);
if (!lores.isEmpty()) { if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>(); List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) { Collections.addAll(loreList, lores.split("%newline%"));
loreList.add(s);
}
meta.setLore(loreList); meta.setLore(loreList);
} }
if (meta != null) if (meta != null)
@ -348,14 +328,13 @@ public class FileCache {
Attributes attributes = null; Attributes attributes = null;
count = 1; count = 1;
boolean v = true; boolean v = true;
while (reader.hasNextLine() && v == true) { while (reader.hasNextLine() && v) {
String line = reader.nextLine(); String line = reader.nextLine();
switch (count) { switch (count) {
case 1: case 1:
item = new ItemStack(Material.getMaterial(line)); item = new ItemStack(Material.getMaterial(line));
if (item.getType() == Material.AIR) if (item.getType() == Material.AIR)
v = false; v = false;
meta = item.getItemMeta();
count++; count++;
continue; continue;
case 2: case 2:
@ -379,8 +358,7 @@ public class FileCache {
if (line.startsWith("lore=")) { if (line.startsWith("lore=")) {
line = line.substring(5); line = line.substring(5);
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
for (String s : line.split("%newline%")) Collections.addAll(lore, line.split("%newline%"));
lore.add(s);
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
continue; continue;
@ -430,7 +408,7 @@ public class FileCache {
Attributes attributes = null; Attributes attributes = null;
count = 1; count = 1;
boolean v = true; boolean v = true;
while (reader.hasNextLine() && v == true) { while (reader.hasNextLine() && v) {
String line = reader.nextLine(); String line = reader.nextLine();
switch (count) { switch (count) {
case 1: case 1:
@ -460,9 +438,8 @@ public class FileCache {
} }
if (line.startsWith("lore=")) { if (line.startsWith("lore=")) {
line = line.substring(5); line = line.substring(5);
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<>();
for (String s : line.split("%newline%")) Collections.addAll(lore, line.split("%newline%"));
lore.add(s);
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
continue; continue;
@ -504,10 +481,6 @@ public class FileCache {
armours[i] = attributes.getStack(); armours[i] = attributes.getStack();
else armours[i] = item; else armours[i] = item;
} }
} catch (final RuntimeException e) {
//verbose
e.printStackTrace();
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
} catch (final Exception e) { } catch (final Exception e) {
//verbose //verbose
e.printStackTrace(); e.printStackTrace();
@ -518,11 +491,6 @@ public class FileCache {
} }
return new DataFileCache(inv, armours, group, op, flying); return new DataFileCache(inv, armours, group, op, flying);
} }
} catch (RuntimeException e) {
// Verbose
e.printStackTrace();
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
return null;
} catch (Exception e) { } catch (Exception e) {
// Verbose // Verbose
e.printStackTrace(); e.printStackTrace();
@ -535,9 +503,7 @@ public class FileCache {
String path = ""; String path = "";
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase();
} catch (Error e) {
path = player.getName().toLowerCase(); path = player.getName().toLowerCase();
} }
try { try {
@ -562,9 +528,7 @@ public class FileCache {
String path = ""; String path = "";
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase();
} catch (Error e) {
path = player.getName().toLowerCase(); path = player.getName().toLowerCase();
} }
File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache");

View File

@ -53,6 +53,7 @@ public class LimboCache {
operator = playerData.readCache(player).getOperator(); operator = playerData.readCache(player).getOperator();
flying = playerData.readCache(player).isFlying(); flying = playerData.readCache(player).isFlying();
} catch (Exception e) { } catch (Exception e) {
ConsoleLogger.writeStackTrace(e);
ConsoleLogger.showError("Some error on reading cache of " + name); ConsoleLogger.showError("Some error on reading cache of " + name);
} }
} else { } else {
@ -65,12 +66,8 @@ public class LimboCache {
inv = null; inv = null;
arm = null; arm = null;
} }
if (player.isOp()) operator = player.isOp();
operator = true; flying = player.isFlying();
else operator = false;
if (player.isFlying())
flying = true;
else flying = false;
if (plugin.permission != null) { if (plugin.permission != null) {
try { try {
playerGroup = plugin.permission.getPrimaryGroup(player); playerGroup = plugin.permission.getPrimaryGroup(player);

View File

@ -1,20 +1,15 @@
package fr.xephi.authme.commands; package fr.xephi.authme.commands;
import java.security.NoSuchAlgorithmException; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.ChangePasswordTask;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
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.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
public class ChangePasswordCommand implements CommandExecutor { public class ChangePasswordCommand implements CommandExecutor {
private Messages m = Messages.getInstance(); private Messages m = Messages.getInstance();
@ -25,8 +20,8 @@ public class ChangePasswordCommand implements CommandExecutor {
} }
@Override @Override
public boolean onCommand(final CommandSender sender, Command cmnd, String label, public boolean onCommand(CommandSender sender, Command cmnd, String label,
final String[] args) { String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return true; return true;
} }
@ -36,8 +31,8 @@ public class ChangePasswordCommand implements CommandExecutor {
return true; return true;
} }
final Player player = (Player) sender; Player player = (Player) sender;
final String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
if (!PlayerCache.getInstance().isAuthenticated(name)) { if (!PlayerCache.getInstance().isAuthenticated(name)) {
m.send(player, "not_logged_in"); m.send(player, "not_logged_in");
return true; return true;
@ -67,35 +62,7 @@ public class ChangePasswordCommand implements CommandExecutor {
return true; return true;
} }
} }
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, args[0]));
@Override
public void run() {
try {
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, args[1], name);
if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
auth.setHash(hashnew);
if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null)
auth.setSalt(PasswordSecurity.userSalt.get(name));
else auth.setSalt("");
if (!plugin.database.updatePassword(auth)) {
m.send(player, "error");
return;
}
plugin.database.updateSalt(auth);
PlayerCache.getInstance().updatePlayer(auth);
m.send(player, "pwd_changed");
ConsoleLogger.info(player.getName() + " changed his password");
} else {
m.send(player, "wrong_pwd");
}
} catch (NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage());
m.send(sender, "error");
}
}
});
return true; return true;
} }
} }

View File

@ -575,17 +575,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
int playersOnline = 0; int playersOnline = Utils.getOnlinePlayers().length;
try {
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class)
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).size();
else playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null, new Object[0])).length;
} catch (NoSuchMethodException ex) {
} // can never happen
catch (InvocationTargetException ex) {
} // can also never happen
catch (IllegalAccessException ex) {
} // can still never happen
if (playersOnline > plugin.getServer().getMaxPlayers()) { if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow(); event.allow();
return; return;
@ -625,13 +615,12 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
Player player = event.getPlayer();
if ((!Settings.isForceSingleSessionEnabled) && (event.getReason().contains(m.getString("same_nick")))) { if ((!Settings.isForceSingleSessionEnabled) && (event.getReason().contains(m.getString("same_nick")))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
Player player = event.getPlayer();
plugin.management.performQuit(player, true); plugin.management.performQuit(player, true);
} }

View File

@ -0,0 +1,55 @@
package fr.xephi.authme.task;
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.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
import java.security.NoSuchAlgorithmException;
public class ChangePasswordTask implements Runnable {
private final AuthMe plugin;
private final Player player;
private String password;
public ChangePasswordTask(AuthMe plugin, Player player, String password) {
this.plugin = plugin;
this.player = player;
this.password = password;
}
@Override
public void run() {
Messages m = Messages.getInstance();
try {
String name = player.getName().toLowerCase();
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
if (PasswordSecurity.comparePasswordWithHash(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
auth.setHash(hashnew);
if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null)
auth.setSalt(PasswordSecurity.userSalt.get(name));
else auth.setSalt("");
if (!plugin.database.updatePassword(auth)) {
m.send(player, "error");
return;
}
plugin.database.updateSalt(auth);
PlayerCache.getInstance().updatePlayer(auth);
m.send(player, "pwd_changed");
ConsoleLogger.info(player.getName() + " changed his password");
} else {
m.send(player, "wrong_pwd");
}
} catch (NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage());
m.send(player, "error");
}
}
}