Ejemplo n.º 1
0
 public boolean showUsage(Command command) {
   commandSender.sendMessage(
       ChatColor.YELLOW
           + "Usage: "
           + command.getUsage().replaceAll("<command>", command.getName()));
   return true;
 }
Ejemplo n.º 2
0
 @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());
     }
   }
 }
Ejemplo n.º 3
0
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (isName(cmd.getName(), args)) return findName(sender, args);
    else if (isNick(cmd.getName(), args)) return findNick(sender, args);
    else if (isReload(cmd.getName(), args)) return reloadConfig(sender);
    else if (isVersion(cmd.getName(), args)) return showVersion(sender);
    else if (isHelp(cmd.getName(), args)) return showHelp(sender, label);
    else if (isNameButWrongArgs(cmd.getName(), args)) {
      sender.sendMessage(cmd.getUsage().replace("<command>", label));
      return true;
    }

    return false;
  }
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length > 0) {

      // TODO: check correctness of arguments, we expect "user" "reason" "the" "rest" "is"
      // "description"

      String description = null;

      if (args.length > 2) {
        description = args[2];
        for (int i = 3; i < args.length; i++) {
          description += " " + args[i];
        }
      }

      reportCmd(sender.getName(), args[0], description);

    } else {
      sender.sendMessage(command.getUsage());
    }
    return false;
  }
Ejemplo n.º 5
0
  // Command Handlers
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Player player = null;
    if (sender instanceof Player) {
      player = (Player) sender;
    }
    if (cmd.getName().equalsIgnoreCase("shout")) {
      if (player == null) {
        sender.sendMessage("This command can only be run by a player");
      } else {
        if (!BH.shoutUsed(player)) {
          if (args.length > 0) {
            BH.broadcast(player, args);
            BH.usedShout(player);
          } else {
            player.sendMessage(ChatColor.RED + "Usage: " + cmd.getUsage());
          }
        } else {
          BH.sendTimeRemain(player);
        }
      }
      return true;
    }
    if (cmd.getName().equalsIgnoreCase("apb")) {
      if (player == null) {
        sender.sendMessage("This command can only be run by a player.");
      } else {
        if (args.length > 0) {
          BH.perfAdminShout(player, args);
          return true;
        }
      }
      return false;
    }

    return false;
  }
Ejemplo n.º 6
0
  @Override
  public void performCommand(CommandSender sender, Command command, String[] args) {
    if (args.length >= 1) {
      if (args[0].equalsIgnoreCase("join")) {
        if (args.length < 2) {
          if (args.length < 3 && !(sender instanceof Player)) {
            throw new WrongUsageException("/team join <team> <player> [keepInventory]");
          } else {
            throw new WrongUsageException("/team join <team> [player] [keepInventory]");
          }
        }

        joinTeam(sender, args);
      } else if (args[0].equalsIgnoreCase("leave")) {
        if (args.length < 2 && !(sender instanceof Player)) {
          throw new WrongUsageException("/team leave <player>");
        }

        leaveTeam(sender, args);
      }
    } else {
      throw new WrongUsageException(command.getUsage());
    }
  }
 public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) {
   String pname = sender.getName();
   String password = LoginData.getPass(pname.toLowerCase(), plugin);
   if (!(sender instanceof Player)) {
     return true;
   }
   if (args.length < 2) {
     sender.sendMessage("[LoginSecurity] " + ChatColor.RED + Messages.getMessage(9, plugin));
     sender.sendMessage(cmnd.getUsage());
     return true;
   }
   if (args.length > 2) {
     sender.sendMessage("[LoginSecurity] " + ChatColor.RED + Messages.getMessage(10, plugin));
     sender.sendMessage(cmnd.getUsage());
     return true;
   }
   if (args[1].length() < plugin.getConfig().getInt("options.min-length")) {
     String min = String.valueOf(plugin.getConfig().getInt("options.min-length"));
     sender.sendMessage(
         "[LoginSecurity] "
             + ChatColor.RED
             + Messages.getMessage(2, plugin).replace("{Min}", min));
     return true;
   }
   if (args[1].length() > plugin.getConfig().getInt("options.max-lenght")) {
     String max = String.valueOf(plugin.getConfig().getInt("options.max-lenght"));
     sender.sendMessage(
         "[LoginSecurity] "
             + ChatColor.RED
             + Messages.getMessage(3, plugin).replace("{Max}", max));
     return true;
   }
   if (plugin.getConfig().getBoolean("options.use-MD5 Enryption") == true) {
     try {
       MessageDigest md1 = MessageDigest.getInstance("MD5");
       MessageDigest md2 = MessageDigest.getInstance("MD5");
       md1.update(args[0].getBytes(), 0, args[0].length());
       md2.update(args[1].getBytes(), 0, args[1].length());
       if (new BigInteger(1, md1.digest()).toString(16).equals(password)) {
         LoginData.setPass(
             pname.toLowerCase(), new BigInteger(1, md2.digest()).toString(16), plugin, 1);
         sender.sendMessage(
             "[LoginSecurity] "
                 + ChatColor.GREEN
                 + Messages.getMessage(12, plugin).replace("{Password}", args[1]));
       } else {
         sender.sendMessage("[LoginSecurity] " + ChatColor.BLUE + Messages.getMessage(4, plugin));
         return true;
       }
     } catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
     }
   } else {
     if (args[0].equals(password)) {
       LoginData.setPass(pname.toLowerCase(), args[1], plugin, 1);
       sender.sendMessage(
           "[LoginSecurity] "
               + ChatColor.GREEN
               + Messages.getMessage(12, plugin).replace("{Password}", args[1]));
     } else {
       sender.sendMessage("[LoginSecurity] " + ChatColor.BLUE + Messages.getMessage(4, plugin));
       return true;
     }
   }
   return true;
 }
	@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;
		}
	}
