Пример #1
0
  /**
   * @param player the player who sent the command
   * @param args the command arguments
   * @return whether the command was successful
   */
  private boolean doCommand(Player player, String[] args) {

    if (!player.hasPermission("vgtrade.trade")) {
      player.sendMessage(
          ChatColor.GREEN + LanguageManager.getString(LanguageManager.Strings.UNABLE));
      return true;
    }

    if (args.length == 0) {
      // You must specify an option
      player.sendMessage(ChatColor.RED + languageManager.getString(LanguageManager.Strings.OPTION));

    } else if ("accept".equalsIgnoreCase(args[0]) || "decline".equalsIgnoreCase(args[0])) {

      manager.handleCommand(args[0], player);

    } else if ("ignore".equalsIgnoreCase(args[0])) {

      if (playersIgnoring.contains(player.getName())) {
        playersIgnoring.remove(player.getName());
        player.sendMessage(
            ChatColor.GREEN + LanguageManager.getString(LanguageManager.Strings.NOTIGNORING));
      } else {
        playersIgnoring.add(player.getName());
        player.sendMessage(
            ChatColor.GREEN + LanguageManager.getString(LanguageManager.Strings.IGNORING));
      }

    } else {

      Player target;

      if ((target = getServer().getPlayer(args[0])) == null) {
        player.sendMessage(
            ChatColor.RED
                // The player you specified is not online
                + languageManager.getString(LanguageManager.Strings.ONLINE));
        return true;
      } else if (player.equals(target)) {
        player.sendMessage(
            ChatColor.RED
                // You can't trade with yourself!
                + languageManager.getString(LanguageManager.Strings.YOURSELF));
        return true;
      }

      if (!isBusy(player)) {
        requestTrade(player, target);
      } else {
        // Unable to trade with <target name>
        player.sendMessage(
            ChatColor.RED
                + LanguageManager.getString(LanguageManager.Strings.UNABLE)
                + " "
                + target.getName());
      }
    }
    return true;
  }
Пример #2
0
 /**
  * Attempts to begin a trade for the two given players
  *
  * @param initiator The player who initiated the trade
  * @param target The target of the initiator
  */
 public void requestTrade(Player initiator, Player target) {
   if (playersIgnoring.contains(target.getName())) {
     initiator.sendMessage(
         ChatColor.RED
             + target.getName()
             + " "
             + LanguageManager.getString(LanguageManager.Strings.PLAYERIGNORING));
   } else if (config.canTrade(initiator, target)) {
     manager.begin(new TradePlayer(initiator), new TradePlayer(target));
   }
 }