mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Update non-chat parts of fabric platform
This commit is contained in:
7 files changed
+82
-79
No files matched your search
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-25
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user