@Override public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) { boolean disabled = false; boolean overridden = false; ISettings settings = ess.getSettings(); settings.acquireReadLock(); try { disabled = settings.getData().getCommands().isDisabled(command.getName()); overridden = !disabled || settings.getData().getCommands().isOverridden(command.getName()); } finally { settings.unlock(); } // Allow plugins to override the command via onCommand if (!overridden && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { final PluginCommand pc = getAlternative(commandLabel); if (pc != null) { executed(commandLabel, pc.getLabel()); try { return pc.execute(sender, commandLabel, args); } catch (final Exception ex) { final ArrayList<StackTraceElement> elements = new ArrayList<StackTraceElement>(Arrays.asList(ex.getStackTrace())); elements.remove(0); final ArrayList<StackTraceElement> toRemove = new ArrayList<StackTraceElement>(); for (final StackTraceElement e : elements) { if (e.getClassName().equals("net.ess3.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; } } } try { IUser user = null; if (sender instanceof Player) { user = ess.getUserMap().getUser((Player)sender); LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0))); } // Check for disabled commands if (disabled) { return true; } final String commandName = command.getName().toLowerCase(Locale.ENGLISH); IEssentialsCommand cmd = commands.get(commandName); if (cmd == null) { try { cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + commandName).newInstance(); cmd.init(ess, commandName); cmd.setEssentialsModule(module); commands.put(commandName, cmd); } catch (Exception ex) { sender.sendMessage(_("commandNotLoaded", commandName)); LOGGER.log(Level.SEVERE, _("commandNotLoaded", commandName), ex); return true; } } // Check authorization if (sender != null && !cmd.isAuthorized(sender)) { LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName())); user.sendMessage(_("noAccessCommand")); return true; } // Run the command try { if (user == null) { cmd.run(sender, command, commandLabel, args); } else { user.acquireReadLock(); try { cmd.run(user, command, commandLabel, args); } finally { user.unlock(); } } return true; } catch (NoChargeException ex) { return true; } catch (NotEnoughArgumentsException ex) { sender.sendMessage(command.getDescription()); sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel)); if (!ex.getMessage().isEmpty()) { sender.sendMessage(ex.getMessage()); } return true; } catch (Throwable ex) { showCommandError(sender, commandLabel, ex); return true; } } catch (Throwable ex) { LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex); return true; } }
@Override public boolean onCommandEssentials(final CommandSender sender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) { // Allow plugins to override the command via onCommand if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { alternativeCommandsHandler.executed(commandLabel, pc.getLabel()); try { return pc.execute(sender, commandLabel, args); } catch (final Exception ex) { Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); sender.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); return true; } } } try { User user = null; if (sender instanceof Player) { user = getUser(sender); LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0))); } // New mail notification if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail")) { final List<String> mail = user.getMails(); if (mail != null && !mail.isEmpty()) { user.sendMessage(_("youHaveNewMail", mail.size())); } } // Check for disabled commands if (getSettings().isCommandDisabled(commandLabel)) { return true; } IEssentialsCommand cmd; try { cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + command.getName()).newInstance(); cmd.setEssentials(this); cmd.setEssentialsModule(module); } catch (Exception ex) { sender.sendMessage(_("commandNotLoaded", commandLabel)); LOGGER.log(Level.SEVERE, _("commandNotLoaded", commandLabel), ex); return true; } // Check authorization if (user != null && !user.isAuthorized(cmd, permissionPrefix)) { LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName())); user.sendMessage(_("noAccessCommand")); return true; } // Run the command try { if (user == null) { cmd.run(getServer(), sender, commandLabel, command, args); } else { cmd.run(getServer(), user, commandLabel, command, args); } return true; } catch (NoChargeException ex) { return true; } catch (NotEnoughArgumentsException ex) { sender.sendMessage(command.getDescription()); sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel)); if (!ex.getMessage().isEmpty()) { sender.sendMessage(ex.getMessage()); } return true; } catch (Throwable ex) { showError(sender, ex, commandLabel); return true; } } catch (Throwable ex) { LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex); return true; } }