Ejemplo n.º 9
0
  /* (non-Javadoc)
   * @see org.morganm.homespawnplus.command.Command#execute(org.bukkit.entity.Player, org.bukkit.command.Command, java.lang.String[])
   */
  @Override
  public boolean execute(Player p, Command command, String[] args) {
    if (!defaultCommandChecks(p)) return true;

    if (args.length < 1) {
      util.sendMessage(p, command.getUsage());
      //			util.sendMessage(p, "Usage:");
      //			util.sendMessage(p, "  /homeother player : go to \"player\"'s home on current world");
      //			util.sendMessage(p, "  /homeother player w:world_name : go to \"player\"'s home on world
      // \"world_name\"");
      //			util.sendMessage(p, "  /homeother player home_name : go to \"player\"'s home named
      // \"home_name\"");
      return true;
    }

    final String playerName = args[0];
    String worldName = null;
    String homeName = null;

    for (int i = 1; i < args.length; i++) {
      if (args[i].startsWith("w:")) {
        worldName = args[i].substring(2);
      } else {
        if (homeName != null) {
          util.sendLocalizedMessage(p, HSPMessages.TOO_MANY_ARGUMENTS);
          //					util.sendMessage(p,  "Too many arguments");
          return true;
        }
        homeName = args[i];
      }
    }

    if (worldName == null) worldName = p.getWorld().getName();

    org.morganm.homespawnplus.entity.Home home;
    if (homeName != null) {
      home = plugin.getStorage().getNamedHome(homeName, playerName);
    } else {
      home = util.getDefaultHome(playerName, worldName);
    }

    // didn't find an exact match?  try a best guess match
    if (home == null) home = util.getBestMatchHome(playerName, worldName);

    if (home != null) {
      util.sendLocalizedMessage(
          p,
          HSPMessages.CMD_HOMEOTHER_TELEPORTING,
          "home",
          home.getName(),
          "player",
          home.getPlayerName(),
          "world",
          home.getWorld());
      //			util.sendMessage(p, "Teleporting to player home for "+home.getPlayerName()+" on world
      // \""+home.getWorld()+"\"");
      if (applyCost(p)) p.teleport(home.getLocation());
    } else if (homeName != null)
      util.sendLocalizedMessage(
          p, HSPMessages.CMD_HOMEDELETEOTHER_NO_HOME_FOUND, "home", homeName, "player", playerName);
    //			util.sendMessage(p, "No home found for player "+playerName+" on world "+worldName);
    else
      util.sendLocalizedMessage(
          p,
          HSPMessages.CMD_HOMEDELETEOTHER_NO_DEFAULT_HOME_FOUND,
          "player",
          playerName,
          "world",
          worldName);

    return true;
  }
