From 2202448cee5d3cb2414194b8aefa8467bea58ecf Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 14 Dec 2011 03:41:24 +0000 Subject: Read current exp, instead of stored exp. This means that exp used in enchanting is subtracted from total exp. --- Essentials/src/com/earth2me/essentials/Trade.java | 6 +++--- .../earth2me/essentials/craftbukkit/SetExpFix.java | 23 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java index ca9db12a7..6cd9ce93a 100644 --- a/Essentials/src/com/earth2me/essentials/Trade.java +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -81,7 +81,7 @@ public class Trade } if (exp != null && exp > 0 - && user.getTotalExperience() < exp) { + && SetExpFix.getTotalExperience(user) < exp) { throw new ChargeException(_("notEnoughExperience")); } } @@ -116,7 +116,7 @@ public class Trade } if (getExperience() != null) { - SetExpFix.setTotalExperience(user, user.getTotalExperience() + getExperience()); + SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience()); } return success; } @@ -155,7 +155,7 @@ public class Trade } if (getExperience() != null) { - final int experience = user.getTotalExperience(); + final int experience = SetExpFix.getTotalExperience(user); if (experience < getExperience() && getExperience() > 0) { throw new ChargeException(_("notEnoughExperience")); diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java index caf6e71c7..5b1161851 100644 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java @@ -17,7 +17,7 @@ public class SetExpFix int amount = exp; while (amount > 0) { - final int expToLevel = getExpTolevel(player); + final int expToLevel = getExpToLevel(player); amount -= expToLevel; if (amount >= 0) { @@ -34,8 +34,25 @@ public class SetExpFix } } - private static int getExpTolevel(final Player player) + private static int getExpToLevel(final Player player) + { + return getExpToLevel(player.getLevel()); + } + + private static int getExpToLevel(final int level) + { + return 7 + (level * 7 >> 1); + } + + public static int getTotalExperience(final Player player) { - return 7 + (player.getLevel() * 7 >> 1); + int exp = (int) (getExpToLevel(player) * player.getExp()); + int currentLevel = player.getLevel(); + + while (currentLevel > 0) { + currentLevel--; + exp += getExpToLevel(currentLevel); + } + return exp; } } -- cgit v1.2.3 From 8d29a2c57835565d95b03b2c0e1c9671b6ee17c2 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Wed, 14 Dec 2011 04:26:02 +0000 Subject: deleting the contents of GlobalGroups.yml will no longer thrown a NullPointerException. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GlobalGroups.java | 86 +++++++++++----------- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index b3a95d830..47a0f6b79 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -84,4 +84,5 @@ v 1.7: - GM now supports offline players without having to mantogglevalidate - Offline player checks now support partial name matches. - Added custom events so plugins can now be notified of changes within GroupManager. - - GM now registers with Bukkits ServicesManager. \ No newline at end of file + - GM now registers with Bukkits ServicesManager. + - deleting the contents of GlobalGroups.yml will no longer thrown a NullPointerException. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 33b7b46f1..f1bf10985 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -107,49 +107,53 @@ public class GlobalGroups { throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex); } - // Read all global groups - Map allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); - - // Load each groups permissions list. - if (allGroups != null) { - // Clear out old groups - resetGlobalGroups(); - for (String groupName : allGroups.keySet()) { - Group newGroup = new Group(groupName.toLowerCase()); - Object element; - - // Permission nodes - element = GGroups.get("groups." + groupName + ".permissions"); - - if (element != null) - if (element instanceof List) { - for (String node : (List) element) { - newGroup.addPermission(node); - } - } else if (element instanceof String) { - newGroup.addPermission((String) element); - } else - throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); - - // Info nodes - element = GGroups.get("groups." + groupName + ".info"); - - if (element != null) - if (element instanceof MemorySection) { - Map vars = new HashMap(); - for (String key : ((MemorySection) element).getKeys(false)) { - vars.put(key, ((MemorySection) element).get(key)); - } - newGroup.setVariables(vars); - } else - throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); - - // Push a new group - addGroup(newGroup); + // Clear out old groups + resetGlobalGroups(); + + if (!GGroups.getKeys(false).isEmpty()) { + // Read all global groups + Map allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); + + // Load each groups permissions list. + if (allGroups != null) { + for (String groupName : allGroups.keySet()) { + Group newGroup = new Group(groupName.toLowerCase()); + Object element; + + // Permission nodes + element = GGroups.get("groups." + groupName + ".permissions"); + + if (element != null) + if (element instanceof List) { + for (String node : (List) element) { + newGroup.addPermission(node); + } + } else if (element instanceof String) { + newGroup.addPermission((String) element); + } else + throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); + + // Info nodes + element = GGroups.get("groups." + groupName + ".info"); + + if (element != null) + if (element instanceof MemorySection) { + Map vars = new HashMap(); + for (String key : ((MemorySection) element).getKeys(false)) { + vars.put(key, ((MemorySection) element).get(key)); + } + newGroup.setVariables(vars); + } else + throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); + + // Push a new group + addGroup(newGroup); + } } + + removeGroupsChangedFlag(); } - - removeGroupsChangedFlag(); + setTimeStampGroups(GlobalGroupsFile.lastModified()); GroupManager.setLoaded(true); //GlobalGroupsFile = null; -- cgit v1.2.3