Exemple #1
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("kits")) {
     if (!plugin.isAuthorized(cs, "rcmds.kits")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (!(cs instanceof Player) && args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     final Map<String, Object> opts =
         plugin.getConfig().getConfigurationSection("kits").getValues(false);
     if (opts.keySet().isEmpty()) {
       cs.sendMessage(ChatColor.RED + "No kits found!");
       return true;
     }
     String kits = "";
     for (String s : opts.keySet()) {
       if (plugin.kitPerms && plugin.isAuthorized(cs, "rcmds.kit." + s))
         kits = (kits.isEmpty()) ? kits + s : kits + ", " + s;
       else if (!plugin.kitPerms) kits = (kits.isEmpty()) ? kits + s : kits + ", " + s;
     }
     cs.sendMessage(ChatColor.BLUE + "Kits:");
     if (kits.isEmpty()) return true;
     cs.sendMessage(kits);
     return true;
   }
   return false;
 }
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("mobignore")) {
     if (!plugin.ah.isAuthorized(cs, "rcmds.mobignore")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       if (!(cs instanceof Player)) {
         cs.sendMessage(cmd.getDescription());
         return false;
       }
       Player p = (Player) cs;
       PConfManager pcm = PConfManager.getPConfManager(p);
       Boolean isHidden = pcm.getBoolean("mobignored");
       if (isHidden == null) isHidden = false;
       pcm.set("mobignored", !isHidden);
       String status = BooleanUtils.toStringOnOff(isHidden);
       cs.sendMessage(
           MessageColor.POSITIVE
               + "Toggled mob ignore "
               + MessageColor.NEUTRAL
               + status
               + MessageColor.POSITIVE
               + ".");
       return true;
     }
     Player t = plugin.getServer().getPlayer(args[0]);
     if (t == null || plugin.isVanished(t, cs)) {
       cs.sendMessage(MessageColor.NEGATIVE + "That player does not exist.");
       return true;
     }
     PConfManager pcm = PConfManager.getPConfManager(t);
     Boolean isHidden = pcm.getBoolean("mobignored");
     if (isHidden == null) isHidden = false;
     pcm.set("mobignored", !isHidden);
     String status = BooleanUtils.toStringOnOff(isHidden);
     cs.sendMessage(
         MessageColor.POSITIVE
             + "Toggled mob ignore "
             + MessageColor.NEUTRAL
             + status
             + MessageColor.POSITIVE
             + " for "
             + MessageColor.NEUTRAL
             + t.getName()
             + MessageColor.POSITIVE
             + ".");
     t.sendMessage(
         MessageColor.NEUTRAL
             + cs.getName()
             + MessageColor.POSITIVE
             + " toggled mob ignore "
             + MessageColor.NEUTRAL
             + status
             + MessageColor.POSITIVE
             + " for you.");
     return true;
   }
   return false;
 }
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("loadplayer")) {
     if (!plugin.ah.isAuthorized(cs, "rcmds.loadplayer")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     final Player t = plugin.getServer().getPlayer(args[0]);
     if (t == null) {
       cs.sendMessage(MessageColor.NEGATIVE + "No such player!");
       return true;
     }
     if (!t.getName().equals(cs.getName())
         && !plugin.ah.isAuthorized(cs, "rcmds.others.loadplayer")) {
       cs.sendMessage(MessageColor.NEGATIVE + "You cannot load other players' data!");
       return true;
     }
     t.loadData();
     cs.sendMessage(MessageColor.POSITIVE + "Data loaded.");
     return true;
   }
   return false;
 }
