Exemplo n.º 1
0
	public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
	{
		final ISign sign = new EventSign(event);
		final IUser user = ess.getUserMap().getUser(event.getPlayer());
		if (!SignsPermissions.CREATE.isAuthorized(user, signName))
		{
			// Return true, so other plugins can use the same sign title, just hope
			// they won't change it to §1[Signname]
			return true;
		}
		sign.setLine(0, _("[{0}]", this.signName));
		try
		{
			final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
			if (ret)
			{
				sign.setLine(0, getSuccessName());
			}
			return ret;
		}
		catch (ChargeException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
		}
		catch (SignException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
		}
		// Return true, so the player sees the wrong sign.
		return true;
	}
	public EssentialsPlayerListener(final IEssentials parent)
	{
		super();
		this.ess = parent;
		userMap = ess.getUserMap();
		this.server = parent.getServer();
	}
Exemplo n.º 3
0
	public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
	{
		final IUser user = ess.getUserMap().getUser(player);
		try
		{
			return onBlockBreak(block, user, getUsername(user), ess);
		}
		catch (SignException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
		}
		return false;
	}
Exemplo n.º 4
0
	public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
	{
		final ISign sign = new BlockSign(block);
		final IUser user = ess.getUserMap().getUser(player);
		try
		{
			return SignsPermissions.BREAK.isAuthorized(user, signName) && onSignBreak(sign, user, getUsername(user), ess);
		}
		catch (SignException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
			return false;
		}
	}
Exemplo n.º 5
0
	public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess, final ISignsPlugin isp)
	{
		final ISign sign = new BlockSign(block);
		final IUser user = ess.getUserMap().getUser(player);
		if (user.checkSignThrottle(isp.getSettings().getData().getSignUsePerSecond()))
		{
			return false;
		}
		try
		{
			return SignsPermissions.USE.isAuthorized(user, signName) && onSignInteract(sign, user, getUsername(user), ess);
		}
		catch (ChargeException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
			return false;
		}
		catch (SignException ex)
		{
			ess.getCommandHandler().showCommandError(user, signName, ex);
			return false;
		}
	}
	@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;
		}
	}
Exemplo n.º 7
0
	@Override
	public IUser getUserByAddress(final String address)
	{
		String username = instance.users.getUserByAddress(address);
		return username == null ? null : ess.getUserMap().getUser(username);
	}