Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions Essentials/src/com/earth2me/essentials/commands/Commandmore.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,22 +19,37 @@ public Commandmore() {
@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();
}
}
}
7 changes: 7 additions & 0 deletions Essentials/src/com/earth2me/essentials/utils/NumberUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ public static boolean isInt(final String sInt) {
}
return true;
}

public static boolean isPositiveInt(final String sInt) {
if (!isInt(sInt)) {
return false;
}
return Integer.parseInt(sInt) > 0;
}
}
7 changes: 5 additions & 2 deletions Essentials/src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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.
Expand Down Expand Up @@ -434,8 +436,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]
Expand Down Expand Up @@ -502,6 +504,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.
Expand Down
4 changes: 2 additions & 2 deletions Essentials/src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,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.
Expand Down