Fix Item unstacking, disable customAttributes by default

This commit is contained in:
Xephi 2015-05-26 13:11:10 +02:00
parent 9ba90bfb97
commit 514d5bfe6e
3 changed files with 87 additions and 69 deletions

View File

@ -23,6 +23,7 @@ import com.comphenix.attribute.Attributes.Operation;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.api.API; import fr.xephi.authme.api.API;
import fr.xephi.authme.settings.Settings;
public class FileCache { public class FileCache {
@ -104,19 +105,21 @@ public class FileCache {
for (Enchantment ench : item.getEnchantments().keySet()) { 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);
} }
if (Settings.customAttributes) {
try { try {
Attributes attributes = new Attributes(item); Attributes attributes = new Attributes(item);
if (attributes != null) 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 if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != 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 e) {
} catch (Error e) {} } catch (Error e) {
}
}
} else { } else {
writer.write("AIR"); writer.write("AIR");
} }
@ -159,19 +162,20 @@ public class FileCache {
for (Enchantment ench : item.getEnchantments().keySet()) { 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);
} }
if (Settings.customAttributes) {
try { try {
Attributes attributes = new Attributes(item); Attributes attributes = new Attributes(item);
if (attributes != null) 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 if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null && a.getAttributeType().getMinecraftId() != 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) {
}
}
} else { } else {
writer.write("AIR" + API.newline); writer.write("AIR" + API.newline);
} }
@ -216,7 +220,8 @@ public class FileCache {
String line = reader.nextLine(); String line = reader.nextLine();
if (!line.contains(":")) { if (!line.contains(":")) {
// the fist line represent the player group, operator // the fist line represent the player group,
// operator
// status // status
// and flying status // and flying status
final String[] playerInfo = line.split(";"); final String[] playerInfo = line.split(";");
@ -388,6 +393,8 @@ public class FileCache {
line = line.substring(8); line = line.substring(8);
item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1])); item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1]));
} }
if (Settings.customAttributes)
{
if (line.startsWith("attribute=")) { if (line.startsWith("attribute=")) {
if (attributes == null) if (attributes == null)
attributes = new Attributes(item); attributes = new Attributes(item);
@ -406,14 +413,14 @@ public class FileCache {
} catch (Exception e) { } catch (Exception e) {
} }
} }
}
count++; count++;
} }
if (reader != null) if (reader != null)
reader.close(); reader.close();
if (attributes != null) if (attributes != null)
inv[i] = attributes.getStack(); inv[i] = attributes.getStack();
else else inv[i] = item;
inv[i] = item;
} }
for (int i = 0; i < armours.length; i++) { 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")); reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "armours" + File.separator + i + ".cache"));
@ -461,6 +468,8 @@ public class FileCache {
line = line.substring(8); line = line.substring(8);
item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1])); item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1]));
} }
if (Settings.customAttributes)
{
if (line.startsWith("attribute=")) { if (line.startsWith("attribute=")) {
if (attributes == null) if (attributes == null)
attributes = new Attributes(item); attributes = new Attributes(item);
@ -479,14 +488,14 @@ public class FileCache {
} catch (Exception e) { } catch (Exception e) {
} }
} }
}
count++; count++;
} }
if (reader != null) if (reader != null)
reader.close(); reader.close();
if (attributes != null) if (attributes != null)
armours[i] = attributes.getStack(); armours[i] = attributes.getStack();
else else armours[i] = item;
armours[i] = item;
} }
} catch (final Exception e) { } catch (final Exception e) {

View File

@ -70,7 +70,7 @@ public final class Settings extends YamlConfiguration {
purgePermissions, enableProtection, enableAntiBot, recallEmail, purgePermissions, enableProtection, enableAntiBot, recallEmail,
useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick,
forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport,
applyBlindEffect; applyBlindEffect, customAttributes;
public static String getNickRegex, getUnloggedinGroup, getMySQLHost, public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
@ -270,6 +270,7 @@ public final class Settings extends YamlConfiguration {
emailWhitelist = configFile.getStringList("Email.emailWhitelisted"); emailWhitelist = configFile.getStringList("Email.emailWhitelisted");
forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>()); forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>());
forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>()); forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
customAttributes = configFile.getBoolean("Hooks.customAttributes");
// Load the welcome message // Load the welcome message
getWelcomeMessage(plugin); getWelcomeMessage(plugin);
@ -437,6 +438,7 @@ public final class Settings extends YamlConfiguration {
emailWhitelist = configFile.getStringList("Email.emailWhitelisted"); emailWhitelist = configFile.getStringList("Email.emailWhitelisted");
forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>()); forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>());
forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>()); forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
customAttributes = configFile.getBoolean("Hooks.customAttributes");
// Reload the welcome message // Reload the welcome message
getWelcomeMessage(AuthMe.getInstance()); getWelcomeMessage(AuthMe.getInstance());
@ -579,6 +581,11 @@ public final class Settings extends YamlConfiguration {
set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>()); set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("Hooks.customAttributes"))
{
set("Hooks.customAttributes", false);
changes = true;
}
if (changes) { if (changes) {
plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me"); plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me");

View File

@ -381,6 +381,8 @@ Hooks:
disableSocialSpy: true disableSocialSpy: true
# Do we need to force /motd Essentials command on join ? # Do we need to force /motd Essentials command on join ?
useEssentialsMotd: false useEssentialsMotd: false
# Do we need to cache custom Attributes ?
customAttributes: false
Performances: Performances:
# HIGHLY recommended to use this! This will increase database performance # HIGHLY recommended to use this! This will increase database performance
# Default is true, change it to false if you experience issues # Default is true, change it to false if you experience issues