From 78dd71d71da5fa57c1c27ec71ac9190ebe4dd776 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Mon, 17 Oct 2022 19:10:59 +0200 Subject: [PATCH] Fix display name breaking if some mod accesses it too early --- build.gradle | 4 ++-- gradle.properties | 2 +- src/main/java/eu/pb4/styledchat/StyledChatUtils.java | 10 ++++++++-- src/main/java/eu/pb4/styledchat/config/ChatStyle.java | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 729bcd7..34fa6bd 100644 --- a/build.gradle +++ b/build.gradle @@ -35,10 +35,10 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" //modCompileOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - //modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") + modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version) - modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version) + //modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version) modCompileOnly fabricApi.module("fabric-message-api-v1", project.fabric_version) diff --git a/gradle.properties b/gradle.properties index 46b165e..6792218 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version=0.14.8 fabric_version=0.59.0+1.19.2 # Mod Properties - mod_version = 2.0.0+1.19.2 + mod_version = 2.0.1+1.19.2 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 3d22a0d..9a7f829 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -489,11 +489,17 @@ public static void sendAutocompliton(ServerPlayerEntity player) { } public static ChatStyle getPersonalStyle(ServerPlayerEntity player) { - return ((ExtPlayNetworkHandler) player.networkHandler).styledChat$getStyle(); + if (player.networkHandler != null) { + return ((ExtPlayNetworkHandler) player.networkHandler).styledChat$getStyle(); + } else { + return ChatStyle.EMPTY; + } } public static void updateStyle(ServerPlayerEntity player) { - ((ExtPlayNetworkHandler) player.networkHandler).styledChat$setStyle(createStyleOf(player)); + if (player.networkHandler != null) { + ((ExtPlayNetworkHandler) player.networkHandler).styledChat$setStyle(createStyleOf(player)); + } } @Nullable diff --git a/src/main/java/eu/pb4/styledchat/config/ChatStyle.java b/src/main/java/eu/pb4/styledchat/config/ChatStyle.java index 3045446..fb24dd3 100644 --- a/src/main/java/eu/pb4/styledchat/config/ChatStyle.java +++ b/src/main/java/eu/pb4/styledchat/config/ChatStyle.java @@ -24,6 +24,7 @@ import java.util.Map; public class ChatStyle { + public static final ChatStyle EMPTY = new ChatStyle(new ChatStyleData()); public final MinecraftPredicate require; public final TextNode displayName;