@Override
  public void onPlayerCommand(Player player, String[] args) {
    if (Mineopoly.plugin.getGame().isRunning()) {
      if (Mineopoly.plugin.getGame().hasPlayer(player)) {
        MineopolyPlayer mp = Mineopoly.plugin.getGame().getBoard().getPlayer(player);
        if (!mp.hasTurn()) {
          mp.sendMessage(new InvalidTurnMessage());
          return;
        }
        if (mp.hasRolled()) {
          mp.sendMessage("&cYou can only add hotels before you roll");
          return;
        }
        if (mp.isJailed() && !Mineopoly.houseRules.improveWhileJailed()) {
          mp.sendMessage("&cYou cannot do that while in jail");
          return;
        }
        Property p = null;
        if (args.length == 0) {
          MineopolySection section = mp.getCurrentSection();
          if (section.getType() != SectionType.PROPERTY) {
            mp.sendMessage(new CannotPerformActionMessage() + "add a house to that");
          } else {
            p = (Property) section;
          }
        } else {
          if (TacoAPI.getChatUtils().isNum(args[0])) {
            int id = Integer.parseInt(args[0]);
            MineopolySection section = Mineopoly.plugin.getGame().getBoard().getSection(id);
            if (section.getType() != SectionType.PROPERTY) {
              mp.sendMessage(new CannotPerformActionMessage() + "add a house to that");
              return;
            } else {
              p = (Property) section;
            }
          } else {
            MineopolySection section = Mineopoly.plugin.getGame().getBoard().getSection(args[0]);
            if (section == null) {
              mp.sendMessage(new SectionNotFoundMessage());
              return;
            }
            if (section.getType() != SectionType.PROPERTY) {
              mp.sendMessage(new CannotPerformActionMessage() + "add a house to that");
              return;
            } else {
              p = (Property) section;
            }
          }
        }

        if (Mineopoly.houseRules.improvementRequiresLocation()
            && p.getId() != mp.getCurrentSection().getId()) {
          mp.sendMessage("&cYou can only improve the property you are on");
          return;
        }

        if (p.getOwner().getName().equalsIgnoreCase(mp.getName())) {
          if (mp.hasMoney(p.getHotelPrice())) {
            if (!p.canAddHotel()) {
              if (Mineopoly.houseRules.improvementRequiresMonopoly()
                  && mp.hasMonopoly(p.getColor())) {
                mp.sendMessage(
                    "&cYou do not have a monopoly for the color " + p.getColor().getName());
                return;
              }
              ArrayList<Property> props = mp.getPropertiesLessHousing(p.getColor(), 4);
              if (props.size() > 0) {
                String message = "";
                for (int i = 0; i < props.size(); i++) {
                  if (i == props.size() - 1) {
                    message += (message.isEmpty() ? "" : "and ") + props.get(i).getColorfulName();
                  } else {
                    message += props.get(i).getColorfulName() + " &7, &3";
                  }
                }
                message += " &3 " + (props.size() == 1 ? "does" : "do") + " not have four houses";
                mp.sendMessage(message);
              }
            } else {
              Mineopoly.plugin
                  .getGame()
                  .getChannel()
                  .sendMessage(
                      "&b" + mp.getName() + " &3 added a hotel to " + p.getColorfulName(), mp);
              mp.sendMessage("&3You added a &chotel &3to " + p.getColorfulName());
              p.addHotel();
            }
          } else {
            int amount = p.getHotelPrice() - mp.getBalance();
            mp.sendMessage("&cYou need an additional &2" + amount + " &cbefore you can do that");
          }
        } else {
          mp.sendMessage("&cYou do not own " + p.getColorfulName());
        }
      } else {
        Mineopoly.plugin.chat.sendPlayerMessage(player, new NotPlayingGameMessage());
      }
    } else {
      Mineopoly.plugin.chat.sendPlayerMessage(player, new GameNotInProgressMessage());
    }
  }
Beispiel #2
0
 @Override
 public void onPlayerCommand(Player player, String[] args) {
   if (Mineopoly.plugin.getGame().isRunning()) {
     if (Mineopoly.plugin.getGame().hasPlayer(player)) {
       MineopolyPlayer mp = Mineopoly.plugin.getGame().getBoard().getPlayer(player);
       if (mp.hasTurn()) {
         if (mp.isJailed()) {
           if (mp.hasChanceJailCard() || mp.hasCommunityChestJailCard()) {
             if (mp.hasChanceJailCard()) {
               mp.takeChanceJailCard();
               Mineopoly.plugin.getGame().getBoard().getPot().addChanceJailCard();
             } else if (mp.hasCommunityChestJailCard()) {
               mp.takeCommunityChestJailCard();
               Mineopoly.plugin.getGame().getBoard().getPot().addCommunityChestJailCard();
             }
             Mineopoly.plugin
                 .getGame()
                 .getChannel()
                 .sendMessage(
                     "&b" + mp.getName() + " &3has used a &bGet out of Jail Free &3card", mp);
             mp.sendMessage(
                 "&3You are out of jail. You can now use &b/"
                     + Mineopoly.getMAlias()
                     + " roll on your next turn");
             mp.setJailed(false, true);
           } else {
             mp.sendMessage("&cYou do not have a &6Get out of Jail Free &ccard to use");
           }
         } else {
           mp.sendMessage(new NotInJailMessage());
         }
       } else {
         mp.sendMessage(new InvalidTurnMessage());
       }
     } else {
       Mineopoly.plugin.chat.sendPlayerMessage(player, new NotPlayingGameMessage());
     }
   } else {
     Mineopoly.plugin.chat.sendPlayerMessage(player, new GameNotInProgressMessage());
   }
 }
	@Override
	public String replace(String s) {
		MineopolyPlayer random = Mineopoly.plugin.getGame().getBoard().getRandomPlayerNotCurrent();
		return s.replaceAll("%randomPlayer", random.getName());
	}