public EssentialsPlayerListener(final IEssentials parent)
	{
		super();
		this.ess = parent;
		userMap = ess.getUserMap();
		this.server = parent.getServer();
	}
	public final void addPlugin(final Plugin plugin)
	{
		if (plugin.getDescription().getMain().contains("com.earth2me.essentials"))
		{
			return;
		}
		final List<Command> commands = PluginCommandYamlParser.parse(plugin);
		final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH);

		for (Command command : commands)
		{
			final PluginCommand pc = (PluginCommand)command;
			final List<String> labels = new ArrayList<String>(pc.getAliases());
			labels.add(pc.getName());

			PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH));
			if (reg == null)
			{
				reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH));
			}
			if (reg == null || !reg.getPlugin().equals(plugin))
			{
				continue;
			}
			for (String label : labels)
			{
				List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH));
				if (plugincommands == null)
				{
					plugincommands = new ArrayList<PluginCommand>();
					altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands);
				}
				boolean found = false;
				for (PluginCommand pc2 : plugincommands)
				{
					if (pc2.getPlugin().equals(plugin))
					{
						found = true;
					}
				}
				if (!found)
				{
					plugincommands.add(reg);
				}
			}
		}
	}
Exemple #3
0
	public Backup(final IEssentials ess)
	{
		this.ess = ess;
		server = ess.getServer();
		if (!server.getOnlinePlayers().isEmpty())
		{
			startTask();
		}
	}
Exemple #4
0
	public Backup(final IEssentials ess)
	{
		this.ess = ess;
		server = ess.getServer();
		if (server.getOnlinePlayers().length > 0)
		{
			startTask();
		}
	}
Exemple #5
0
  @Override
  public User load(final String stringUUID) throws Exception {
    UUID uuid = UUID.fromString(stringUUID);
    Player player = ess.getServer().getPlayer(uuid);
    if (player != null) {
      final User user = new User(player, ess);
      trackUUID(uuid, user.getName(), true);
      return user;
    }

    final File userFile = getUserFileFromID(uuid);

    if (userFile.exists()) {
      player = new OfflinePlayer(uuid, ess.getServer());
      final User user = new User(player, ess);
      ((OfflinePlayer) player).setName(user.getLastAccountName());
      trackUUID(uuid, user.getName(), false);
      return user;
    }

    throw new Exception("User not found!");
  }
	public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module, IEssentials ess)
	{
		this.classLoader = classLoader;
		this.commandPath = commandPath;
		this.permissionPrefix = permissionPrefix;
		this.module = module;
		this.ess = ess;
		for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
		{
			if (plugin.isEnabled())
			{
				addPlugin(plugin);
			}
		}
	}
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPluginEnable(final PluginEnableEvent event) {
   if (event.getPlugin().getName().equals("EssentialsChat")) {
     ess.getSettings().setEssentialsChatActive(true);
   }
   ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
   ess.getPermissionsHandler().checkPermissions();
   ess.getAlternativeCommandsHandler().addPlugin(event.getPlugin());
   if (!Methods.hasMethod() && Methods.setMethod(ess.getServer().getPluginManager())) {
     ess.getLogger()
         .log(
             Level.INFO,
             "Payment method found ("
                 + Methods.getMethod().getLongName()
                 + " version: "
                 + ess.getPaymentMethod().getMethod().getVersion()
                 + ")");
   }
 }
Exemple #8
0
  public User getUser(final String name) {
    try {
      final String sanitizedName = StringUtil.safeString(name);
      if (names.containsKey(sanitizedName)) {
        final UUID uuid = names.get(sanitizedName);
        return getUser(uuid);
      }

      final File userFile = getUserFileFromString(sanitizedName);
      if (userFile.exists()) {
        ess.getLogger().info("Importing user " + name + " to usermap.");
        User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
        trackUUID(user.getBase().getUniqueId(), user.getName(), true);
        return user;
      }
      return null;
    } catch (UncheckedExecutionException ex) {
      return null;
    }
  }
	@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
	public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		final String cmd = spaceSplit.split(event.getMessage().toLowerCase(Locale.ENGLISH))[0].replace("/", "").toLowerCase(Locale.ENGLISH);
		if (ess.getSettings().getData().getCommands().getSocialspy().getSocialspyCommands().contains(cmd))
		{
			for (Player player : ess.getServer().getOnlinePlayers())
			{
				IUser spyer = userMap.getUser(player);
				if (spyer.getData().isSocialspy() && !user.equals(spyer))
				{
					player.sendMessage(user.getPlayer().getDisplayName() + " : " + event.getMessage());
				}
			}
		}
		if (!cmd.equalsIgnoreCase("afk"))
		{
			user.updateActivity(true);
		}
	}
Exemple #10
0
	public static void registerPermissions(String path, Collection<String> nodes, boolean hasDefault, IEssentials ess)
	{
		if (nodes == null || nodes.isEmpty())
		{
			return;
		}
		final PluginManager pluginManager = ess.getServer().getPluginManager();
		Permission basePerm = pluginManager.getPermission(path + ".*");
		if (basePerm != null && !basePerm.getChildren().isEmpty())
		{
			basePerm.getChildren().clear();
		}
		if (basePerm == null)
		{
			basePerm = new Permission(path + ".*", PermissionDefault.OP);
			pluginManager.addPermission(basePerm);
			Permission mainPerm = pluginManager.getPermission("essentials.*");
			if (mainPerm == null)
			{
				mainPerm = new Permission("essentials.*", PermissionDefault.OP);
				pluginManager.addPermission(mainPerm);
			}
			mainPerm.getChildren().put(basePerm.getName(), Boolean.TRUE);
		}

		for (String nodeName : nodes)
		{
			final String permissionName = path + "." + nodeName;
			Permission perm = pluginManager.getPermission(permissionName);
			if (perm == null)
			{
				final PermissionDefault defaultPerm = hasDefault && nodeName.equalsIgnoreCase("default") ? PermissionDefault.TRUE : PermissionDefault.OP;
				perm = new Permission(permissionName, defaultPerm);
				pluginManager.addPermission(perm);
			}
			basePerm.getChildren().put(permissionName, Boolean.TRUE);
		}
		basePerm.recalculatePermissibles();
	}
Exemple #11
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);
	}