Package org.bukkit.scoreboard

Examples of org.bukkit.scoreboard.Team


                            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();
                if (!option.equals("friendlyfire") && !option.equals("color") && !option.equals("seefriendlyinvisibles")) {
                    sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
                    return false;
                }
                if (args.length == 4) {
                    if (option.equals("color")) {
                        sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
                    } else {
                        sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
                    }
                } else {
                    String value = args[4].toLowerCase();
                    if (option.equals("color")) {
                        ChatColor color = TEAMS_OPTION_COLOR.get(value);
                        if (color == null) {
                            sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
                            return false;
                        }
                        team.setPrefix(color.toString());
                        team.setSuffix(ChatColor.RESET.toString());
                    } else {
                        if (!value.equals("true") && !value.equals("false")) {
                            sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
                            return false;
                        }
                        if (option.equals("friendlyfire")) {
                            team.setAllowFriendlyFire(value.equals("true"));
                        } else {
                            team.setCanSeeFriendlyInvisibles(value.equals("true"));
                        }
                    }
                    sender.sendMessage("Set option " + option + " for team " + team.getName() + " to " + value);
                }
            }
        } else {
            sender.sendMessage(ChatColor.RED + "Usage: /scoreboard <objectives|players|teams>");
            return false;
View Full Code Here


        for (int j = 0; j < list.size(); ++j) {
            Player player = list.get(j);
            Location location;

            if (teams) {
                Team team = player.getScoreboard().getPlayerTeam(player);

                if (!hashmap.containsKey(team)) {
                    hashmap.put(team, locations[i++]);
                }
View Full Code Here

              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();
        if (!option.equals("friendlyfire") && !option.equals("color") && !option.equals("seefriendlyinvisibles")) {
          sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
          return false;
        }
        if (args.length == 4) {
          if (option.equals("color")) {
            sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
          } else {
            sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
          }
        } else {
          String value = args[4].toLowerCase();
          if (option.equals("color")) {
            ChatColor color = TEAMS_OPTION_COLOR.get(value);
            if (color == null) {
              sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
              return false;
            }
            team.setPrefix(color.toString());
            team.setSuffix(ChatColor.RESET.toString());
          } else {
            if (!value.equals("true") && !value.equals("false")) {
              sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
              return false;
            }
            if (option.equals("friendlyfire")) {
              team.setAllowFriendlyFire(value.equals("true"));
            } else {
              team.setCanSeeFriendlyInvisibles(value.equals("true"));
            }
          }
          sender.sendMessage("Set option " + option + " for team " + team.getName() + " to " + value);
        }
      }
    } else {
      sender.sendMessage(ChatColor.RED + "Usage: /scoreboard <objectives|players|teams>");
      return false;
View Full Code Here

      File scoreboardFile = new File(dataFolder, "scoreboard.xml");
      Element sbroot = new SAXBuilder().build(scoreboardFile).getRootElement();

      for (Element teamnode : sbroot.getChild("teams").getChildren("team"))
      {
        Team team = scoreboard.registerNewTeam(teamnode.getAttributeValue("name"));
        team.setPrefix(teamnode.getAttributeValue("prefix"));
        team.setSuffix(teamnode.getAttributeValue("suffix"));
      }

      for (Element objroot : sbroot.getChild("objectives").getChildren("objective"))
      {
        Objective obj = scoreboard.registerNewObjective(
View Full Code Here

TOP

Related Classes of org.bukkit.scoreboard.Team

Copyright © 2018 www.massapicom. 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.