mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
1.19.1 - fabric
aaaaaaaaaaaa
This commit is contained in:
1 parent
f4a8390d76
commit
af3410f874
8 files changed
+83
-15
No files matched your search
@@ -20,7 +20,7 @@
|
||||
package net.draycia.carbon.api.users;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
/**
|
||||
* The result of a player data operation.
|
||||
@@ -29,6 +29,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
* @param reason the reason of the result, typically empty unless {@link #player} is null
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public record ComponentPlayerResult<C extends CarbonPlayer>(@Nullable C player, Component reason) {
|
||||
public record ComponentPlayerResult<C extends CarbonPlayer>(@MonotonicNonNull C player, Component reason) {
|
||||
|
||||
}
|
||||
@@ -15,8 +15,8 @@ dependencies {
|
||||
minecraft(libs.fabricMinecraft)
|
||||
mappings(loom.officialMojangMappings())
|
||||
modImplementation(libs.fabricLoader)
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:0.57.2+1.19.1")
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.57.2+1.19.1") // LuckPerms needs to work at dev time
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:0.58.5+1.19.1")
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.58.5+1.19.1") // LuckPerms needs to work at dev time
|
||||
|
||||
carbon(projects.carbonchatCommon) {
|
||||
exclude("net.kyori", "adventure-api")
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.draycia.carbon.fabric.chat;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class MessageRecipientFilter {
|
||||
|
||||
private final ServerPlayer sender;
|
||||
private final @MonotonicNonNull ChatChannel channel;
|
||||
|
||||
public MessageRecipientFilter(final ServerPlayer sender, @Nullable ChatChannel channel) {
|
||||
this.sender = sender;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public boolean shouldFilterMessageTo(final ServerPlayer serverPlayer) {
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> authorResult = CarbonChatProvider.carbonChat().server().userManager().carbonPlayer(sender.getUUID()).join();
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> recipientResult = CarbonChatProvider.carbonChat().server().userManager().carbonPlayer(serverPlayer.getUUID()).join();
|
||||
|
||||
final @MonotonicNonNull CarbonPlayer author = authorResult.player();
|
||||
final @MonotonicNonNull CarbonPlayer recipient = recipientResult.player();
|
||||
|
||||
if (author == null || recipient == null) {
|
||||
return true; // TODO: should we filter messages when this happens?
|
||||
}
|
||||
|
||||
if (author.ignoring(recipient) || recipient.ignoring(author)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.channel == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !this.channel.hearingPermitted(recipient).permitted();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.draycia.carbon.fabric.mixin;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.network.chat.ChatSender;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public interface PlayerListAccessor {
|
||||
|
||||
@Invoker("broadcastChatMessage")
|
||||
void broadcastChatMessage(PlayerChatMessage playerChatMessage, Predicate<ServerPlayer> predicate, ServerPlayer serverPlayer, ChatSender chatSender, ChatType.Bound bound);
|
||||
|
||||
}
|
||||
+14
-8
@@ -19,12 +19,15 @@
|
||||
*/
|
||||
package net.draycia.carbon.fabric.mixin;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.fabric.CarbonChatFabric;
|
||||
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
|
||||
import net.draycia.carbon.fabric.chat.MessageRecipientFilter;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
@@ -32,7 +35,6 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
|
||||
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;
|
||||
@@ -70,19 +72,23 @@ abstract class ServerGamePacketListenerImplMixin {
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V",
|
||||
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void sendPacket(final Packet<?> packet, final GenericFutureListener<? extends Future<? super Void>> genericFutureListener, final CallbackInfo ci) {
|
||||
private void sendPacket(final Packet<?> packet, final PacketSendListener packetSendListener, final CallbackInfo ci) {
|
||||
if (packet instanceof ClientboundPlayerChatPacket chatPacket) {
|
||||
final UUID uuid = UUID.nameUUIDFromBytes(chatPacket.message().headerSignature().bytes());
|
||||
CarbonChatFabric.addMessageSignature(uuid, chatPacket.message().headerSignature());
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V"))
|
||||
private void broadcastChatMessage(final PlayerList instance, final FilteredText<PlayerChatMessage> filteredText, final ServerPlayer serverPlayer, final ChatType.Bound bound) {
|
||||
this.server.getPlayerList().broadcastChatMessage(filteredText, this.player, ChatType.bind(CarbonChatFabric.CHAT_TYPE, serverPlayer.level.registryAccess(), filteredText.filtered().signedContent()));
|
||||
@Redirect(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V"))
|
||||
private void broadcastChatMessage(final PlayerList instance, final PlayerChatMessage playerChatMessage, final ServerPlayer serverPlayer, final ChatType.Bound bound) {
|
||||
// TODO: Get the channel the message was sent in, when the player uses /channel <message>
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> result = CarbonChatProvider.carbonChat().server().userManager().carbonPlayer(serverPlayer.getUUID()).join();
|
||||
final MessageRecipientFilter filter = new MessageRecipientFilter(serverPlayer, result.player().selectedChannel());
|
||||
|
||||
((PlayerListAccessor) this.server.getPlayerList()).broadcastChatMessage(playerChatMessage, filter::shouldFilterMessageTo, serverPlayer, serverPlayer.asChatSender(), bound);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
"mixins": [
|
||||
"ChatTypeMixin",
|
||||
"PlayerListMixin",
|
||||
"PlayerListAccessor",
|
||||
"ServerGamePacketListenerImplMixin",
|
||||
"ServerPlayerMixin"
|
||||
],
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
"carbonchat.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.7",
|
||||
"fabricloader": ">=0.14.8",
|
||||
"fabric": "*",
|
||||
"cloud": "*",
|
||||
"adventure-platform-fabric": "*",
|
||||
"minecraft": "~1.19",
|
||||
"minecraft": "~1.19.1",
|
||||
"luckperms": ">=5.0.0"
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ versions:
|
||||
guice: 5.1.0
|
||||
velocityApi: 3.1.1
|
||||
geantyref: 1.3.11
|
||||
fabricMinecraft: 1.19.1-pre4
|
||||
fabricMinecraft: 1.19.1
|
||||
fabricLoader: 0.14.8
|
||||
adventurePlatformFabric: 5.4.0-SNAPSHOT
|
||||
luckPermsApi: 5.3
|
||||
|
||||
Reference in new issue
Block a user