Пример #1
0
 public void addTeam(Team team) {
   Preconditions.checkNotNull(team, "team");
   Preconditions.checkArgument(
       !teams.containsKey(team.getName()),
       "Team %s already exists in this scoreboard",
       team.getName());
   teams.put(team.getName(), team);
 }
Пример #2
0
  public void clean() {

    PlayerInventory inv = this.player.getInventory();
    inv.setArmorContents(new ItemStack[4]);
    inv.setContents(new ItemStack[] {});

    this.player.setAllowFlight(false);
    this.player.setFlying(false);
    this.player.setExp(0.0F);
    this.player.setLevel(0);
    this.player.setSneaking(false);
    this.player.setSprinting(false);
    this.player.setFoodLevel(20);
    this.player.setMaxHealth(20.0D);
    this.player.setHealth(20.0D);
    this.player.setFireTicks(0);
    this.player.setGameMode(GameMode.SURVIVAL);

    boolean teamnameOnTab = Main.getInstance().getBooleanConfig("teamname-on-tab", true);
    boolean overwriteNames = Main.getInstance().getBooleanConfig("overwrite-names", false);
    if (overwriteNames) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setDisplayName(team.getChatColor() + this.player.getName());
        } else {
          this.player.setDisplayName(this.player.getName());
        }
      }
    }

    if (teamnameOnTab && Utils.isSupportingTitles()) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setPlayerListName(
              team.getChatColor()
                  + team.getName()
                  + ChatColor.WHITE
                  + " | "
                  + team.getChatColor()
                  + this.player.getName());
        } else {
          this.player.setPlayerListName(this.player.getName());
        }
      }
    }

    if (this.player.isInsideVehicle()) {
      this.player.leaveVehicle();
    }

    for (PotionEffect e : this.player.getActivePotionEffects()) {
      this.player.removePotionEffect(e.getType());
    }

    this.player.updateInventory();
  }
Пример #3
0
  @SuppressWarnings("deprecation")
  public void openTeamSelection(Game game) {
    BedwarsOpenTeamSelectionEvent openEvent = new BedwarsOpenTeamSelectionEvent(game, this.player);
    Main.getInstance().getServer().getPluginManager().callEvent(openEvent);

    if (openEvent.isCancelled()) {
      return;
    }

    HashMap<String, Team> teams = game.getTeams();

    int nom = (teams.size() % 9 == 0) ? 9 : (teams.size() % 9);
    Inventory inv =
        Bukkit.createInventory(this.player, teams.size() + (9 - nom), Main._l("lobby.chooseteam"));
    for (Team team : teams.values()) {
      List<Player> players = team.getPlayers();
      if (players.size() >= team.getMaxPlayers()) {
        continue;
      }

      ItemStack is = new ItemStack(Material.WOOL, 1, team.getColor().getDyeColor().getData());
      ItemMeta im = is.getItemMeta();
      im.setDisplayName(team.getChatColor() + team.getName());
      ArrayList<String> teamplayers = new ArrayList<>();

      int teamPlayerSize = team.getPlayers().size();
      int maxPlayers = team.getMaxPlayers();

      String current = "0";
      if (teamPlayerSize >= maxPlayers) {
        current = ChatColor.RED + String.valueOf(teamPlayerSize);
      } else {
        current = ChatColor.YELLOW + String.valueOf(teamPlayerSize);
      }

      teamplayers.add(
          ChatColor.GRAY
              + "("
              + current
              + ChatColor.GRAY
              + "/"
              + ChatColor.YELLOW
              + String.valueOf(maxPlayers)
              + ChatColor.GRAY
              + ")");
      teamplayers.add(ChatColor.WHITE + "---------");

      for (Player teamPlayer : players) {
        teamplayers.add(team.getChatColor() + teamPlayer.getName());
      }

      im.setLore(teamplayers);
      is.setItemMeta(im);
      inv.addItem(is);
    }

    this.player.openInventory(inv);
  }
 public boolean validateTeam(Team team) {
   if (team == null) return false;
   if (team.getName() == null) return false;
   if (team.getName().trim().equals("")) return false;
   if (team.getTrainer() == null) return false;
   if (team.getPlayers() == null) return false;
   if (team.getPlayers().length != 22) return false;
   for (Player player : team.getPlayers()) {
     if (player == null) return false;
   }
   if (team.getYearOfFoundation() == null) return false;
   if (team.getYearOfFoundation() < 1950) return false;
   return true;
 }
