Skip to content

Commit

Permalink
Update to 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Sep 19, 2023
1 parent 661f5d7 commit b13a9a9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 82 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ dependencies {
//modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version)
//modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version)

modImplementation include("eu.pb4:predicate-api:0.1.2+1.20")
modImplementation include("eu.pb4:predicate-api:0.3.0+1.20.2")
modImplementation include("eu.pb4:placeholder-api:2.1.3+1.20.1")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
modImplementation include("eu.pb4:player-data-api:0.2.2+1.19.3")
modImplementation include("eu.pb4:player-data-api:0.3.0+1.20.2")

modCompileOnly("maven.modrinth:vanish:1.1.0")
//modLocalRuntime("fr.catcore:server-translations-api:1.4.17+1.19.2")
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.1
loader_version=0.14.21
minecraft_version=1.20.2-rc2
yarn_mappings=1.20.2-rc2+build.1
loader_version=0.14.22

#Fabric api
fabric_version=0.83.0+1.20.1
fabric_version=0.89.0+1.20.2

# Mod Properties

mod_version = 2.2.3+1.20.1
mod_version = 2.3.0+1.20.2
maven_group = eu.pb4
archives_base_name = styled-chat

Expand Down
59 changes: 3 additions & 56 deletions src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static Text formatFor(PlaceholderContext context, String input) {

if (config.configData.formatting.respectColors) {
try {
text = context.server().getMessageDecorator().decorate(context.player(), text).get();
text = context.server().getMessageDecorator().decorate(context.player(), text);
} catch (Exception e) {
// noop
}
Expand All @@ -203,63 +203,10 @@ public static Text formatFor(PlaceholderContext context, String input) {
return text;
}

// Todo: Remove this
public static String legacyFormatMessage(String input, Set<String> handlers) {
var config = ConfigManager.getConfig();

try {
if (config.configData.formatting.markdown) {
if (handlers.contains(SPOILER_TAG)) {
input = input.replaceAll(getMarkdownRegex("||", "\\|\\|"), "<spoiler>$2</spoiler>");
}

if (handlers.contains("bold")) {
input = input.replaceAll(getMarkdownRegex("**", "\\*\\*"), "<bold>$2</bold>");
}

if (handlers.contains("underline")) {
input = input.replaceAll(getMarkdownRegex("__", "__"), "<underline>$2</underline>");
}

if (handlers.contains("strikethrough")) {
input = input.replaceAll(getMarkdownRegex("~~", "~~"), "<strikethrough>$2</strikethrough>");
}

if (handlers.contains("italic")) {
input = input.replaceAll(getMarkdownRegex("*", "\\*"), "<italic>$2</italic>");
}
}
} catch (Exception e) {
e.printStackTrace();
}

return input;
}

private static String getMarkdownRegex(String base, String sides) {
return "(" + sides + ")(?<id>[^" + base + "]+)(" + sides + ")";
}

public static MessageDecorator getChatDecorator() {
return (player, message) -> {
if (player != null) {
return CompletableFuture.completedFuture(StyledChatStyles.getChat(player, formatFor(PlaceholderContext.of(player), message.getString())));
} else {
return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(StyledChatMod.server), message.getString()));
}
};
}

public static MessageDecorator getRawDecorator() {
return (player, message) -> {
if (player != null) {
return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(player), message.getString()));
} else {
return CompletableFuture.completedFuture(formatFor(PlaceholderContext.of(StyledChatMod.server), message.getString()));
}
};
}

