Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
27 changes: 22 additions & 5 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.isPosInt(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 isPosInt(final String sInt) {
if (!isInt(sInt)) {
return false;
}
return Integer.parseInt(sInt) > 0;
}
}
5 changes: 4 additions & 1 deletion Essentials/src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,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.
gcfree=\u00a76Free memory\:\u00a7c {0} MB.
Expand Down Expand Up @@ -356,6 +358,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 All @@ -374,7 +377,7 @@ nothingInHand=\u00a74You have nothing in your hand.
now=now
noWarpsDefined=\u00a76No warps defined.
nuke=\u00a75May death rain upon them.
numberRequired=A number goes there, silly.
numberRequired=\u00a74A number is required.
onlyDayNight=/time only supports day/night.
onlyPlayers=\u00a74Only in-game players can use \u00a7c{0}\u00a74.
onlyPlayerSkulls=\u00a74You can only set the owner of player skulls (\u00a7c397\:3\u00a74).
Expand Down
2 changes: 1 addition & 1 deletion Essentials/src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ commands:
aliases: [action,eaction,describe,edescribe,eme]
more:
description: Fills the item stack in hand to maximum size.
usage: /<command>
usage: /<command> [amount]
aliases: [emore]
motd:
description: Views the Message Of The Day.
Expand Down