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)
This commit is contained in:
snowleo 2011-11-28 19:55:51 +01:00
parent 0354b8d019
commit 9acc7db06f
8 changed files with 33 additions and 18 deletions

View file

@ -31,7 +31,7 @@ public interface ISettings extends IConf
String getCurrencySymbol(); String getCurrencySymbol();
int getDefaultStackSize(); int getOversizedStackSize();
double getHealCooldown(); double getHealCooldown();

View file

@ -81,10 +81,10 @@ public final class InventoryWorkaround
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items) public static Map<Integer, ItemStack> 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<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final boolean dontBreakStacks, 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>(); final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
@ -146,11 +146,12 @@ public final class InventoryWorkaround
} }
else else
{ {
final int maxAmount = oversizedStacks > 0 ? oversizedStacks : item.getType().getMaxStackSize();
// More than a single stack! // More than a single stack!
if (item.getAmount() > (dontBreakStacks ? 64 : item.getType().getMaxStackSize())) if (item.getAmount() > maxAmount)
{ {
ItemStack stack = item.clone(); final ItemStack stack = item.clone();
stack.setAmount(dontBreakStacks ? 64 : item.getType().getMaxStackSize()); stack.setAmount(maxAmount);
if (cinventory instanceof FakeInventory) if (cinventory instanceof FakeInventory)
{ {
cinventory.setItem(firstFree, stack); cinventory.setItem(firstFree, stack);
@ -159,7 +160,7 @@ public final class InventoryWorkaround
{ {
EnchantmentFix.setItem(cinventory, firstFree, stack); EnchantmentFix.setItem(cinventory, firstFree, stack);
} }
item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); item.setAmount(item.getAmount() - maxAmount);
} }
else else
{ {
@ -183,7 +184,7 @@ public final class InventoryWorkaround
final int amount = item.getAmount(); final int amount = item.getAmount();
final int partialAmount = partialItem.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 // Check if it fully fits
if (amount + partialAmount <= maxAmount) if (amount + partialAmount <= maxAmount)

View file

@ -114,7 +114,7 @@ public class ItemDb implements IConf
throw new Exception(_("unknownItemId", itemid)); throw new Exception(_("unknownItemId", itemid));
} }
final ItemStack retval = new ItemStack(mat); final ItemStack retval = new ItemStack(mat);
retval.setAmount(ess.getSettings().getDefaultStackSize()); retval.setAmount(mat.getMaxStackSize());
retval.setDurability(metaData); retval.setDurability(metaData);
return retval; return retval;
} }

View file

@ -82,9 +82,9 @@ public class Settings implements ISettings
} }
@Override @Override
public int getDefaultStackSize() public int getOversizedStackSize()
{ {
return config.getInt("default-stack-size", 64); return config.getInt("oversized-stacksize", 64);
} }
@Override @Override

View file

@ -77,7 +77,11 @@ public class Commandgive extends EssentialsCommand
final User giveTo = getPlayer(server, args, 0); final User giveTo = getPlayer(server, args, 0);
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + "."); 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(); giveTo.updateInventory();
} }
} }

View file

@ -72,7 +72,11 @@ public class Commanditem extends EssentialsCommand
final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName)); 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(); user.updateInventory();
} }
} }

View file

@ -119,12 +119,16 @@ public class Commandsell extends EssentialsCommand
{ {
continue; continue;
} }
if (!s.getEnchantments().equals(is.getEnchantments()))
{
continue;
}
max += s.getAmount(); max += s.getAmount();
} }
if (stack) if (stack)
{ {
amount *= 64; amount *= is.getType().getMaxStackSize();
} }
if (amount < 1) if (amount < 1)
{ {
@ -133,7 +137,7 @@ public class Commandsell extends EssentialsCommand
if (requireStack) if (requireStack)
{ {
amount -= amount % 64; amount -= amount % is.getType().getMaxStackSize();
} }
if (amount > max || amount < 1) if (amount > max || amount < 1)
{ {

View file

@ -53,9 +53,6 @@ teleport-delay: 0
# The delay, in seconds, required between /heal attempts # The delay, in seconds, required between /heal attempts
heal-cooldown: 60 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 # What to prevent from /i /give
# e.g item-spawn-blacklist: 46,11,10 # e.g item-spawn-blacklist: 46,11,10
item-spawn-blacklist: item-spawn-blacklist:
@ -230,6 +227,11 @@ death-messages: true
no-god-in-worlds: no-god-in-worlds:
# - world_nether # - 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 | # # | EssentialsHome | #