Examples of Scoreboard


Examples of org.bukkit.scoreboard.Scoreboard

        if (player == null) {
            ScoreboardManager.cleanup(this);
            return;
        }

        Scoreboard oldBoard = player.getScoreboard();

        if (oldBoard == scoreboard) { // Already displaying it
            if (this.oldBoard == null) {
                // (Shouldn't happen) Use failsafe value - we're already displaying our board, but we don't have the one we should revert to
                this.oldBoard = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard();
View Full Code Here

Examples of org.bukkit.scoreboard.Scoreboard

        if (args.length < 1 || args[0].length() == 0) {
            sender.sendMessage(ChatColor.RED + "Usage: /scoreboard <objectives|players|teams>");
            return false;
        }

        final Scoreboard mainScoreboard = Bukkit.getScoreboardManager().getMainScoreboard();

        if (args[0].equalsIgnoreCase("objectives")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "Usage: /scoreboard objectives <list|add|remove|setdisplay>");
                return false;
            }
            if (args[1].equalsIgnoreCase("list")) {
                Set<Objective> objectives = mainScoreboard.getObjectives();
                if (objectives.isEmpty()) {
                    sender.sendMessage(ChatColor.RED + "There are no objectives on the scoreboard");
                    return false;
                }
                sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + objectives.size() + " objective(s) on scoreboard");
                for (Objective objective : objectives) {
                    sender.sendMessage("- " + objective.getName() + ": displays as '" + objective.getDisplayName() + "' and is type '" + objective.getCriteria() + "'");
                }
            } else if (args[1].equalsIgnoreCase("add")) {
                if (args.length < 4) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard objectives add <name> <criteriaType> [display name ...]");
                    return false;
                }
                String name = args[2];
                String criteria = args[3];

                if (criteria == null) {
                    sender.sendMessage(ChatColor.RED + "Invalid objective criteria type. Valid types are: " + stringCollectionToString(OBJECTIVES_CRITERIA));
                } else if (name.length() > 16) {
                    sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for an objective, it can be at most 16 characters long");
                } else if (mainScoreboard.getObjective(name) != null) {
                    sender.sendMessage(ChatColor.RED + "An objective with the name '" + name + "' already exists");
                } else {
                    String displayName = null;
                    if (args.length > 4) {
                        displayName = StringUtils.join(ArrayUtils.subarray(args, 4, args.length), ' ');
                        if (displayName.length() > 32) {
                            sender.sendMessage(ChatColor.RED + "The name '" + displayName + "' is too long for an objective, it can be at most 32 characters long");
                            return false;
                        }
                    }
                    Objective objective = mainScoreboard.registerNewObjective(name, criteria);
                    if (displayName != null && displayName.length() > 0) {
                        objective.setDisplayName(displayName);
                    }
                    sender.sendMessage("Added new objective '" + name + "' successfully");
                }
            } else if (args[1].equalsIgnoreCase("remove")) {
                if (args.length != 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard objectives remove <name>");
                    return false;
                }
                String name = args[2];
                Objective objective = mainScoreboard.getObjective(name);
                if (objective == null) {
                    sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + name + "'");
                } else {
                    objective.unregister();
                    sender.sendMessage("Removed objective '" + name + "' successfully");
                }
            } else if (args[1].equalsIgnoreCase("setdisplay")) {
                if (args.length != 3 && args.length != 4) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard objectives setdisplay <slot> [objective]");
                    return false;
                }
                String slotName = args[2];
                DisplaySlot slot = OBJECTIVES_DISPLAYSLOT.get(slotName);
                if (slot == null) {
                    sender.sendMessage(ChatColor.RED + "No such display slot '" + slotName + "'");
                } else {
                    if (args.length == 4) {
                        String objectiveName = args[3];
                        Objective objective = mainScoreboard.getObjective(objectiveName);
                        if (objective == null) {
                            sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
                            return false;
                        }

                        objective.setDisplaySlot(slot);
                        sender.sendMessage("Set the display objective in slot '" + slotName + "' to '" + objective.getName() + "'");
                    } else {
                        Objective objective = mainScoreboard.getObjective(slot);
                        if (objective != null) {
                            objective.setDisplaySlot(null);
                        }
                        sender.sendMessage("Cleared objective display slot '" + slotName + "'");
                    }
                }
            }
        } else if (args[0].equalsIgnoreCase("players")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/scoreboard players <set|add|remove|reset|list>");
                return false;
            }
            if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
                if (args.length != 5) {
                    if (args[1].equalsIgnoreCase("set")) {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players set <player> <objective> <score>");
                    } else if (args[1].equalsIgnoreCase("add")) {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players add <player> <objective> <count>");
                    } else {
                        sender.sendMessage(ChatColor.RED + "/scoreboard players remove <player> <objective> <count>");
                    }
                    return false;
                }
                String objectiveName = args[3];
                Objective objective = mainScoreboard.getObjective(objectiveName);
                if (objective == null) {
                    sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
                    return false;
                } else if (!objective.isModifiable()) {
                    sender.sendMessage(ChatColor.RED + "The objective '" + objectiveName + "' is read-only and cannot be set");
                    return false;
                }

                String valueString = args[4];
                int value;
                try {
                    value = Integer.parseInt(valueString);
                } catch (NumberFormatException e) {
                    sender.sendMessage(ChatColor.RED + "'" + valueString + "' is not a valid number");
                    return false;
                }
                if (value < 1 && !args[1].equalsIgnoreCase("set")) {
                    sender.sendMessage(ChatColor.RED + "The number you have entered (" + value + ") is too small, it must be at least 1");
                    return false;
                }

                String playerName = args[2];
                if (playerName.length() > 16) {
                    sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
                    return false;
                }
                Score score = objective.getScore(playerName);
                int newScore;
                if (args[1].equalsIgnoreCase("set")) {
                    newScore = value;
                } else if (args[1].equalsIgnoreCase("add")) {
                    newScore = score.getScore() + value;
                } else {
                    newScore = score.getScore() - value;
                }
                score.setScore(newScore);
                sender.sendMessage("Set score of " + objectiveName + " for player " + playerName + " to " + newScore);
            } else if (args[1].equalsIgnoreCase("reset")) {
                if (args.length != 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard players reset <player>");
                    return false;
                }
                String playerName = args[2];
                if (playerName.length() > 16) {
                    sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
                    return false;
                }
                mainScoreboard.resetScores(playerName);
                sender.sendMessage("Reset all scores of player " + playerName);
            } else if (args[1].equalsIgnoreCase("list")) {
                if (args.length > 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard players list <player>");
                    return false;
                }
                if (args.length == 2) {
                    Set<String> entries = mainScoreboard.getEntries();
                    if (entries.isEmpty()) {
                        sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard");
                    } else {
                        sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + entries.size() + " tracked players on the scoreboard");
                        sender.sendMessage(stringCollectionToString(entries));
                    }
                } else {
                    String playerName = args[2];
                    if (playerName.length() > 16) {
                        sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
                        return false;
                    }
                    Set<Score> scores = mainScoreboard.getScores(playerName);
                    if (scores.isEmpty()) {
                        sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded");
                    } else {
                        sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + scores.size() + " tracked objective(s) for " + playerName);
                        for (Score score : scores) {
                            sender.sendMessage("- " + score.getObjective().getDisplayName() + ": " + score.getScore() + " (" + score.getObjective().getName() + ")");
                        }
                    }
                }
            }
        } else if (args[0].equalsIgnoreCase("teams")) {
            if (args.length == 1) {
                sender.sendMessage(ChatColor.RED + "/scoreboard teams <list|add|remove|empty|join|leave|option>");
                return false;
            }
            if (args[1].equalsIgnoreCase("list")) {
                if (args.length == 2) {
                    Set<Team> teams = mainScoreboard.getTeams();
                    if (teams.isEmpty()) {
                        sender.sendMessage(ChatColor.RED + "There are no teams registered on the scoreboard");
                    } else {
                        sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + teams.size() + " teams on the scoreboard");
                        for (Team team : teams) {
                            sender.sendMessage("- " + team.getName() + ": '" + team.getDisplayName() + "' has " + team.getSize() + " players");
                        }
                    }
                } else if (args.length == 3) {
                    String teamName = args[2];
                    Team team = mainScoreboard.getTeam(teamName);
                    if (team == null) {
                        sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
                    } else {
                        Set<OfflinePlayer> players = team.getPlayers();
                        if (players.isEmpty()) {
                            sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " has no players");
                        } else {
                            sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " player(s) in team " + team.getName());
                            sender.sendMessage(offlinePlayerSetToString(players));
                        }
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams list [name]");
                    return false;
                }
            } else if (args[1].equalsIgnoreCase("add")) {
                if (args.length < 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams add <name> [display name ...]");
                    return false;
                }
                String name = args[2];
                if (name.length() > 16) {
                    sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for a team, it can be at most 16 characters long");
                } else if (mainScoreboard.getTeam(name) != null) {
                    sender.sendMessage(ChatColor.RED + "A team with the name '" + name + "' already exists");
                } else {
                    String displayName = null;
                    if (args.length > 3) {
                        displayName = StringUtils.join(ArrayUtils.subarray(args, 3, args.length), ' ');
                        if (displayName.length() > 32) {
                            sender.sendMessage(ChatColor.RED + "The display name '" + displayName + "' is too long for a team, it can be at most 32 characters long");
                            return false;
                        }
                    }
                    Team team = mainScoreboard.registerNewTeam(name);
                    if (displayName != null && displayName.length() > 0) {
                        team.setDisplayName(displayName);
                    }
                    sender.sendMessage("Added new team '" + team.getName() + "' successfully");
                }
            } else if (args[1].equalsIgnoreCase("remove")) {
                if (args.length != 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams remove <name>");
                    return false;
                }
                String name = args[2];
                Team team = mainScoreboard.getTeam(name);
                if (team == null) {
                    sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
                } else {
                    team.unregister();
                    sender.sendMessage("Removed team " + name);
                }
            } else if (args[1].equalsIgnoreCase("empty")) {
                if (args.length != 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams clear <name>");
                    return false;
                }
                String name = args[2];
                Team team = mainScoreboard.getTeam(name);
                if (team == null) {
                    sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
                } else {
                    Set<OfflinePlayer> players = team.getPlayers();
                    if (players.isEmpty()) {
                        sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " is already empty, cannot remove nonexistant players");
                    } else {
                        for (OfflinePlayer player : players) {
                            team.removePlayer(player);
                        }
                        sender.sendMessage("Removed all " + players.size() + " player(s) from team " + team.getName());
                    }
                }
            } else if (args[1].equalsIgnoreCase("join")) {
                if ((sender instanceof Player) ? args.length < 3 : args.length < 4) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams join <team> [player...]");
                    return false;
                }
                String teamName = args[2];
                Team team = mainScoreboard.getTeam(teamName);
                if (team == null) {
                    sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
                } else {
                    Set<String> addedPlayers = new HashSet<String>();
                    if ((sender instanceof Player) && args.length == 3) {
                        team.addPlayer((Player) sender);
                        addedPlayers.add(sender.getName());
                    } else {
                        for (int i = 3; i < args.length; i++) {
                            String playerName = args[i];
                            OfflinePlayer offlinePlayer;
                            Player player = Bukkit.getPlayerExact(playerName);
                            if (player != null) {
                                offlinePlayer = player;
                            } else {
                                offlinePlayer = Bukkit.getOfflinePlayer(playerName);
                            }
                            team.addPlayer(offlinePlayer);
                            addedPlayers.add(offlinePlayer.getName());
                        }
                    }
                    sender.sendMessage("Added " + addedPlayers.size() + " player(s) to team " + team.getName() + ": " + stringCollectionToString(addedPlayers));
                }
            } else if (args[1].equalsIgnoreCase("leave")) {
                if (!(sender instanceof Player) && args.length < 3) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams leave [player...]");
                    return false;
                }
                Set<String> left = new HashSet<String>();
                Set<String> noTeam = new HashSet<String>();
                if ((sender instanceof Player) && args.length == 2) {
                    Team team = mainScoreboard.getPlayerTeam((Player) sender);
                    if (team != null) {
                        team.removePlayer((Player) sender);
                        left.add(sender.getName());
                    } else {
                        noTeam.add(sender.getName());
                    }
                } else {
                    for (int i = 2; i < args.length; i++) {
                        String playerName = args[i];
                        OfflinePlayer offlinePlayer;
                        Player player = Bukkit.getPlayerExact(playerName);
                        if (player != null) {
                            offlinePlayer = player;
                        } else {
                            offlinePlayer = Bukkit.getOfflinePlayer(playerName);
                        }
                        Team team = mainScoreboard.getPlayerTeam(offlinePlayer);
                        if (team != null) {
                            team.removePlayer(offlinePlayer);
                            left.add(offlinePlayer.getName());
                        } else {
                            noTeam.add(offlinePlayer.getName());
                        }
                    }
                }
                if (!left.isEmpty()) {
                    sender.sendMessage("Removed " + left.size() + " player(s) from their teams: " + stringCollectionToString(left));
                }
                if (!noTeam.isEmpty()) {
                    sender.sendMessage("Could not remove " + noTeam.size() + " player(s) from their teams: " + stringCollectionToString(noTeam));
                }
            } else if (args[1].equalsIgnoreCase("option")) {
                if (args.length != 4 && args.length != 5) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
                    return false;
                }
                String teamName = args[2];
                Team team = mainScoreboard.getTeam(teamName);
                if (team == null) {
                    sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
                    return false;
                }
                String option = args[3].toLowerCase();
