From 4bacdb327a79bfa0c497b60d3487db3bcaca1ddb Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 00:30:06 +0100 Subject: [PATCH 01/14] Fix NPE when reading old player files --- .../earth2me/essentials/EssentialsConf.java | 24 +++++++++++-------- .../src/com/earth2me/essentials/UserMap.java | 7 ++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index b07c9710f..8b8b79279 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -232,21 +232,25 @@ public class EssentialsConf extends Configuration Material.valueOf(getString(path + ".type", "AIR")), getInt(path + ".amount", 1), (short)getInt(path + ".damage", 0)); - List enchants = getKeys(path + ".enchant"); - for (String enchant : enchants) + final List enchants = getKeys(path + ".enchant"); + if (enchants != null) { - Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH)); - if (enchantment == null) { - continue; + for (String enchant : enchants) + { + final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH)); + if (enchantment == null) + { + continue; + } + final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel()); + stack.addUnsafeEnchantment(enchantment, level); } - int level = getInt(path+ ".enchant."+enchant, enchantment.getStartLevel()); - stack.addUnsafeEnchantment(enchantment, level); } return stack; /* - * , - * (byte)getInt(path + ".data", 0) - */ + * , + * (byte)getInt(path + ".data", 0) + */ } public void setProperty(final String path, final ItemStack stack) diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index c30d97214..8ac2c4a12 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -4,11 +4,14 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ConcurrentHashMultiset; +import com.google.common.util.concurrent.UncheckedExecutionException; import java.io.File; import java.util.Collections; import java.util.Locale; import java.util.Set; import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import java.util.logging.Logger; import org.bukkit.entity.Player; @@ -67,6 +70,10 @@ public class UserMap extends CacheLoader implements IConf { throw new NullPointerException(); } + catch (UncheckedExecutionException ex) + { + throw new NullPointerException(); + } } @Override From 525fefc484b83feecd8cc024eca4ba8e3d906c64 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 00:36:36 +0100 Subject: [PATCH 02/14] UserMap.getUser() will return null on failure. --- .../com/earth2me/essentials/Essentials.java | 32 ++++++------------- .../src/com/earth2me/essentials/UserMap.java | 6 ++-- .../commands/Commandbalancetop.java | 10 +++--- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index ca4c6ad6a..15419b014 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -345,7 +345,8 @@ public class Essentials extends JavaPlugin implements IEssentials { sender.sendMessage(command.getDescription()); sender.sendMessage(command.getUsage().replaceAll("", commandLabel)); - if (!ex.getMessage().isEmpty()) { + if (!ex.getMessage().isEmpty()) + { sender.sendMessage(ex.getMessage()); } return true; @@ -420,14 +421,7 @@ public class Essentials extends JavaPlugin implements IEssentials } if (base instanceof String) { - try - { - return userMap.getUser((String)base); - } - catch (NullPointerException ex) - { - return null; - } + return userMap.getUser((String)base); } return null; } @@ -443,27 +437,19 @@ public class Essentials extends JavaPlugin implements IEssentials { return (User)base; } - try + User user = userMap.getUser(base.getName()).update(base); + + if (user == null) { - return userMap.getUser(base.getName()).update(base); - } - catch (NullPointerException ex) - { - return new User(base, this); + user = new User(base, this); } + return user; } @Override public User getOfflineUser(final String name) { - try - { - return userMap.getUser(name); - } - catch (NullPointerException ex) - { - return null; - } + return userMap.getUser(name); } @Override diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index 8ac2c4a12..708494296 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -60,7 +60,7 @@ public class UserMap extends CacheLoader implements IConf return keys.contains(name.toLowerCase(Locale.ENGLISH)); } - public User getUser(final String name) throws NullPointerException + public User getUser(final String name) { try { @@ -68,11 +68,11 @@ public class UserMap extends CacheLoader implements IConf } catch (ExecutionException ex) { - throw new NullPointerException(); + return null; } catch (UncheckedExecutionException ex) { - throw new NullPointerException(); + return null; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 7a19b6f41..2212f4664 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.User; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Util; import java.util.*; @@ -15,7 +16,6 @@ public class Commandbalancetop extends EssentialsCommand { super("balancetop"); } - private static final int CACHETIME = 5 * 60 * 1000; public static final int MINUSERS = 50; private static List cache = new ArrayList(); @@ -107,12 +107,10 @@ public class Commandbalancetop extends EssentialsCommand final Map balances = new HashMap(); for (String u : ess.getUserMap().getAllUniqueUsers()) { - try - { - balances.put(u, ess.getUserMap().getUser(u).getMoney()); - } - catch (NullPointerException ex) + final User user = ess.getUserMap().getUser(u); + if (user != null) { + balances.put(u, user.getMoney()); } } From 1838dbc931babfa474b3114ae425009bb4c2a494 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 29 Nov 2011 02:32:09 +0000 Subject: [PATCH 03/14] globalgroups prefix 'g:' is now not case sensitive. --- .../src/org/anjocaido/groupmanager/GlobalGroups.java | 8 ++++---- .../groupmanager/dataholder/WorldDataHolder.java | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 861c5e3d4..d7971d424 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -294,7 +294,7 @@ public class GlobalGroups { */ public boolean hasPermission(String groupName, String permissionNode) { - if (!hasGroup(groupName.toLowerCase())) + if (!hasGroup(groupName)) return false; return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode); @@ -315,7 +315,7 @@ public class GlobalGroups { result.askedPermission = permissionNode; result.resultType = PermissionCheckResult.Type.NOTFOUND; - if (!hasGroup(groupName.toLowerCase())) + if (!hasGroup(groupName)) return result; Group tempGroup = groups.get(groupName.toLowerCase()); @@ -337,7 +337,7 @@ public class GlobalGroups { * @return List of all group names */ public List getGroupsPermissions(String groupName) { - if (!hasGroup(groupName.toLowerCase())) + if (!hasGroup(groupName)) return null; return groups.get(groupName.toLowerCase()).getPermissionList(); @@ -374,7 +374,7 @@ public class GlobalGroups { * @return Group object */ public Group getGroup(String groupName) { - if (!hasGroup(groupName.toLowerCase())) + if (!hasGroup(groupName)) return null; return groups.get(groupName.toLowerCase()); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 59c5949f4..2b6a80da6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -195,7 +195,7 @@ public class WorldDataHolder { * @return a group if it is found. null if not found. */ public Group getGroup(String groupName) { - if (groupName.startsWith("g:")) + if (groupName.toLowerCase().startsWith("g:")) return GroupManager.getGlobalGroups().getGroup(groupName); else return groups.get(groupName.toLowerCase()); @@ -208,7 +208,7 @@ public class WorldDataHolder { * @return true if exists. false if not. */ public boolean groupExists(String groupName) { - if (groupName.startsWith("g:")) + if (groupName.toLowerCase().startsWith("g:")) return GroupManager.getGlobalGroups().hasGroup(groupName); else return groups.containsKey(groupName.toLowerCase()); @@ -219,7 +219,7 @@ public class WorldDataHolder { * @param groupToAdd */ public void addGroup(Group groupToAdd) { - if (groupToAdd.getName().startsWith("g:")) { + if (groupToAdd.getName().toLowerCase().startsWith("g:")) { GroupManager.getGlobalGroups().addGroup(groupToAdd); return; } @@ -238,7 +238,7 @@ public class WorldDataHolder { * @return true if had something to remove. false the group was default or non-existant */ public boolean removeGroup(String groupName) { - if (groupName.startsWith("g:")) { + if (groupName.toLowerCase().startsWith("g:")) { return GroupManager.getGlobalGroups().removeGroup(groupName); } @@ -278,7 +278,7 @@ public class WorldDataHolder { * @return null if group already exists. or new Group */ public Group createGroup(String groupName) { - if (groupName.startsWith("g:")) { + if (groupName.toLowerCase().startsWith("g:")) { Group newGroup = new Group(groupName); return GroupManager.getGlobalGroups().newGroup(newGroup); } From a36b755248f9029cfa2f02f9514ea445f0d253f5 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 04:51:29 +0100 Subject: [PATCH 04/14] New format guidelines? --- Essentials/nbproject/project.properties | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties index 0d7673bbd..3e78aedc7 100644 --- a/Essentials/nbproject/project.properties +++ b/Essentials/nbproject/project.properties @@ -27,21 +27,14 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.align auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineTryResources=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesAfterClassHeader=0 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesBeforeClass=2 -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement=NEW_LINE auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=* auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width=4 -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indentCasesFromSwitch=false -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement=NEW_LINE -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement=NEW_LINE -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeCatchOnNewLine=true -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeElseOnNewLine=true -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeFinallyOnNewLine=true -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeWhileOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.separateImportGroups=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size=4 +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapEnumConstants=WRAP_ALWAYS build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: From 183343c388171e3f08f20dd225d0dccfc8616459 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 05:06:07 +0100 Subject: [PATCH 05/14] 1TBS? Nope, Allman This reverts commit a36b755248f9029cfa2f02f9514ea445f0d253f5. --- Essentials/nbproject/project.properties | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties index 3e78aedc7..0d7673bbd 100644 --- a/Essentials/nbproject/project.properties +++ b/Essentials/nbproject/project.properties @@ -27,14 +27,21 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.align auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineTryResources=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesAfterClassHeader=0 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesBeforeClass=2 +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement=NEW_LINE auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=* auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width=4 +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indentCasesFromSwitch=false +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement=NEW_LINE +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement=NEW_LINE +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeCatchOnNewLine=true +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeElseOnNewLine=true +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeFinallyOnNewLine=true +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeWhileOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.separateImportGroups=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size=4 -auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapEnumConstants=WRAP_ALWAYS build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: From 0c81a68c7ba128b465264ac37d33dc51fac71d62 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 29 Nov 2011 13:10:00 +0000 Subject: [PATCH 06/14] Handle a null handler (GM) --- .../essentials/perm/GroupManagerHandler.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/perm/GroupManagerHandler.java b/Essentials/src/com/earth2me/essentials/perm/GroupManagerHandler.java index 8fd375eae..8c3cdf1e2 100644 --- a/Essentials/src/com/earth2me/essentials/perm/GroupManagerHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/GroupManagerHandler.java @@ -21,6 +21,10 @@ public class GroupManagerHandler implements IPermissionsHandler public String getGroup(final Player base) { final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return null; + } return handler.getGroup(base.getName()); } @@ -28,6 +32,10 @@ public class GroupManagerHandler implements IPermissionsHandler public List getGroups(final Player base) { final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return null; + } return Arrays.asList(handler.getGroups(base.getName())); } @@ -35,6 +43,10 @@ public class GroupManagerHandler implements IPermissionsHandler public boolean canBuild(final Player base, final String group) { final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return false; + } return handler.canUserBuild(base.getName()); } @@ -42,6 +54,10 @@ public class GroupManagerHandler implements IPermissionsHandler public boolean inGroup(final Player base, final String group) { AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return false; + } return handler.inGroup(base.getName(), group); } @@ -49,6 +65,10 @@ public class GroupManagerHandler implements IPermissionsHandler public boolean hasPermission(final Player base, final String node) { AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return false; + } return handler.has(base, node); } @@ -56,6 +76,10 @@ public class GroupManagerHandler implements IPermissionsHandler public String getPrefix(final Player base) { AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return null; + } return handler.getUserPrefix(base.getName()); } @@ -63,6 +87,10 @@ public class GroupManagerHandler implements IPermissionsHandler public String getSuffix(final Player base) { AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base); + if (handler == null) + { + return null; + } return handler.getUserSuffix(base.getName()); } } From 414d6b79e97ee41c94ad789a7c4aefd8bcbe5ea8 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 29 Nov 2011 16:06:39 +0000 Subject: [PATCH 07/14] GC: Never force reclaiming RAM on user logout, it will be done automatically, when the time is right. ~ Should reduce player event lag a little bit ~ --- .../essentials/EssentialsPlayerListener.java | 27 ------------------- Essentials/src/config.yml | 5 ---- 2 files changed, 32 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 94a095df4..537a2de06 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -120,33 +120,6 @@ public class EssentialsPlayerListener extends PlayerListener } user.updateActivity(false); user.dispose(); - if (!ess.getSettings().getReclaimSetting()) - { - return; - } - final Thread thread = new Thread(new Runnable() - { - @Override - public void run() - { - try - { - Thread.sleep(1000); - Runtime rt = Runtime.getRuntime(); - double mem = rt.freeMemory(); - rt.runFinalization(); - rt.gc(); - mem = rt.freeMemory() - mem; - mem /= 1024 * 1024; - LOGGER.log(Level.INFO, _("freedMemory", mem)); - } - catch (InterruptedException ex) - { - } - } - }); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); } @Override diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index b06fdd1d4..22cac25a9 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -68,11 +68,6 @@ item-spawn-blacklist: # - essentials.give.item-[itemid] permission-based-item-spawn: false -# Whether or not to reclaim memory on player logout; this is technical, and should only be changed under special circumstances. -# This generally increases server stability unless very specific runtime configurations are used. -# HOWEVER, it is known to cause lag upon users logging OUT, so beware! -reclaim-onlogout: false - # Mob limit on spawnmob spawnmob-limit: 10 From cdbae1631dfd4e9cd71aa030260bbc43b75ad94e Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 29 Nov 2011 16:16:45 +0000 Subject: [PATCH 08/14] Settings Cleanup. --- Essentials/src/com/earth2me/essentials/I18n.java | 3 +++ Essentials/src/com/earth2me/essentials/ISettings.java | 2 -- Essentials/src/com/earth2me/essentials/Settings.java | 6 ------ .../com/earth2me/essentials/commands/Commandenchant.java | 2 ++ 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index d3ffe5f76..4e2b033e6 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -69,6 +69,9 @@ public class I18n public static String _(final String string, final Object... objects) { + if (instance == null) { + return ""; + } if (objects.length == 0) { return instance.translate(string); diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index ed76ef325..1b71f30e4 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -59,8 +59,6 @@ public interface ISettings extends IConf String getProtectString(final String configName); - boolean getReclaimSetting(); - boolean getRespawnAtHome(); List getMultipleHomes(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index aa6bb6cef..961b0b9b6 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -243,12 +243,6 @@ public class Settings implements ISettings return ChatColor.getByCode(Integer.parseInt(colorName, 16)); } - @Override - public boolean getReclaimSetting() - { - return config.getBoolean("reclaim-onlogout", false); - } - @Override public int getSpawnMobLimit() { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index 6b028a634..3ef886347 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -67,6 +67,8 @@ public class Commandenchant extends EssentialsCommand super("enchant"); } + + //TODO: Implement charge costs: final Trade charge = new Trade("enchant-" + enchantmentName, ess); @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { From 60067964befac36651a9f5f232652b1daf794c7b Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 17:39:13 +0100 Subject: [PATCH 09/14] Fix NPE in getUser() --- Essentials/src/com/earth2me/essentials/Essentials.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 15419b014..e33e70f18 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -437,11 +437,13 @@ public class Essentials extends JavaPlugin implements IEssentials { return (User)base; } - User user = userMap.getUser(base.getName()).update(base); + User user = userMap.getUser(base.getName()); if (user == null) { user = new User(base, this); + } else { + user.update(base); } return user; } From af7eae6201702950268758a2b993c4bdc4f7b45c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 29 Nov 2011 17:21:18 +0000 Subject: [PATCH 10/14] Adding some debug info to /essentials --- .../AlternativeCommandsHandler.java | 13 ++++- .../com/earth2me/essentials/Essentials.java | 3 +- .../commands/Commandessentials.java | 48 +++++++++++++++---- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java index a9291e629..a16f8031a 100644 --- a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -11,6 +11,7 @@ import org.bukkit.plugin.Plugin; public class AlternativeCommandsHandler { private final transient Map> altcommands = new HashMap>(); + private final transient Set executed = new HashSet(); private final transient IEssentials ess; public AlternativeCommandsHandler(final IEssentials ess) @@ -100,7 +101,7 @@ public class AlternativeCommandsHandler if (commands == null || commands.isEmpty()) { return null; - } + } if (commands.size() == 1) { return commands.get(0); @@ -114,4 +115,14 @@ public class AlternativeCommandsHandler // return the first alias return commands.get(0); } + + public void executed(final String label) + { + executed.add(label); + } + + public List disabledCommands() + { + return new ArrayList(executed); + } } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 15419b014..f82aec91a 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -273,7 +273,8 @@ public class Essentials extends JavaPlugin implements IEssentials final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { - LOGGER.info("Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel()); + alternativeCommandsHandler.executed(commandLabel); + LOGGER.log(Level.FINE,"Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel()); return pc.execute(sender, commandLabel, args); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index cc541299d..7701bf575 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.Util; import java.util.HashMap; import java.util.Map; import org.bukkit.Location; @@ -23,12 +24,44 @@ public class Commandessentials extends EssentialsCommand @Override public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - if (args.length > 0 && args[0].equalsIgnoreCase("debug")) - { - ess.getSettings().setDebug(!ess.getSettings().isDebug()); - sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); - return; + if (args.length == 0) { + run_disabled(server, sender, commandLabel, args); } + else if (args[0].equalsIgnoreCase("debug")) + { + run_debug(server, sender, commandLabel, args); + } + else if (args[0].equalsIgnoreCase("nya")) + { + run_nya(server, sender, commandLabel, args); + } + else { + run_reload(server, sender, commandLabel, args); + } + } + + private void run_disabled(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { + sender.sendMessage("Essentials " + ess.getDescription().getVersion()); + sender.sendMessage("/ "); + sender.sendMessage("Essentials blocked the following commands, due to command conflicts:"); + sender.sendMessage(Util.joinList(ess.getAlternativeCommandsHandler().disabledCommands())); + } + + private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { + ess.getSettings().setDebug(!ess.getSettings().isDebug()); + sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); + } + + private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { + ess.reload(); + sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion())); + } + + private void run_nya(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { final Map noteMap = new HashMap(); noteMap.put("1F#", (byte)0x0); noteMap.put("1G", (byte)0x1); @@ -54,8 +87,6 @@ public class Commandessentials extends EssentialsCommand noteMap.put("2D#", (byte)(0x9 + 0xC)); noteMap.put("2E", (byte)(0xA + 0xC)); noteMap.put("2F", (byte)(0xB + 0xC)); - if (args.length > 0 && args[0].equalsIgnoreCase("nya")) - { if (!noteBlocks.isEmpty()) { return; @@ -106,9 +137,6 @@ public class Commandessentials extends EssentialsCommand } }, 20, 2); return; - } - ess.reload(); - sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion())); } private void stopTune() From 57a0ec9912a16261a2c2cf341eabf0b11b57a0b2 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 18:40:13 +0100 Subject: [PATCH 11/14] Allow joinList to understand Collections. --- .../com/earth2me/essentials/AlternativeCommandsHandler.java | 4 ++-- Essentials/src/com/earth2me/essentials/Util.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java index a16f8031a..d15a86d7e 100644 --- a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -121,8 +121,8 @@ public class AlternativeCommandsHandler executed.add(label); } - public List disabledCommands() + public Set disabledCommands() { - return new ArrayList(executed); + return executed; } } diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 8fc7da3af..5ee3e3123 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -376,9 +376,9 @@ public class Util buf.append(seperator); } - if (each instanceof List) + if (each instanceof Collection) { - buf.append(joinList(seperator, ((List)each).toArray())); + buf.append(joinList(seperator, ((Collection)each).toArray())); } else { From 0b2a3fcf7f1a38848d941ed125470c0c547d5fa1 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 18:48:52 +0100 Subject: [PATCH 12/14] Output the redirected plugin too. --- .../AlternativeCommandsHandler.java | 34 ++++++++++--------- .../com/earth2me/essentials/Essentials.java | 2 +- .../commands/Commandessentials.java | 10 +++++- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java index d15a86d7e..366c86cc6 100644 --- a/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -1,7 +1,6 @@ package com.earth2me.essentials; import java.util.*; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommandYamlParser; @@ -11,20 +10,21 @@ import org.bukkit.plugin.Plugin; public class AlternativeCommandsHandler { private final transient Map> altcommands = new HashMap>(); - private final transient Set executed = new HashSet(); + private final transient Map executed = new HashMap(); private final transient IEssentials ess; - + public AlternativeCommandsHandler(final IEssentials ess) { this.ess = ess; for (Plugin plugin : ess.getServer().getPluginManager().getPlugins()) { - if (plugin.isEnabled()) { + if (plugin.isEnabled()) + { addPlugin(plugin); } } } - + public final void addPlugin(final Plugin plugin) { if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) @@ -101,28 +101,30 @@ public class AlternativeCommandsHandler if (commands == null || commands.isEmpty()) { return null; - } + } if (commands.size() == 1) { return commands.get(0); } // return the first command that is not an alias - for (PluginCommand command : commands) { - if (command.getName().equalsIgnoreCase(label)) { + for (PluginCommand command : commands) + { + if (command.getName().equalsIgnoreCase(label)) + { return command; } } // return the first alias return commands.get(0); } - - public void executed(final String label) + + public void executed(final String label, final String otherlabel) { - executed.add(label); - } - - public Set disabledCommands() + executed.put(label, otherlabel); + } + + public Map disabledCommands() { - return executed; - } + return executed; + } } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index a83db16e3..19073b1aa 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -273,7 +273,7 @@ public class Essentials extends JavaPlugin implements IEssentials final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { - alternativeCommandsHandler.executed(commandLabel); + alternativeCommandsHandler.executed(commandLabel, pc.getLabel()); LOGGER.log(Level.FINE,"Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel()); return pc.execute(sender, commandLabel, args); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 7701bf575..507298a0b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -45,7 +45,15 @@ public class Commandessentials extends EssentialsCommand sender.sendMessage("Essentials " + ess.getDescription().getVersion()); sender.sendMessage("/ "); sender.sendMessage("Essentials blocked the following commands, due to command conflicts:"); - sender.sendMessage(Util.joinList(ess.getAlternativeCommandsHandler().disabledCommands())); + final StringBuilder disabledCommands = new StringBuilder(); + for (Map.Entry entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet()) + { + if (disabledCommands.length() > 0) { + disabledCommands.append(", "); + } + disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue()); + } + sender.sendMessage(disabledCommands.toString()); } private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception From aed160b5fc88c44d781fa46454d7c16f8174984e Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 19:24:54 +0100 Subject: [PATCH 13/14] Using this code until Bukkit fixes spawnCreature() --- Essentials/src/com/earth2me/essentials/Mob.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Mob.java b/Essentials/src/com/earth2me/essentials/Mob.java index 5565cde3e..049f7b8a3 100644 --- a/Essentials/src/com/earth2me/essentials/Mob.java +++ b/Essentials/src/com/earth2me/essentials/Mob.java @@ -76,8 +76,7 @@ public enum Mob public LivingEntity spawn(final Player player, final Server server, final Location loc) throws MobException { - - final LivingEntity entity = player.getWorld().spawnCreature(loc, this.bukkitType); + final LivingEntity entity = player.getWorld().spawn(loc, (Class)this.bukkitType.getEntityClass()); if (entity == null) { logger.log(Level.WARNING, _("unableToSpawnMob")); From 5f0936cf44185ea4116dd3c396b0909e008d9c6b Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 29 Nov 2011 21:34:31 +0100 Subject: [PATCH 14/14] mirror world_the_end in default config.yml --- EssentialsGroupManager/src/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/EssentialsGroupManager/src/config.yml b/EssentialsGroupManager/src/config.yml index d9f469477..2fe5e509c 100644 --- a/EssentialsGroupManager/src/config.yml +++ b/EssentialsGroupManager/src/config.yml @@ -31,6 +31,7 @@ settings: # user/groups permissions as the parent. world: - world_nether + - world_the_end - world2 - world3 # world4: