New command: /find <item>

Test #278
Test #293
Test #348
This commit is contained in:
Khyperia 2011-12-06 06:25:54 +08:00 committed by snowleo
parent 854fc05c5b
commit a0d66ce230
4 changed files with 74 additions and 3 deletions

View file

@ -0,0 +1,25 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
public class Commandfind extends EssentialsCommand
{
public Commandfind()
{
super("find");
}
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
ItemStack itemStack = ess.getItemDb().get(args[0]);
sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getData().getData()));
}
}

View file

@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
@ -34,10 +35,30 @@ public class Commandlightning extends EssentialsCommand
throw new Exception(_("playerNotFound"));
}
int power = 1;
if (args.length > 1)
{
try
{
power = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex)
{
}
}
for (Player matchPlayer : server.matchPlayer(args[0]))
{
sender.sendMessage(_("lightningUse", matchPlayer.getDisplayName()));
matchPlayer.getWorld().strikeLightning(matchPlayer.getLocation());
if (power <= 0)
{
matchPlayer.getWorld().strikeLightningEffect(matchPlayer.getLocation());
}
else
{
LightningStrike strike = matchPlayer.getWorld().strikeLightning(matchPlayer.getLocation());
matchPlayer.damage(power - 1, strike);
}
if (!ess.getUser(matchPlayer).isGodModeEnabled())
{
matchPlayer.setHealth(matchPlayer.getHealth() < 5 ? 0 : matchPlayer.getHealth() - 5);

View file

@ -50,7 +50,14 @@ public class Commandnick extends EssentialsCommand
{
throw new Exception(_("nickDisplayName"));
}
setNickname(server, getPlayer(server, args, 0), formatNickname(null, args[1]));
if ((args[0].equalsIgnoreCase("*") || args[0].equalsIgnoreCase("all")) && args[1].equalsIgnoreCase("off"))
{
resetAllNicknames(server);
}
else
{
setNickname(server, getPlayer(server, args, 0), formatNickname(null, args[1]));
}
sender.sendMessage(_("nickChanged"));
}
@ -63,6 +70,20 @@ public class Commandnick extends EssentialsCommand
return nick;
}
private void resetAllNicknames(final Server server)
{
for (Player player : server.getOnlinePlayers())
{
try
{
setNickname(server, ess.getUser(player), "off");
}
catch (Exception ex)
{
}
}
}
private void setNickname(final Server server, final User target, final String nick) throws Exception
{
if (nick.matches("[^a-zA-Z_0-9]"))

View file

@ -102,6 +102,10 @@ commands:
description: Satisfy the hunger.
usage: /<command> [player]
aliases: [efeed]
find:
description: Searches for an item.
usage: /<command> <item>
aliases: [efind]
fireball:
description: Throw a fireball.
usage: /<command> [small]
@ -188,7 +192,7 @@ commands:
aliases: [playerlist,who,online,elist,ewho,eplayerlist,eonline]
lightning:
description: The power of Thor. Strike at cursor or player.
usage: /<command> [player]
usage: /<command> [player] [power]
aliases: [strike,smite,thor,shock,elightning,estrike,esmite,ethor,eshock]
mail:
description: Manages inter-player, intra-server mail.