Little more command cleanup.

This commit is contained in:
KHobbits 2011-11-18 13:48:31 +00:00
parent 5655509c62
commit a05f730e76
8 changed files with 54 additions and 53 deletions

View File

@ -16,15 +16,15 @@ public class Commandkickall extends EssentialsCommand
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
for (Player onlinePlaer : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (sender instanceof Player && onlinePlaer.getName().equalsIgnoreCase(((Player)sender).getName()))
if (sender instanceof Player && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName()))
{
continue;
}
else
{
onlinePlaer.kickPlayer(args.length > 0 ? getFinalArg(args, 0) : Util.i18n("kickDefault"));
onlinePlayer.kickPlayer(args.length > 0 ? getFinalArg(args, 0) : Util.i18n("kickDefault"));
}
}
}

View File

@ -15,24 +15,24 @@ public class Commandkill extends EssentialsCommand
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
for (Player p : server.matchPlayer(args[0]))
for (Player matchPlayer : server.matchPlayer(args[0]))
{
final EntityDamageEvent ede = new EntityDamageEvent(p, sender instanceof Player && ((Player)sender).getName().equals(p.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, 1000);
final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender instanceof Player && ((Player)sender).getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, 1000);
server.getPluginManager().callEvent(ede);
if (ede.isCancelled() && !sender.hasPermission("essentials.kill.force"))
{
continue;
}
p.setHealth(0);
sender.sendMessage(Util.format("kill", p.getDisplayName()));
matchPlayer.setHealth(0);
sender.sendMessage(Util.format("kill", matchPlayer.getDisplayName()));
}
}
}

View File

