Add color API for Teams

Dieser Commit ist enthalten in:
md_5 2017-05-28 11:00:02 +10:00
Ursprung 44dd60ac27
Commit c037fe3d44
4 geänderte Dateien mit 71 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,11 @@
--- a/net/minecraft/server/EnumChatFormat.java
+++ b/net/minecraft/server/EnumChatFormat.java
@@ -16,7 +16,7 @@
private static final Map<String, EnumChatFormat> w = Maps.newHashMap();
private static final Pattern x = Pattern.compile("(?i)\u00a7[0-9A-FK-OR]");
private final String y;
- private final char z;
+ public final char z; // PAIL
private final boolean A;
private final String B;
private final int C;

Datei anzeigen

@ -13,6 +13,8 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.server.ScoreboardTeam; import net.minecraft.server.ScoreboardTeam;
import net.minecraft.server.ScoreboardTeamBase; import net.minecraft.server.ScoreboardTeamBase;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.util.CraftChatMessage;
final class CraftTeam extends CraftScoreboardComponent implements Team { final class CraftTeam extends CraftScoreboardComponent implements Team {
private final ScoreboardTeam team; private final ScoreboardTeam team;
@ -70,6 +72,21 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
team.setSuffix(suffix); team.setSuffix(suffix);
} }
@Override
public ChatColor getColor() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
return CraftChatMessage.getColor(team.m()); // PAIL: rename
}
@Override
public void setColor(ChatColor color) {
Validate.notNull(color, "Color cannot be null");
CraftScoreboard scoreboard = checkState();
team.a(CraftChatMessage.getColor(color)); // PAIL: rename
}
public boolean allowFriendlyFire() throws IllegalStateException { public boolean allowFriendlyFire() throws IllegalStateException {
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();

Datei anzeigen

@ -16,21 +16,31 @@ import net.minecraft.server.IChatBaseComponent;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import net.minecraft.server.ChatMessage; import net.minecraft.server.ChatMessage;
import org.bukkit.ChatColor;
public final class CraftChatMessage { public final class CraftChatMessage {
private static final Pattern LINK_PATTERN = Pattern.compile("((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " \\n]|$))))");
private static class StringMessage {
private static final Map<Character, EnumChatFormat> formatMap;
private static final Pattern INCREMENTAL_PATTERN = Pattern.compile("(" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + "[0-9a-fk-or])|(\\n)|((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " \\n]|$))))", Pattern.CASE_INSENSITIVE);
static { private static final Pattern LINK_PATTERN = Pattern.compile("((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " \\n]|$))))");
Builder<Character, EnumChatFormat> builder = ImmutableMap.builder(); private static final Map<Character, EnumChatFormat> formatMap;
for (EnumChatFormat format : EnumChatFormat.values()) {
builder.put(Character.toLowerCase(format.toString().charAt(1)), format); static {
} Builder<Character, EnumChatFormat> builder = ImmutableMap.builder();
formatMap = builder.build(); for (EnumChatFormat format : EnumChatFormat.values()) {
builder.put(Character.toLowerCase(format.toString().charAt(1)), format);
} }
formatMap = builder.build();
}
public static EnumChatFormat getColor(ChatColor color) {
return formatMap.get(color.getChar());
}
public static ChatColor getColor(EnumChatFormat format) {
return ChatColor.getByChar(format.z);
}
private static class StringMessage {
private static final Pattern INCREMENTAL_PATTERN = Pattern.compile("(" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + "[0-9a-fk-or])|(\\n)|((?:(?:https?):\\/\\/)?(?:[-\\w_\\.]{2,}\\.[a-z]{2,4}.*?(?=[\\.\\?!,;:]?(?:[" + String.valueOf(org.bukkit.ChatColor.COLOR_CHAR) + " \\n]|$))))", Pattern.CASE_INSENSITIVE);
private final List<IChatBaseComponent> list = new ArrayList<IChatBaseComponent>(); private final List<IChatBaseComponent> list = new ArrayList<IChatBaseComponent>();
private IChatBaseComponent currentChatComponent = new ChatComponentText(""); private IChatBaseComponent currentChatComponent = new ChatComponentText("");

Datei anzeigen

@ -0,0 +1,22 @@
package org.bukkit;
import net.minecraft.server.EnumChatFormat;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.junit.Assert;
import org.junit.Test;
public class ChatTest {
@Test
public void testColors() {
for (ChatColor color : ChatColor.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(color));
Assert.assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color)));
}
for (EnumChatFormat format : EnumChatFormat.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(format));
Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format)));
}
}
}