Java Code Examples for org.bukkit.ChatColor#values()

The following examples show how to use org.bukkit.ChatColor#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageMessage.java    From AnnihilationPro with MIT License 6 votes vote down vote up
private ChatColor getClosestChatColor(Color color) {
    if (color.getAlpha() < 128) return null;

    int index = 0;
    double best = -1;

    for (int i = 0; i < colors.length; i++) {
        if (areIdentical(colors[i], color)) {
            return ChatColor.values()[i];
        }
    }

    for (int i = 0; i < colors.length; i++) {
        double distance = getDistance(color, colors[i]);
        if (distance < best || best == -1) {
            best = distance;
            index = i;
        }
    }

    // Minecraft has 15 colors
    return ChatColor.values()[index];
}
 
Example 2
Source File: CommandHelp.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
private static void help(CommandSender sender) {
    ChatColor titleColor = ChatColor.RESET, commandColor = ChatColor.RESET;
    while (disallowedChatColorCharacters.contains(titleColor))
        titleColor = ChatColor.values()[DiscordSRV.getPlugin().getRandom().nextInt(ChatColor.values().length)];
    while (disallowedChatColorCharacters.contains(commandColor) || commandColor == titleColor)
        commandColor = ChatColor.values()[DiscordSRV.getPlugin().getRandom().nextInt(ChatColor.values().length)];

    List<Method> commandMethods = new ArrayList<>();
    for (Method method : DiscordSRV.getPlugin().getCommandManager().getCommands().values())
        if (!commandMethods.contains(method)) commandMethods.add(method);

    sender.sendMessage(ChatColor.DARK_GRAY + "================[ " + titleColor + "DiscordSRV" + ChatColor.DARK_GRAY + " ]================");
    for (Method commandMethod : commandMethods) {
        Command commandAnnotation = commandMethod.getAnnotation(Command.class);

        // make sure sender has permission to run the commands before showing them permissions for it
        if (!GamePermissionUtil.hasPermission(sender, commandAnnotation.permission())) continue;

        sender.sendMessage(ChatColor.GRAY + "- " + commandColor + "/discord " + String.join("/", commandAnnotation.commandNames()));
        sender.sendMessage("    " + ChatColor.ITALIC + commandAnnotation.helpMessage());
        if (!commandAnnotation.usageExample().equals("")) sender.sendMessage("    " + ChatColor.GRAY + ChatColor.ITALIC + "ex. /discord " + commandAnnotation.usageExample());
    }
}
 
Example 3
Source File: CommandHelp.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send help specific for the given commands
 * @param sender
 * @param commands
 */
private static void help(CommandSender sender, List<String> commands) {
    ChatColor titleColor = ChatColor.RESET, commandColor = ChatColor.RESET;
    while (disallowedChatColorCharacters.contains(titleColor))
        titleColor = ChatColor.values()[DiscordSRV.getPlugin().getRandom().nextInt(ChatColor.values().length - 1)];
    while (disallowedChatColorCharacters.contains(commandColor) || commandColor == titleColor)
        commandColor = ChatColor.values()[DiscordSRV.getPlugin().getRandom().nextInt(ChatColor.values().length - 1)];

    List<Method> commandMethods = new LinkedList<>();
    for (String commandName : commands) commandMethods.add(DiscordSRV.getPlugin().getCommandManager().getCommands().get(commandName));

    sender.sendMessage(ChatColor.DARK_GRAY + "===================[ " + titleColor + "DiscordSRV" + ChatColor.DARK_GRAY + " ]===================");
    for (Method commandMethod : commandMethods) {
        Command commandAnnotation = commandMethod.getAnnotation(Command.class);

        // make sure sender has permission to run the commands before showing them permissions for it
        if (!GamePermissionUtil.hasPermission(sender, commandAnnotation.permission())) continue;

        sender.sendMessage(ChatColor.GRAY + "- " + commandColor + "/discord " + String.join("/", commandAnnotation.commandNames()));
        sender.sendMessage("   " + ChatColor.ITALIC + commandAnnotation.helpMessage());
        if (!commandAnnotation.usageExample().equals("")) sender.sendMessage("   " + ChatColor.GRAY + ChatColor.ITALIC + "ex. /discord " + commandAnnotation.usageExample());
    }
}
 
