Updated ChatMessageHandler to use Minecraft's Chat Component System instead of Strings with Color Codes | https://trello.com/c/jdl5t5Wj/
This commit is contained in:
@@ -4,8 +4,7 @@ import eu.crushedpixel.replaymod.ReplayMod;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.*;
|
||||||
import net.minecraft.util.IChatComponent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
@@ -15,10 +14,23 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class ChatMessageHandler {
|
public class ChatMessageHandler {
|
||||||
|
|
||||||
|
private static final IChatComponent prefix;
|
||||||
|
|
||||||
|
static {
|
||||||
|
//results in "§8[§6Replay Mod§8]§r "
|
||||||
|
|
||||||
|
ChatStyle dark_gray = new ChatStyle().setColor(EnumChatFormatting.DARK_GRAY);
|
||||||
|
ChatStyle gold = new ChatStyle().setColor(EnumChatFormatting.GOLD);
|
||||||
|
|
||||||
|
prefix = new ChatComponentText("[").setChatStyle(dark_gray)
|
||||||
|
.appendSibling(new ChatComponentTranslation("replaymod.title").setChatStyle(gold))
|
||||||
|
.appendSibling(new ChatComponentText("] "));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean active = true;
|
private boolean active = true;
|
||||||
private boolean alive = true;
|
private boolean alive = true;
|
||||||
private Queue<IChatComponent> requests = new ConcurrentLinkedQueue<IChatComponent>();
|
private Queue<IChatComponent> requests = new ConcurrentLinkedQueue<IChatComponent>();
|
||||||
private String prefix = "§8[§6Replay Mod§8]§r ";
|
|
||||||
private EntityPlayerSP player = null;
|
private EntityPlayerSP player = null;
|
||||||
public Thread t = new Thread(new Runnable() {
|
public Thread t = new Thread(new Runnable() {
|
||||||
|
|
||||||
@@ -61,20 +73,12 @@ public class ChatMessageHandler {
|
|||||||
public void addLocalizedChatMessage(String message, ChatMessageType type, Object... options) {
|
public void addLocalizedChatMessage(String message, ChatMessageType type, Object... options) {
|
||||||
message = I18n.format(message, options);
|
message = I18n.format(message, options);
|
||||||
if(ReplayMod.replaySettings.isShowNotifications()) {
|
if(ReplayMod.replaySettings.isShowNotifications()) {
|
||||||
message = prefix + toColor(message, type);
|
|
||||||
ChatComponentText cct = new ChatComponentText(message);
|
ChatComponentText cct = new ChatComponentText(message);
|
||||||
requests.add(cct);
|
cct.setChatStyle(type.getChatStyle());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String toColor(String message, ChatMessageType type) {
|
requests.add(prefix.createCopy().appendSibling(cct));
|
||||||
if(type == ChatMessageType.INFORMATION) {
|
|
||||||
return "§2" + message;
|
|
||||||
} else if(type == ChatMessageType.WARNING) {
|
|
||||||
return "§c" + message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@@ -90,6 +94,16 @@ public class ChatMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum ChatMessageType {
|
public enum ChatMessageType {
|
||||||
INFORMATION, WARNING;
|
INFORMATION(new ChatStyle().setColor(EnumChatFormatting.DARK_GREEN)), WARNING(new ChatStyle().setColor(EnumChatFormatting.RED));
|
||||||
|
|
||||||
|
private ChatStyle chatStyle;
|
||||||
|
|
||||||
|
public ChatStyle getChatStyle() {
|
||||||
|
return chatStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatMessageType(ChatStyle chatStyle) {
|
||||||
|
this.chatStyle = chatStyle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user