Exemple #4
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("kill")) {
     if (!plugin.isAuthorized(cs, "rcmds.kill")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player t = plugin.getServer().getPlayer(args[0].trim());
     if (t == null || plugin.isVanished(t, cs)) {
       cs.sendMessage(ChatColor.RED + "That player does not exist!");
       return true;
     }
     if (plugin.isAuthorized(t, "rcmds.exempt.kill")) {
       cs.sendMessage(ChatColor.RED + "You cannot kill that player!");
       return true;
     }
     t.setHealth(0);
     cs.sendMessage(
         ChatColor.BLUE
             + "You have killed "
             + ChatColor.GRAY
             + t.getDisplayName()
             + ChatColor.BLUE
             + ".");
     return true;
   }
   return false;
 }
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equals("playertime")) {
     if (!plugin.isAuthorized(cs, "rcmds.playertime")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player t = plugin.getServer().getPlayer(args[0]);
     if (t == null || plugin.isVanished(t, cs)) {
       cs.sendMessage(ChatColor.RED + "That player does not exist!");
       return true;
     }
     String possessive = (t.getName().toLowerCase().endsWith("s")) ? "'" : "'s";
     Integer time = null;
     if (args.length > 1) {
       try {
         time = Integer.valueOf(args[1]);
       } catch (Exception e) {
         cs.sendMessage(ChatColor.RED + "That time was invalid!");
         return true;
       }
     }
     if (time == null) {
       t.resetPlayerTime();
       cs.sendMessage(
           ChatColor.BLUE
               + "Synced "
               + ChatColor.GRAY
               + t.getName()
               + possessive
               + ChatColor.BLUE
               + " time with the server's.");
       return true;
     }
     if (plugin.smoothTime) smoothPlayerTimeChange(time, t);
     t.setPlayerTime(time, true);
     cs.sendMessage(
         ChatColor.BLUE
             + "Set "
             + ChatColor.GRAY
             + t.getName()
             + possessive
             + ChatColor.BLUE
             + " time to "
             + ChatColor.GRAY
             + time
             + " ticks"
             + ChatColor.BLUE
             + ".");
     return true;
   }
   return false;
 }
 @Override
 public void sendCommandList(CommandSender sender) {
   Player player = null;
   if (sender instanceof Player) {
     player = (Player) sender;
   }
   if (player != null) {
     Command c = plugin.getCommand("ignore");
     if (PickleCraftPlugin.hasPerm(player, c.getPermission())) {
       player.sendMessage(
           plugin.getStringFromConfig("ignorecraft.messages.commandhelplist.header"));
       player.sendMessage(c.getUsage() + " " + c.getDescription());
       c = plugin.getCommand("ignoreall");
       player.sendMessage(c.getUsage() + " " + c.getDescription());
       c = plugin.getCommand("ignorelist");
       player.sendMessage(c.getUsage() + " " + c.getDescription());
     }
   }
 }
Exemple #7
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("banip")) {
     if (!plugin.ah.isAuthorized(cs, "rcmds.banip")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     OfflinePlayer op = plugin.getServer().getOfflinePlayer(args[0]);
     String ip =
         (!op.hasPlayedBefore()) ? args[0] : PConfManager.getPConfManager(op).getString("ip");
     if (ip == null) ip = args[0];
     if (!isValid(ip)) {
       cs.sendMessage(
           MessageColor.NEGATIVE
               + "Invalid IP ("
               + MessageColor.NEUTRAL
               + ip
               + MessageColor.NEGATIVE
               + ").");
       return true;
     }
     plugin.getServer().banIP(ip);
     if (!op.hasPlayedBefore()) {
       cs.sendMessage(
           MessageColor.POSITIVE
               + "Banned IP "
               + MessageColor.NEUTRAL
               + ip
               + MessageColor.POSITIVE
               + ".");
       return true;
     } else {
       op.setBanned(true);
       RUtils.writeBanHistory(op);
       cs.sendMessage(
           MessageColor.POSITIVE
               + "Banned IP of "
               + MessageColor.NEUTRAL
               + op.getName()
               + MessageColor.POSITIVE
               + " ("
               + MessageColor.NEUTRAL
               + ip
               + MessageColor.POSITIVE
               + ").");
       return true;
     }
   }
   return false;
 }
