Пример #1
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onItemDrop(PlayerDropItemEvent event) {
    if (!isInDropOffArea(event.getPlayer().getLocation())) return;

    ItemStack stack = event.getItemDrop().getItemStack();
    if (!isAllowedToDrop(stack.getType())) {
      event.setCancelled(true);
      return;
    }
    if (!isScoringItemType(stack.getType())) return;

    FarmTeamInfo team = (FarmTeamInfo) getTeam(event.getPlayer());
    int teamNum = indexOfTeam(team);
    long dropScore = 0;

    for (int i = 0; i < stack.getAmount(); i++)
      dropScore += getScoreForItem(stack.getType(), teamNum);

    event.getPlayer().sendMessage(stack.getType().name() + ": score +" + dropScore);
    team.addScore(dropScore);

    event
        .getItemDrop()
        .remove(); // don't actually DROP the item ... should we schedule a brief delay here?
  }
Пример #2
0
  private String writeCurrentScores() {
    StringBuilder message = new StringBuilder();
    long winningScore = 0;
    ArrayList<FarmTeamInfo> winningTeams = new ArrayList<FarmTeamInfo>();
    for (int i = 0; i < teams.length; i++) {
      FarmTeamInfo team = teams[i];
      message.append(
          "\n"
              + team.getChatColor()
              + team.getName()
              + ": "
              + ChatColor.RESET
              + team.getScore()
              + " points");

      // also count the scores to decide the winning teams
      if (team.getScore() > winningScore) {
        winningScore = team.getScore();
        winningTeams.clear();
        winningTeams.add(team);
      } else if (team.getScore() == winningScore) winningTeams.add(team);
    }

    if (winningTeams.size() == teams.length)
      message.append("\n\nThe game was drawn, the scores are equal");
    else {
      message.append("\n\nThe ");
      for (int i = 0; i < winningTeams.size(); i++) {
        if (i == winningTeams.size() - 1) message.append(" and ");
        else if (i > 0) message.append(", ");

        FarmTeamInfo team = teams[i];
        message.append(team.getChatColor() + team.getName() + ChatColor.RESET);
      }

      message.append(winningTeams.size() == 0 ? " wins!" : " win!");
    }
    return message.toString();
  }