From 9b1ba66efc5240ad2148faa65d8afc12e0e2bd3b Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 19 Nov 2013 00:50:39 +1300 Subject: [PATCH] Throw errors if there is a error when doing the commands --- .../disguise/commands/DisguiseCommand.java | 12 ++++-- .../commands/DisguiseEntityCommand.java | 14 ++++--- .../commands/DisguisePlayerCommand.java | 30 ++++++++------ .../commands/DisguiseRadiusCommand.java | 41 ++++++++++--------- 4 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index 124ed849..7f403644 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -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); - DisguiseAPI.disguiseToAll((Player) sender, disguise); - sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); + disguise = parseDisguise(sender, args); } catch (Exception ex) { - if (ex.getMessage() != null) { + 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()); return true; } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index a5a43e59..29c41860 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -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); - 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() + "!"); + disguise = parseDisguise(sender, args); } catch (Exception ex) { - if (ex.getMessage() != null) { + 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() + "!"); return true; } diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 4c9e4999..c8d7880d 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -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); - 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()); - } + String[] newArgs = new String[args.length - 1]; + for (int i = 0; i < newArgs.length; i++) { + newArgs[i] = args[i + 1]; } + 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() + "!"); return true; } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index bf914886..f75b7040 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -46,26 +46,29 @@ 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! - int disguisedEntitys = 0; - for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { - if (entity == sender) - continue; - DisguiseAPI.disguiseToAll(entity, disguise); - disguisedEntitys++; - } - sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); - } catch (Exception ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } + String[] newArgs = new String[args.length - 1]; + for (int i = 0; i < newArgs.length; i++) { + newArgs[i] = args[i + 1]; } + 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) + continue; + DisguiseAPI.disguiseToAll(entity, disguise); + disguisedEntitys++; + } + sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); return true; }