View Full Code Here

Examples of org.bukkit.scoreboard.Scoreboard

  @AutoRefPermission(console=true, nodes={"bukkit.command.scoreboard"})

  public boolean scoreboard(CommandSender sender, AutoRefMatch match, String[] args, CommandLine options)
  {
    World world = plugin.getSenderWorld(sender);
    final Scoreboard scoreboard = AutoReferee.getInstance().getWorldScoreboard(world);

    // the remainder of this method is the property of the Bukkit dev team, to be updated
    // in the event that this command's format or behavior changes appreciably

    if (args[0].equalsIgnoreCase("objectives")) {
      if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Usage: /scoreboard objectives <list|add|remove|setdisplay>");
        return false;
      }
      if (args[1].equalsIgnoreCase("list")) {
        Set<Objective> objectives = scoreboard.getObjectives();
        if (objectives.isEmpty()) {
          sender.sendMessage(ChatColor.RED + "There are no objectives on the scoreboard");
          return false;
        }
        sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + objectives.size() + " objective(s) on scoreboard");
        for (Objective objective : objectives) {
          sender.sendMessage("- " + objective.getName() + ": displays as '" + objective.getDisplayName() + "' and is type '" + objective.getCriteria() + "'");
        }
      } else if (args[1].equalsIgnoreCase("add")) {
        if (args.length < 4) {
          sender.sendMessage(ChatColor.RED + "/scoreboard objectives add <name> <criteriaType> [display name ...]");
          return false;
        }
        String name = args[2];
        String criteria = args[3];

        if (criteria == null) {
          sender.sendMessage(ChatColor.RED + "Invalid objective criteria type. Valid types are: " + stringCollectionToString(OBJECTIVES_CRITERIA));
        } else if (name.length() > 16) {
          sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for an objective, it can be at most 16 characters long");
        } else if (scoreboard.getObjective(name) != null) {
          sender.sendMessage(ChatColor.RED + "An objective with the name '" + name + "' already exists");
        } else {
          String displayName = null;
          if (args.length > 4) {
            displayName = StringUtils.join(ArrayUtils.subarray(args, 4, args.length), ' ');
            if (displayName.length() > 32) {
              sender.sendMessage(ChatColor.RED + "The name '" + displayName + "' is too long for an objective, it can be at most 32 characters long");
              return false;
            }
          }
          Objective objective = scoreboard.registerNewObjective(name, criteria);
          if (displayName != null && displayName.length() > 0) {
            objective.setDisplayName(displayName);
          }
          sender.sendMessage("Added new objective '" + name + "' successfully");
        }
      } else if (args[1].equalsIgnoreCase("remove")) {
        if (args.length != 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard objectives remove <name>");
          return false;
        }
        String name = args[2];
        Objective objective = scoreboard.getObjective(name);
        if (objective == null) {
          sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + name + "'");
        } else {
          objective.unregister();
          sender.sendMessage("Removed objective '" + name + "' successfully");
        }
      } else if (args[1].equalsIgnoreCase("setdisplay")) {
        if (args.length != 3 && args.length != 4) {
          sender.sendMessage(ChatColor.RED + "/scoreboard objectives setdisplay <slot> [objective]");
          return false;
        }
        String slotName = args[2];
        DisplaySlot slot = OBJECTIVES_DISPLAYSLOT.get(slotName);
        if (slot == null) {
          sender.sendMessage(ChatColor.RED + "No such display slot '" + slotName + "'");
        } else {
          if (args.length == 4) {
            String objectiveName = args[3];
            Objective objective = scoreboard.getObjective(objectiveName);
            if (objective == null) {
              sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
              return false;
            }

            objective.setDisplaySlot(slot);
            sender.sendMessage("Set the display objective in slot '" + slotName + "' to '" + objective.getName() + "'");
          } else {
            Objective objective = scoreboard.getObjective(slot);
            if (objective != null) {
              objective.setDisplaySlot(null);
            }
            sender.sendMessage("Cleared objective display slot '" + slotName + "'");
          }
        }
      }
    } else if (args[0].equalsIgnoreCase("players")) {
      if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "/scoreboard players <set|add|remove|reset|list>");
        return false;
      }
      if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
        if (args.length != 5) {
          if (args[1].equalsIgnoreCase("set")) {
            sender.sendMessage(ChatColor.RED + "/scoreboard players set <player> <objective> <score>");
          } else if (args[1].equalsIgnoreCase("add")) {
            sender.sendMessage(ChatColor.RED + "/scoreboard players add <player> <objective> <count>");
          } else {
            sender.sendMessage(ChatColor.RED + "/scoreboard players remove <player> <objective> <count>");
          }
          return false;
        }
        String objectiveName = args[3];
        Objective objective = scoreboard.getObjective(objectiveName);
        if (objective == null) {
          sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
          return false;
        } else if (!objective.isModifiable()) {
          sender.sendMessage(ChatColor.RED + "The objective '" + objectiveName + "' is read-only and cannot be set");
          return false;
        }

        String valueString = args[4];
        int value;
        try {
          value = Integer.parseInt(valueString);
        } catch (NumberFormatException e) {
          sender.sendMessage(ChatColor.RED + "'" + valueString + "' is not a valid number");
          return false;
        }
        if (value < 1 && !args[1].equalsIgnoreCase("set")) {
          sender.sendMessage(ChatColor.RED + "The number you have entered (" + value + ") is too small, it must be at least 1");
          return false;
        }

        String playerName = args[2];
        if (playerName.length() > 16) {
          sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
          return false;
        }
        Score score = objective.getScore(Bukkit.getOfflinePlayer(playerName));
        int newScore;
        if (args[1].equalsIgnoreCase("set")) {
          newScore = value;
        } else if (args[1].equalsIgnoreCase("add")) {
          newScore = score.getScore() + value;
        } else {
          newScore = score.getScore() - value;
        }
        score.setScore(newScore);
        sender.sendMessage("Set score of " + objectiveName + " for player " + playerName + " to " + newScore);
      } else if (args[1].equalsIgnoreCase("reset")) {
        if (args.length != 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard players reset <player>");
          return false;
        }
        String playerName = args[2];
        if (playerName.length() > 16) {
          sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
          return false;
        }
        scoreboard.resetScores(Bukkit.getOfflinePlayer(playerName));
        sender.sendMessage("Reset all scores of player " + playerName);
      } else if (args[1].equalsIgnoreCase("list")) {
        if (args.length > 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard players list <player>");
          return false;
        }
        if (args.length == 2) {
          Set<OfflinePlayer> players = scoreboard.getPlayers();
          if (players.isEmpty()) {
            sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard");
          } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " tracked players on the scoreboard");
            sender.sendMessage(offlinePlayerSetToString(players));
          }
        } else {
          String playerName = args[2];
          if (playerName.length() > 16) {
            sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
            return false;
          }
          Set<Score> scores = scoreboard.getScores(Bukkit.getOfflinePlayer(playerName));
          if (scores.isEmpty()) {
            sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded");
          } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + scores.size() + " tracked objective(s) for " + playerName);
            for (Score score : scores) {
              sender.sendMessage("- " + score.getObjective().getDisplayName() + ": " + score.getScore() + " (" + score.getObjective().getName() + ")");
            }
          }
        }
      }
    } else if (args[0].equalsIgnoreCase("teams")) {
      if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "/scoreboard teams <list|add|remove|empty|join|leave|option>");
        return false;
      }
      if (args[1].equalsIgnoreCase("list")) {
        if (args.length == 2) {
          Set<Team> teams = scoreboard.getTeams();
          if (teams.isEmpty()) {
            sender.sendMessage(ChatColor.RED + "There are no teams registered on the scoreboard");
          } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + teams.size() + " teams on the scoreboard");
            for (Team team : teams) {
              sender.sendMessage("- " + team.getName() + ": '" + team.getDisplayName() + "' has " + team.getSize() + " players");
            }
          }
        } else if (args.length == 3) {
          String teamName = args[2];
          Team team = scoreboard.getTeam(teamName);
          if (team == null) {
            sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
          } else {
            Set<OfflinePlayer> players = team.getPlayers();
            if (players.isEmpty()) {
              sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " has no players");
            } else {
              sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " player(s) in team " + team.getName());
              sender.sendMessage(offlinePlayerSetToString(players));
            }
          }
        } else {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams list [name]");
          return false;
        }
      } else if (args[1].equalsIgnoreCase("add")) {
        if (args.length < 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams add <name> [display name ...]");
          return false;
        }
        String name = args[2];
        if (name.length() > 16) {
          sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for a team, it can be at most 16 characters long");
        } else if (scoreboard.getTeam(name) != null) {
          sender.sendMessage(ChatColor.RED + "A team with the name '" + name + "' already exists");
        } else {
          String displayName = null;
          if (args.length > 3) {
            displayName = StringUtils.join(ArrayUtils.subarray(args, 3, args.length), ' ');
            if (displayName.length() > 32) {
              sender.sendMessage(ChatColor.RED + "The display name '" + displayName + "' is too long for a team, it can be at most 32 characters long");
              return false;
            }
          }
          Team team = scoreboard.registerNewTeam(name);
          if (displayName != null && displayName.length() > 0) {
            team.setDisplayName(displayName);
          }
          sender.sendMessage("Added new team '" + team.getName() + "' successfully");
        }
      } else if (args[1].equalsIgnoreCase("remove")) {
        if (args.length != 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams remove <name>");
          return false;
        }
        String name = args[2];
        Team team = scoreboard.getTeam(name);
        if (team == null) {
          sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
        } else {
          team.unregister();
          sender.sendMessage("Removed team " + name);
        }
      } else if (args[1].equalsIgnoreCase("empty")) {
        if (args.length != 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams clear <name>");
          return false;
        }
        String name = args[2];
        Team team = scoreboard.getTeam(name);
        if (team == null) {
          sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
        } else {
          Set<OfflinePlayer> players = team.getPlayers();
          if (players.isEmpty()) {
            sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " is already empty, cannot remove nonexistant players");
          } else {
            for (OfflinePlayer player : players) {
              team.removePlayer(player);
            }
            sender.sendMessage("Removed all " + players.size() + " player(s) from team " + team.getName());
          }
        }
      } else if (args[1].equalsIgnoreCase("join")) {
        if ((sender instanceof Player) ? args.length < 3 : args.length < 4) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams join <team> [player...]");
          return false;
        }
        String teamName = args[2];
        Team team = scoreboard.getTeam(teamName);
        if (team == null) {
          sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
        } else {
          Set<String> addedPlayers = new HashSet<String>();
          if ((sender instanceof Player) && args.length == 3) {
            team.addPlayer((Player) sender);
            addedPlayers.add(sender.getName());
          } else {
            for (int i = 3; i < args.length; i++) {
              String playerName = args[i];
              OfflinePlayer offlinePlayer;
              Player player = Bukkit.getPlayerExact(playerName);
              if (player != null) {
                offlinePlayer = player;
              } else {
                offlinePlayer = Bukkit.getOfflinePlayer(playerName);
              }
              team.addPlayer(offlinePlayer);
              addedPlayers.add(offlinePlayer.getName());

              // AUTOREFEREE START - check for AutoRefTeam
              if (match != null)
              {
                AutoRefTeam autorefteam = match.getScoreboardTeam(teamName);
                if (autorefteam != null && player != null)
                {
                  PlayerTeamJoinEvent.Reason reason = PlayerTeamJoinEvent.Reason.AUTOMATIC;
                  match.joinTeam(player, autorefteam, reason, false);
                }
              }
              // AUTOREFEREE END
            }
          }
          sender.sendMessage("Added " + addedPlayers.size() + " player(s) to team " + team.getName() + ": " + stringCollectionToString(addedPlayers));
        }
      } else if (args[1].equalsIgnoreCase("leave")) {
        if (!(sender instanceof Player) && args.length < 3) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams leave [player...]");
          return false;
        }
        Set<String> left = new HashSet<String>();
        Set<String> noTeam = new HashSet<String>();
        if ((sender instanceof Player) && args.length == 2) {
          Team team = scoreboard.getPlayerTeam((Player) sender);
          if (team != null) {
            team.removePlayer((Player) sender);
            left.add(sender.getName());
          } else {
            noTeam.add(sender.getName());
          }
        } else {
          for (int i = 2; i < args.length; i++) {
            String playerName = args[i];
            OfflinePlayer offlinePlayer;
            Player player = Bukkit.getPlayerExact(playerName);
            if (player != null) {
              offlinePlayer = player;
            } else {
              offlinePlayer = Bukkit.getOfflinePlayer(playerName);
            }
            Team team = scoreboard.getPlayerTeam(offlinePlayer);
            if (team != null) {
              team.removePlayer(offlinePlayer);
              left.add(offlinePlayer.getName());
            } else {
              noTeam.add(offlinePlayer.getName());
            }
          }
        }
        if (!left.isEmpty()) {
          sender.sendMessage("Removed " + left.size() + " player(s) from their teams: " + stringCollectionToString(left));
        }
        if (!noTeam.isEmpty()) {
          sender.sendMessage("Could not remove " + noTeam.size() + " player(s) from their teams: " + stringCollectionToString(noTeam));
        }
      } else if (args[1].equalsIgnoreCase("option")) {
        if (args.length != 4 && args.length != 5) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
          return false;
        }
        String teamName = args[2];
        Team team = scoreboard.getTeam(teamName);
        if (team == null) {
          sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
          return false;
        }
        String option = args[3].toLowerCase();
