Update non-chat parts of fabric platform

This commit is contained in:
Jason Penilla committed 2022-07-08 12:47:07 -07:00
1 parent 11f95f9d0c
commit 0ed4a25108
7 files changed
+56 -53

No files matched your search

+3 -3
View File
@@ -15,6 +15,8 @@ dependencies {
minecraft(libs.fabricMinecraft) minecraft(libs.fabricMinecraft)
mappings(loom.officialMojangMappings()) mappings(loom.officialMojangMappings())
modImplementation(libs.fabricLoader) modImplementation(libs.fabricLoader)
modImplementation("net.fabricmc.fabric-api:fabric-api:0.57.0+1.19")
modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.57.0+1.19") // LuckPerms needs to work at dev time
carbon(projects.carbonchatCommon) { carbon(projects.carbonchatCommon) {
exclude("net.kyori", "adventure-api") exclude("net.kyori", "adventure-api")
@@ -28,9 +30,7 @@ dependencies {
modImplementation(libs.cloudFabric) modImplementation(libs.cloudFabric)
include(libs.cloudFabric) include(libs.cloudFabric)
modImplementation(libs.adventurePlatformFabric) { modImplementation(libs.adventurePlatformFabric)
exclude("ca.stellardrift", "colonel") // causes classloading issues when running in dev
}
include(libs.adventurePlatformFabric) include(libs.adventurePlatformFabric)
} }
@@ -19,15 +19,15 @@
*/ */
package net.draycia.carbon.fabric.mixin; package net.draycia.carbon.fabric.mixin;
import cloud.commandframework.types.tuples.Triplet; import cloud.commandframework.types.tuples.Pair;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents; import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences; import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.Connection; import net.minecraft.network.Connection;
import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList; import net.minecraft.server.players.PlayerList;
@@ -46,20 +46,20 @@ abstract class PlayerListMixin {
@Shadow @Final private MinecraftServer server; @Shadow @Final private MinecraftServer server;
@Shadow @Shadow
public abstract void broadcastMessage(Component component, ChatType chatType, UUID uUID); public abstract void broadcastSystemMessage(Component component, ResourceKey<ChatType> resourceKey);
public Map<Thread, Triplet<Component, ChatType, UUID>> carbon$joinMsg = new ConcurrentHashMap<>(); public Map<Thread, Pair<Component, ResourceKey<ChatType>>> carbon$joinMsg = new ConcurrentHashMap<>();
@Redirect( @Redirect(
method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V", method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V" target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/resources/ResourceKey;)V"
) )
) )
public void redirectJoinMessage(final PlayerList instance, final Component component, final ChatType chatType, final UUID uuid) { public void redirectJoinMessage(final PlayerList instance, final Component component, final ResourceKey<ChatType> resourceKey) {
// move to after player is added to playerlist and world // move to after player is added to playerlist and world
this.carbon$joinMsg.put(Thread.currentThread(), Triplet.of(component, chatType, uuid)); this.carbon$joinMsg.put(Thread.currentThread(), Pair.of(component, resourceKey));
} }
@Inject( @Inject(
@@ -67,7 +67,7 @@ abstract class PlayerListMixin {
at = @At("RETURN") at = @At("RETURN")
) )
public void injectJoin(final Connection connection, final ServerPlayer serverPlayer, final CallbackInfo ci) { public void injectJoin(final Connection connection, final ServerPlayer serverPlayer, final CallbackInfo ci) {
final @Nullable Triplet<Component, ChatType, UUID> remove = this.carbon$joinMsg.remove(Thread.currentThread()); final @Nullable Pair<Component, ResourceKey<ChatType>> remove = this.carbon$joinMsg.remove(Thread.currentThread());
if (remove != null) { if (remove != null) {
final PlayerStatusMessageEvents.MessageEvent event = PlayerStatusMessageEvents.MessageEvent.of( final PlayerStatusMessageEvents.MessageEvent event = PlayerStatusMessageEvents.MessageEvent.of(
serverPlayer, remove.getFirst().asComponent() serverPlayer, remove.getFirst().asComponent()
@@ -75,7 +75,7 @@ abstract class PlayerListMixin {
PlayerStatusMessageEvents.JOIN_MESSAGE.invoker().onMessage(event); PlayerStatusMessageEvents.JOIN_MESSAGE.invoker().onMessage(event);
final net.kyori.adventure.text.@Nullable Component message = event.message(); final net.kyori.adventure.text.@Nullable Component message = event.message();
if (message != null) { if (message != null) {
this.broadcastMessage(FabricServerAudiences.of(this.server).toNative(message), remove.getSecond(), remove.getThird()); this.broadcastSystemMessage(FabricServerAudiences.of(this.server).toNative(message), remove.getSecond());
} }
} }
} }
@@ -19,14 +19,16 @@
*/ */
package net.draycia.carbon.fabric.mixin; package net.draycia.carbon.fabric.mixin;
import java.util.UUID; import java.util.concurrent.CompletableFuture;
import net.draycia.carbon.fabric.callback.ChatCallback;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents; import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences; import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.FilteredText;
import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList; import net.minecraft.server.players.PlayerList;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -34,59 +36,55 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerGamePacketListenerImpl.class) @Mixin(ServerGamePacketListenerImpl.class)
abstract class ServerGamePacketListenerImplMixin { abstract class ServerGamePacketListenerImplMixin {
@Shadow
protected abstract void handleCommand(String string);
@Shadow @Final private MinecraftServer server; @Shadow @Final private MinecraftServer server;
@Shadow public ServerPlayer player; @Shadow public ServerPlayer player;
@Redirect( @Inject(
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;Lnet/minecraft/server/network/FilteredText;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z" target = "Lnet/minecraft/network/protocol/game/ServerboundChatPacket;getSignature(Ljava/util/UUID;)Lnet/minecraft/network/chat/MessageSignature;",
shift = At.Shift.BEFORE
) )
// , cancellable = true // todo
) )
public boolean redirectStartsWith(final String string, final String prefix) { public void injectHandleChat(final ServerboundChatPacket serverboundChatPacket, final FilteredText<String> filteredText, final CallbackInfo ci) {
return true; // todo
} }
@Redirect( @Inject(
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V", method = "queryChatPreview",
at = @At( at = @At("HEAD")
value = "INVOKE", // , cancellable = true // todo
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;handleCommand(Ljava/lang/String;)V"
) )
) public void injectQueryChatPreview(final String string, final CallbackInfoReturnable<CompletableFuture<Component>> cir) {
public void redirectHandleCommand(final ServerGamePacketListenerImpl serverGamePacketListener, final String string) { // todo
if (string.startsWith("/")) {
this.handleCommand(string);
return;
}
ChatCallback.INSTANCE.fireAsync(this.server, this.player, string);
} }
@Redirect( @Redirect(
method = "onDisconnect(Lnet/minecraft/network/chat/Component;)V", method = "onDisconnect(Lnet/minecraft/network/chat/Component;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V" target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/resources/ResourceKey;)V"
) )
) )
public void redirectQuitMessage(final PlayerList instance, final Component component, final ChatType chatType, final UUID uuid) { public void redirectQuitMessage(final PlayerList instance, final Component component, final ResourceKey<ChatType> resourceKey) {
final PlayerStatusMessageEvents.MessageEvent event = PlayerStatusMessageEvents.MessageEvent.of( final PlayerStatusMessageEvents.MessageEvent event = PlayerStatusMessageEvents.MessageEvent.of(
this.player, component.asComponent() this.player, component.asComponent()
); );
PlayerStatusMessageEvents.QUIT_MESSAGE.invoker().onMessage(event); PlayerStatusMessageEvents.QUIT_MESSAGE.invoker().onMessage(event);
final net.kyori.adventure.text.@Nullable Component message = event.message(); final net.kyori.adventure.text.@Nullable Component message = event.message();
if (message != null) { if (message != null) {
instance.broadcastMessage(FabricServerAudiences.of(this.server).toNative(message), chatType, uuid); instance.broadcastSystemMessage(FabricServerAudiences.of(this.server).toNative(message), resourceKey);
} }
} }
@@ -19,11 +19,11 @@
*/ */
package net.draycia.carbon.fabric.mixin; package net.draycia.carbon.fabric.mixin;
import java.util.UUID;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents; import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences; import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList; import net.minecraft.server.players.PlayerList;
@@ -44,13 +44,13 @@ abstract class ServerPlayerMixin {
method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V" target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/resources/ResourceKey;)V"
) )
) )
public void redirectBroadcastDeath(final PlayerList instance, final Component component, final ChatType chatType, final UUID uuid) { public void redirectBroadcastDeath(final PlayerList instance, final Component component, final ResourceKey<ChatType> resourceKey) {
final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component); final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component);
if (msg != null) { if (msg != null) {
instance.broadcastMessage(msg, chatType, uuid); instance.broadcastSystemMessage(msg, resourceKey);
} }
} }
@@ -58,13 +58,13 @@ abstract class ServerPlayerMixin {
method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastToTeam(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/network/chat/Component;)V" target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemToTeam(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/network/chat/Component;)V"
) )
) )
public void redirectBroadcastDeathToTeam(final PlayerList instance, final Player player, final Component component) { public void redirectBroadcastDeathToTeam(final PlayerList instance, final Player player, final Component component) {
final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component); final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component);
if (msg != null) { if (msg != null) {
instance.broadcastToTeam(player, msg); instance.broadcastSystemToTeam(player, msg);
} }
} }
@@ -72,13 +72,13 @@ abstract class ServerPlayerMixin {
method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V", method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastToAllExceptTeam(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/network/chat/Component;)V" target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemToAllExceptTeam(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/network/chat/Component;)V"
) )
) )
public void redirectBroadcastDeathToAllExceptTeam(final PlayerList instance, final Player player, final Component component) { public void redirectBroadcastDeathToAllExceptTeam(final PlayerList instance, final Player player, final Component component) {
final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component); final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component);
if (msg != null) { if (msg != null) {
instance.broadcastToAllExceptTeam(player, msg); instance.broadcastSystemToAllExceptTeam(player, msg);
} }
} }
+5 -3
View File
@@ -23,9 +23,11 @@
"carbonchat.mixins.json" "carbonchat.mixins.json"
], ],
"depends": { "depends": {
"fabricloader": ">=0.12.5", "fabricloader": ">=0.14.7",
"fabric": ">=0.31.0", "fabric": "*",
"minecraft": "1.18.2", "cloud": "*",
"adventure-platform-fabric": "*",
"minecraft": "~1.19",
"luckperms": ">=5.0.0" "luckperms": ">=5.0.0"
} }
} }
+4 -4
View File
@@ -17,7 +17,7 @@ versions:
cloud: 1.7.0-SNAPSHOT cloud: 1.7.0-SNAPSHOT
configurate: 4.1.2 configurate: 4.1.2
typesafeConfig: 1.4.1 typesafeConfig: 1.4.1
checkerQual: 3.22.0 checkerQual: 3.22.2
stylecheck: 0.1 stylecheck: 0.1
gson: 2.8.0 gson: 2.8.0
guava: 30.1-jre guava: 30.1-jre
@@ -31,9 +31,9 @@ versions:
guice: 5.1.0 guice: 5.1.0
velocityApi: 3.1.1 velocityApi: 3.1.1
geantyref: 1.3.11 geantyref: 1.3.11
fabricMinecraft: 1.18.2 fabricMinecraft: 1.19
fabricLoader: 0.14.4 fabricLoader: 0.14.8
adventurePlatformFabric: 5.3.1 adventurePlatformFabric: 5.4.0-SNAPSHOT
luckPermsApi: 5.3 luckPermsApi: 5.3
essentialsx: 2.19.3 essentialsx: 2.19.3
discordsrv: 1.26.0-SNAPSHOT discordsrv: 1.26.0-SNAPSHOT
+4 -1
View File
@@ -11,6 +11,9 @@ dependencyResolutionManagement {
includeGroup("cloud.commandframework") includeGroup("cloud.commandframework")
} }
} }
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
mavenContent { snapshotsOnly() }
}
maven("https://oss.sonatype.org/content/repositories/snapshots/") { maven("https://oss.sonatype.org/content/repositories/snapshots/") {
mavenContent { snapshotsOnly() } mavenContent { snapshotsOnly() }
} }
@@ -65,7 +68,7 @@ pluginManagement {
plugins { plugins {
id("ca.stellardrift.polyglot-version-catalogs") version "5.0.1" id("ca.stellardrift.polyglot-version-catalogs") version "5.0.1"
id("quiet-fabric-loom") version "0.11-SNAPSHOT" id("quiet-fabric-loom") version "0.12-SNAPSHOT"
} }
rootProject.name = "CarbonChat" rootProject.name = "CarbonChat"