Example 4
Source File: ColourMap.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
protected static ChatColor getClosest(Color color) {
    if (color.getAlpha() < 128) return null;

    int index = 0;
    double best = -1;

    for (int i = 0; i < ColourMap.colors.length; i++) {
        if (areIdentical(ColourMap.colors[i], color)) {
            return ChatColor.values()[i];
        }
    }

    for (int i = 0; i < ColourMap.colors.length; i++) {
        double distance = getDistance(color, ColourMap.colors[i]);
        if (distance < best || best == -1) {
            best = distance;
            index = i;
        }
    }

    // Minecraft has 15 colors
    return ChatColor.values()[index];
}
 
Example 5
Source File: LegacyItemTag.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static ChatColor nextId() {
  ChatColor[] colors = ChatColor.values();
  int id = IDS.getAndIncrement();

  // Unfortunately, there can only be as many item tags as there are color codes.
  if (id >= colors.length) throw new IllegalStateException("Exhausted item tag space");

  return colors[id];
}
 
Example 6
Source File: CustomScoreBoard.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private void initializeScoreboard() {
    ChatColor[] colorArray = ChatColor.values();
    for(int i = 0; i < colorArray.length; i++) {
        ChatColor color = colorArray[i];
        Team team = this.scoreboard.registerNewTeam("line" + i);
        team.addEntry(color.toString());

        CustomLine line = new CustomLine(color, i, team);
        this.lineList.add(line);
    }
}
 
Example 7
Source File: GlowUtil.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    color = ChatColor.values()[RANDOM.nextInt(ChatColor.values().length - 1)];
    for (Entry<Object, Long> entry : entities.entrySet().toArray(new Entry[entities.size()])) {
        if (entry.getKey() instanceof org.bukkit.entity.Entity) {
            run((org.bukkit.entity.Entity) entry.getKey(), entry.getValue());
        } else if (entry.getKey() instanceof net.minecraft.server.v1_16_R1.Entity) {
            run((net.minecraft.server.v1_16_R1.Entity) entry.getKey(), entry.getValue());
        }
    }
}
 
Example 8
Source File: HBLogger.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String translateColors(String message) {
    for (ChatColor color : ChatColor.values()) {
        if (replacements.containsKey(color)) {
            message = message.replaceAll("(?i)" + color.toString(), replacements.get(color));
        } else {
            message = message.replaceAll("(?i)" + color.toString(), "");
        }
    }
    return message + "\u001B[m";
}
 
Example 9
Source File: CivColor.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public static String strip(String line) {

		for (ChatColor cc : ChatColor.values())
			line.replaceAll(cc.toString(), "");
		return line;
	}
 
Example 10
Source File: Parser.java    From CardinalPGM with MIT License 4 votes vote down vote up
public static ChatColor parseChatColor(String string) {
    for (ChatColor color : ChatColor.values()) {
        if (color.name().equals(Strings.getTechnicalName(string))) return color;
    }
    return ChatColor.WHITE;
}
 
Example 11
Source File: HelpProviderTest.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
private static String removeColors(String str) {
    for (ChatColor color : ChatColor.values()) {
        str = str.replace(color.toString(), "");
    }
    return str;
}
 
Example 12
Source File: HelpCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
private static String removeColors(String str) {
    for (ChatColor color : ChatColor.values()) {
        str = str.replace(color.toString(), "");
    }
    return str;
}
 
Example 13
Source File: ConsoleLogFormatter.java    From Bukkit-SSHD with Apache License 2.0 4 votes vote down vote up
private void colorize(LogRecord logrecord) {
    // ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender
    final Map<ChatColor, String> replacements = new EnumMap<>(ChatColor.class);

    replacements
            .put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
    replacements
            .put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
    replacements.put(ChatColor.DARK_GREEN,
            Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
    replacements
            .put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
    replacements
            .put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
    replacements.put(ChatColor.DARK_PURPLE,
            Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
    replacements
            .put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
    replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
    replacements
            .put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
    replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
    replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
    replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
    replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
    replacements.put(ChatColor.LIGHT_PURPLE,
            Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
    replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
    replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
    replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());
    replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString());
    replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString());
    replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString());
    replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString());
    replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString());

    String result = logrecord.getMessage();
    for (ChatColor color : ChatColor.values()) {
        if (replacements.containsKey(color)) {
            result = result.replaceAll("(?i)" + color.toString(), replacements.get(color));
        } else {
            result = result.replaceAll("(?i)" + color.toString(), "");
        }
    }
    result += Ansi.ansi().reset().toString();
    logrecord.setMessage(result);
}