Skip to content

Commit

Permalink
Update to 1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jul 27, 2022
1 parent c6e286b commit 489a9c8
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 148 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ dependencies {

loom {
enableTransitiveAccessWideners = false
interfaceInjection {
enableDependencyInterfaceInjection = false
}
}

processResources {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19.1-pre5
yarn_mappings=1.19.1-pre5+build.1
minecraft_version=1.19.1
yarn_mappings=1.19.1+build.1
loader_version=0.14.8

#Fabric api
fabric_version=0.57.2+1.19.1
fabric_version=0.58.4+1.19.1

# Mod Properties
mod_version = 1.4.0+1.19.1
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/styledchat/StyledChatMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Decoration;
import net.minecraft.util.Identifier;
Expand All @@ -28,7 +29,6 @@ public class StyledChatMod implements ModInitializer {
public void onInitialize() {
this.crabboardDetection();
Placeholders.registerChangeEvent((id, removed) -> ConfigManager.clearCached());

}


Expand Down
32 changes: 23 additions & 9 deletions src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import eu.pb4.styledchat.ducks.ExtSignedMessage;
import eu.pb4.styledchat.parser.SpoilerNode;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.class_7649;
import net.minecraft.command.EntitySelector;
import net.minecraft.network.message.MessageDecorator;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.network.message.*;
import net.minecraft.network.packet.s2c.play.ChatSuggestionsS2CPacket;
import net.minecraft.scoreboard.Team;
import net.minecraft.server.command.ServerCommandSource;
Expand Down Expand Up @@ -296,13 +295,13 @@ public static boolean isHandledByMod(RegistryKey<MessageType> typeKey) {
return DECORABLE.contains(typeKey);
}

public static void modifyForSending(FilteredMessage<SignedMessage> message, ServerCommandSource source, RegistryKey<MessageType> type) {
/*public static void modifyForSending(FilteredMessage<SignedMessage> message, ServerCommandSource source, RegistryKey<MessageType> type) {
((ExtSignedMessage) (Object) message.raw()).styledChat_setArg("override", StyledChatUtils.formatMessage(message.raw(), source, type));
if (message.raw() != message.filtered()) {
((ExtSignedMessage) (Object) message.filtered()).styledChat_setArg("override", StyledChatUtils.formatMessage(message.filtered(), source, type));
}
}
}*/

public static void modifyForSending(SignedMessage message, ServerCommandSource source, RegistryKey<MessageType> type) {
try {
Expand All @@ -317,7 +316,11 @@ public static Text formatMessage(SignedMessage message, ServerCommandSource sour
var ext = (ExtSignedMessage) (Object) message;

var baseInput = ext.styledChat_getArg("base_input");
var input = baseInput != null && baseInput.getContent() != TextContent.EMPTY ? baseInput : formatFor(source, ext.styledChat_getOriginal());

var input = baseInput != null && baseInput.getContent() != TextContent.EMPTY
? baseInput
: maybeFormatFor(source, ext.styledChat_getOriginal(), message.getContent());


return switch (type.getValue().getPath()) {
case "msg_command_incoming" -> {
Expand Down Expand Up @@ -375,6 +378,14 @@ public static Text formatMessage(SignedMessage message, ServerCommandSource sour
};
}

public static Text maybeFormatFor(ServerCommandSource source, String original, Text originalContent) {
if (source.isExecutedByPlayer() && ConfigManager.getConfig().configData.requireChatPreviewForFormatting) {
return originalContent;
}

return formatFor(source, original);
}

public static Text formatFor(ServerCommandSource source, String original) {
if (source.getEntity() instanceof ServerPlayerEntity player) {
return formatFor(PlaceholderContext.of(player), original);
Expand All @@ -383,13 +394,16 @@ public static Text formatFor(ServerCommandSource source, String original) {
}
}

public static FilteredMessage<SignedMessage> toEventMessage(FilteredMessage<SignedMessage> message, PlaceholderContext context) {
var ext = (ExtSignedMessage) (Object) message.raw();
public static SignedMessage toEventMessage(SignedMessage message, PlaceholderContext context) {
var ext = (ExtSignedMessage) (Object) message;

var baseInput = ext.styledChat_getArg("base_input");
var input = baseInput != null && baseInput.getContent() != TextContent.EMPTY ? baseInput : formatFor(context, ext.styledChat_getOriginal());

return FilteredMessage.permitted(SignedMessage.ofUnsigned(message.raw().createMetadata(), input));
MessageMetadata messageMetadata = message.createMetadata();
MessageBody messageBody = new MessageBody(new DecoratedContents(ext.styledChat_getOriginal(), input), messageMetadata.timestamp(), messageMetadata.salt(), LastSeenMessageList.EMPTY);
MessageHeader messageHeader = new MessageHeader(null, messageMetadata.sender());
return new SignedMessage(messageHeader, MessageSignatureData.EMPTY, messageBody, Optional.empty(), null);
}

public static void sendAutocompliton(ServerPlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ConfigData {
public boolean enableMarkdown = true;
public boolean allowModdedDecorators = true;
public boolean sendFullMessageInChatPreview = false;
public boolean requireChatPreviewForFormatting = false;
public boolean sendAutoCompletionForTags = false;
public boolean sendAutoCompletionForTagAliases = false;
public boolean sendAutoCompletionForEmotes = true;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/eu/pb4/styledchat/ducks/ExtSentMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eu.pb4.styledchat.ducks;

import net.minecraft.network.message.SentMessage;
import net.minecraft.network.message.SignedMessage;

public interface ExtSentMessage {
static SignedMessage getWrapped(SentMessage x) {
return ((ExtSentMessage) x).styledChat_getMessage();
}

SignedMessage styledChat_getMessage();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@Mixin(MessageArgumentType.SignedMessage.class)
public class MessageArgumentTypeSignedMessageMixin {
@Redirect(method = "decorate(Lnet/minecraft/server/command/ServerCommandSource;Lnet/minecraft/server/filter/FilteredMessage;Lnet/minecraft/server/filter/FilteredMessage;)Ljava/util/concurrent/CompletableFuture;", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;"))
@Redirect(method = "method_45069", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;"))
private MessageDecorator styledChat_returnCached(MinecraftServer instance) {
return (player, message) -> {
if (player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private void styledChat_registerStarting(CallbackInfo ci) {

@Inject(method = "shutdown", at = @At("TAIL"))
private void styledChat_registerStopping(CallbackInfo ci) {
StyledChatMod.serverStarting((MinecraftServer) (Object) this);
StyledChatMod.serverStopped((MinecraftServer) (Object) this);
}

@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private void styledChat_sendTree(ServerPlayerEntity player, CallbackInfo ci) {
StyledChatUtils.sendAutocompliton(player);
}

@Redirect(method = "broadcast(Lnet/minecraft/server/filter/FilteredMessage;Ljava/util/function/Predicate;Lnet/minecraft/network/message/MessageSourceProfile;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;logChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageType$Parameters;Ljava/lang/String;)V"), require = 0)
private void styledChat_fixServerLogs(MinecraftServer instance, Text text, MessageType.Parameters parameters, String string, FilteredMessage<SignedMessage> filteredMessage) {
var out = ((ExtSignedMessage) (Object) filteredMessage.raw()).styledChat_getArg("override");
@Redirect(method = "broadcast(Lnet/minecraft/network/message/SignedMessage;Ljava/util/function/Predicate;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageSourceProfile;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;logChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageType$Parameters;Ljava/lang/String;)V"), require = 0)
private void styledChat_fixServerLogs(MinecraftServer instance, Text text, MessageType.Parameters parameters, String string, SignedMessage signedMessage) {
var out = ((ExtSignedMessage) (Object) signedMessage).styledChat_getArg("override");
if (out != null) {
if (out != StyledChatUtils.IGNORED_TEXT) {
this.server.sendMessage(out);
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/eu/pb4/styledchat/mixin/SentMessageChatMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.styledchat.mixin;

import eu.pb4.styledchat.StyledChatMod;
import eu.pb4.styledchat.ducks.ExtSentMessage;
import eu.pb4.styledchat.ducks.ExtSignedMessage;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SentMessage;
Expand All @@ -9,23 +10,30 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(SentMessage.Chat.class)
public abstract class SentMessageChatMixin {
@Shadow public abstract SignedMessage getWrappedMessage();
public abstract class SentMessageChatMixin implements ExtSentMessage {

@Redirect(method = "toPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;"))
@Shadow @Final private SignedMessage message;

@Redirect(method = "method_45095", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;"))
private MessageType.Serialized styledChat_replaceSerialized(MessageType.Parameters instance, DynamicRegistryManager registryManager) {
var override = ((ExtSignedMessage) (Object) this.getWrappedMessage()).styledChat_getArg("override");
var override = ((ExtSignedMessage) (Object) this.message).styledChat_getArg("override");
if (override != null) {
var reg = registryManager.get(Registry.MESSAGE_TYPE_KEY);
return new MessageType.Serialized(reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE_ID)), override, null);
} else {
return instance.toSerialized(registryManager);
}
}

@Override
public SignedMessage styledChat_getMessage() {
return this.message;
}
}
33 changes: 0 additions & 33 deletions src/main/java/eu/pb4/styledchat/mixin/SentMessageEntityMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.styledchat.mixin;

import eu.pb4.styledchat.StyledChatMod;
import eu.pb4.styledchat.ducks.ExtSentMessage;
import eu.pb4.styledchat.ducks.ExtSignedMessage;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SentMessage;
Expand All @@ -9,6 +10,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -17,17 +19,22 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(SentMessage.Profileless.class)
public abstract class SentMessageProfilelessMixin {
@Shadow public abstract SignedMessage getWrappedMessage();
public abstract class SentMessageProfilelessMixin implements ExtSentMessage {
@Shadow @Final private SignedMessage message;

@Redirect(method = "toPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;"))
@Redirect(method = "method_45095", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType$Parameters;toSerialized(Lnet/minecraft/util/registry/DynamicRegistryManager;)Lnet/minecraft/network/message/MessageType$Serialized;"))
private MessageType.Serialized styledChat_replaceSerialized(MessageType.Parameters instance, DynamicRegistryManager registryManager) {
var override = ((ExtSignedMessage) (Object) this.getWrappedMessage()).styledChat_getArg("override");
var override = ((ExtSignedMessage) (Object) this.message).styledChat_getArg("override");
if (override != null) {
var reg = registryManager.get(Registry.MESSAGE_TYPE_KEY);
return new MessageType.Serialized(reg.getRawId(reg.get(StyledChatMod.MESSAGE_TYPE_ID)), override, null);
} else {
return instance.toSerialized(registryManager);
}
}

@Override
public SignedMessage styledChat_getMessage() {
return this.message;
}
}
Loading

0 comments on commit 489a9c8

Please sign in to comment.