mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-06-26 17:20:03 +00:00
Allow for specifying amount to increase itemstack in /more (#3302)
Fixes #2342.
This commit is contained in:
parent
76e511a774
commit
1a6ad2fdb0
4 changed files with 37 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@ -17,22 +19,37 @@ public class Commandmore extends EssentialsCommand {
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||||
final ItemStack stack = user.getItemInHand();
|
final ItemStack stack = user.getItemInHand();
|
||||||
if (stack == null) {
|
if (stack == null || stack.getType() == Material.AIR) {
|
||||||
throw new Exception(tl("cantSpawnItem", "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"));
|
throw new Exception(tl("fullStack"));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||||
if (!user.canSpawnItem(stack.getType())) {
|
if (!user.canSpawnItem(stack.getType())) {
|
||||||
throw new Exception(tl("cantSpawnItem", itemname));
|
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 {
|
} else {
|
||||||
stack.setAmount(stack.getMaxStackSize());
|
newStackSize = stack.getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
stack.setAmount(newStackSize);
|
||||||
user.getBase().updateInventory();
|
user.getBase().updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,4 +105,11 @@ public class NumberUtil {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPositiveInt(final String sInt) {
|
||||||
|
if (!isInt(sInt)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Integer.parseInt(sInt) > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,6 +220,8 @@ flying=flying
|
||||||
flyMode=\u00a76Set fly mode\u00a7c {0} \u00a76for {1}\u00a76.
|
flyMode=\u00a76Set fly mode\u00a7c {0} \u00a76for {1}\u00a76.
|
||||||
foreverAlone=\u00a74You have nobody to whom you can reply.
|
foreverAlone=\u00a74You have nobody to whom you can reply.
|
||||||
fullStack=\u00a74You already have a full stack.
|
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.
|
gameMode=\u00a76Set game mode\u00a7c {0} \u00a76for \u00a7c{1}\u00a76.
|
||||||
gameModeInvalid=\u00a74You need to specify a valid player/mode.
|
gameModeInvalid=\u00a74You need to specify a valid player/mode.
|
||||||
gamemodeCommandDescription=Change player gamemode.
|
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}.
|
moneySentTo=\u00a7a{0} has been sent to {1}.
|
||||||
month=month
|
month=month
|
||||||
months=months
|
months=months
|
||||||
moreCommandDescription=Fills the item stack in hand to maximum size.
|
moreCommandDescription=Fills the item stack in hand to specified amount, or to maximum size if none is specified.
|
||||||
moreCommandUsage=/<command>
|
moreCommandUsage=/<command> [amount]
|
||||||
moreThanZero=\u00a74Quantities must be greater than 0.
|
moreThanZero=\u00a74Quantities must be greater than 0.
|
||||||
motdCommandDescription=Views the Message Of The Day.
|
motdCommandDescription=Views the Message Of The Day.
|
||||||
motdCommandUsage=/<command> [chapter] [page]
|
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.
|
noMetaPerm=\u00a74You do not have permission to apply \u00a7c{0}\u00a74 meta to this item.
|
||||||
none=none
|
none=none
|
||||||
noNewMail=\u00a76You have no new mail.
|
noNewMail=\u00a76You have no new mail.
|
||||||
|
nonZeroPosNumber=\u00a74A non-zero number is required.
|
||||||
noPendingRequest=\u00a74You do not have a pending request.
|
noPendingRequest=\u00a74You do not have a pending request.
|
||||||
noPerm=\u00a74You do not have the \u00a7c{0}\u00a74 permission.
|
noPerm=\u00a74You do not have the \u00a7c{0}\u00a74 permission.
|
||||||
noPermissionSkull=\u00a74You do not have permission to modify that skull.
|
noPermissionSkull=\u00a74You do not have permission to modify that skull.
|
||||||
|
|
|
@ -269,8 +269,8 @@ commands:
|
||||||
usage: /<command> <description>
|
usage: /<command> <description>
|
||||||
aliases: [action,eaction,describe,edescribe,eme]
|
aliases: [action,eaction,describe,edescribe,eme]
|
||||||
more:
|
more:
|
||||||
description: Fills the item stack in hand to maximum size.
|
description: Fills the item stack in hand to specified amount, or to maximum size if none is specified.
|
||||||
usage: /<command>
|
usage: /<command> [amount]
|
||||||
aliases: [emore]
|
aliases: [emore]
|
||||||
motd:
|
motd:
|
||||||
description: Views the Message Of The Day.
|
description: Views the Message Of The Day.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue