Esempio n. 1
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		ISettings settings = ess.getSettings();
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final IUser player = ess.getUserMap().matchUserExcludingHidden(args[0], user.getPlayer());
			if (!player.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", player.getPlayer().getDisplayName()));
			}
			if (settings.getData().getGeneral().isPerGroupTeleport() && !Permissions.PERGROUPTELEPORT.isAuthorized(
					user, ess.getRanks().getMainGroup(player)))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.teleport.groups." + ess.getRanks().getMainGroup(player)));
			}
			if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() && !Permissions.WORLD.isAuthorized(
					user, player.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.world." + player.getPlayer().getWorld().getName()));
			}
			user.sendMessage(_("Teleporting..."));
			final Trade charge = new Trade(commandName, ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player.getPlayer(), charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!Permissions.TPOHERE.isAuthorized(user))
			{
				throw new Exception(_("needTpohere"));
			}
			user.sendMessage(_("Teleporting..."));

			final IUser target = ess.getUserMap().matchUserExcludingHidden(args[0], user.getPlayer());

			final IUser toPlayer = ess.getUserMap().matchUserExcludingHidden(args[1], user.getPlayer());

			if (!target.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", target.getPlayer().getDisplayName()));
			}
			if (!toPlayer.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", toPlayer.getPlayer().getDisplayName()));
			}
			if (target.getPlayer().getWorld() != toPlayer.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() && !Permissions.WORLD.isAuthorized(
					user, toPlayer.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.world." + toPlayer.getPlayer().getWorld().getName()));
			}
			target.getTeleport().now(toPlayer.getPlayer(), false, TeleportCause.COMMAND);
			target.sendMessage(_("{0} teleported you to {1}.", user.getPlayer().getDisplayName(), toPlayer.getPlayer().getDisplayName()));
			break;
		}
	}
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
	{
		final ISettings settings = ess.getSettings();

		final IUser user = userMap.getUser(event.getPlayer());
		if (settings.getData().getChat().getChangeDisplayname())
		{
			user.updateDisplayName();
		}
		if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !Permissions.NOGOD_OVERRIDE.isAuthorized(
				user))
		{
			if (user.getData().isGodmode())
			{
				user.sendMessage(_("§4Warning! God mode in this world disabled."));
			}
		}
		if (settings.getData().getCommands().getTeleport().isCancelRequestsOnWorldChange())
		{
			if (user.getTeleportRequester() != null)
			{
				user.requestTeleport(null, false);
				user.sendMessage(_("teleportRequestsCancelledWorldChange"));
			}
		}
		if (settings.getData().getGeneral().isPtClearOnWorldChange())
		{
			user.getData().clearAllPowertools();
			user.queueSave();
			user.sendMessage(_("§6All powertool commands have been cleared."));
		}
	}
Esempio n. 3
0
	public String getNick(boolean addprefixsuffix)
	{

		final String nick = getData().getNickname();
		final ISettings settings = ess.getSettings();
		final IRanks groups = ess.getRanks();
		// default: {PREFIX}{NICKNAMEPREFIX}{NAME}{SUFFIX}
		String displayname = settings.getData().getChat().getDisplaynameFormat();
		if (settings.getData().getCommands().isDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
		{
			displayname = displayname.replace("{NAME}", getName());
			displayname = displayname.replace("{NICKNAMEPREFIX}", "");
		}
		else
		{
			displayname = displayname.replace("{NAME}", nick);
			displayname = displayname.replace("{NICKNAMEPREFIX}", settings.getData().getChat().getNicknamePrefix());
		}

		if (displayname.contains("{PREFIX}"))
		{
			displayname = displayname.replace("{PREFIX}", addprefixsuffix ? groups.getPrefix(this) : "");
		}
		if (displayname.contains("{SUFFIX}"))
		{
			displayname = displayname.replace("{SUFFIX}", addprefixsuffix ? groups.getSuffix(this) : "");
		}
		displayname = displayname.replace("{WORLDNAME}", this.getPlayer().getWorld().getName());
		displayname = displayname.replace('&', '\u00a7');
		displayname = displayname.concat("\u00a7r");

		return displayname;
	}
Esempio n. 4
0
	@Override
	public void checkActivity()
	{
		final ISettings settings = ess.getSettings();
		final long autoafkkick = settings.getData().getCommands().getAfk().getAutoAFKKick();
		if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
			//&& !hidden
			&& !Permissions.KICK_EXEMPT.isAuthorized(this) && !Permissions.AFK_KICKEXEMPT.isAuthorized(this))
		{
			final String kickReason = _("You have been kicked for idling more than {0} minutes.", autoafkkick / 60.0);
			lastActivity = 0;
			getPlayer().kickPlayer(kickReason);


			for (Player player : ess.getServer().getOnlinePlayers())
			{
				if (Permissions.KICK_NOTIFY.isAuthorized(player))
				{
					player.sendMessage(_("Player {0} kicked {1} for {2}.", Console.NAME, getName(), kickReason));
				}
			}
		}
		final long autoafk = settings.getData().getCommands().getAfk().getAutoAFK();

		if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && Permissions.AFK_AUTO.isAuthorized(this))
		{
			setAfk(true);
			ess.broadcastMessage(this, _("{0} is now AFK.", getPlayer().getDisplayName()));
		}
	}
Esempio n. 5
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		ISettings settings = ess.getSettings();
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final IUser player = ess.getUserMap().matchUser(args[0], false, false);
			if (!player.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));
			}
			if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
				&& !Permissions.WORLD.isAuthorized(user, player.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + player.getPlayer().getWorld().getName()));
			}
			user.sendMessage(_("teleporting"));
			final Trade charge = new Trade(commandName, ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player.getPlayer(), charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!Permissions.TPOHERE.isAuthorized(user))
			{
				throw new Exception(_("needTpohere"));
			}
			user.sendMessage(_("teleporting"));
			
			final IUser target = ess.getUserMap().matchUser(args[0], false, false);
			
			final IUser toPlayer = ess.getUserMap().matchUser(args[1], false, false);

			if (!target.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", target.getPlayer().getDisplayName()));
			}
			if (!toPlayer.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", toPlayer.getPlayer().getDisplayName()));
			}
			if (target.getPlayer().getWorld() != toPlayer.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
				&& !Permissions.WORLD.isAuthorized(user, toPlayer.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + toPlayer.getPlayer().getWorld().getName()));
			}
			target.getTeleport().now(toPlayer.getPlayer(), false, TeleportCause.COMMAND);
			target.sendMessage(_("teleportAtoB", user.getPlayer().getDisplayName(), toPlayer.getPlayer().getDisplayName()));
			break;
		}
	}
	@EventHandler(priority = EventPriority.NORMAL)
	public void onPlayerInteract(final PlayerInteractEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		user.updateActivity(true);
		switch (event.getAction())
		{
		case RIGHT_CLICK_BLOCK:
			if (event.isCancelled())
			{
				return;
			}

			final ISettings settings = ess.getSettings();
			if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK)
			{
				event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
			}
			break;
		case LEFT_CLICK_AIR:
		case LEFT_CLICK_BLOCK:
			if (user.getData().hasPowerTools() && user.getData().isPowerToolsEnabled())
			{
				if (usePowertools(user))
				{
					event.setCancelled(true);
				}
			}
			break;
		default:
			break;
		}
	}
Esempio n. 7
0
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}

		final ISettings settings = ess.getSettings();

		final net.ess3.settings.Backup backupSettings = settings.getData().getGeneral().getBackup();

		String backupCommand = backupSettings.getCommand() == null || backupSettings.getCommand().isEmpty() ? ("NORUN") : backupSettings.getCommand();
		
		/*if (backupCommand.equals("NORUN")) { TODO: Un-comment if you do not want commands to be run if there is no backup command
			return;
		}*/

		ess.getLogger().log(Level.INFO, _("backupStarted"));

		if (!backupSettings.getCommandsBeforeBackup().isEmpty())
		{
			final CommandSender consoleSender = server.getConsoleSender();
			for (String command : backupSettings.getCommandsBeforeBackup())
			{
				server.dispatchCommand(consoleSender, command);
			}
		}

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(backupCommand));
	}
	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerMove(final PlayerMoveEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());

		final ISettings settings = ess.getSettings();

		if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
		{
			final Location from = event.getFrom();
			final Location to = event.getTo().clone();
			to.setX(from.getX());
			to.setY(from.getY());
			to.setZ(from.getZ());
			try
			{
				event.setTo(LocationUtil.getSafeDestination(to));
			}
			catch (Exception ex)
			{
				event.setTo(to);
			}
			return;
		}

		final Location afk = user.getAfkPosition();
		if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9)
		{
			user.updateActivity(true);
		}
	}
Esempio n. 9
0
	public static String shortCurrency(final double value, final IEssentials ess)
	{
		@Cleanup
		final ISettings settings = ess.getSettings();
		settings.acquireReadLock();
		return settings.getData().getEconomy().getCurrencySymbol() + formatAsCurrency(value);
	}
Esempio n. 10
0
	@Override
	public boolean isGodModeEnabled()
	{
		final ISettings settings = ess.getSettings();
		return (getData().isGodmode() && !settings.getData().getWorldOptions(
				getPlayer().getLocation().getWorld().getName()).isGodmode()) || (getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers());
	}
Esempio n. 11
0
	public void enableInvulnerabilityAfterTeleport()
	{
		final ISettings settings = ess.getSettings();

		final long time = settings.getData().getCommands().getTeleport().getInvulnerability();
		if (time > 0)
		{
			teleportInvulnerabilityTimestamp = System.currentTimeMillis() + time;
		}
	}
Esempio n. 12
0
	@Override
	public boolean canAfford(final double cost)
	{
		final double mon = getMoney();
		if (Permissions.ECO_LOAN.isAuthorized(this))
		{
			final ISettings settings = ess.getSettings();
			return (mon - cost) >= settings.getData().getEconomy().getMinMoney();
		}
		return cost <= mon;
	}
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPlayerQuit(final PlayerQuitEvent event)
	{
		final String quitMessage = ess.getSettings().getData().getGeneral().getLeaveMessage();
		if (quitMessage != null)
		{
			final IText itOutput = new KeywordReplacer(new SimpleTextInput(quitMessage), userMap.getUser(event.getPlayer()), ess);
			final SimpleTextPager stPager = new SimpleTextPager(itOutput);
			event.setQuitMessage(FormatUtil.replaceFormat(stPager.getString(0)));
		}
		else
		{
			event.setQuitMessage(null);
		}


		final IUser user = userMap.getUser(event.getPlayer());

		final ISettings settings = ess.getSettings();
		if (settings.getData().getCommands().getGod().isRemoveOnDisconnect() && user.isGodModeEnabled())
		{
			user.setGodModeEnabled(false);
		}
		if (user.isVanished())
		{
			user.toggleVanished();
		}
		if (user.getData().getInventory() != null)
		{
			user.getPlayer().getInventory().setContents(user.getData().getInventory().getBukkitInventory());
			user.getData().setInventory(null);
		}
		user.updateActivity(false);
		//user.getPlayer().dispose();
		if (settings.getData().getGeneral().isPtClearOnQuit())
		{
			user.getData().clearAllPowertools();
			user.queueSave();
			user.sendMessage(_("§6All powertool commands have been cleared."));
		}
	}
Esempio n. 14
0
	@Override
	public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{

		IUser user = null;
		if (sender instanceof Player)
		{
			user = ess.getUser(((Player)sender));
		}
		if ((args.length < 1 || !Permissions.LIGHTNING_OTHERS.isAuthorized(user)) && user != null)
		{
			user.getWorld().strikeLightning(user.getTargetBlock(null, 600).getLocation());
			return;
		}

		if (server.matchPlayer(args[0]).isEmpty())
		{
			throw new Exception(_("playerNotFound"));
		}

		int power = 5;
		if (args.length > 1)
		{
			try
			{
				power = Integer.parseInt(args[1]);
			}
			catch (NumberFormatException ex)
			{
			}
		}

		for (Player matchPlayer : server.matchPlayer(args[0]))
		{
			sender.sendMessage(_("lightningUse", matchPlayer.getDisplayName()));
			final LightningStrike strike = matchPlayer.getWorld().strikeLightningEffect(matchPlayer.getLocation());
			if (!ess.getUser(matchPlayer).isGodModeEnabled())
			{
				matchPlayer.damage(power, strike);
			}
			@Cleanup
			final ISettings settings = ess.getSettings();
			settings.acquireReadLock();
			if (settings.getData().getCommands().getLightning().isWarnPlayer())
			{
				matchPlayer.sendMessage(_("lightningSmited"));
			}
		}
	}
	@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
	public void onPlayerPickupItem(final PlayerPickupItemEvent event)
	{
		final ISettings settings = ess.getSettings();
		if (!settings.getData().getCommands().getAfk().isDisableItemPickupWhileAfk())
		{
			return;
		}

		final IUser user = userMap.getUser(event.getPlayer());
		if (user.getData().isAfk())
		{
			event.setCancelled(true);
		}
	}
Esempio n. 16
0
	@Override
	public final void startTask()
	{
		if (running.compareAndSet(false, true))
		{
			final ISettings settings = ess.getSettings();
			final long interval = settings.getData().getGeneral().getBackup().getInterval() * 1200; // minutes -> ticks
			if (interval < 1200)
			{
				running.set(false);
				return;
			}
			taskId = ess.getPlugin().scheduleSyncRepeatingTask(this, interval, interval);
		}
	}
Esempio n. 17
0
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}
		@Cleanup
		final ISettings settings = ess.getSettings();
		settings.acquireReadLock();
		final String command = settings.getData().getGeneral().getBackup().getCommand();
		if (command == null || command.isEmpty())
		{
			return;
		}
		ess.getLogger().log(Level.INFO, _("backupStarted"));
		final CommandSender consoleSender = server.getConsoleSender();
		server.dispatchCommand(consoleSender, "save-all");
		server.dispatchCommand(consoleSender, "save-off");

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(command));
	}
Esempio n. 18
0
	private boolean giveItemStack(ItemStack itemStack, Boolean canSpew) throws ChargeException
	{
		boolean spew = false;

		if (itemStack == null || itemStack.getTypeId() == 0)
		{
			return spew;
		}

		final Map<Integer, ItemStack> overfilled;
		if (Permissions.OVERSIZEDSTACKS.isAuthorized(this))
		{
			final ISettings settings = ess.getSettings();
			int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();

			overfilled = InventoryWorkaround.addOversizedItems(getPlayer().getInventory(), oversizedStackSize, itemStack);
		}
		else
		{
			overfilled = InventoryWorkaround.addItems(getPlayer().getInventory(), itemStack);
		}
		if (canSpew)
		{
			for (ItemStack overflowStack : overfilled.values())
			{
				getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), overflowStack);
				spew = true;
			}
		}
		else
		{
			if (!overfilled.isEmpty())
			{
				throw new ChargeException("Inventory full");
			}
		}
		return spew;
	}
Esempio n. 19
0
	public HelpInput(final IUser user, final String match, final IEssentials ess) throws IOException
	{
		final ISettings settings = ess.getSettings();
		boolean reported = false;
		final List<String> newLines = new ArrayList<String>();
		String pluginName = "";
		String pluginNameLow = "";
		if (!match.equalsIgnoreCase(""))
		{
			lines.add(_("Commands matching \"{0}\":", match));
		}

		for (Plugin p : ess.getServer().getPluginManager().getPlugins())
		{
			try
			{
				final List<String> pluginLines = new ArrayList<String>();
				final PluginDescriptionFile desc = p.getDescription();
				final Map<String, Map<String, Object>> cmds = desc.getCommands();
				pluginName = p.getDescription().getName();
				pluginNameLow = pluginName.toLowerCase(Locale.ENGLISH);
				if (pluginNameLow.equals(match))
				{
					lines.clear();
					newLines.clear();
					lines.add(_("Commands from {0}:", p.getDescription().getName()));
				}

				for (Map.Entry<String, Map<String, Object>> k : cmds.entrySet())
				{
					try
					{
						if (!match.equalsIgnoreCase("") && (!pluginNameLow.contains(match)) && (!k.getKey().toLowerCase(Locale.ENGLISH).contains(
								match)) && (!(k.getValue().get(DESCRIPTION) instanceof String && ((String)k.getValue().get(DESCRIPTION)).toLowerCase(
								Locale.ENGLISH).contains(match))))
						{
							continue;
						}

						if (pluginNameLow.contains("essentials"))
						{
							final String node = "essentials." + k.getKey();
							if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.hasPermission(node))
							{
								pluginLines.add(_("/{0}: {1}", k.getKey(), k.getValue().get(DESCRIPTION)));
							}
						}
						else
						{
							if (settings.getData().getCommands().getHelp().isShowNonEssCommandsInHelp())
							{
								final Map<String, Object> value = k.getValue();
								Object permissions = null;
								if (value.containsKey(PERMISSION))
								{
									permissions = value.get(PERMISSION);
								}
								else if (value.containsKey(PERMISSIONS))
								{
									permissions = value.get(PERMISSIONS);
								}
								if (Permissions.HELP.isAuthorized(user, pluginNameLow))
								{
									pluginLines.add(_("/{0}: {1}", k.getKey(), value.get(DESCRIPTION)));
								}
								else if (permissions instanceof List && !((List<Object>)permissions).isEmpty())
								{
									boolean enabled = false;
									for (Object o : (List<Object>)permissions)
									{
										if (o instanceof String && user.hasPermission(o.toString()))
										{
											enabled = true;
											break;
										}
									}
									if (enabled)
									{
										pluginLines.add(_("/{0}: {1}", k.getKey(), value.get(DESCRIPTION)));
									}
								}
								else if (permissions instanceof String && !"".equals(permissions))
								{
									if (user.hasPermission(permissions.toString()))
									{
										pluginLines.add(_("/{0}: {1}", k.getKey(), value.get(DESCRIPTION)));
									}
								}
								else
								{
									if (!settings.getData().getCommands().getHelp().isHidePermissionlessCommands())
									{
										pluginLines.add(_("/{0}: {1}", k.getKey(), value.get(DESCRIPTION)));
									}
								}
							}
						}
					}
					catch (NullPointerException ex)
					{
						continue;
					}
				}
				if (!pluginLines.isEmpty())
				{
					newLines.addAll(pluginLines);
					if (pluginNameLow.equals(match))
					{
						break;
					}
					if (match.equalsIgnoreCase(""))
					{
						lines.add(_("{0}: Plugin Help: /help {1}", pluginName, pluginNameLow));
					}
				}
			}
			catch (NullPointerException ex)
			{
				continue;
			}
			catch (Exception ex)
			{
				if (!reported)
				{
					logger.log(Level.WARNING, _("Error getting help for: {0}", pluginNameLow), ex);
				}
				reported = true;
				continue;
			}
		}
		lines.addAll(newLines);
	}
	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerTeleport(final PlayerTeleportEvent event)
	{

		final ISettings settings = ess.getSettings();
		//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
		if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && settings.getData().getCommands().getBack().isRegisterBackInListener())
		{
			final IUser user = userMap.getUser(event.getPlayer());
			user.setLastLocation();
		}

	}
	@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;
		}
	}