diff --git a/Plan/build.gradle b/Plan/build.gradle index 3087cbedd..f5cfb7273 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -17,7 +17,7 @@ plugins { id "jacoco" id "checkstyle" id "org.sonarqube" version "4.0.0.2929" - id 'fabric-loom' version '0.12.+' apply false + id 'fabric-loom' version '1.1-SNAPSHOT' apply false } apply plugin: 'nebula-aggregate-javadocs' @@ -113,7 +113,6 @@ subprojects { maven { url = "https://papermc.io/repo/repository/maven-public/" } // Paper maven { url = "https://repo.spongepowered.org/repository/maven-public/" } // Sponge maven { url = "https://oss.sonatype.org/content/repositories/snapshots" } // BungeeCord - maven { url = "https://repo.velocitypowered.com/snapshots/" } // Velocity maven { url = "https://repo.playeranalytics.net/releases" } // Plan maven { url = "https://repo.md-5.net/content/repositories/snapshots/" } // RedisBungee maven { url = "https://jitpack.io" } // RedisBungee fork diff --git a/Plan/fabric/build.gradle b/Plan/fabric/build.gradle index c7ef2a77f..c86e1f7bf 100644 --- a/Plan/fabric/build.gradle +++ b/Plan/fabric/build.gradle @@ -8,9 +8,9 @@ dependencies { shadow "net.playeranalytics:platform-abstraction-layer-api:$palVersion" - minecraft "com.mojang:minecraft:1.19.3" - mappings "net.fabricmc:yarn:1.19.3+build.2:v2" - modImplementation "net.fabricmc:fabric-loader:0.14.11" + minecraft "com.mojang:minecraft:1.19.4" + mappings "net.fabricmc:yarn:1.19.4+build.1:v2" + modImplementation "net.fabricmc:fabric-loader:0.14.17" modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT') // Fabric API @@ -24,7 +24,7 @@ dependencies { ] apiModules.forEach { - modImplementation(fabricApi.module(it, "0.68.1+1.19.3")) + modImplementation(fabricApi.module(it, "0.76.0+1.19.4")) } testImplementation project(path: ":common", configuration: 'testArtifacts') @@ -111,14 +111,10 @@ shadowJar { mergeServiceFiles() } -prepareRemapJar { - dependsOn tasks.shadowJar -} - remapJar { dependsOn tasks.shadowJar mustRunAfter tasks.shadowJar - input = shadowJar.archiveFile.get() + inputFile = shadowJar.archiveFile.get() addNestedDependencies = true destinationDirectory.set(file("$rootDir/builds/")) diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/domain/FabricPlayerData.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/domain/FabricPlayerData.java index cd3930beb..4f57e047b 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/domain/FabricPlayerData.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/domain/FabricPlayerData.java @@ -73,7 +73,7 @@ public class FabricPlayerData implements PlatformPlayerData { private Optional getIPFromSocketAddress() { try { - SocketAddress socketAddress = player.networkHandler.connection.getAddress(); + SocketAddress socketAddress = player.networkHandler.getConnectionAddress(); if (socketAddress instanceof InetSocketAddress inetSocketAddress) { return Optional.of(inetSocketAddress.getAddress()); } else if (socketAddress instanceof UnixDomainSocketAddress) { diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ClientToServerHandshakePacketMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ClientToServerHandshakePacketMixin.java index 370179447..bac17d5bd 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ClientToServerHandshakePacketMixin.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ClientToServerHandshakePacketMixin.java @@ -17,23 +17,19 @@ package net.playeranalytics.plan.gathering.listeners.events.mixin; import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket; -import net.minecraft.server.network.LocalServerHandshakeNetworkHandler; import net.minecraft.server.network.ServerHandshakeNetworkHandler; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin({ServerHandshakeNetworkHandler.class, LocalServerHandshakeNetworkHandler.class}) +@Mixin(ServerHandshakeNetworkHandler.class) public class ClientToServerHandshakePacketMixin { - @Inject(method = "onHandshake", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerHandshakeNetworkHandler;onHandshake(Lnet/minecraft/network/packet/c2s/handshake/HandshakeC2SPacket;)V")) - public static void onClientHandshakeFromNetwork(HandshakeC2SPacket packet) { + @Inject(method = "onHandshake", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/network/ClientConnection;setPacketListener(Lnet/minecraft/network/listener/PacketListener;)V")) + public void onClientHandshakeFromNetwork(HandshakeC2SPacket packet, CallbackInfo ci) { PlanFabricEvents.ON_HANDSHAKE.invoker().onHandshake(packet); } - @Inject(method = "onHandshake", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/LocalServerHandshakeNetworkHandler;onHandshake(Lnet/minecraft/network/packet/c2s/handshake/HandshakeC2SPacket;)V")) - public static void onClienthandshakeFromLocal(HandshakeC2SPacket packet) { - PlanFabricEvents.ON_HANDSHAKE.invoker().onHandshake(packet); - } } diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayerEntityMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayerEntityMixin.java index 506f27a9e..acc673740 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayerEntityMixin.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayerEntityMixin.java @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ServerPlayerEntity.class) public class ServerPlayerEntityMixin { - @Inject(method = "changeGameMode", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V")) + @Inject(method = "changeGameMode", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V")) public void onGameModeChanged(GameMode gameMode, CallbackInfoReturnable cir) { PlanFabricEvents.ON_GAMEMODE_CHANGE.invoker().onGameModeChange((ServerPlayerEntity) (Object) this, gameMode); } diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/ChatListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/ChatListener.java index 87ae2b66d..0eba0b1c2 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/ChatListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/ChatListener.java @@ -28,6 +28,7 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.playeranalytics.plan.gathering.listeners.FabricListener; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.UUID; /** @@ -35,6 +36,7 @@ import java.util.UUID; * * @author AuroraLS3 */ +@Singleton public class ChatListener implements FabricListener { private final ServerInfo serverInfo; @@ -43,6 +45,7 @@ public class ChatListener implements FabricListener { private final ErrorLogger errorLogger; private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject @@ -59,7 +62,6 @@ public class ChatListener implements FabricListener { } public void onChat(ServerPlayerEntity player) { - try { actOnChatEvent(player); } catch (Exception e) { @@ -80,6 +82,10 @@ public class ChatListener implements FabricListener { @Override public void register() { + if (this.wasRegistered) { + return; + } + ServerMessageEvents.CHAT_MESSAGE.register((message, sender, params) -> { if (!isEnabled) { return; @@ -88,6 +94,7 @@ public class ChatListener implements FabricListener { }); this.enable(); + this.wasRegistered = true; } @Override @@ -105,4 +112,3 @@ public class ChatListener implements FabricListener { this.isEnabled = false; } } - diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/DeathEventListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/DeathEventListener.java index 253d2cadf..85730cfbb 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/DeathEventListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/DeathEventListener.java @@ -36,8 +36,10 @@ import net.playeranalytics.plan.gathering.listeners.FabricListener; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Optional; +@Singleton public class DeathEventListener implements FabricListener { private final Processing processing; @@ -45,6 +47,7 @@ public class DeathEventListener implements FabricListener { private final ServerInfo serverInfo; private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject public DeathEventListener( @@ -59,9 +62,19 @@ public class DeathEventListener implements FabricListener { @Override public void register() { + if (this.wasRegistered) { + return; + } + ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, killer, killedEntity) -> - PlanFabricEvents.ON_KILLED.invoker().onKilled(killedEntity, killer) + { + if (!this.isEnabled) { + return; + } + PlanFabricEvents.ON_KILLED.invoker().onKilled(killedEntity, killer); + } ); + PlanFabricEvents.ON_KILLED.register((victim, killer) -> { if (!this.isEnabled) { return; @@ -89,7 +102,9 @@ public class DeathEventListener implements FabricListener { } }); + this.enable(); + this.wasRegistered = true; } private PlayerKill.Killer getKiller(ServerPlayerEntity killer) { diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/FabricAFKListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/FabricAFKListener.java index 190e98878..61cc1ff8c 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/FabricAFKListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/FabricAFKListener.java @@ -29,10 +29,12 @@ import net.playeranalytics.plan.gathering.listeners.FabricListener; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +@Singleton public class FabricAFKListener implements FabricListener { // Static so that /reload does not cause afk tracking to fail. @@ -40,6 +42,7 @@ public class FabricAFKListener implements FabricListener { private final Map ignorePermissionInfo; private final ErrorLogger errorLogger; private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject public FabricAFKListener(PlanConfig config, ErrorLogger errorLogger) { @@ -85,7 +88,10 @@ public class FabricAFKListener implements FabricListener { @Override public void register() { - this.enable(); + if (this.wasRegistered) { + return; + } + ServerMessageEvents.CHAT_MESSAGE.register((message, sender, params) -> { if (!isEnabled) { return; @@ -109,7 +115,15 @@ public class FabricAFKListener implements FabricListener { } ignorePermissionInfo.remove(handler.player.getUuid()); }); - PlanFabricEvents.ON_MOVE.register((handler, packet) -> event(handler.player)); + PlanFabricEvents.ON_MOVE.register((handler, packet) -> { + if (!this.isEnabled) { + return; + } + event(handler.player); + }); + + this.enable(); + this.wasRegistered = true; } diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/GameModeChangeListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/GameModeChangeListener.java index 9c9ae2306..396f53459 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/GameModeChangeListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/GameModeChangeListener.java @@ -30,6 +30,7 @@ import net.playeranalytics.plan.gathering.listeners.FabricListener; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Optional; import java.util.UUID; @@ -38,6 +39,7 @@ import java.util.UUID; * * @author AuroraLS3 */ +@Singleton public class GameModeChangeListener implements FabricListener { private final WorldAliasSettings worldAliasSettings; @@ -46,6 +48,7 @@ public class GameModeChangeListener implements FabricListener { private final ErrorLogger errorLogger; private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject public GameModeChangeListener( @@ -83,11 +86,19 @@ public class GameModeChangeListener implements FabricListener { @Override public void register() { - if (!this.isEnabled) { + if (this.wasRegistered) { return; } - PlanFabricEvents.ON_GAMEMODE_CHANGE.register(this::onGameModeChange); + + PlanFabricEvents.ON_GAMEMODE_CHANGE.register((player, newGameMode) -> { + if (!this.isEnabled) { + return; + } + this.onGameModeChange(player, newGameMode); + }); + this.enable(); + this.wasRegistered = true; } @Override diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/PlayerOnlineListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/PlayerOnlineListener.java index 1b5531a25..d91235934 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/PlayerOnlineListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/PlayerOnlineListener.java @@ -40,10 +40,12 @@ import net.playeranalytics.plan.gathering.listeners.FabricListener; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import javax.inject.Inject; +import javax.inject.Singleton; import java.net.SocketAddress; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +@Singleton public class PlayerOnlineListener implements FabricListener { private final PlayerJoinEventConsumer joinEventConsumer; @@ -58,6 +60,7 @@ public class PlayerOnlineListener implements FabricListener { private final AtomicReference joinAddress = new AtomicReference<>(); private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject public PlayerOnlineListener( @@ -79,6 +82,10 @@ public class PlayerOnlineListener implements FabricListener { @Override public void register() { + if (this.wasRegistered) { + return; + } + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { if (!this.isEnabled) { return; @@ -112,7 +119,9 @@ public class PlayerOnlineListener implements FabricListener { } onHandshake(packet); }); + this.enable(); + this.wasRegistered = true; } private void onHandshake(HandshakeC2SPacket packet) { diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/WorldChangeListener.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/WorldChangeListener.java index 614eac780..4679c3a66 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/WorldChangeListener.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/WorldChangeListener.java @@ -29,9 +29,11 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.playeranalytics.plan.gathering.listeners.FabricListener; import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Optional; import java.util.UUID; +@Singleton public class WorldChangeListener implements FabricListener { private final WorldAliasSettings worldAliasSettings; @@ -40,6 +42,7 @@ public class WorldChangeListener implements FabricListener { private final ErrorLogger errorLogger; private boolean isEnabled = false; + private boolean wasRegistered = false; @Inject public WorldChangeListener( @@ -79,11 +82,19 @@ public class WorldChangeListener implements FabricListener { @Override public void register() { - this.enable(); - if (!isEnabled) { + if (this.wasRegistered) { return; } - ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> onWorldChange(player)); + + ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> { + if (!this.isEnabled) { + return; + } + onWorldChange(player); + }); + + this.enable(); + this.wasRegistered = true; } @Override @@ -101,4 +112,3 @@ public class WorldChangeListener implements FabricListener { this.isEnabled = false; } } - diff --git a/Plan/fabric/src/main/resources/plan.mixins.json b/Plan/fabric/src/main/resources/plan.mixins.json index 829d07635..943fbcb48 100644 --- a/Plan/fabric/src/main/resources/plan.mixins.json +++ b/Plan/fabric/src/main/resources/plan.mixins.json @@ -4,6 +4,7 @@ "package": "net.playeranalytics.plan.gathering.listeners.events.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "ClientToServerHandshakePacketMixin", "KickCommandMixin", "PlayerManagerMixin", "ServerCommandSourceMixin",