Search in sources :

Example 41 with ChatColor

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

the class FormatUtil method unformatString.

public static String unformatString(String message, final EnumSet<ChatColor> supported, boolean rgb) {
    if (message == null) {
        return null;
    }
    final StringBuffer rgbBuilder = new StringBuffer();
    final Matcher rgbMatcher = STRIP_RGB_PATTERN.matcher(message);
    while (rgbMatcher.find()) {
        final String code = rgbMatcher.group(1).replace(String.valueOf(ChatColor.COLOR_CHAR), "");
        if (rgb) {
            rgbMatcher.appendReplacement(rgbBuilder, "&#" + code);
            continue;
        }
        rgbMatcher.appendReplacement(rgbBuilder, "");
    }
    rgbMatcher.appendTail(rgbBuilder);
    // arreter de parler
    message = rgbBuilder.toString();
    // Legacy Colors
    final StringBuffer builder = new StringBuffer();
    final Matcher matcher = STRIP_ALL_PATTERN.matcher(message);
    searchLoop: while (matcher.find()) {
        final char code = matcher.group(1).toLowerCase(Locale.ROOT).charAt(0);
        for (final ChatColor color : supported) {
            if (color.getChar() == code) {
                matcher.appendReplacement(builder, "&" + code);
                continue searchLoop;
            }
        }
        matcher.appendReplacement(builder, "");
    }
    matcher.appendTail(builder);
    return builder.toString();
}
Also used : Matcher(java.util.regex.Matcher) ChatColor(org.bukkit.ChatColor)

Example 42 with ChatColor

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

the class FormatUtil method stripColor.

static String stripColor(final String input, final Set<ChatColor> strip) {
    final StringBuffer builder = new StringBuffer();
    final Matcher matcher = STRIP_ALL_PATTERN.matcher(input);
    searchLoop: while (matcher.find()) {
        final char code = matcher.group(1).toLowerCase(Locale.ROOT).charAt(0);
        for (final ChatColor color : strip) {
            if (color.getChar() == code) {
                matcher.appendReplacement(builder, "");
                continue searchLoop;
            }
        }
        // Don't replace
        matcher.appendReplacement(builder, "$0");
    }
    matcher.appendTail(builder);
    return builder.toString();
}
Also used : Matcher(java.util.regex.Matcher) ChatColor(org.bukkit.ChatColor)

Example 43 with ChatColor

use of org.bukkit.ChatColor in project Arcade2 by ShootGame.

the class TeamCommands method paintCommand.

public void paintCommand(Sender sender, String teamId, String paint) {
    Team team = this.fetchTeam(teamId);
    ChatColor color = Color.parseChat(new Context(this.game.getPlugin()), paint);
    if (color == null) {
        StringBuilder colors = new StringBuilder();
        for (int i = 0; i < ChatColor.values().length; i++) {
            ChatColor value = ChatColor.values()[i];
            if (i != 0) {
                colors.append(", ");
            }
            ChatColor result = ChatColor.RED;
            if (!value.equals(ChatColor.MAGIC)) {
                result = value;
            }
            colors.append(result).append(value.name().toLowerCase().replace("_", "-")).append(ChatColor.RESET).append(ChatColor.RED);
        }
        throw new CommandException("Available colors: " + colors.toString() + ".");
    }
    Team oldState = new Team(team);
    team.setChatColor(color);
    this.callEditEvent(team, oldState, TeamEditEvent.Reason.PAINT);
    sender.sendSuccess(oldState.getName() + " has been painted from " + oldState.getChatColor().name().toLowerCase().replace("_", "-") + " to " + team.getChatColor().name().toLowerCase().replace("_", "-") + ".");
}
Also used : Context(pl.themolka.arcade.parser.Context) CommandException(pl.themolka.arcade.command.CommandException) ChatColor(org.bukkit.ChatColor)

Example 44 with ChatColor

use of org.bukkit.ChatColor in project Citizens2 by CitizensDev.

the class NPCCommands method glowing.

@Command(aliases = { "npc" }, usage = "glowing --color [minecraft chat color]", desc = "Toggles an NPC's glowing status", modifiers = { "glowing" }, min = 1, max = 1, permission = "citizens.npc.glowing")
@Requirements(selected = true, ownership = true)
public void glowing(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (args.hasValueFlag("color")) {
        ChatColor chatColor = Util.matchEnum(ChatColor.values(), args.getFlag("color"));
        npc.getOrAddTrait(ScoreboardTrait.class).setColor(chatColor);
        if (!npc.data().has(NPC.Metadata.GLOWING)) {
            npc.data().setPersistent(NPC.Metadata.GLOWING, true);
        }
        Messaging.sendTr(sender, Messages.GLOWING_COLOR_SET, npc.getName(), chatColor == null ? ChatColor.WHITE + "white" : chatColor + Util.prettyEnum(chatColor));
        return;
    }
    npc.data().setPersistent(NPC.Metadata.GLOWING, !npc.data().get(NPC.Metadata.GLOWING, false));
    boolean glowing = npc.data().get(NPC.Metadata.GLOWING);
    Messaging.sendTr(sender, glowing ? Messages.GLOWING_SET : Messages.GLOWING_UNSET, npc.getName());
}
Also used : ScoreboardTrait(net.citizensnpcs.trait.ScoreboardTrait) ChatColor(org.bukkit.ChatColor) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 45 with ChatColor

use of org.bukkit.ChatColor in project UltimateChat by FabioZumbi12.

the class ReflectionUtil method addColorToArray.

private JSONArray addColorToArray(String text) {
    JSONArray extraArr = new JSONArray();
    ChatColor color = ChatColor.WHITE;
    for (String part : text.split("(?=" + ChatColor.COLOR_CHAR + "[0-9a-fA-Fk-oK-ORr])")) {
        JSONObject objExtraTxt = new JSONObject();
        Matcher match = Pattern.compile("^" + ChatColor.COLOR_CHAR + "([0-9a-fA-Fk-oK-ORr]).*$").matcher(part);
        if (match.find()) {
            color = ChatColor.getByChar(match.group(1).charAt(0));
            if (part.length() == 2)
                continue;
        }
        objExtraTxt.put("text", UChatColor.stripColor(part));
        if (color.isColor()) {
            objExtraTxt.put("color", color.name().toLowerCase());
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.equals(ChatColor.RESET)) {
            objExtraTxt.put("color", "white");
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.isFormat()) {
            if (color.equals(ChatColor.MAGIC)) {
                objExtraTxt.put("obfuscated", true);
            } else if (color.equals(ChatColor.UNDERLINE)) {
                objExtraTxt.put("underlined", true);
            } else {
                objExtraTxt.put(color.name().toLowerCase(), true);
            }
        }
        extraArr.add(objExtraTxt);
    }
    return extraArr;
}
Also used : JSONObject(org.json.simple.JSONObject) Matcher(java.util.regex.Matcher) JSONArray(org.json.simple.JSONArray) ChatColor(org.bukkit.ChatColor)

Aggregations

ChatColor (org.bukkit.ChatColor)128 ArrayList (java.util.ArrayList)23 Player (org.bukkit.entity.Player)17 Matcher (java.util.regex.Matcher)9 World (org.bukkit.World)9 JSONObject (org.json.simple.JSONObject)9 ItemStack (org.bukkit.inventory.ItemStack)8 DyeColor (org.bukkit.DyeColor)7 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Material (org.bukkit.Material)6 Team (org.bukkit.scoreboard.Team)6 Method (java.lang.reflect.Method)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 List (java.util.List)3 UUID (java.util.UUID)3 Scoreboard (org.bukkit.scoreboard.Scoreboard)3