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
+82 -79

No files matched your search

+3 -3
View File
@@ -15,6 +15,8 @@ dependencies {
minecraft(libs.fabricMinecraft)
mappings(loom.officialMojangMappings())
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) {
exclude("net.kyori", "adventure-api")
@@ -28,9 +30,7 @@ dependencies {
modImplementation(libs.cloudFabric)
include(libs.cloudFabric)
modImplementation(libs.adventurePlatformFabric) {
exclude("ca.stellardrift", "colonel") // causes classloading issues when running in dev
}
modImplementation(libs.adventurePlatformFabric)
include(libs.adventurePlatformFabric)
}
@@ -19,15 +19,15 @@
*/
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.UUID;
import java.util.concurrent.ConcurrentHashMap;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
@@ -46,20 +46,20 @@ abstract class PlayerListMixin {
@Shadow @Final private MinecraftServer server;
@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(
method = "placeNewPlayer(Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V",
at = @At(
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
this.carbon$joinMsg.put(Thread.currentThread(), Triplet.of(component, chatType, uuid));
this.carbon$joinMsg.put(Thread.currentThread(), Pair.of(component, resourceKey));
}
@Inject(
@@ -67,7 +67,7 @@ abstract class PlayerListMixin {
at = @At("RETURN")
)
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) {
final PlayerStatusMessageEvents.MessageEvent event = PlayerStatusMessageEvents.MessageEvent.of(
serverPlayer, remove.getFirst().asComponent()
@@ -75,7 +75,7 @@ abstract class PlayerListMixin {
PlayerStatusMessageEvents.JOIN_MESSAGE.invoker().onMessage(event);
final net.kyori.adventure.text.@Nullable Component message = event.message();
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;
import java.util.UUID;
import net.draycia.carbon.fabric.callback.ChatCallback;
import java.util.concurrent.CompletableFuture;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.chat.ChatType;
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.level.ServerPlayer;
import net.minecraft.server.network.FilteredText;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList;
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.Shadow;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerGamePacketListenerImpl.class)
abstract class ServerGamePacketListenerImplMixin {
@Shadow
protected abstract void handleCommand(String string);
@Shadow @Final private MinecraftServer server;
@Shadow public ServerPlayer player;
@Redirect(
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
@Inject(
method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;Lnet/minecraft/server/network/FilteredText;)V",
at = @At(
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) {
return true;
public void injectHandleChat(final ServerboundChatPacket serverboundChatPacket, final FilteredText<String> filteredText, final CallbackInfo ci) {
// todo
}
@Redirect(
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;handleCommand(Ljava/lang/String;)V"
)
@Inject(
method = "queryChatPreview",
at = @At("HEAD")
// , cancellable = true // todo
)
public void redirectHandleCommand(final ServerGamePacketListenerImpl serverGamePacketListener, final String string) {
if (string.startsWith("/")) {
this.handleCommand(string);
return;
}
ChatCallback.INSTANCE.fireAsync(this.server, this.player, string);
public void injectQueryChatPreview(final String string, final CallbackInfoReturnable<CompletableFuture<Component>> cir) {
// todo
}
@Redirect(
method = "onDisconnect(Lnet/minecraft/network/chat/Component;)V",
at = @At(
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(
this.player, component.asComponent()
);
PlayerStatusMessageEvents.QUIT_MESSAGE.invoker().onMessage(event);
final net.kyori.adventure.text.@Nullable Component message = event.message();
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;
import java.util.UUID;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
@@ -44,13 +44,13 @@ abstract class ServerPlayerMixin {
method = "die(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At(
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);
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",
at = @At(
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) {
final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component);
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",
at = @At(
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) {
final @Nullable Component msg = this.carbon$fireDeathMessageEvent(component);
if (msg != null) {
instance.broadcastToAllExceptTeam(player, msg);
instance.broadcastSystemToAllExceptTeam(player, msg);
}
}
+31 -29
View File
@@ -1,31 +1,33 @@
{
"schemaVersion": 1,
"id": "${modId}",
"version": "${version}",
"name": "${name}",
"description": "${description}",
"authors": [
"Draycia"
],
"contact": {
"homepage": "${github_url}",
"sources": "${github_url}",
"issues": "${github_url}/issues"
},
"license": "GPLv3",
"environment": "*",
"entrypoints": {
"main": [
"net.draycia.carbon.fabric.CarbonChatFabric"
]
},
"mixins": [
"carbonchat.mixins.json"
],
"depends": {
"fabricloader": ">=0.12.5",
"fabric": ">=0.31.0",
"minecraft": "1.18.2",
"luckperms": ">=5.0.0"
}
"schemaVersion": 1,
"id": "${modId}",
"version": "${version}",
"name": "${name}",
"description": "${description}",
"authors": [
"Draycia"
],
"contact": {
"homepage": "${github_url}",
"sources": "${github_url}",
"issues": "${github_url}/issues"
},
"license": "GPLv3",
"environment": "*",
"entrypoints": {
"main": [
"net.draycia.carbon.fabric.CarbonChatFabric"
]
},
"mixins": [
"carbonchat.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.7",
"fabric": "*",
"cloud": "*",
"adventure-platform-fabric": "*",
"minecraft": "~1.19",
"luckperms": ">=5.0.0"
}
}
+4 -4
View File
@@ -17,7 +17,7 @@ versions:
cloud: 1.7.0-SNAPSHOT
configurate: 4.1.2
typesafeConfig: 1.4.1
checkerQual: 3.22.0
checkerQual: 3.22.2
stylecheck: 0.1
gson: 2.8.0
guava: 30.1-jre
@@ -31,9 +31,9 @@ versions:
guice: 5.1.0
velocityApi: 3.1.1
geantyref: 1.3.11
fabricMinecraft: 1.18.2
fabricLoader: 0.14.4
adventurePlatformFabric: 5.3.1
fabricMinecraft: 1.19
fabricLoader: 0.14.8
adventurePlatformFabric: 5.4.0-SNAPSHOT
luckPermsApi: 5.3
essentialsx: 2.19.3
discordsrv: 1.26.0-SNAPSHOT
+4 -1
View File
@@ -11,6 +11,9 @@ dependencyResolutionManagement {
includeGroup("cloud.commandframework")
}
}
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
mavenContent { snapshotsOnly() }
}
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
mavenContent { snapshotsOnly() }
}
@@ -65,7 +68,7 @@ pluginManagement {
plugins {
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"