Пример #5
0
 public synchronized boolean equals(java.lang.Object obj) {
   if (!(obj instanceof Team)) return false;
   Team other = (Team) obj;
   if (obj == null) return false;
   if (this == obj) return true;
   if (__equalsCalc != null) {
     return (__equalsCalc == obj);
   }
   __equalsCalc = obj;
   boolean _equals;
   _equals =
       true
           && ((this.id == null && other.getId() == null)
               || (this.id != null && this.id.equals(other.getId())))
           && ((this.name == null && other.getName() == null)
               || (this.name != null && this.name.equals(other.getName())))
           && ((this.description == null && other.getDescription() == null)
               || (this.description != null && this.description.equals(other.getDescription())))
           && ((this.hasAllCompanies == null && other.getHasAllCompanies() == null)
               || (this.hasAllCompanies != null
                   && this.hasAllCompanies.equals(other.getHasAllCompanies())))
           && ((this.hasAllInventory == null && other.getHasAllInventory() == null)
               || (this.hasAllInventory != null
                   && this.hasAllInventory.equals(other.getHasAllInventory())))
           && ((this.teamAccessType == null && other.getTeamAccessType() == null)
               || (this.teamAccessType != null
                   && this.teamAccessType.equals(other.getTeamAccessType())))
           && ((this.companyIds == null && other.getCompanyIds() == null)
               || (this.companyIds != null
                   && java.util.Arrays.equals(this.companyIds, other.getCompanyIds())))
           && ((this.adUnitIds == null && other.getAdUnitIds() == null)
               || (this.adUnitIds != null
                   && java.util.Arrays.equals(this.adUnitIds, other.getAdUnitIds())));
   __equalsCalc = null;
   return _equals;
 }
Пример #6
0
  public Commentary checkForGamePoint(Commentary commentary) {
    if (leftTeam.getScore() >= this.getGameLength().getPoints() - 1
        && leftTeam.getScore() - rightTeam.getScore() >= 1) {
      if (isOvertime()) {
        commentary.next("Advantage ").add(leftTeam.getName());
      } else if (leftTeam.getWins() == matchLength.getMinGames() - 1) {
        commentary.next("Match point");
      } else {
        commentary.next("Game point");
      }
    }
    if (rightTeam.getScore() >= this.getGameLength().getPoints() - 1
        && rightTeam.getScore() - leftTeam.getScore() >= 1) {
      if (isOvertime()) {
        commentary.next("Advantage ").add(rightTeam.getName());
      } else if (rightTeam.getWins() == matchLength.getMinGames() - 1) {
        commentary.next("Match point");
      } else {
        commentary.next("Game point");
      }
    }

    return commentary;
  }
Пример #7
0
 public FootballManager(Console con) {
   this.con = con;
   cache =
       new MemcachedCache(jdgProperty(JDG_HOST), Integer.parseInt(jdgProperty(MEMCACHED_PORT)));
   List<String> teams = (List<String>) cache.get(teamsKey);
   if (teams == null) {
     teams = new ArrayList<String>();
     Team t = new Team("Lakers");
     t.addPlayer("Kobe Bryant");
     t.addPlayer("Pau Gasol");
     t.addPlayer("Steve Nash");
     cache.put(t.getName(), t);
     teams.add(t.getName());
   }
   cache.put(teamsKey, teams);
 }