View Full Code Here

Examples of org.bukkit.scoreboard.Scoreboard

  public boolean scoreboardSave(CommandSender sender, AutoRefMatch match, String[] args, CommandLine options)
  {
    if (match == null || !match.getCurrentState().isBeforeMatch()) return false;

    Scoreboard scoreboard = match.getScoreboard();
    if (options.hasOption('m')) scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();

    match.saveScoreboardData(scoreboard);
    sender.sendMessage(ChatColor.GREEN + "Scoreboard saved to file.");
View Full Code Here

Examples of org.spout.vanilla.scoreboard.Scoreboard

          correctName = p.getName().equals(playerName);
        }
      }

      // check if the team is correct if specified
      Scoreboard board = p.get(Scoreboard.class);
      boolean correctTeam = teamName == null; // default to whether the team name is set
      if (teamName != null && board != null) {
        Team team = board.getTeam(teamName);
        if (team != null) {
          if (teamNameInverted) {
            // make sure the player is not on the specified team
            correctTeam = !team.getPlayerNames().contains(p.getName());
          } else {
            // make sure the player is on the specified team
            correctTeam = team.getPlayerNames().contains(p.getName());
          }
        }
      }

      // make sure the player has the right amount of points for the specified objectives
      boolean enoughPoints = minScores.isEmpty() && maxScores.isEmpty(); // default to whether there are any objectives set
      if (board != null) {
        // first make sure the player has the minimum requirements
        for (Map.Entry<String, Integer> e : minScores.entrySet()) {
          Objective obj = board.getObjective(e.getKey());
          if (obj == null) {
            continue;
          }

          int score = obj.getScore(p.getName()); // player's score for specified objective
          int minScore = e.getValue(); // specified minimum score
          enoughPoints = score >= minScore;
          if (!enoughPoints) {
            // not enough? break.
            break;
          }
        }

        // next make sure the player isn't over the maximums
        for (Map.Entry<String, Integer> e : maxScores.entrySet()) {
          Objective obj = board.getObjective(e.getKey());
          if (obj == null) {
            continue;
          }

          int score = obj.getScore(p.getName()); // player's score for specified objective
View Full Code Here

Examples of org.spout.vanilla.scoreboard.Scoreboard

    args.assertCompletelyParsed();

    String name = player.getName();
    player.sendMessage(ChatStyle.GREEN + "Displaying scoreboard...");

    Scoreboard scoreboard = player.add(Scoreboard.class);
    scoreboard.createObjective("test_obj_1")
        .setDisplayName(ChatStyle.GREEN + "Test Objective 1")
        .setScore(name, 9001)
        .setCriteria(Objective.CRITERIA_HEALTH)
        .setSlot(ObjectiveSlot.SIDEBAR);

    scoreboard.createObjective("test_obj_2")
        .setDisplayName(ChatStyle.DARK_AQUA + "Test Objective 2")
        .setScore(name, 0)
        .setCriteria(Objective.CRITERIA_TOTAL_KILL_COUNT)
        .setSlot(ObjectiveSlot.LIST);
  }
View Full Code Here

Examples of org.spout.vanilla.scoreboard.Scoreboard

    args.assertCompletelyParsed();

    String name = player.getName();
    player.sendMessage("Creating team...");

    Scoreboard scoreboard = player.get(Scoreboard.class);
    if (scoreboard == null) {
      throw new CommandException("You do not have an active scoreboard.");
    }

    Team t = scoreboard.createTeam("spoutdev");
    t.setDisplayName(ChatStyle.DARK_AQUA + "Spout", false);
    t.setPrefix(ChatStyle.GREEN.toString(), true);
    t.addPlayerName(name);
  }
View Full Code Here

Examples of view.ScoreBoard

    scores = new ArrayList<Integer>();
    for ( Snake player : players ) {
      scores.add(0);
    }
   
    scoreBoard = new ScoreBoard(players);
    window.addToControlPanel(scoreBoard);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.