Exemple #8
0
 @Override
 public boolean runCommand(
     final CommandSender cs, final Command cmd, final String label, final String[] args) {
   if (args.length < 1) {
     cs.sendMessage(cmd.getDescription());
     return false;
   }
   final OfflinePlayer t = RUtils.getOfflinePlayer(args[0]);
   if (t.isOnline() && !this.plugin.isVanished((Player) t, cs)) {
     cs.sendMessage(
         MessageColor.POSITIVE
             + "The player "
             + MessageColor.NEUTRAL
             + t.getName()
             + MessageColor.POSITIVE
             + " was last seen "
             + MessageColor.NEUTRAL
             + "now"
             + MessageColor.POSITIVE
             + ".");
     return true;
   }
   final PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(t);
   if (!pcm.exists()) {
     cs.sendMessage(MessageColor.NEGATIVE + "That player doesn't exist!");
     return true;
   }
   if (pcm.get("seen") == null) {
     cs.sendMessage(MessageColor.NEGATIVE + "I don't know when that player was last seen!");
     return true;
   }
   final long seen = pcm.getLong("seen");
   if (seen < 1L) {
     cs.sendMessage(MessageColor.NEGATIVE + "I don't know when that player was last seen!");
     return true;
   }
   final String lastseen = RUtils.formatDateDiff(seen);
   cs.sendMessage(
       MessageColor.POSITIVE
           + "The player "
           + MessageColor.NEUTRAL
           + t.getName()
           + MessageColor.POSITIVE
           + " was last seen"
           + MessageColor.NEUTRAL
           + lastseen
           + MessageColor.POSITIVE
           + " ago.");
   return true;
 }
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("teleport")) {
     if (!plugin.ah.isAuthorized(cs, "rcmds.teleport")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (!(cs instanceof Player)) {
       cs.sendMessage(MessageColor.NEGATIVE + "This command is only available to players!");
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player t = plugin.getServer().getPlayer(args[0]);
     if (t == null || plugin.isVanished(t, cs)) {
       cs.sendMessage(MessageColor.NEGATIVE + "That player does not exist!");
       return true;
     }
     if (!RUtils.isTeleportAllowed(t) && !plugin.ah.isAuthorized(cs, "rcmds.tpoverride")) {
       cs.sendMessage(MessageColor.NEGATIVE + "That player has teleportation off!");
       return true;
     }
     Player p = (Player) cs;
     p.sendMessage(
         MessageColor.POSITIVE
             + "Teleporting you to "
             + MessageColor.NEUTRAL
             + t.getName()
             + MessageColor.POSITIVE
             + ".");
     String error = RUtils.teleport(p, t);
     if (!error.isEmpty()) {
       p.sendMessage(MessageColor.NEGATIVE + error);
       return true;
     }
     return true;
   }
   return false;
 }
Exemple #10
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("slap")) {
     if (!plugin.isAuthorized(cs, "rcmds.slap")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player victim;
     victim = plugin.getServer().getPlayer(args[0]);
     if (victim == null || plugin.isVanished(victim)) {
       cs.sendMessage(ChatColor.RED + "That person is not online!");
       return true;
     }
     if (plugin.isAuthorized(victim, "rcmds.exempt.slap")) {
       cs.sendMessage(ChatColor.RED + "You may not slap that player.");
       return true;
     }
     Vector push = victim.getVelocity();
     push.setY(push.getY() + .5);
     push.setX(push.getX() + .5);
     push.setZ(push.getZ() + .5);
     victim.setVelocity(push);
     plugin
         .getServer()
         .broadcastMessage(
             ChatColor.GOLD
                 + cs.getName()
                 + ChatColor.WHITE
                 + " slaps "
                 + ChatColor.RED
                 + victim.getName()
                 + ChatColor.WHITE
                 + "!");
     return true;
   }
   return false;
 }
Exemple #11
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("banned")) {
     if (!plugin.isAuthorized(cs, "rcmds.banned")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     OfflinePlayer t = plugin.getServer().getOfflinePlayer(args[0]);
     if (!t.isBanned()) {
       cs.sendMessage(ChatColor.GREEN + t.getName() + ChatColor.WHITE + " is not banned.");
       return true;
     }
     cs.sendMessage(ChatColor.RED + t.getName() + ChatColor.WHITE + " is banned.");
     return true;
   }
   return false;
 }
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("vtphere")) {
     if (!plugin.isAuthorized(cs, "rcmds.vtphere")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player victim = plugin.getServer().getPlayer(args[0]);
     if (victim == null) {
       cs.sendMessage(ChatColor.RED + "That player does not exist!");
       return true;
     }
     if (!(cs instanceof Player)) {
       cs.sendMessage(ChatColor.RED + "This command cannot be used in console.");
       return true;
     }
     Player player = (Player) cs;
     cs.sendMessage(
         ChatColor.BLUE
             + "Teleporting player "
             + ChatColor.GRAY
             + victim.getName()
             + ChatColor.BLUE
             + " to you.");
     String error = RUtils.teleport(victim, player);
     if (!error.isEmpty()) {
       cs.sendMessage(ChatColor.RED + error);
       return true;
     }
     return true;
   }
   return false;
 }
Exemple #13
0
  @Override
  public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("weather")) {
      if (!plugin.isAuthorized(cs, "rcmds.weather")) {
        RUtils.dispNoPerms(cs);
        return true;
      }
      if (args.length < 1) {
        cs.sendMessage(cmd.getDescription());
        return false;
      }

      if (!(cs instanceof Player)) {
        cs.sendMessage(ChatColor.RED + "This command is only available to players!");
        return true;
      }
      if (args.length == 1) {
        Player p = (Player) cs;
        changeWeather(p, args[0].trim());
        return true;
      } else if (args.length == 2) {
        Player p = (Player) cs;
        String conds = args[0].trim();
        String slength = args[1].trim();
        int length;
        try {
          length = Integer.parseInt(slength);
        } catch (Exception e) {
          p.sendMessage(ChatColor.RED + "The time specified was invalid!");
          return true;
        }
        changeWeather(p, conds, length);
        return true;
      }
    }
    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;
		}
	}
Exemple #15
0
	@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;
		}
	}