From e8d64aca5ebf6334844dbca80e83dd694557f862 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 28 Nov 2011 06:15:51 +0100 Subject: New option for EssProtect: Prevent villager death. --- Essentials/src/config.yml | 1 + .../essentials/protect/EssentialsProtectEntityListener.java | 7 +++++++ .../src/com/earth2me/essentials/protect/ProtectConfig.java | 1 + 3 files changed, 9 insertions(+) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 52c87bb4b..c0358dec9 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -388,6 +388,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 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), -- cgit v1.2.3 From 4a83d17fecb9f0fcbbf56af2b1b677d5121bb5e3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 28 Nov 2011 12:55:54 +0000 Subject: Adding extra mobs to essentials protect, changing some default settings. --- Essentials/src/com/earth2me/essentials/Mob.java | 2 +- Essentials/src/com/earth2me/essentials/Settings.java | 6 +++--- Essentials/src/config.yml | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) 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..1e9f66c6e 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -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/config.yml b/Essentials/src/config.yml index 52c87bb4b..eef1d883d 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -415,6 +415,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. -- cgit v1.2.3 From 7268e1965d24b443d3ec4b2eddd6cde1967250e2 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 28 Nov 2011 17:58:06 +0100 Subject: Ignore defaultstacksize from config, just use 64 --- .../src/com/earth2me/essentials/InventoryWorkaround.java | 10 +++++----- .../src/com/earth2me/essentials/commands/Commandgive.java | 2 +- .../src/com/earth2me/essentials/commands/Commanditem.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 0b8121f89..53bb5c7f7 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 addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items) { - return addItem(cinventory, forceDurability, false, null, items); + return addItem(cinventory, forceDurability, false, items); } - public static Map addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final IEssentials ess, final ItemStack... items) + public static Map addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final ItemStack... items) { final Map leftover = new HashMap(); @@ -147,10 +147,10 @@ public final class InventoryWorkaround else { // More than a single stack! - if (item.getAmount() > (dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize())) + if (item.getAmount() > (dontBreakStacks ? 64 : item.getType().getMaxStackSize())) { ItemStack stack = item.clone(); - stack.setAmount(dontBreakStacks ? ess.getSettings().getDefaultStackSize() : item.getType().getMaxStackSize()); + stack.setAmount(dontBreakStacks ? 64 : item.getType().getMaxStackSize()); if (cinventory instanceof FakeInventory) { cinventory.setItem(firstFree, stack); @@ -183,7 +183,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 = dontBreakStacks ? 64 : partialItem.getType().getMaxStackSize(); // Check if it fully fits if (amount + partialAmount <= maxAmount) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 32b0564b7..2147392a6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -77,7 +77,7 @@ 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); + InventoryWorkaround.addItem(giveTo.getInventory(), true, 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..5f9e80ed9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -72,7 +72,7 @@ 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); + InventoryWorkaround.addItem(user.getInventory(), true, true, stack); user.updateInventory(); } } -- cgit v1.2.3 From eea7785b7f1281b63cefa86363dd4ffbf5d3f54e Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 28 Nov 2011 18:53:38 +0100 Subject: Calculation of /balancetop is now async to prevent slowdown of the server --- .../src/com/earth2me/essentials/UserMap.java | 20 +-- .../essentials/commands/Commandbalancetop.java | 150 ++++++++++++++++++--- 2 files changed, 136 insertions(+), 34 deletions(-) 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 implements IConf users.invalidate(name.toLowerCase(Locale.ENGLISH)); } - public Set getAllUsers() + public Set getAllUniqueUsers() { - final Set userSet = new HashSet(); - 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..0a02ee7a7 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 cache = new ArrayList(); + 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 balances = new HashMap(); - 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("Calculating results"); + } + } + finally + { + lock.readLock().unlock(); + } + ess.scheduleAsyncDelayedTask(new Viewer(sender, max)); } - - final List> sortedEntries = new ArrayList>(balances.entrySet()); - Collections.sort(sortedEntries, new Comparator>() + else { - @Override - public int compare(final Entry entry1, final Entry entry2) + if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - return -entry1.getValue().compareTo(entry2.getValue()); + sender.sendMessage("Calculating results"); } - }); - 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 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 balances = new HashMap(); + for (String u : ess.getUserMap().getAllUniqueUsers()) + { + try + { + balances.put(u, ess.getUserMap().getUser(u).getMoney()); + } + catch (NullPointerException ex) + { + } + } + + final List> sortedEntries = new ArrayList>(balances.entrySet()); + Collections.sort(sortedEntries, new Comparator>() + { + @Override + public int compare(final Entry entry1, final Entry entry2) + { + return -entry1.getValue().compareTo(entry2.getValue()); + } + }); + int count = 0; + for (Map.Entry 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))); } } } -- cgit v1.2.3 From 0354b8d01925bcfd64ea5a09e2eec7d6c894ca00 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 28 Nov 2011 18:59:33 +0100 Subject: Translation of /balancetop --- .../src/com/earth2me/essentials/commands/Commandbalancetop.java | 4 ++-- Essentials/src/messages.properties | 1 + Essentials/src/messages_da.properties | 1 + Essentials/src/messages_de.properties | 1 + Essentials/src/messages_en.properties | 1 + Essentials/src/messages_es.properties | 1 + Essentials/src/messages_fr.properties | 1 + Essentials/src/messages_nl.properties | 1 + 8 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 0a02ee7a7..7a19b6f41 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -52,7 +52,7 @@ public class Commandbalancetop extends EssentialsCommand } if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - sender.sendMessage("Calculating results"); + sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers())); } } finally @@ -65,7 +65,7 @@ public class Commandbalancetop extends EssentialsCommand { if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - sender.sendMessage("Calculating results"); + sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers())); } ess.scheduleAsyncDelayedTask(new Viewer(sender, max)); } 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. -- cgit v1.2.3 From 9acc7db06fcae590764fb252fb57a728af57fea9 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 28 Nov 2011 19:55:51 +0100 Subject: Changes to /sell /give and /item Material.getMaxStackSize() will now be used in /give and /item The config option default-stack-size has been removed New config option oversized-stacksize and permission essentials.oversizedstacks Fixes bug giving out too many items on /give and /item when a stacksize > 64 is given. Fixes bug in /sell that ignores enchantments /sell now uses Material.getMaxStackSize() for /sell egg 2s (will sell 32 instead of 128 now) --- Essentials/src/com/earth2me/essentials/ISettings.java | 2 +- .../src/com/earth2me/essentials/InventoryWorkaround.java | 15 ++++++++------- Essentials/src/com/earth2me/essentials/ItemDb.java | 2 +- Essentials/src/com/earth2me/essentials/Settings.java | 4 ++-- .../src/com/earth2me/essentials/commands/Commandgive.java | 6 +++++- .../src/com/earth2me/essentials/commands/Commanditem.java | 6 +++++- .../src/com/earth2me/essentials/commands/Commandsell.java | 8 ++++++-- Essentials/src/config.yml | 8 +++++--- 8 files changed, 33 insertions(+), 18 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 53bb5c7f7..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 addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items) { - return addItem(cinventory, forceDurability, false, items); + return addItem(cinventory, forceDurability, 0, items); } - public static Map addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, final ItemStack... items) + public static Map addItem(final Inventory cinventory, final boolean forceDurability, final int oversizedStacks, final ItemStack... items) { final Map leftover = new HashMap(); @@ -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 ? 64 : item.getType().getMaxStackSize())) + if (item.getAmount() > maxAmount) { - ItemStack stack = item.clone(); - stack.setAmount(dontBreakStacks ? 64 : 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 ? 64 : 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/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 1e9f66c6e..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 diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 2147392a6..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, 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 5f9e80ed9..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, 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 77b3fc3a4..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 | # -- cgit v1.2.3