From 62cd219b4ecd48464037dd898ed14ab7de4972b2 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 11 Feb 2012 13:45:15 +1100 Subject: [PATCH] Clean up the CommandException stack traces so they appear as if Essentials was never there. --- .../com/earth2me/essentials/Essentials.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 21f2e38ea..3ee7c1777 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -32,15 +32,20 @@ import com.earth2me.essentials.signs.SignPlayerListener; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.Command; +import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; @@ -277,7 +282,29 @@ public class Essentials extends JavaPlugin implements IEssentials if (pc != null) { alternativeCommandsHandler.executed(commandLabel, pc.getLabel()); - return pc.execute(sender, commandLabel, args); + try + { + return pc.execute(sender, commandLabel, args); + } + catch (final Exception ex) + { + final ArrayList elements = new ArrayList(Arrays.asList(ex.getStackTrace())); + elements.remove(0); + final ArrayList toRemove = new ArrayList(); + for (final StackTraceElement e : elements) + { + if (e.getClassName().equals("com.earth2me.essentials.Essentials")) + { + toRemove.add(e); + } + } + elements.removeAll(toRemove); + final StackTraceElement[] trace = elements.toArray(new StackTraceElement[elements.size()]); + ex.setStackTrace(trace); + ex.printStackTrace(); + sender.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); + return true; + } } }