Merge pull request #278 from GunfighterJ/2.9

Adds vanilla syntax for /clearinventory
This commit is contained in:
KHobbits 2013-01-27 08:40:39 -08:00
commit c65353350f
2 changed files with 103 additions and 14 deletions

View File

@ -2,10 +2,12 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Commandclearinventory extends EssentialsCommand
@ -22,7 +24,22 @@ public class Commandclearinventory extends EssentialsCommand
if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others"))
{
//TODO: Fix fringe user match case.
if (args[0].length() >= 3)
if (args[0].contentEquals("*") && user.isAuthorized("essentials.clearinventory.all"))
{
if (args.length > 1)
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
}
user.sendMessage("Cleared everyone's inventory");
}
else
{
throw new NotEnoughArgumentsException();
}
}
else if (args[0].length() >= 3)
{
List<Player> online = server.matchPlayer(args[0]);
@ -30,30 +47,48 @@ public class Commandclearinventory extends EssentialsCommand
{
for (Player p : online)
{
p.getInventory().clear();
if (args.length > 1)
{
clearInventory(p, args[1]);
}
else
{
p.getInventory().clear();
}
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
return;
}
throw new Exception(_("playerNotFound"));
else
{
clearInventory(user, args[0]);
user.sendMessage(_("inventoryCleared"));
}
}
else
{
Player p = server.getPlayer(args[0]);
if (p != null)
{
p.getInventory().clear();
clearInventory(p, args[1]);
user.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
else
{
throw new Exception(_("playerNotFound"));
clearInventory(user, args[0]);
user.sendMessage(_("inventoryCleared"));
}
}
}
else
{
user.getInventory().clear();
if (args.length > 0)
{
clearInventory(user, args[0]);
}
else
{
user.getInventory().clear();
}
user.sendMessage(_("inventoryCleared"));
}
}
@ -66,7 +101,22 @@ public class Commandclearinventory extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
if (args[0].length() >= 3)
if (args[0].contentEquals("*"))
{
if (args.length > 1)
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
clearInventory(onlinePlayer, args[1]);
}
sender.sendMessage("Cleared everyone's inventory");
}
else
{
throw new NotEnoughArgumentsException();
}
}
else if (args[0].length() >= 3)
{
List<Player> online = server.matchPlayer(args[0]);
@ -74,19 +124,28 @@ public class Commandclearinventory extends EssentialsCommand
{
for (Player p : online)
{
p.getInventory().clear();
if (args.length > 1)
{
clearInventory(p, args[1]);
}
else
{
p.getInventory().clear();
}
sender.sendMessage(_("inventoryClearedOthers", p.getDisplayName()));
}
return;
}
throw new Exception(_("playerNotFound"));
else
{
throw new Exception(_("playerNotFound"));
}
}
else
{
Player u = server.getPlayer(args[0]);
if (u != null)
{
u.getInventory().clear();
clearInventory(u, args[0]);
sender.sendMessage(_("inventoryClearedOthers", u.getDisplayName()));
}
else
@ -95,4 +154,34 @@ public class Commandclearinventory extends EssentialsCommand
}
}
}
}
public void clearInventory(Player player, String arg) throws Exception
{
final String[] split = arg.split(":");
if (arg.contentEquals("*"))
{
player.getInventory().clear();
}
else
{
final ItemStack item = ess.getItemDb().get(split[0]);
final int type = item.getTypeId();
if (split.length > 1 && Util.isInt(arg.replace(":", "")))
{
player.getInventory().clear(type, Integer.parseInt(split[1]));
}
else
{
if (Util.isInt(split[0]))
{
player.getInventory().clear(type, -1);
}
else
{
player.getInventory().clear(type, item.getDurability());
}
}
}
}
}

View File

@ -62,7 +62,7 @@ commands:
clearinventory:
description: Clear all items in your inventory.
usage: /<command>
aliases: [ci,eci,clearinvent,clean,eclean,eclearinvent,eclearinventory]
aliases: [clear,ci,eci,clearinvent,clean,eclean,eclearinvent,eclearinventory]
compass:
description: Describes your current bearing.
usage: /<command>