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();
int getDefaultStackSize();
int getOversizedStackSize();
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)
{
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>();
@ -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)

View file

@ -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;
}

View file

@ -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

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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)
{

View file

@ -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 | #