Allow for specifying amount to increase itemstack in /more (#3302)

Fixes #2342.
This commit is contained in:
Josh Roy 2020-07-06 14:55:07 -04:00 committed by GitHub
parent 76e511a774
commit 1a6ad2fdb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
@ -17,22 +19,37 @@ public class Commandmore extends EssentialsCommand {
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getItemInHand();
if (stack == null) {
if (stack == null || stack.getType() == Material.AIR) {
throw new Exception(tl("cantSpawnItem", "Air"));
}
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks")) ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize())) {
boolean canOversized = user.isAuthorized("essentials.oversizedstacks");
if (stack.getAmount() >= ((canOversized) ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize())) {
throw new Exception(tl("fullStack"));
}
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!user.canSpawnItem(stack.getType())) {
throw new Exception(tl("cantSpawnItem", itemname));
}
if (user.isAuthorized("essentials.oversizedstacks")) {
stack.setAmount(ess.getSettings().getOversizedStackSize());
int newStackSize = stack.getAmount();
if (args.length >= 1) {
if (!NumberUtil.isPositiveInt(args[0])) {
throw new Exception(tl("nonZeroPosNumber"));
}
newStackSize += Integer.parseInt(args[0]);
if (newStackSize > ((canOversized) ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize())) {
user.sendMessage(tl(canOversized ? "fullStackDefaultOversize" : "fullStackDefault", canOversized ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize()));
newStackSize = canOversized ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize();
}
} else if (canOversized) {
newStackSize = ess.getSettings().getOversizedStackSize();
} else {
stack.setAmount(stack.getMaxStackSize());
newStackSize = stack.getMaxStackSize();
}
stack.setAmount(newStackSize);
user.getBase().updateInventory();
}
}
}

View File

@ -105,4 +105,11 @@ public class NumberUtil {
}
return true;
}
public static boolean isPositiveInt(final String sInt) {
if (!isInt(sInt)) {
return false;
}
return Integer.parseInt(sInt) > 0;
}
}

View File

@ -220,6 +220,8 @@ flying=flying
flyMode=\u00a76Set fly mode\u00a7c {0} \u00a76for {1}\u00a76.
foreverAlone=\u00a74You have nobody to whom you can reply.
fullStack=\u00a74You already have a full stack.
fullStackDefault=\u00a76Your stack has been set to its default size, \u00a7c{0}\u00a76.
fullStackDefaultOversize=\u00a76Your stack has been set to its maximum size, \u00a7c{0}\u00a76.
gameMode=\u00a76Set game mode\u00a7c {0} \u00a76for \u00a7c{1}\u00a76.
gameModeInvalid=\u00a74You need to specify a valid player/mode.
gamemodeCommandDescription=Change player gamemode.
@ -444,8 +446,8 @@ moneyRecievedFrom=\u00a7a{0}\u00a76 has been received from\u00a7a {1}\u00a76.
moneySentTo=\u00a7a{0} has been sent to {1}.
month=month
months=months
moreCommandDescription=Fills the item stack in hand to maximum size.
moreCommandUsage=/<command>
moreCommandDescription=Fills the item stack in hand to specified amount, or to maximum size if none is specified.
moreCommandUsage=/<command> [amount]
moreThanZero=\u00a74Quantities must be greater than 0.
motdCommandDescription=Views the Message Of The Day.
motdCommandUsage=/<command> [chapter] [page]
@ -512,6 +514,7 @@ noMetaJson=JSON Metadata is not supported in this version of Bukkit.
noMetaPerm=\u00a74You do not have permission to apply \u00a7c{0}\u00a74 meta to this item.
none=none
noNewMail=\u00a76You have no new mail.
nonZeroPosNumber=\u00a74A non-zero number is required.
noPendingRequest=\u00a74You do not have a pending request.
noPerm=\u00a74You do not have the \u00a7c{0}\u00a74 permission.
noPermissionSkull=\u00a74You do not have permission to modify that skull.

View File

@ -269,8 +269,8 @@ commands:
usage: /<command> <description>
aliases: [action,eaction,describe,edescribe,eme]
more:
description: Fills the item stack in hand to maximum size.
usage: /<command>
description: Fills the item stack in hand to specified amount, or to maximum size if none is specified.
usage: /<command> [amount]
aliases: [emore]
motd:
description: Views the Message Of The Day.