summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2017-05-28 11:00:02 +1000
committermd_5 <git@md-5.net>2017-05-28 11:00:02 +1000
commitc037fe3d442702885d9c6bfa65621fb624210c02 (patch)
tree02869ffcc33d0ecda80e5f0b8a2ac1347f5f72db /src
parent44dd60ac27b4d48f612a4290f8bb4e7cc71b3003 (diff)
downloadcraftbukkit-c037fe3d442702885d9c6bfa65621fb624210c02.tar
craftbukkit-c037fe3d442702885d9c6bfa65621fb624210c02.tar.gz
craftbukkit-c037fe3d442702885d9c6bfa65621fb624210c02.tar.lz
craftbukkit-c037fe3d442702885d9c6bfa65621fb624210c02.tar.xz
craftbukkit-c037fe3d442702885d9c6bfa65621fb624210c02.zip
Add color API for Teams
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java17
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java30
-rw-r--r--src/test/java/org/bukkit/ChatTest.java22
3 files changed, 59 insertions, 10 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
index e7688340..a2496e79 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
@@ -13,6 +13,8 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.server.ScoreboardTeam;
import net.minecraft.server.ScoreboardTeamBase;
+import org.bukkit.ChatColor;
+import org.bukkit.craftbukkit.util.CraftChatMessage;
final class CraftTeam extends CraftScoreboardComponent implements Team {
private final ScoreboardTeam team;
@@ -70,6 +72,21 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
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 {
CraftScoreboard scoreboard = checkState();
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
index 560f95cc..598d088f 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
@@ -16,21 +16,31 @@ import net.minecraft.server.IChatBaseComponent;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import net.minecraft.server.ChatMessage;
+import org.bukkit.ChatColor;
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);
+ private static final Map<Character, EnumChatFormat> formatMap;
- static {
- Builder<Character, EnumChatFormat> builder = ImmutableMap.builder();
- for (EnumChatFormat format : EnumChatFormat.values()) {
- builder.put(Character.toLowerCase(format.toString().charAt(1)), format);
- }
- formatMap = builder.build();
+ static {
+ Builder<Character, EnumChatFormat> builder = ImmutableMap.builder();
+ 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 IChatBaseComponent currentChatComponent = new ChatComponentText("");
diff --git a/src/test/java/org/bukkit/ChatTest.java b/src/test/java/org/bukkit/ChatTest.java
new file mode 100644
index 00000000..444ce6eb
--- /dev/null
+++ b/src/test/java/org/bukkit/ChatTest.java
@@ -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)));
+ }
+ }
+}