From 25211803675f3fa9ecca1a2c14b71fe728addbbf Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Sat, 19 Oct 2024 21:42:23 +0100 Subject: [PATCH] feat: game profiles are player references --- gradle.properties | 2 +- .../audience/mixin/GameProfileMixin.java | 43 +++++++++++++++++++ .../mixin/ServerPlayerEntityMixin.java | 6 ++- src/main/resources/audience.mixins.json | 1 + src/main/resources/fabric.mod.json | 4 ++ .../dev/andante/audience/test/AudienceTest.kt | 9 ++++ 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/main/java/dev/andante/audience/mixin/GameProfileMixin.java diff --git a/gradle.properties b/gradle.properties index 268993a..3630aed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,5 @@ kache_version=1.0.5 inject_version=1.2.2 # Mod Properties -mod_version=2.12.2 +mod_version=2.13 maven_group=dev.andante diff --git a/src/main/java/dev/andante/audience/mixin/GameProfileMixin.java b/src/main/java/dev/andante/audience/mixin/GameProfileMixin.java new file mode 100644 index 0000000..6777760 --- /dev/null +++ b/src/main/java/dev/andante/audience/mixin/GameProfileMixin.java @@ -0,0 +1,43 @@ +package dev.andante.audience.mixin; + +import com.mojang.authlib.GameProfile; +import dev.andante.audience.Audience; +import dev.andante.audience.player.PlayerReference; +import dev.andante.audience.player.PlayerSet; +import dev.andante.audience.player.StandalonePlayerReference; +import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@SuppressWarnings("AddedMixinMembersNamePattern") +@Mixin(GameProfile.class) +public abstract class GameProfileMixin implements Audience, PlayerReference { + @Override + public @NotNull PlayerSet getAudiencePlayers() { + StandalonePlayerReference reference = this.getHardReference(); + return new PlayerSet(List.of(reference)); + } + + @Override + public @NotNull UUID getReferenceUuid() { + GameProfile that = (GameProfile) (Object) this; + return that.getId(); + } + + @Override + public boolean equals(Object other) { + if (super.equals(other)) { + return true; + } + + if (other instanceof PlayerReference reference) { + return reference.getReferenceUuid() == this.getReferenceUuid(); + } + + return false; + } +} diff --git a/src/main/java/dev/andante/audience/mixin/ServerPlayerEntityMixin.java b/src/main/java/dev/andante/audience/mixin/ServerPlayerEntityMixin.java index d9f3816..21647bd 100644 --- a/src/main/java/dev/andante/audience/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/dev/andante/audience/mixin/ServerPlayerEntityMixin.java @@ -3,11 +3,13 @@ import dev.andante.audience.Audience; import dev.andante.audience.player.PlayerReference; import dev.andante.audience.player.PlayerSet; +import dev.andante.audience.player.StandalonePlayerReference; import net.minecraft.server.network.ServerPlayerEntity; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import java.util.Collections; +import java.util.List; import java.util.UUID; @SuppressWarnings("AddedMixinMembersNamePattern") @@ -15,8 +17,8 @@ public abstract class ServerPlayerEntityMixin implements Audience, PlayerReference { @Override public @NotNull PlayerSet getAudiencePlayers() { - ServerPlayerEntity that = (ServerPlayerEntity) (Object) this; - return new PlayerSet(Collections.singletonList(that)); + StandalonePlayerReference reference = this.getHardReference(); + return new PlayerSet(List.of(reference)); } @Override diff --git a/src/main/resources/audience.mixins.json b/src/main/resources/audience.mixins.json index 2777a76..ae4b84e 100644 --- a/src/main/resources/audience.mixins.json +++ b/src/main/resources/audience.mixins.json @@ -5,6 +5,7 @@ "mixins": [ "BlockMixin", "BlockStateMixin", + "GameProfileMixin", "MinecraftServerMixin", "ServerPlayerEntityMixin", "ServerWorldMixin" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6cd0973..dbc004a 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,6 +21,10 @@ "dev/andante/audience/Audience", "dev/andante/audience/player/PlayerReference" ], + "com/mojang/authlib/GameProfile": [ + "dev/andante/audience/Audience", + "dev/andante/audience/player/PlayerReference" + ], "net/minecraft/server/MinecraftServer": [ "dev/andante/audience/Audience" ], "net/minecraft/class_3218": [ "dev/andante/audience/Audience" ], "net/minecraft/class_2248": [ "dev/andante/audience/block/BlockStateLike" ], diff --git a/src/test/kotlin/dev/andante/audience/test/AudienceTest.kt b/src/test/kotlin/dev/andante/audience/test/AudienceTest.kt index 680cadf..a63b9b2 100644 --- a/src/test/kotlin/dev/andante/audience/test/AudienceTest.kt +++ b/src/test/kotlin/dev/andante/audience/test/AudienceTest.kt @@ -3,12 +3,16 @@ package dev.andante.audience.test import com.google.gson.JsonParser import com.mojang.serialization.JsonOps import dev.andante.audience.Audience +import dev.andante.audience.player.PlayerReference import dev.andante.audience.player.PlayerSet import dev.andante.audience.player.StandalonePlayerReference import dev.andante.audience.resource.ByteResourcePack import dev.andante.audience.resource.ResourcePackHandler import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents +import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents +import net.minecraft.command.argument.EntityArgumentType.player import org.slf4j.LoggerFactory import kotlin.io.path.Path import kotlin.io.path.readBytes @@ -60,5 +64,10 @@ object AudienceTest : ModInitializer { ResourcePackHandler.add(packTwo) println(packOne.hash) println(packTwo.hash) + + ServerConfigurationConnectionEvents.BEFORE_CONFIGURE.register { handler, server -> + val reference = handler.debugProfile as PlayerReference + println(reference.hardReference) + } } }