@ -29,11 +29,11 @@ public class Commandkit extends EssentialsCommand
{
final Map<String, Object> kits = ess.getSettings().getKits();
final StringBuilder list = new StringBuilder();
for (String k : kits.keySet())
for (String kiteItem : kits.keySet())
{
if (user.isAuthorized("essentials.kit." + k.toLowerCase()))
if (user.isAuthorized("essentials.kit." + kiteItem.toLowerCase()))
{
list.append(" ").append(k);
list.append(" ").append(kiteItem);
}
}
if (list.length() > 0)
@ -74,9 +74,9 @@ public class Commandkit extends EssentialsCommand
final Calendar c = new GregorianCalendar();
c.add(Calendar.SECOND, -(int)delay);
c.add(Calendar.MILLISECOND, -(int)((delay*1000.0)%1000.0));
final long mintime = c.getTimeInMillis();
final Long lastTime = user.getKitTimestamp(kitName);
if (lastTime == null || lastTime < mintime) {
final Calendar now = new GregorianCalendar();

View File

@ -15,7 +15,7 @@ public class Commandlightning extends EssentialsCommand
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
User user = null;
@ -34,16 +34,16 @@ public class Commandlightning extends EssentialsCommand
throw new Exception(Util.i18n("playerNotFound"));
}
for (Player p : server.matchPlayer(args[0]))
for (Player matchPlayer : server.matchPlayer(args[0]))
{
sender.sendMessage(Util.format("lightningUse", p.getDisplayName()));
p.getWorld().strikeLightning(p.getLocation());
if (!ess.getUser(p).isGodModeEnabled()) {
p.setHealth(p.getHealth() < 5 ? 0 : p.getHealth() - 5);
sender.sendMessage(Util.format("lightningUse", matchPlayer.getDisplayName()));
matchPlayer.getWorld().strikeLightning(matchPlayer.getLocation());
if (!ess.getUser(matchPlayer).isGodModeEnabled()) {
matchPlayer.setHealth(matchPlayer.getHealth() < 5 ? 0 : matchPlayer.getHealth() - 5);
}
if (ess.getSettings().warnOnSmite())
{
p.sendMessage(Util.i18n("lightningSmited"));
matchPlayer.sendMessage(Util.i18n("lightningSmited"));
}
}
}

View File

@ -22,7 +22,7 @@ public class Commandlist extends EssentialsCommand
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
boolean showhidden = false;
if (sender instanceof Player)
@ -37,15 +37,15 @@ public class Commandlist extends EssentialsCommand
showhidden = true;
}
int playerHidden = 0;
for (Player p : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (ess.getUser(p).isHidden())
if (ess.getUser(onlinePlayer).isHidden())
{
playerHidden++;
}
}
//TODO: move these to messages file
StringBuilder online = new StringBuilder();
final StringBuilder online = new StringBuilder();
online.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length - playerHidden);
if (showhidden && playerHidden > 0)
{
@ -58,29 +58,29 @@ public class Commandlist extends EssentialsCommand
if (ess.getSettings().getSortListByGroups())
{
Map<String, List<User>> sort = new HashMap<String, List<User>>();
for (Player p : server.getOnlinePlayers())
for (Player OnlinePlayer : server.getOnlinePlayers())
{
User u = ess.getUser(p);
if (u.isHidden() && !showhidden)
final User player = ess.getUser(OnlinePlayer);
if (player.isHidden() && !showhidden)
{
continue;
}
String group = u.getGroup();
final String group = player.getGroup();
List<User> list = sort.get(group);
if (list == null)
{
list = new ArrayList<User>();
sort.put(group, list);
}
list.add(u);
list.add(player);
}
String[] groups = sort.keySet().toArray(new String[0]);
final String[] groups = sort.keySet().toArray(new String[0]);
Arrays.sort(groups, String.CASE_INSENSITIVE_ORDER);
for (String group : groups)
{
StringBuilder groupString = new StringBuilder();
final StringBuilder groupString = new StringBuilder();
groupString.append(group).append(": ");
List<User> users = sort.get(group);
final List<User> users = sort.get(group);
Collections.sort(users);
boolean first = true;
for (User user : users)
@ -109,19 +109,19 @@ public class Commandlist extends EssentialsCommand
}
else
{
List<User> users = new ArrayList<User>();
for (Player p : server.getOnlinePlayers())
final List<User> users = new ArrayList<User>();
for (Player OnlinePlayer : server.getOnlinePlayers())
{
final User u = ess.getUser(p);
if (u.isHidden() && !showhidden)
final User player = ess.getUser(OnlinePlayer);
if (player.isHidden() && !showhidden)
{
continue;
}
users.add(u);
users.add(player);
}
Collections.sort(users);
StringBuilder onlineUsers = new StringBuilder();
final StringBuilder onlineUsers = new StringBuilder();
onlineUsers.append(Util.i18n("connectedPlayers"));
boolean first = true;
for (User user : users)

View File

@ -16,20 +16,21 @@ public class Commandmail extends EssentialsCommand
super("mail");
}
//TODO: Tidy this up
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length >= 1 && "read".equalsIgnoreCase(args[0]))
{
List<String> mail = user.getMails();
final List<String> mail = user.getMails();
if (mail.isEmpty())
{
user.sendMessage(Util.i18n("noMail"));
throw new NoChargeException();
}
for (String s : mail)
for (String messages : mail)
{
user.sendMessage(s);
user.sendMessage(messages);
}
user.sendMessage(Util.i18n("mailClear"));
return;

View File

@ -14,15 +14,15 @@ public class Commandmute extends EssentialsCommand
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
User p = getPlayer(server, args, 0, true);
if (!p.isMuted() && p.isAuthorized("essentials.mute.exempt"))
final User player = getPlayer(server, args, 0, true);
if (!player.isMuted() && player.isAuthorized("essentials.mute.exempt"))
{
throw new Exception(Util.i18n("muteExempt"));
}
@ -32,15 +32,15 @@ public class Commandmute extends EssentialsCommand
String time = getFinalArg(args, 1);
muteTimestamp = Util.parseDateDiff(time, true);
}
p.setMuteTimeout(muteTimestamp);
boolean muted = p.toggleMuted();
player.setMuteTimeout(muteTimestamp);
final boolean muted = player.toggleMuted();
sender.sendMessage(
muted
? (muteTimestamp > 0
? Util.format("mutedPlayerFor", p.getDisplayName(), Util.formatDateDiff(muteTimestamp))
: Util.format("mutedPlayer", p.getDisplayName()))
: Util.format("unmutedPlayer", p.getDisplayName()));
p.sendMessage(
? Util.format("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp))
: Util.format("mutedPlayer", player.getDisplayName()))
: Util.format("unmutedPlayer", player.getDisplayName()));
player.sendMessage(
muted
? (muteTimestamp > 0
? Util.format("playerMutedFor", Util.formatDateDiff(muteTimestamp))

View File

@ -275,7 +275,7 @@ commands:
usage: /<command> <mob>[:data][,<mount>[:data]] [amount]
aliases: [espawnmob]
sudo:
description: Make another user do something.
description: Make another user perform a command.
usage: /<command> <player> <command [args]>
aliases: [esudo]
suicide:
@ -309,7 +309,7 @@ commands:
tpa:
description: Request to teleport to the specified player.
usage: /<command> <player>
aliases: [call,etpa,ecal]
aliases: [call,etpa,ecall]
tpaall:
description: Requests all players online to teleport to you.
usage: /<command> <player>