下面列出了org.bukkit.ChatColor#values ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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];
}
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());
}
}
/**
* 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());
}
}
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];
}
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];
}
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);
}
}
@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());
}
}
}
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";
}
public static String strip(String line) {
for (ChatColor cc : ChatColor.values())
line.replaceAll(cc.toString(), "");
return line;
}
public static ChatColor parseChatColor(String string) {
for (ChatColor color : ChatColor.values()) {
if (color.name().equals(Strings.getTechnicalName(string))) return color;
}
return ChatColor.WHITE;
}
private static String removeColors(String str) {
for (ChatColor color : ChatColor.values()) {
str = str.replace(color.toString(), "");
}
return str;
}
private static String removeColors(String str) {
for (ChatColor color : ChatColor.values()) {
str = str.replace(color.toString(), "");
}
return str;
}
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);
}