diff options
20 files changed, 191 insertions, 56 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index e7ce92a55..ed76ef325 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -31,7 +31,7 @@ public interface ISettings extends IConf String getCurrencySymbol(); - int getDefaultStackSize(); + int getOversizedStackSize(); double getHealCooldown(); diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 0b8121f89..19edce8d0 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -81,10 +81,10 @@ public final class InventoryWorkaround public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items) { - return addItem(cinventory, forceDurability, false, null, items); + return addItem(cinventory, forceDurability, 0, items); } - public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final IEssentials ess, final ItemStack... items) + public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final int oversizedStacks, final ItemStack... items) { final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>(); @@ -146,11 +146,12 @@ public final class InventoryWorkaround } else { + final int maxAmount = oversizedStacks > 0 ? oversizedStacks : item.getType().getMaxStackSize(); // More than a single stack! - if (item.getAmount() > (dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize())) + if (item.getAmount() > maxAmount) { - ItemStack stack = item.clone(); - stack.setAmount(dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize()); + final ItemStack stack = item.clone(); + stack.setAmount(maxAmount); if (cinventory instanceof FakeInventory) { cinventory.setItem(firstFree, stack); @@ -159,7 +160,7 @@ public final class InventoryWorkaround { EnchantmentFix.setItem(cinventory, firstFree, stack); } - item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); + item.setAmount(item.getAmount() - maxAmount); } else { @@ -183,7 +184,7 @@ public final class InventoryWorkaround final int amount = item.getAmount(); final int partialAmount = partialItem.getAmount(); - final int maxAmount = dontBreakStacks ? ess.getSettings().getDefaultStackSize() : partialItem.getType().getMaxStackSize(); + final int maxAmount = oversizedStacks > 0 ? oversizedStacks : partialItem.getType().getMaxStackSize(); // Check if it fully fits if (amount + partialAmount <= maxAmount) diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index cbdca198d..021e316a8 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -114,7 +114,7 @@ public class ItemDb implements IConf throw new Exception(_("unknownItemId", itemid)); } final ItemStack retval = new ItemStack(mat); - retval.setAmount(ess.getSettings().getDefaultStackSize()); + retval.setAmount(mat.getMaxStackSize()); retval.setDurability(metaData); return retval; } diff --git a/Essentials/src/com/earth2me/essentials/Mob.java b/Essentials/src/com/earth2me/essentials/Mob.java index 76e21630e..5565cde3e 100644 --- a/Essentials/src/com/earth2me/essentials/Mob.java +++ b/Essentials/src/com/earth2me/essentials/Mob.java @@ -38,7 +38,7 @@ public enum Mob BLAZE("Blaze", Enemies.ENEMY, CreatureType.BLAZE), MUSHROOMCOW("MushroomCow", Enemies.FRIENDLY, CreatureType.MUSHROOM_COW), MAGMACUBE("MagmaCube", Enemies.ENEMY, CreatureType.MAGMA_CUBE), - SNOWMAN("Snowman", Enemies.FRIENDLY, CreatureType.SNOWMAN); + SNOWMAN("Snowman", Enemies.FRIENDLY, "", CreatureType.SNOWMAN); public static final Logger logger = Logger.getLogger("Minecraft"); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 4fa67a72a..aa6bb6cef 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -82,9 +82,9 @@ public class Settings implements ISettings } @Override - public int getDefaultStackSize() + public int getOversizedStackSize() { - return config.getInt("default-stack-size", 64); + return config.getInt("oversized-stacksize", 64); } @Override @@ -189,13 +189,13 @@ public class Settings implements ISettings @Override public double getTeleportCooldown() { - return config.getDouble("teleport-cooldown", 60); + return config.getDouble("teleport-cooldown", 0); } @Override public double getHealCooldown() { - return config.getDouble("heal-cooldown", 60); + return config.getDouble("heal-cooldown", 0); } @Override @@ -246,7 +246,7 @@ public class Settings implements ISettings @Override public boolean getReclaimSetting() { - return config.getBoolean("reclaim-onlogout", true); + return config.getBoolean("reclaim-onlogout", false); } @Override diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index 3de18080a..c30d97214 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -5,12 +5,10 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ConcurrentHashMultiset; import java.io.File; -import java.util.HashSet; +import java.util.Collections; import java.util.Locale; import java.util.Set; import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -104,21 +102,9 @@ public class UserMap extends CacheLoader<String, User> implements IConf users.invalidate(name.toLowerCase(Locale.ENGLISH)); } - public Set<User> getAllUsers() + public Set<String> getAllUniqueUsers() { - final Set<User> userSet = new HashSet<User>(); - for (String name : keys) - { - try - { - userSet.add(users.get(name)); - } - catch (ExecutionException ex) - { - Bukkit.getLogger().log(Level.INFO, "Failed to load user " + name, ex); - } - } - return userSet; + return Collections.unmodifiableSet(keys.elementSet()); } public int getUniqueUsers() diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 838e27628..7a19b6f41 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import java.util.*; import java.util.Map.Entry; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -15,6 +15,12 @@ public class Commandbalancetop extends EssentialsCommand { super("balancetop"); } + + private static final int CACHETIME = 5 * 60 * 1000; + public static final int MINUSERS = 50; + private static List<String> cache = new ArrayList<String>(); + private static long cacheage = 0; + private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception @@ -24,7 +30,7 @@ public class Commandbalancetop extends EssentialsCommand { try { - if (Integer.parseInt(args[0]) < 10) + if (Integer.parseInt(args[0]) < 19) { max = Integer.parseInt(args[0]); } @@ -34,31 +40,141 @@ public class Commandbalancetop extends EssentialsCommand //catch it because they tried to enter a string not number. } } - final Map<User, Double> balances = new HashMap<User, Double>(); - for (User u : ess.getUserMap().getAllUsers()) + + if (lock.readLock().tryLock()) { - balances.put(u, u.getMoney()); + try + { + if (cacheage > System.currentTimeMillis() - CACHETIME) + { + outputCache(sender, max); + return; + } + if (ess.getUserMap().getUniqueUsers() > MINUSERS) + { + sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers())); + } + } + finally + { + lock.readLock().unlock(); + } + ess.scheduleAsyncDelayedTask(new Viewer(sender, max)); } - - final List<Map.Entry<User, Double>> sortedEntries = new ArrayList<Map.Entry<User, Double>>(balances.entrySet()); - Collections.sort(sortedEntries, new Comparator<Map.Entry<User, Double>>() + else { - @Override - public int compare(final Entry<User, Double> entry1, final Entry<User, Double> entry2) + if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - return -entry1.getValue().compareTo(entry2.getValue()); + sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers())); } - }); - int count = 0; + ess.scheduleAsyncDelayedTask(new Viewer(sender, max)); + } + + } + + private static void outputCache(final CommandSender sender, int max) + { sender.sendMessage(_("balanceTop", max)); - for (Map.Entry<User, Double> entry : sortedEntries) + for (String line : cache) { - if (count == max) + if (max == 0) { break; } - sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue(), ess)); - count++; + max--; + sender.sendMessage(line); + } + } + + + private class Calculator implements Runnable + { + private final transient Viewer viewer; + + public Calculator(final Viewer viewer) + { + this.viewer = viewer; + } + + @Override + public void run() + { + lock.writeLock().lock(); + try + { + if (cacheage < System.currentTimeMillis() - 5 * 60 * 1000) + { + final Map<String, Double> balances = new HashMap<String, Double>(); + for (String u : ess.getUserMap().getAllUniqueUsers()) + { + try + { + balances.put(u, ess.getUserMap().getUser(u).getMoney()); + } + catch (NullPointerException ex) + { + } + } + + final List<Map.Entry<String, Double>> sortedEntries = new ArrayList<Map.Entry<String, Double>>(balances.entrySet()); + Collections.sort(sortedEntries, new Comparator<Map.Entry<String, Double>>() + { + @Override + public int compare(final Entry<String, Double> entry1, final Entry<String, Double> entry2) + { + return -entry1.getValue().compareTo(entry2.getValue()); + } + }); + int count = 0; + for (Map.Entry<String, Double> entry : sortedEntries) + { + if (count == 20) + { + break; + } + cache.add(entry.getKey() + ", " + Util.formatCurrency(entry.getValue(), ess)); + count++; + } + cacheage = System.currentTimeMillis(); + } + } + finally + { + lock.writeLock().unlock(); + } + ess.scheduleAsyncDelayedTask(viewer); + } + } + + + private class Viewer implements Runnable + { + private final transient CommandSender sender; + private final transient int max; + + public Viewer(final CommandSender sender, final int max) + { + this.sender = sender; + this.max = max; + } + + @Override + public void run() + { + lock.readLock().lock(); + try + { + if (cacheage > System.currentTimeMillis() - 5 * 60 * 1000) + { + outputCache(sender, max); + return; + } + } + finally + { + lock.readLock().unlock(); + } + ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, max))); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 32b0564b7..52e3375cd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -77,7 +77,11 @@ public class Commandgive extends EssentialsCommand final User giveTo = getPlayer(server, args, 0); final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + "."); - InventoryWorkaround.addItem(giveTo.getInventory(), true, true, ess, stack); + if (giveTo.isAuthorized("essentials.oversizedstacks")) { + InventoryWorkaround.addItem(giveTo.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack); + } else { + InventoryWorkaround.addItem(giveTo.getInventory(), true, stack); + } giveTo.updateInventory(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 0d30b4e77..a749bb0a8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -72,7 +72,11 @@ public class Commanditem extends EssentialsCommand final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); user.sendMessage(_("itemSpawn", stack.getAmount(), displayName)); - InventoryWorkaround.addItem(user.getInventory(), true, true, ess, stack); + if (user.isAuthorized("essentials.oversizedstacks")) { + InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack); + } else { + InventoryWorkaround.addItem(user.getInventory(), true, stack); + } user.updateInventory(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index 1639f5360..512eeabe3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -119,12 +119,16 @@ public class Commandsell extends EssentialsCommand { continue; } + if (!s.getEnchantments().equals(is.getEnchantments())) + { + continue; + } max += s.getAmount(); } if (stack) { - amount *= 64; + amount *= is.getType().getMaxStackSize(); } if (amount < 1) { @@ -133,7 +137,7 @@ public class Commandsell extends EssentialsCommand if (requireStack) { - amount -= amount % 64; + amount -= amount % is.getType().getMaxStackSize(); } if (amount > max || amount < 1) { diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 52c87bb4b..b06fdd1d4 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -53,9 +53,6 @@ teleport-delay: 0 # The delay, in seconds, required between /heal attempts heal-cooldown: 60 -# The number of items given if the quantity parameter is left out in /item or /give. -default-stack-size: 64 - # What to prevent from /i /give # e.g item-spawn-blacklist: 46,11,10 item-spawn-blacklist: @@ -230,6 +227,11 @@ death-messages: true no-god-in-worlds: # - world_nether +# Oversized stacks are stacks that ignore the normal max stacksize. +# They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission. +# How many items should be in a oversized stack? +oversized-stacksize: 64 + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | # @@ -388,6 +390,7 @@ protect: creeper-playerdamage: false creeper-blockdamage: false enderman-pickup: false + villager-death: false # Monsters won't follow players # permission essentials.protect.entitytarget.bypass disables this entitytarget: false @@ -415,6 +418,8 @@ protect: villager: false blaze: false mushroom_cow: false + magma_cube: false + snowman: false # Maximum height the creeper should explode. -1 allows them to explode everywhere. # Set prevent.creeper-explosion to true, if you want to disable creeper explosions. diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 6df02c655..ce9423503 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -232,6 +232,7 @@ numberRequired=A number goes there, silly. onlyDayNight=/time only supports day/night. onlyPlayers=Only in-game players can use {0}. onlySunStorm=/weather only supports sun/storm. +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}. pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index b3730d1d6..f1345ab62 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -232,6 +232,7 @@ numberRequired=Der skal v\u00e6re et nummer, fjolle. onlyDayNight=/time underst\u00f8tter kun day/night. onlyPlayers=Kun in-game spillere kan bruge {0}. onlySunStorm=/weather only supports sun/storm. +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}. pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server. diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index bc3123d6c..6b2090676 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -232,6 +232,7 @@ numberRequired=Ein Zahl wird ben\u00f6tigt. onlyDayNight=/time unterst\u00fctzt nur day und night. onlyPlayers=Nur Spieler k\u00f6nnen {0} benutzen. onlySunStorm=/weather unterst\u00fctzt nur sun und storm. +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f Zeit wurde zu {1} gesetzt. pTimeNormal=\u00a7e{0}''s\u00a7f Zeit ist normal und entspricht der Serverzeit. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 41c32506c..a9f4b375c 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -232,6 +232,7 @@ numberRequired=A number goes there, silly. onlyDayNight=/time only supports day/night. onlyPlayers=Only in-game players can use {0}. onlySunStorm=/weather only supports sun/storm. +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}. pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server. diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index eae6cf89b..ae3b61f4b 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -232,6 +232,7 @@ numberRequired=Un numero es necesario, amigo. onlyDayNight=/time solo soporta day/night. (dia/noche) onlyPlayers=Solo los jugadores conectados pueden usar {0}. onlySunStorm=/weather solo soporta sun/storm. (sol/tormenta) +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f la hora es {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f la hora ha sido cambiada a {1}. pTimeNormal=\u00a7e{0}''s\u00a7f el tiempo es normal y coincide con el servidor. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 207b84541..a7b73946d 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -232,6 +232,7 @@ numberRequired=Il faut fournir un nombre ici. onlyDayNight=/time ne supporte que (jour) day/night (nuit). onlyPlayers=Seulement les joueurs en jeu peuvent utiliser {0}. onlySunStorm=/weather ne supporte que (soleil) sun/storm (temp\u00eate). +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f l''heure est {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f l''heure est fix\u00e9e \u00e0 {1}. pTimeNormal=\u00a7e{0}''s\u00a7f l''heure est normale et correspond au server. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index caac0b039..d42077923 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -232,6 +232,7 @@ numberRequired=Er moet daar een nummer, grapjas. onlyDayNight=/time ondersteund alleen day/night. onlyPlayers=Alleen in-game spelers kunnen {0} gebruiken. onlySunStorm=/weather only supports sun/storm. +orderBalances=Ordering balances of {0} users, please wait ... pTimeCurrent=\u00a7e{0}''s\u00a7f time is {1}. pTimeCurrentFixed=\u00a7e{0}''s\u00a7f time is fixed to {1}. pTimeNormal=\u00a7e{0}''s\u00a7f time is normal and matches the server. diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index 2c4d1dbab..cd054d732 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -32,6 +32,13 @@ public class EssentialsProtectEntityListener extends EntityListener return; } final Entity target = event.getEntity(); + + if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) + { + event.setCancelled(true); + return; + } + final User user = ess.getUser(target); if (event instanceof EntityDamageByBlockEvent) { diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 369e988ae..817ad66af 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -40,6 +40,7 @@ public enum ProtectConfig prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false), prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false), prevent_enderman_pickup("protect.prevent.enderman-pickup", false), + prevent_villager_death("protect.prevent.villager-death", false), prevent_entitytarget("protect.prevent.entitytarget", false), protect_rails("protect.protect.rails", true), protect_below_rails("protect.protect.block-below", true), |