Throw errors if there is a error when doing the commands

This commit is contained in:
Andrew 2013-11-19 00:50:39 +13:00
parent c25519158a
commit 9b1ba66efc
4 changed files with 56 additions and 41 deletions

View File

@ -18,15 +18,19 @@ public class DisguiseCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Disguise disguise = null;
try {
Disguise disguise = parseDisguise(sender, args);
disguise = parseDisguise(sender, args);
} catch (Exception ex) {
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
sender.sendMessage(ex.getMessage());
} else {
ex.printStackTrace();
}
return true;
}
DisguiseAPI.disguiseToAll((Player) sender, disguise);
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
} catch (Exception ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
return true;
}

View File

@ -23,16 +23,20 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
Disguise disguise;
try {
Disguise disguise = parseDisguise(sender, args);
disguise = parseDisguise(sender, args);
} catch (Exception ex) {
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
sender.sendMessage(ex.getMessage());
} else {
ex.printStackTrace();
}
return true;
}
listener.setSlap(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a "
+ disguise.getType().toReadable() + "!");
} catch (Exception ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
return true;
}

View File

@ -33,20 +33,24 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'");
return true;
}
try {
String[] newArgs = new String[args.length - 1];
for (int i = 0; i < newArgs.length; i++) {
newArgs[i] = args[i + 1];
}
Disguise disguise = parseDisguise(sender, newArgs);
Disguise disguise;
try {
disguise = parseDisguise(sender, newArgs);
} catch (Exception ex) {
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
sender.sendMessage(ex.getMessage());
} else {
ex.printStackTrace();
}
return true;
}
DisguiseAPI.disguiseToAll(player, disguise);
sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a "
+ disguise.getType().toReadable() + "!");
} catch (Exception ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
return true;
}

View File

@ -46,13 +46,21 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
radius = maxRadius;
}
try {
String[] newArgs = new String[args.length - 1];
for (int i = 0; i < newArgs.length; i++) {
newArgs[i] = args[i + 1];
}
Disguise disguise = parseDisguise(sender, newArgs);
// Time to use it!
Disguise disguise;
try {
disguise = parseDisguise(sender, newArgs);
} catch (Exception ex) {
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
sender.sendMessage(ex.getMessage());
} else {
ex.printStackTrace();
}
return true;
} // Time to use it!
int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender)
@ -61,11 +69,6 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
disguisedEntitys++;
}
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
} catch (Exception ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
return true;
}