Пример #8
0
  @Test
  public void testRemoveTeamFromPool() throws Exception {

    // Arrange
    TeamsEditor teamsEditorToTest = new TeamsEditor("Pool1");
    ArrayList<Team> actualListOfAddedTeams = teamsEditorToTest.getListOfAddedTeams();
    ArrayList<Team> expectedListOfAddedTeams = teamsEditorToTest.getListOfAddedTeams();
    String teamToRemove;

    if (expectedListOfAddedTeams.size() > 0) {
      Team team = expectedListOfAddedTeams.remove(0);
      teamToRemove = team.getName();

      // Act
      teamsEditorToTest.removeTeamFromPool(teamToRemove);

      // Assert
      actualListOfAddedTeams = teamsEditorToTest.getListOfAddedTeams();

      Assert.assertEquals(actualListOfAddedTeams, expectedListOfAddedTeams);
    }
  }
Пример #9
0
  /**
   * Creates and runs a scoreboard for a variety of games
   *
   * @param args command line arguments (none expected)
   */
  public static void main(String args[]) {
    Scanner r = new Scanner(System.in);
    int trip = 0;
    boolean err = true;
    Game game = null;
    while (err) {
      try {
        System.out.print(
            "\nSelect Sport (by number): \n"
                + "  1)   Football\n"
                + "  2)   Soccer\n"
                + "  3)   Basketball\n"
                + "  4)   Hockey\n"
                + "Enter choice: ");
        trip = r.nextInt();
        r.nextLine();
        if (trip > 4 || trip < 1) {
          throw new IndexOutOfBoundsException();
        }
        err = false;
      } catch (IndexOutOfBoundsException e) {
        System.out.println("Invalid Option, try again");
        // r.nextLine();
      } catch (InputMismatchException e) {
        System.out.println("Please enter the menu item number");
        r.nextLine();
      }
    }

    if (trip > 0) {
      System.out.println("ENTER TEAMS");
      System.out.print("Home: ");
      Team team1 = new Team(r.nextLine());
      System.out.print("Away: ");
      Team team2 = new Team(r.nextLine());
      System.out.println();

      switch (trip) {
        case 1:
          game = new Football(team1, team2);
          break;
        case 2:
          game = new Soccer(team1, team2);
          break;
        case 3:
          game = new Basketball(team1, team2);
          break;
        case 4:
          game = new Hockey(team1, team2);
          break;
      }

      while (!game.gameOver()) {
        err = true;
        int menuCount = 0;
        while (err) {
          menuCount = 1;
          // PRINT MENU
          try {

            ArrayList<ScoringMethod> scoringMethods = game.getScoringMethods();
            /* Displays dynamically generated scoreboard containing all available scoring methods for both teams */

            System.out.println(
                team1.getName()
                    + " - "
                    + team1.getScore()
                    + ", "
                    + team2.getName()
                    + " - "
                    + team2.getScore());
            System.out.println("Current " + game.getPeriodName() + ": " + game.getPeriod());

            System.out.println("Menu: ");
            for (int i = 0; i < (game.getScoringMethods().size()); i++) {
              System.out.println(
                  "  "
                      + menuCount
                      + ") "
                      + team1.getName()
                      + " "
                      + game.getScoringMethods().get(i).getName());
              menuCount++;
            }
            for (int i = 0; i < (game.getScoringMethods().size()); i++) {
              System.out.println(
                  "  "
                      + menuCount
                      + ") "
                      + team2.getName()
                      + " "
                      + game.getScoringMethods().get(i).getName());
              menuCount++;
            }
            System.out.println("  " + menuCount + ") End " + game.getPeriodName());

            System.out.print("Enter choice: ");

            trip = r.nextInt();

            if (trip > ((scoringMethods.size() * 2) + 1) || trip < 1) {
              throw new IndexOutOfBoundsException();
            }

            err = false;
          } catch (IndexOutOfBoundsException e) {
            System.out.println("Invalid Option, try again " + e);
            r.nextLine();
          } catch (InputMismatchException e) {
            System.out.println("Please enter the menu item number");
            r.nextLine();
          }
        }

        if (trip == menuCount) {
          game.endPeriod();
        } else if (trip > ((menuCount - 1) / 2)) {
          trip -= (menuCount - 1) / 2;
          team2.addScore(game.getScoringMethods().get(trip - 1).getPoints());
        } else {
          team1.addScore(game.getScoringMethods().get(trip - 1).getPoints());
        }
      }
      System.out.println("\n\nGame is over.");
      System.out.println(
          "Final Score: "
              + team1.getName()
              + " - "
              + team1.getScore()
              + ", "
              + team2.getName()
              + " - "
              + team2.getScore());
      String winner = game.getWinner();
      if (winner.equals("Nobody")) {
        System.out.println("Tie");
        // System.out.println(winner+" wins :(");
      } else {
        System.out.println(winner + " wins!");
      }
    }
    r.close();
  }
