1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-30 01:39:51 +02:00

Add command option /more all

This commit is contained in:
snowleo
2012-10-15 23:12:02 +02:00
parent 6f34f208b0
commit c74545d614
2 changed files with 44 additions and 26 deletions

View File

@@ -13,35 +13,53 @@ public class Commandmore extends EssentialsCommand
@Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
final ItemStack stack = user.getPlayer().getItemInHand();
if (stack == null)
ItemStack[] stacks;
if (args.length > 0 && args[0].equalsIgnoreCase("all"))
{
throw new Exception(_("cantSpawnItem", "Air"));
}
ISettings settings = ess.getSettings();
int defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
if (stack.getAmount() >= (Permissions.OVERSIZEDSTACKS.isAuthorized(user)
? oversizedStackSize
: defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize()))
{
throw new NoChargeException();
}
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!Permissions.ITEMSPAWN.isAuthorized(user, stack))
{
throw new Exception(_("cantSpawnItem", itemname));
}
if (Permissions.OVERSIZEDSTACKS.isAuthorized(user))
{
stack.setAmount(oversizedStackSize);
stacks = user.getPlayer().getInventory().getContents();
}
else
{
stack.setAmount(defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize());
stacks = new ItemStack[]
{
user.getPlayer().getItemInHand()
};
}
for (ItemStack stack : stacks)
{
if (stack == null)
{
throw new Exception(_("cantSpawnItem", "Air"));
}
ISettings settings = ess.getSettings();
int defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
if (stack.getAmount() >= (Permissions.OVERSIZEDSTACKS.isAuthorized(user)
? oversizedStackSize
: defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize()))
{
throw new NoChargeException();
}
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!Permissions.ITEMSPAWN.isAuthorized(user, stack))
{
throw new Exception(_("cantSpawnItem", itemname));
}
if (Permissions.OVERSIZEDSTACKS.isAuthorized(user))
{
stack.setAmount(oversizedStackSize);
}
else
{
stack.setAmount(defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize());
}
}
if (stacks.length > 1)
{
user.getPlayer().getInventory().setContents(stacks);
}
user.getPlayer().updateInventory();
}
}
}

View File

@@ -224,7 +224,7 @@ commands:
aliases: [action,describe,eme,eaction,edescribe]
more:
description: Fills the item stack in hand to maximum size.
usage: /<command>
usage: /<command> [all]
aliases: [emore]
motd:
description: Views the Message Of The Day.