Cleanup /exp command, and fix vanilla syntax issues.

Needs double checking with commandblocks with vanilla syntax.
This commit is contained in:
KHobbits 2013-01-20 01:10:41 +00:00
parent 762bb65677
commit 41547e3243

View File

@ -24,35 +24,6 @@ public class Commandexp extends EssentialsCommand
{ {
showExp(user, user); showExp(user, user);
} }
else if (Util.isInt(args[0].toLowerCase().replace("l", ""))) // check vanilla syntax
{
final String lowerArgs0 = args[0].toLowerCase();
final int lvl = Integer.parseInt(lowerArgs0.replace("l", ""));
final boolean containsL = lowerArgs0.contains("l");
if (args.length > 1 && user.isAuthorized("essentials.exp.give.others"))
{
if (containsL)
{
addLevel(server, user, lvl, args[1]);
}
else
{
expMatch(server, user, args[1], args[0], true);
}
}
else
{
if (containsL)
{
addLevel(server, user, lvl, user.getName());
}
else
{
expMatch(server, user, user.getName(), args[0], true);
}
}
}
else if (args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set")) else if (args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set"))
{ {
if (args.length == 3 && user.isAuthorized("essentials.exp.set.others")) if (args.length == 3 && user.isAuthorized("essentials.exp.set.others"))
@ -75,64 +46,71 @@ public class Commandexp extends EssentialsCommand
setExp(user, user, args[1], true); setExp(user, user, args[1], true);
} }
} }
else else if (args[0].equalsIgnoreCase("show"))
{ {
String match = args[0].trim(); if (args.length >= 2 && user.isAuthorized("essentials.exp.others"))
if (args.length == 2)
{ {
match = args[1].trim(); String match = args[1].trim();
} showMatch(server, user, match);
if (match.equalsIgnoreCase("show") || !user.isAuthorized("essentials.exp.others"))
{
showExp(user, user);
} }
else else
{ {
showExp(user, user);
}
}
else
{
if (args.length >= 1 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")) && user.isAuthorized("essentials.exp.give"))
{
if (args.length >= 2 && user.isAuthorized("essentials.exp.give.others"))
{
expMatch(server, user, args[1], args[0], true);
}
else
{
setExp(user, user, args[0], true);
}
}
else if (args.length >= 1 && user.isAuthorized("essentials.exp.others"))
{
String match = args[0].trim();
showMatch(server, user, match); showMatch(server, user, match);
} }
else
{
showExp(user, user);
}
} }
} }
@Override @Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
final String parseLevel = args[0].toLowerCase().replace("l", ""); if (args.length < 1)
if (Util.isInt(parseLevel))
{ {
final int lvl = Integer.parseInt(parseLevel); throw new NotEnoughArgumentsException();
if (args[0].toLowerCase(Locale.ENGLISH).contains("l")) }
{ else if (args.length > 2 && args[0].equalsIgnoreCase("set"))
addLevel(server, sender, lvl, args[1]); {
} expMatch(server, sender, args[1], args[2], false);
else }
{ else if (args.length > 2 && args[0].equalsIgnoreCase("give"))
expMatch(server, sender, args[1], args[0], true); {
} expMatch(server, sender, args[1], args[2], true);
} }
else else
{ {
if (args.length < 1) String match = args[0].trim();
if (args.length >= 2 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")))
{ {
throw new NotEnoughArgumentsException(); match = args[1].trim();
expMatch(server, sender, match, args[0], true);
} }
else if (args.length > 2 && args[0].equalsIgnoreCase("set")) else if (args.length == 1)
{ {
expMatch(server, sender, args[1], args[2], false); match = args[0].trim();
}
else if (args.length > 2 && args[0].equalsIgnoreCase("give"))
{
expMatch(server, sender, args[1], args[2], true);
}
else
{
String match = args[0].trim();
if (args.length == 2)
{
match = args[1].trim();
}
showMatch(server, sender, match);
} }
showMatch(server, sender, match);
} }
} }
@ -151,38 +129,13 @@ public class Commandexp extends EssentialsCommand
} }
} }
private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean toggle) throws NotEnoughArgumentsException private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException
{ {
boolean foundUser = false; boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(match)) for (Player matchPlayer : server.matchPlayer(match))
{ {
final User target = ess.getUser(matchPlayer); final User target = ess.getUser(matchPlayer);
setExp(sender, target, amount, toggle); setExp(sender, target, amount, give);
foundUser = true;
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
private void addLevel(final Server server, final CommandSender sender, final int level, final String target) throws NotEnoughArgumentsException
{
boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(target))
{
final User user = ess.getUser(matchPlayer);
final int curLevel = user.getLevel();
final int fLevel = curLevel + level;
if (fLevel < 0)
{
user.setLevel(0);
user.setExp(0F);
}
else
{
user.setLevel(fLevel);
}
foundUser = true; foundUser = true;
} }
if (!foundUser) if (!foundUser)