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();
}
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();
}
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("_", "-") + ".");
}
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());
}
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;
}
Aggregations