Search in sources :

Example 6 with ChatColor

use of org.bukkit.ChatColor in project Glowstone by GlowstoneMC.

the class TextMessage method append.

@SuppressWarnings("unchecked")
private static void append(List<JSONObject> items, StringBuilder current, ChatColor color, Set<ChatColor> formatting) {
    if (current.length() == 0) {
        return;
    }
    JSONObject object = new JSONObject();
    object.put("text", current.toString());
    if (color != null) {
        object.put("color", color.name().toLowerCase());
    }
    for (ChatColor format : formatting) {
        if (format == ChatColor.MAGIC) {
            object.put("obfuscated", true);
        } else {
            object.put(format.name().toLowerCase(), true);
        }
    }
    current.setLength(0);
    items.add(object);
}
Also used : JSONObject(org.json.simple.JSONObject) ChatColor(org.bukkit.ChatColor)

Example 7 with ChatColor

use of org.bukkit.ChatColor in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoReader method registerTeam.

private static void registerTeam(CompoundTag data, GlowScoreboard scoreboard) {
    boolean allowFriendlyFire = data.getByte("AllowFriendlyFire") == 1;
    boolean seeFriendlyInvisibles = data.getByte("SeeFriendlyInvisibles") == 1;
    Team.OptionStatus nameTagVisibility = Team.OptionStatus.valueOf(data.getString("NameTagVisibility").toUpperCase());
    Team.OptionStatus deathMessageVisibility = Team.OptionStatus.ALWAYS;
    switch(data.getString("DeathMessageVisibility")) {
        case "never":
            deathMessageVisibility = Team.OptionStatus.NEVER;
            break;
        case "hideForOtherTeams":
            deathMessageVisibility = Team.OptionStatus.FOR_OTHER_TEAMS;
            break;
        case "hideForOwnTeam":
            deathMessageVisibility = Team.OptionStatus.FOR_OWN_TEAM;
            break;
    }
    Team.OptionStatus collisionRule = Team.OptionStatus.ALWAYS;
    switch(data.getString("CollisionRule")) {
        case "never":
            collisionRule = Team.OptionStatus.NEVER;
            break;
        case "pushOtherTeams":
            collisionRule = Team.OptionStatus.FOR_OTHER_TEAMS;
            break;
        case "pushOwnTeam":
            collisionRule = Team.OptionStatus.FOR_OWN_TEAM;
            break;
    }
    String displayName = data.getString("DisplayName");
    String name = data.getString("Name");
    String prefix = data.getString("Prefix");
    String suffix = data.getString("Suffix");
    ChatColor teamColor = null;
    if (data.containsKey("TeamColor")) {
        teamColor = ChatColor.valueOf(data.getString("TeamColor").toUpperCase());
    }
    List<String> players = data.getList("Players", TagType.STRING);
    GlowTeam team = (GlowTeam) scoreboard.registerNewTeam(name);
    team.setDisplayName(displayName);
    team.setPrefix(prefix);
    team.setSuffix(suffix);
    team.setAllowFriendlyFire(allowFriendlyFire);
    team.setCanSeeFriendlyInvisibles(seeFriendlyInvisibles);
    team.setOption(Team.Option.NAME_TAG_VISIBILITY, nameTagVisibility);
    team.setOption(Team.Option.DEATH_MESSAGE_VISIBILITY, deathMessageVisibility);
    team.setOption(Team.Option.COLLISION_RULE, collisionRule);
    if (teamColor != null) {
        team.setColor(teamColor);
    }
    players.forEach(team::addEntry);
}
Also used : Team(org.bukkit.scoreboard.Team) ChatColor(org.bukkit.ChatColor)

Example 8 with ChatColor

use of org.bukkit.ChatColor in project Essentials by drtshock.

the class User method getNick.

public String getNick(final boolean longnick, final boolean withPrefix, final boolean withSuffix) {
    final StringBuilder prefix = new StringBuilder();
    String nickname;
    String suffix = "";
    final String nick = getNickname();
    if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName())) {
        nickname = getName();
    } else if (nick.equalsIgnoreCase(getName())) {
        nickname = nick;
    } else {
        nickname = FormatUtil.replaceFormat(ess.getSettings().getNicknamePrefix()) + nick;
        suffix = "§r";
    }
    if (this.getBase().isOp()) {
        try {
            final ChatColor opPrefix = ess.getSettings().getOperatorColor();
            if (opPrefix != null && opPrefix.toString().length() > 0) {
                prefix.insert(0, opPrefix.toString());
                suffix = "§r";
            }
        } catch (Exception e) {
        }
    }
    if (ess.getSettings().addPrefixSuffix()) {
        //These two extra toggles are not documented, because they are mostly redundant #EasterEgg
        if (withPrefix || !ess.getSettings().disablePrefix()) {
            final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
            prefix.insert(0, ptext);
            suffix = "§r";
        }
        if (withSuffix || !ess.getSettings().disableSuffix()) {
            final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
            suffix = stext + "§r";
            suffix = suffix.replace("§f§f", "§f").replace("§f§r", "§r").replace("§r§r", "§r");
        }
    }
    final String strPrefix = prefix.toString();
    String output = strPrefix + nickname + suffix;
    if (!longnick && output.length() > 16) {
        output = strPrefix + nickname;
    }
    if (!longnick && output.length() > 16) {
        output = FormatUtil.lastCode(strPrefix) + nickname;
    }
    if (!longnick && output.length() > 16) {
        output = FormatUtil.lastCode(strPrefix) + nickname.substring(0, 14);
    }
    if (output.charAt(output.length() - 1) == '§') {
        output = output.substring(0, output.length() - 1);
    }
    return output;
}
Also used : ChatColor(org.bukkit.ChatColor) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 9 with ChatColor