public static <T> MessageDecorator getCommandDecorator(String context, ServerCommandSource source, BiFunction<String, Class<?>, Object> argumentGetter) {
Config config = ConfigManager.getConfig();

Expand All @@ -268,7 +215,7 @@ public static <T> MessageDecorator getCommandDecorator(String context, ServerCom
var input = formatFor(player != null ? PlaceholderContext.of(player) : PlaceholderContext.of(StyledChatMod.server), message.getString());


return CompletableFuture.completedFuture(switch (context) {
return switch (context) {
case "msg" -> {
try {
yield config.getPrivateMessageReceived(
Expand Down Expand Up @@ -297,7 +244,7 @@ public static <T> MessageDecorator getCommandDecorator(String context, ServerCom
case "me" -> config.getMeCommand(source, input);

default -> input;
});
};
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PlayerAdvancementTrackerMixin {

@Shadow private ServerPlayerEntity owner;

@ModifyArg(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
@ModifyArg(method = "method_53637", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
private Text styledChat_changeAdvancementMessage(Text text) {
var translatableText = (TranslatableTextContent) text.getContent();
Text advancement = (Text) translatableText.getArgs()[1];
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.message.SignedMessage;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
Expand All @@ -34,12 +35,12 @@ public class PlayerManagerMixin {
private ServerPlayerEntity styledChat_temporaryPlayer = null;

@Inject(method = "onPlayerConnect", at = @At(value = "HEAD"))
private void styledChat_storePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
private void styledChat_storePlayer(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
this.styledChat_temporaryPlayer = player;
}

@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void styledChat_removeStoredPlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
private void styledChat_removeStoredPlayer(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
this.styledChat_temporaryPlayer = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import eu.pb4.styledchat.config.ConfigManager;
import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler;
import eu.pb4.styledchat.StyledChatUtils;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.message.MessageDecorator;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
import net.minecraft.network.packet.c2s.common.ClientOptionsC2SPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.*;
Expand All @@ -31,20 +34,18 @@ public abstract class ServerPlayNetworkManagerMixin implements ExtPlayNetworkHan

@Unique
private ChatStyle styledChat$style;
@Unique
private boolean styledChat$chatColors = true;

@ModifyArg(method = "onDisconnected", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
@ModifyArg(method = "cleanUp", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
private Text styledChat_replaceDisconnectMessage(Text text) {
return StyledChatStyles.getLeft(this.player);
}

@Redirect(method = "method_44900", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageDecorator;decorate(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/text/Text;)Ljava/util/concurrent/CompletableFuture;"))
private CompletableFuture<Text> styledChat_replaceDecorator2(MessageDecorator instance, ServerPlayerEntity player, Text text) {
@Redirect(method = "method_44900", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageDecorator;decorate(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/text/Text;)Lnet/minecraft/text/Text;"))
private Text styledChat_replaceDecorator2(MessageDecorator instance, ServerPlayerEntity player, Text text) {
if (player != null) {
return CompletableFuture.completedFuture(StyledChatUtils.formatFor(PlaceholderContext.of(player), text.getString()));
return StyledChatUtils.formatFor(PlaceholderContext.of(player), text.getString());
} else {
return CompletableFuture.completedFuture(StyledChatUtils.formatFor(PlaceholderContext.of(StyledChatMod.server), text.getString()));
return StyledChatUtils.formatFor(PlaceholderContext.of(StyledChatMod.server), text.getString());
}
}

Expand All @@ -53,11 +54,6 @@ private void styledChat_setFormattedMessage(SignedMessage signedMessage, Callbac
StyledChatUtils.modifyForSending(signedMessage, this.player.getCommandSource(), MessageType.CHAT);
}

@Inject(method = "onClientSettings", at = @At("TAIL"))
private void styledChat_setFormattedMessage(ClientSettingsC2SPacket packet, CallbackInfo ci) {
this.styledChat$chatColors = packet.chatColors();
}

@Override
public ChatStyle styledChat$getStyle() {
if (this.styledChat$style == null) {
Expand All @@ -73,6 +69,6 @@ private void styledChat_setFormattedMessage(ClientSettingsC2SPacket packet, Call

@Override
public boolean styledChat$chatColors() {
return this.styledChat$chatColors || !ConfigManager.getConfig().configData.formatting.respectColors;
return this.player.areClientChatColorsEnabled() || !ConfigManager.getConfig().configData.formatting.respectColors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface StyledChatSentMessage extends SentMessage, ExtendedSentMessage
}

record Chat(SignedMessage message, Text override, MessageType.Parameters parameters, RegistryKey<MessageType> sourceType, MutableObject<MessageType.Parameters> colorless) implements StyledChatSentMessage {
public Text getContent() {
public Text content() {
return message.unsignedContent();
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public StyledChatSentMessage reformat(MessageType.Parameters pars, RegistryKey<M
}

record System(SignedMessage message, Text override, MessageType.Parameters parameters, RegistryKey<MessageType> sourceType, MutableObject<MessageType.Parameters> colorless) implements StyledChatSentMessage {
public Text getContent() {
public Text content() {
return this.message.unsignedContent();
}

Expand Down

0 comments on commit b13a9a9

Please sign in to comment.