Merge pull request #22 from okamosy/master

Adding hidden players to tpo/unlimited update
This commit is contained in:
KHobbits 2011-08-11 13:01:01 -07:00
commit 81d7be4f77
3 changed files with 104 additions and 46 deletions

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
@ -21,9 +22,23 @@ public class Commandtpo extends EssentialsCommand
} }
//Just basically the old tp command //Just basically the old tp command
User p = getPlayer(server, args, 0); User p = getPlayer(server, args, 0, true);
// Check if user is offline
if (p.getBase() instanceof OfflinePlayer)
{
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
}
// Verify permission
if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden"))
{
charge(user); charge(user);
user.getTeleport().now(p, false); user.getTeleport().now(p, false);
user.sendMessage(Util.i18n("teleporting")); user.sendMessage(Util.i18n("teleporting"));
} }
else
{
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
}
}
} }

View file

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
@ -21,9 +22,24 @@ public class Commandtpohere extends EssentialsCommand
} }
//Just basically the old tphere command //Just basically the old tphere command
User p = getPlayer(server, args, 0); User p = getPlayer(server, args, 0, true);
// Check if user is offline
if (p.getBase() instanceof OfflinePlayer)
{
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
}
// Verify permission
if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden"))
{
charge(user); charge(user);
p.getTeleport().now(user, false); p.getTeleport().now(user, false);
user.sendMessage(Util.i18n("teleporting")); user.sendMessage(Util.i18n("teleporting"));
} }
else
{
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
}
}
} }

View file

@ -32,6 +32,31 @@ public class Commandunlimited extends EssentialsCommand
} }
if (args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{
String list = getList(target);
user.sendMessage(list);
}
else if (args[0].equalsIgnoreCase("clear"))
{
List<Integer> itemList = target.getUnlimited();
int index = 0;
while (itemList.size() > index)
{
Integer item = itemList.get(index);
if (toggleUnlimited(user, target, item.toString()) == false)
{
index++;
}
}
}
else
{
toggleUnlimited(user, target, args[0]);
}
}
private String getList(User target)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(Util.i18n("unlimitedItems")).append(" "); sb.append(Util.i18n("unlimitedItems")).append(" ");
@ -51,45 +76,47 @@ public class Commandunlimited extends EssentialsCommand
String matname = Material.getMaterial(integer).toString().toLowerCase().replace("_", ""); String matname = Material.getMaterial(integer).toString().toLowerCase().replace("_", "");
sb.append(matname); sb.append(matname);
} }
user.sendMessage(sb.toString());
return; return sb.toString();
} }
final ItemStack stack = ess.getItemDb().get(args[0], 1); private Boolean toggleUnlimited(User user, User target, String item) throws Exception
{
ItemStack stack = ess.getItemDb().get(item, 1);
stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2));
String itemname = stack.getType().toString().toLowerCase().replace("_", ""); String itemname = stack.getType().toString().toLowerCase().replace("_", "");
if (!user.isAuthorized("essentials.unlimited.item-all") if (ess.getSettings().permissionBasedItemSpawn()
&& (!user.isAuthorized("essentials.unlimited.item-all")
&& !user.isAuthorized("essentials.unlimited.item-" + itemname) && !user.isAuthorized("essentials.unlimited.item-" + itemname)
&& !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId()) && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId())
&& !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET) && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET)
&& user.isAuthorized("essentials.unlimited.item-bucket"))) && user.isAuthorized("essentials.unlimited.item-bucket"))))
{ {
user.sendMessage(Util.format("unlimitedItemPermission", itemname)); user.sendMessage(Util.format("unlimitedItemPermission", itemname));
return; return false;
} }
String message = "disableUnlimited";
if (target.hasUnlimited(stack)) Boolean enableUnlimited = false;
if (!target.hasUnlimited(stack))
{ {
if (user != target) message = "enableUnlimited";
{ enableUnlimited = true;
user.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName()));
}
target.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName()));
target.setUnlimited(stack, false);
return;
}
charge(user); charge(user);
if (user != target)
{
user.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName()));
}
target.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName()));
if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack)) if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack))
{ {
target.getInventory().addItem(stack); target.getInventory().addItem(stack);
} }
target.setUnlimited(stack, true); }
if (user != target)
{
user.sendMessage(Util.format(message, itemname, target.getDisplayName()));
}
target.sendMessage(Util.format(message, itemname, target.getDisplayName()));
target.setUnlimited(stack, enableUnlimited);
return true;
} }
} }