Replace all '/' in path to File.separator - Code Refactor
This commit is contained in:
+8
-12
@@ -129,7 +129,8 @@ public class PlayerAuth {
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
if (ip == null || ip.isEmpty()) ip = "127.0.0.1";
|
||||
if (ip == null || ip.isEmpty())
|
||||
ip = "127.0.0.1";
|
||||
return ip;
|
||||
}
|
||||
|
||||
@@ -139,8 +140,7 @@ public class PlayerAuth {
|
||||
|
||||
public String getHash() {
|
||||
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
||||
if (salt != null && !salt.isEmpty()
|
||||
&& Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
||||
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
||||
vBhash = "$MD5vb$" + salt + "$" + hash;
|
||||
return vBhash;
|
||||
}
|
||||
@@ -186,7 +186,8 @@ public class PlayerAuth {
|
||||
|
||||
public long getLastLogin() {
|
||||
try {
|
||||
if (Long.valueOf(lastLogin) == null) lastLogin = 0L;
|
||||
if (Long.valueOf(lastLogin) == null)
|
||||
lastLogin = 0L;
|
||||
} catch (NullPointerException e) {
|
||||
lastLogin = 0L;
|
||||
}
|
||||
@@ -219,15 +220,13 @@ public class PlayerAuth {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth other = (PlayerAuth) obj;
|
||||
return other.getIp().equals(this.ip)
|
||||
&& other.getNickname().equals(this.nickname);
|
||||
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 7;
|
||||
hashCode = 71 * hashCode
|
||||
+ (this.nickname != null ? this.nickname.hashCode() : 0);
|
||||
hashCode = 71 * hashCode + (this.nickname != null ? this.nickname.hashCode() : 0);
|
||||
hashCode = 71 * hashCode + (this.ip != null ? this.ip.hashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
@@ -242,10 +241,7 @@ public class PlayerAuth {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : "
|
||||
+ lastLogin + " ! LastPosition : " + x + "," + y + "," + z
|
||||
+ "," + world + " ! Email : " + email + " ! Hash : " + hash
|
||||
+ " ! Salt : " + salt + " ! RealName : " + realName;
|
||||
String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt + " ! RealName : " + realName;
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
+58
-73
@@ -29,9 +29,9 @@ public class FileCache {
|
||||
|
||||
public FileCache(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
final File file = new File(plugin.getDataFolder() + File.separator
|
||||
+ "cache");
|
||||
if (!file.exists()) file.mkdir();
|
||||
final File file = new File(plugin.getDataFolder() + File.separator + "cache");
|
||||
if (!file.exists())
|
||||
file.mkdir();
|
||||
}
|
||||
|
||||
public void createCache(Player player, DataFileCache playerData,
|
||||
@@ -44,8 +44,7 @@ public class FileCache {
|
||||
} catch (Error e) {
|
||||
path = player.getName();
|
||||
}
|
||||
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");
|
||||
|
||||
if (file.exists()) {
|
||||
return;
|
||||
@@ -61,16 +60,13 @@ public class FileCache {
|
||||
writer.write(String.valueOf(flying) + API.newline);
|
||||
writer.close();
|
||||
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache"
|
||||
+ File.separator + path + File.separator + "inventory");
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory");
|
||||
|
||||
file.mkdir();
|
||||
ItemStack[] inv = playerData.getInventory();
|
||||
for (int i = 0; i < inv.length; i++) {
|
||||
ItemStack item = inv[i];
|
||||
file = new File(plugin.getDataFolder() + File.separator
|
||||
+ "cache" + File.separator + path + File.separator
|
||||
+ "inventory" + File.separator + i + ".cache");
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory" + File.separator + i + ".cache");
|
||||
writer = new FileWriter(file);
|
||||
writer.write(item.getType().name() + API.newline);
|
||||
writer.write(item.getDurability() + API.newline);
|
||||
@@ -78,8 +74,8 @@ public class FileCache {
|
||||
writer.flush();
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) writer.write("name="
|
||||
+ meta.getDisplayName() + API.newline);
|
||||
if (meta.hasDisplayName())
|
||||
writer.write("name=" + meta.getDisplayName() + API.newline);
|
||||
if (meta.hasLore()) {
|
||||
String lores = "";
|
||||
for (String lore : meta.getLore())
|
||||
@@ -88,40 +84,33 @@ public class FileCache {
|
||||
}
|
||||
if (meta.hasEnchants()) {
|
||||
for (Enchantment ench : meta.getEnchants().keySet()) {
|
||||
writer.write("metaenchant=" + ench.getName() + ":"
|
||||
+ meta.getEnchants().get(ench)
|
||||
+ API.newline);
|
||||
writer.write("metaenchant=" + ench.getName() + ":" + meta.getEnchants().get(ench) + API.newline);
|
||||
}
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
for (Enchantment ench : item.getEnchantments().keySet()) {
|
||||
writer.write("enchant=" + ench.getName() + ":"
|
||||
+ item.getEnchantments().get(ench) + API.newline);
|
||||
writer.write("enchant=" + ench.getName() + ":" + item.getEnchantments().get(ench) + API.newline);
|
||||
}
|
||||
Attributes attributes = new Attributes(item);
|
||||
if (attributes != null)
|
||||
while (attributes.values().iterator().hasNext()) {
|
||||
Attribute a = attributes.values().iterator().next();
|
||||
if (a != 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());
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache"
|
||||
+ File.separator + path + File.separator + "armours");
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "armours");
|
||||
|
||||
file.mkdir();
|
||||
|
||||
ItemStack[] armors = playerData.getArmour();
|
||||
for (int i = 0; i < armors.length; i++) {
|
||||
ItemStack item = armors[i];
|
||||
file = new File(plugin.getDataFolder() + File.separator
|
||||
+ "cache" + File.separator + path + File.separator
|
||||
+ "armours" + File.separator + i + ".cache");
|
||||
file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "armours" + File.separator + i + ".cache");
|
||||
writer = new FileWriter(file);
|
||||
if (item != null) {
|
||||
writer.write(item.getType().name() + API.newline);
|
||||
@@ -130,8 +119,8 @@ public class FileCache {
|
||||
writer.flush();
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) writer.write("name="
|
||||
+ meta.getDisplayName() + API.newline);
|
||||
if (meta.hasDisplayName())
|
||||
writer.write("name=" + meta.getDisplayName() + API.newline);
|
||||
if (meta.hasLore()) {
|
||||
String lores = "";
|
||||
for (String lore : meta.getLore())
|
||||
@@ -141,17 +130,14 @@ public class FileCache {
|
||||
writer.flush();
|
||||
}
|
||||
for (Enchantment ench : item.getEnchantments().keySet()) {
|
||||
writer.write("enchant=" + ench.getName() + ":"
|
||||
+ item.getEnchantments().get(ench)
|
||||
+ API.newline);
|
||||
writer.write("enchant=" + ench.getName() + ":" + item.getEnchantments().get(ench) + API.newline);
|
||||
}
|
||||
Attributes attributes = new Attributes(item);
|
||||
if (attributes != null)
|
||||
while (attributes.values().iterator().hasNext()) {
|
||||
Attribute a = attributes.values().iterator().next();
|
||||
if (a != 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());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -197,7 +183,8 @@ public class FileCache {
|
||||
String line = reader.nextLine();
|
||||
|
||||
if (!line.contains(":")) {
|
||||
// the fist line represent the player group, operator status
|
||||
// the fist line represent the player group, operator
|
||||
// status
|
||||
// and flying status
|
||||
final String[] playerInfo = line.split(";");
|
||||
group = playerInfo[0];
|
||||
@@ -206,7 +193,8 @@ public class FileCache {
|
||||
op = true;
|
||||
} else op = false;
|
||||
if (playerInfo.length > 2) {
|
||||
if (Integer.parseInt(playerInfo[2]) == 1) flying = true;
|
||||
if (Integer.parseInt(playerInfo[2]) == 1)
|
||||
flying = true;
|
||||
else flying = false;
|
||||
}
|
||||
|
||||
@@ -227,22 +215,19 @@ public class FileCache {
|
||||
line = line.split(";")[0];
|
||||
}
|
||||
final String[] in = line.split(":");
|
||||
// can enchant item? size ofstring in file - 4 all / 2 = number
|
||||
// can enchant item? size ofstring in file - 4 all / 2 =
|
||||
// number
|
||||
// of enchant
|
||||
if (in[0].equals("i")) {
|
||||
stacki[i] = new ItemStack(Material.getMaterial(in[1]),
|
||||
Integer.parseInt(in[2]), Short.parseShort((in[3])));
|
||||
stacki[i] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
|
||||
if (in.length > 4 && !in[4].isEmpty()) {
|
||||
for (int k = 4; k < in.length - 1; k++) {
|
||||
stacki[i].addUnsafeEnchantment(
|
||||
Enchantment.getByName(in[k]),
|
||||
Integer.parseInt(in[k + 1]));
|
||||
stacki[i].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
|
||||
k++;
|
||||
}
|
||||
}
|
||||
try {
|
||||
ItemMeta meta = plugin.getServer().getItemFactory()
|
||||
.getItemMeta(stacki[i].getType());
|
||||
ItemMeta meta = plugin.getServer().getItemFactory().getItemMeta(stacki[i].getType());
|
||||
if (!name.isEmpty()) {
|
||||
meta.setDisplayName(name);
|
||||
}
|
||||
@@ -253,25 +238,23 @@ public class FileCache {
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
}
|
||||
if (meta != null) stacki[i].setItemMeta(meta);
|
||||
if (meta != null)
|
||||
stacki[i].setItemMeta(meta);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
stacka[a] = new ItemStack(Material.getMaterial(in[1]),
|
||||
Integer.parseInt(in[2]), Short.parseShort((in[3])));
|
||||
stacka[a] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
|
||||
if (in.length > 4 && !in[4].isEmpty()) {
|
||||
for (int k = 4; k < in.length - 1; k++) {
|
||||
stacka[a].addUnsafeEnchantment(
|
||||
Enchantment.getByName(in[k]),
|
||||
Integer.parseInt(in[k + 1]));
|
||||
stacka[a].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
|
||||
k++;
|
||||
}
|
||||
}
|
||||
try {
|
||||
ItemMeta meta = plugin.getServer().getItemFactory()
|
||||
.getItemMeta(stacka[a].getType());
|
||||
if (!name.isEmpty()) meta.setDisplayName(name);
|
||||
ItemMeta meta = plugin.getServer().getItemFactory().getItemMeta(stacka[a].getType());
|
||||
if (!name.isEmpty())
|
||||
meta.setDisplayName(name);
|
||||
if (!lores.isEmpty()) {
|
||||
List<String> loreList = new ArrayList<String>();
|
||||
for (String s : lores.split("%newline%")) {
|
||||
@@ -279,7 +262,8 @@ public class FileCache {
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
}
|
||||
if (meta != null) stacki[i].setItemMeta(meta);
|
||||
if (meta != null)
|
||||
stacki[i].setItemMeta(meta);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
a++;
|
||||
@@ -325,9 +309,8 @@ public class FileCache {
|
||||
}
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
for (int i = 0 ; i < inv.length; i++) {
|
||||
reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path
|
||||
+ File.separator + "inventory" + File.separator + i + ".cache"));
|
||||
for (int i = 0; i < inv.length; i++) {
|
||||
reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory" + File.separator + i + ".cache"));
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
ItemMeta meta = null;
|
||||
Attributes attributes = new Attributes(item);
|
||||
@@ -350,7 +333,8 @@ public class FileCache {
|
||||
case 4:
|
||||
meta = Bukkit.getItemFactory().getItemMeta(item.getType());
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (line.startsWith("name=")) {
|
||||
line = line.substring(5);
|
||||
@@ -375,7 +359,8 @@ public class FileCache {
|
||||
try {
|
||||
line = line.substring(10);
|
||||
String[] args = line.split(";");
|
||||
if (args.length != 5) continue;
|
||||
if (args.length != 5)
|
||||
continue;
|
||||
String name = args[0];
|
||||
AttributeType type = AttributeType.fromId(args[1]);
|
||||
double amount = Double.parseDouble(args[2]);
|
||||
@@ -383,7 +368,8 @@ public class FileCache {
|
||||
UUID uuid = UUID.fromString(args[4]);
|
||||
Attribute attribute = new Attribute(new Builder(amount, operation, type, name, uuid));
|
||||
attributes.add(attribute);
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@@ -391,9 +377,8 @@ public class FileCache {
|
||||
reader.close();
|
||||
inv[i] = attributes.getStack();
|
||||
}
|
||||
for (int i = 0 ; i < armours.length; i++) {
|
||||
reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path
|
||||
+ File.separator + "armours" + File.separator + i + ".cache"));
|
||||
for (int i = 0; i < armours.length; i++) {
|
||||
reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "armours" + File.separator + i + ".cache"));
|
||||
ItemStack item = new ItemStack(Material.AIR);
|
||||
ItemMeta meta = null;
|
||||
Attributes attributes = new Attributes(item);
|
||||
@@ -416,7 +401,8 @@ public class FileCache {
|
||||
case 4:
|
||||
meta = Bukkit.getItemFactory().getItemMeta(item.getType());
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (line.startsWith("name=")) {
|
||||
line = line.substring(5);
|
||||
@@ -441,7 +427,8 @@ public class FileCache {
|
||||
try {
|
||||
line = line.substring(10);
|
||||
String[] args = line.split(";");
|
||||
if (args.length != 5) continue;
|
||||
if (args.length != 5)
|
||||
continue;
|
||||
String name = args[0];
|
||||
AttributeType type = AttributeType.fromId(args[1]);
|
||||
double amount = Double.parseDouble(args[2]);
|
||||
@@ -449,7 +436,8 @@ public class FileCache {
|
||||
UUID uuid = UUID.fromString(args[4]);
|
||||
Attribute attribute = new Attribute(new Builder(amount, operation, type, name, uuid));
|
||||
attributes.add(attribute);
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@@ -478,18 +466,17 @@ public class FileCache {
|
||||
} catch (Error e) {
|
||||
path = player.getName();
|
||||
}
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "cache"
|
||||
+ File.separator + path);
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path);
|
||||
if (!file.exists()) {
|
||||
file = new File("cache/" + player.getName().toLowerCase()
|
||||
+ ".cache");
|
||||
file = new File("cache/" + player.getName().toLowerCase() + ".cache");
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles())
|
||||
if (f.isDirectory()) for (File a : f.listFiles())
|
||||
a.delete();
|
||||
if (f.isDirectory())
|
||||
for (File a : f.listFiles())
|
||||
a.delete();
|
||||
else f.delete();
|
||||
} else file.delete();
|
||||
}
|
||||
@@ -504,11 +491,9 @@ public class FileCache {
|
||||
} catch (Error e) {
|
||||
path = player.getName();
|
||||
}
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "cache"
|
||||
+ File.separator + path);
|
||||
File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path);
|
||||
if (!file.exists()) {
|
||||
file = new File("cache/" + player.getName().toLowerCase()
|
||||
+ ".cache");
|
||||
file = new File("cache/" + player.getName().toLowerCase() + ".cache");
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
|
||||
+11
-18
@@ -39,11 +39,9 @@ public class LimboCache {
|
||||
boolean flying;
|
||||
|
||||
if (playerData.doesCacheExist(player)) {
|
||||
StoreInventoryEvent event = new StoreInventoryEvent(player,
|
||||
playerData);
|
||||
StoreInventoryEvent event = new StoreInventoryEvent(player, playerData);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled() && event.getInventory() != null
|
||||
&& event.getArmor() != null) {
|
||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
||||
inv = event.getInventory();
|
||||
arm = event.getArmor();
|
||||
} else {
|
||||
@@ -56,34 +54,31 @@ public class LimboCache {
|
||||
} else {
|
||||
StoreInventoryEvent event = new StoreInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled() && event.getInventory() != null
|
||||
&& event.getArmor() != null) {
|
||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
||||
inv = event.getInventory();
|
||||
arm = event.getArmor();
|
||||
} else {
|
||||
inv = null;
|
||||
arm = null;
|
||||
}
|
||||
if (player.isOp()) operator = true;
|
||||
if (player.isOp())
|
||||
operator = true;
|
||||
else operator = false;
|
||||
if (player.isFlying()) flying = true;
|
||||
if (player.isFlying())
|
||||
flying = true;
|
||||
else flying = false;
|
||||
if (plugin.permission != null) {
|
||||
try {
|
||||
playerGroup = plugin.permission.getPrimaryGroup(player);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
ConsoleLogger
|
||||
.showError("Your permission system ("
|
||||
+ plugin.permission.getName()
|
||||
+ ") do not support Group system with that config... unhook!");
|
||||
ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!");
|
||||
plugin.permission = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.isForceSurvivalModeEnabled) {
|
||||
if (Settings.isResetInventoryIfCreative
|
||||
&& player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (Settings.isResetInventoryIfCreative && player.getGameMode() == GameMode.CREATIVE) {
|
||||
ResetInventoryEvent event = new ResetInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
@@ -96,13 +91,11 @@ public class LimboCache {
|
||||
if (player.isDead()) {
|
||||
loc = plugin.getSpawnLocation(player);
|
||||
}
|
||||
cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc,
|
||||
inv, arm, gameMode, operator, playerGroup, flying));
|
||||
cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying));
|
||||
}
|
||||
|
||||
public void addLimboPlayer(Player player, String group) {
|
||||
cache.put(player.getName().toLowerCase(), new LimboPlayer(player
|
||||
.getName().toLowerCase(), group));
|
||||
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
|
||||
}
|
||||
|
||||
public void deleteLimboPlayer(String name) {
|
||||
|
||||
Reference in New Issue
Block a user