Пример #10
0
  public void incrementTeamScore(Team.Side side) {
    Team team = getTeam(side);
    log.trace("Increment team: " + team);
    Commentary commentary = new Commentary();

    if (isEndOfMatch()) {
      return;
    }
    if (isEndOfGame()) {
      Team winner = getWinner();
      Team loser = getLoser();
      leftTeam.setScore(0);
      rightTeam.setScore(0);
      server = loser.getSide();
      switchSides();
      return;
    }

    if (server == null) {
      server = side;
      commentary.add(team.getName()).add(" serves first");
    } else {
      team.setScore(team.getScore() + 1);
      histories.add(0, new PointHistory(side, PointHistory.Type.INCREMENT));
      if (!isOvertime() && !isEndOfGame()) {
        commentary.add("Point ").add(team.getName());
      }
      if (isEndOfGame()) {
        Team winner = getWinner();
        Team loser = getLoser();

        winner.setWins(winner.getWins() + 1);

        if (leftTeam.getWins() == matchLength.getMinGames()
            || rightTeam.getWins() == matchLength.getMinGames()) {

          commentary
              .next("Congratulations ")
              .add(winner.getName())
              .next("You have defeated ")
              .add(loser.getName());
        } else {
          commentary
              .add(winner.getName())
              .add(" wins the game")
              .next("Switch sides")
              .next("Losers serve first");
        }
        if (loser.getScore() == 0) {
          commentary.next("Perfect game!", "Perfect, game!");
        } else if (loser.getScore() <= 12 && gameLength == GameLength.TWENTY_ONE) {
          commentary.next("Sorry ").add(loser.getName()).add(", Jacob is not impressed!");
        }
      } else {
        int totalScore = leftTeam.getScore() + rightTeam.getScore();
        // check for o-fer and add to commentary
        if (!isOvertime() && totalScore != 0 && isServerChange()) {
          log.trace("Check for ofer");
          commentary = checkForOfer(team, commentary);
        }

        if (isServerChange()) {
          if (!isOvertime()) {
            commentary.next("Change servers", "Change servers!");
          }
          switchServers();
          // String name = getTeam(server).getName();
        }
        // announce score
        if (!isOvertime()) {
          AnnounceScore announceScore = new AnnounceScore(this);
          commentary.next(announceScore.getScore());
        } else {
          if (leftTeam.getScore() == rightTeam.getScore()) {
            commentary.next("Deuce", "Deuce!");
          }
        }

        // check for gamepoint or matchpoint
        commentary = checkForGamePoint(commentary);
      }
    }

    log.trace(
        "Score: "
            + leftTeam.getName()
            + " "
            + leftTeam.getScore()
            + " to "
            + rightTeam.getName()
            + " "
            + rightTeam.getScore());
    talker.say(commentary);
  }