use of org.bukkit.ChatColor in project Denizen-For-Bukkit by DenizenScript.

the class TextTags method colorTags.

// <--[tag]
// @attribute <&0>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Black.
// -->
// <--[tag]
// @attribute <&1>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Blue.
// -->
// <--[tag]
// @attribute <&2>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Green.
// -->
// <--[tag]
// @attribute <&3>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Cyan.
// -->
// <--[tag]
// @attribute <&4>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Red.
// -->
// <--[tag]
// @attribute <&5>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Magenta.
// -->
// <--[tag]
// @attribute <&6>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Gold.
// -->
// <--[tag]
// @attribute <&7>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Gray.
// -->
// <--[tag]
// @attribute <&8>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Gray.
// -->
// <--[tag]
// @attribute <&9>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Blue.
// -->
// <--[tag]
// @attribute <&a>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Green.
// -->
// <--[tag]
// @attribute <&b>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Cyan.
// -->
// <--[tag]
// @attribute <&c>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Red.
// -->
// <--[tag]
// @attribute <&d>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Magenta.
// -->
// <--[tag]
// @attribute <&e>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Yellow.
// -->
// <--[tag]
// @attribute <&f>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters White.
// -->
// <--[tag]
// @attribute <&k>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters obfuscated.
// -->
// <--[tag]
// @attribute <&l>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters bold.
// -->
// <--[tag]
// @attribute <&m>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters have a strike-through.
// -->
// <--[tag]
// @attribute <&n>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters have an underline.
// -->
// <--[tag]
// @attribute <&o>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters italicized.
// -->
// <--[tag]
// @attribute <&r>
// @returns Element
// @description
// Returns the ChatColor that resets the following characters to normal.
// -->
// <--[tag]
// @attribute <black>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Black.
// -->
// <--[tag]
// @attribute <dark_blue>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Blue.
// -->
// <--[tag]
// @attribute <dark_green>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Green.
// -->
// <--[tag]
// @attribute <dark_aqua>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Cyan.
// -->
// <--[tag]
// @attribute <dark_red>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Red.
// -->
// <--[tag]
// @attribute <dark_purple>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Magenta.
// -->
// <--[tag]
// @attribute <gold>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Gold.
// -->
// <--[tag]
// @attribute <gray>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Gray.
// -->
// <--[tag]
// @attribute <dark_gray>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Dark Gray.
// -->
// <--[tag]
// @attribute <blue>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Blue.
// -->
// <--[tag]
// @attribute <green>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Green.
// -->
// <--[tag]
// @attribute <aqua>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Cyan.
// -->
// <--[tag]
// @attribute <red>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Light Red.
// -->
// <--[tag]
// @attribute <light_purple>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Magenta.
// -->
// <--[tag]
// @attribute <yellow>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters Yellow.
// -->
// <--[tag]
// @attribute <white>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters White.
// -->
// <--[tag]
// @attribute <magic>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters obfuscated.
// -->
// <--[tag]
// @attribute <bold>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters bold.
// -->
// <--[tag]
// @attribute <strikethrough>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters have a strike-through.
// -->
// <--[tag]
// @attribute <underline>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters have an underline.
// -->
// <--[tag]
// @attribute <italic>
// @returns Element
// @description
// Returns the ChatColor that makes the following characters italicized.
// -->
// <--[tag]
// @attribute <reset>
// @returns Element
// @description
// Returns the ChatColor that resets the following characters to normal.
// -->
@TagManager.TagEvents
public void colorTags(ReplaceableTagEvent event) {
    Attribute attribute = event.getAttributes();
    int i = 0;
    for (ChatColor color : ChatColor.values()) {
        if (i > 22) {
            break;
        }
        if (event.matches(color.name())) {
            event.setReplaced(new Element(color.toString()).getAttribute(attribute.fulfill(1)));
        } else if (event.matches("&" + code[i])) {
            event.setReplaced(new Element(ChatColor.getByChar(code[i]).toString()).getAttribute(attribute.fulfill(1)));
        }
        i++;
    }
}
Also used : Attribute(net.aufdemrand.denizencore.tags.Attribute) Element(net.aufdemrand.denizencore.objects.Element) ChatColor(org.bukkit.ChatColor)

Example 10 with ChatColor

use of org.bukkit.ChatColor in project Bukkit by Bukkit.

the class ScoreboardCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    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();
            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;
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) Set(java.util.Set) HashSet(java.util.HashSet) Objective(org.bukkit.scoreboard.Objective) Score(org.bukkit.scoreboard.Score) Scoreboard(org.bukkit.scoreboard.Scoreboard) DisplaySlot(org.bukkit.scoreboard.DisplaySlot) OfflinePlayer(org.bukkit.OfflinePlayer) Team(org.bukkit.scoreboard.Team) ChatColor(org.bukkit.ChatColor) HashSet(java.util.HashSet)

Aggregations

ChatColor (org.bukkit.ChatColor)12 JSONObject (org.json.simple.JSONObject)3 ArrayList (java.util.ArrayList)2 Player (org.bukkit.entity.Player)2 Team (org.bukkit.scoreboard.Team)2 DefaultPermission (fr.xephi.authme.permission.DefaultPermission)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 Element (net.aufdemrand.denizencore.objects.Element)1 Attribute (net.aufdemrand.denizencore.tags.Attribute)1 MaxMoneyException (net.ess3.api.MaxMoneyException)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 EventHandler (org.bukkit.event.EventHandler)1 DisplaySlot (org.bukkit.scoreboard.DisplaySlot)1 Objective (org.bukkit.scoreboard.Objective)1 Score (org.bukkit.scoreboard.Score)1 Scoreboard (org.bukkit.scoreboard.Scoreboard)1