Ejemplo n.º 10
0
  public static boolean onCommand(
      PerkPlayer player, Command cmd, String commandLabel, PerkArgSet args) {

    if (cmd.getName().equalsIgnoreCase("tpr")
        || cmd.getName().equalsIgnoreCase("tphr")
        || cmd.getName().equalsIgnoreCase("tpd")
        || cmd.getName().equalsIgnoreCase("tpa")) {
      PerkPlayer toPlayer = null;

      if (args.size() == 1) {
        String playerName = args.getString(0);
        toPlayer = PerkUtils.getPlayer(PerkUtils.server().getPlayer(playerName));

        if (toPlayer == null || toPlayer.isVanished()) {
          PerkUtils.OutputToPlayer(player, playerName + " isn't online.");
          return true;
        }
      }

      if (cmd.getName().equalsIgnoreCase("tpr")) {

        if (args.size() != 1) {
          PerkUtils.OutputToPlayer(player, cmd.getUsage());
          return true;
        }

        if (!player.hasPermission("perks.teleport.tpr", true)) {
          return true;
        }

        toPlayer.sendTpRequest(player);

        return true;
      }

      if (cmd.getName().equalsIgnoreCase("tphr")) {

        if (args.size() != 1) {
          PerkUtils.OutputToPlayer(player, cmd.getUsage());
          return true;
        }

        if (!player.hasPermission("perks.teleport.tphr", true)) {
          return true;
        }

        toPlayer.sendTpHereRequest(player);

        return true;
      }

      // accepting and declining shouldn't have a permission as everyone needs to do it

      if (cmd.getName().equalsIgnoreCase("tpa")) {

        player.acceptTpRequest(toPlayer);

        return true;
      }

      if (cmd.getName().equalsIgnoreCase("tpd")) {

        player.declineTpRequest(toPlayer);

        return true;
      }
    }

    if (cmd.getName().equalsIgnoreCase("tp")) {

      if (!player.hasPermission("perks.teleport.tp", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      Location loc = null;

      // Handle coordinates
      if (args.getString(0).matches("^[\\-0-9\\.]+,[\\-0-9\\.]+,[\\-0-9\\.]+(?:.+)?$")) {

        String[] arg = args.getString(0).split(":");
        String[] parts = args.getString(0).split(",");
        double x = 0, y = 0, z = 0;

        try {
          x = Double.parseDouble(parts[0]);
          y = Double.parseDouble(parts[1]);
          z = Double.parseDouble(parts[2]);
        } catch (NumberFormatException e) {
          PerkUtils.OutputToPlayer(player, "");
        }

        if (arg.length > 1) {
          loc = new Location(PerkUtils.server().getWorld(arg[1]), x, y, z);
        } else {
          loc = new Location(player.getPlayer().getWorld(), x, y, z);
        }

        player.teleport(loc);

        PerkUtils.OutputToPlayer(player, "You have been teleported");

        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));
      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      loc = target.getPlayer().getLocation();

      player.teleport(loc);

      PerkUtils.OutputToPlayer(player, "You have been teleported");

      return true;
    }

    if (cmd.getName().equalsIgnoreCase("tphere")
        || cmd.getName().equalsIgnoreCase("s")
        || cmd.getName().equalsIgnoreCase("bring")) {

      if (!player.hasPermission("perks.teleport.tphere", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));

      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      player.teleportHere(target);

      PerkUtils.OutputToPlayer(
          player, target.getPlayer().getName() + " has been teleported to you.");

      return true;
    }

    if (cmd.getName().equalsIgnoreCase("put")) {

      if (!player.hasPermission("perks.teleport.put", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));

      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      target.getPlayer().teleport(player.getPlayer().getTargetBlock(null, 300).getLocation());
      return true;
    }

    return false;
  }
Ejemplo n.º 11
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;
		}
	}