Add color API for Teams
Dieser Commit ist enthalten in:
Ursprung
44dd60ac27
Commit
c037fe3d44
11
nms-patches/EnumChatFormat.patch
Normale Datei
11
nms-patches/EnumChatFormat.patch
Normale Datei
@ -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;
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
||||
static {
|
||||
Builder<Character, EnumChatFormat> builder = ImmutableMap.builder();
|
||||
for (EnumChatFormat format : EnumChatFormat.values()) {
|
||||
builder.put(Character.toLowerCase(format.toString().charAt(1)), format);
|
||||
}
|
||||
formatMap = builder.build();
|
||||
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 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();
|
||||
}
|
||||
|
||||
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("");
|
||||
|
22
src/test/java/org/bukkit/ChatTest.java
Normale Datei
22
src/test/java/org/bukkit/ChatTest.java
Normale Datei
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren