Fabric 1.19.4 compatibility (#2944)

* Fabric 1.19.4 compatibility

- Upgraded to loom 1.1-SNAPSHOT
- Updated mappings & fixed injection targets
- Enabled ClientToServerHandshakePacketMixin (was missing from mixins JSON)
- Removed mixin for LocalServerHandshakeNetworkHandler, as that only handles local connections (client <-> its integrated server)
- Removed sunsetted velocitypowered.com repository

* Fix GameModeChangeListener not firing & add redundancy for not registering listeners twice

* Update Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/fabric/DeathEventListener.java

---------

Co-authored-by: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com>
This commit is contained in:
Antti Koponen 2023-03-26 14:51:25 +03:00 committed by GitHub
parent 5de8ae84ce
commit 64e2655466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 89 additions and 32 deletions

View File

@ -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

View File

@ -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/"))

View File

@ -73,7 +73,7 @@ public class FabricPlayerData implements PlatformPlayerData {
private Optional<InetAddress> 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) {

View File

@ -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);
}
}

View File

@ -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<Boolean> cir) {
PlanFabricEvents.ON_GAMEMODE_CHANGE.invoker().onGameModeChange((ServerPlayerEntity) (Object) this, gameMode);
}

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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<UUID, Boolean> 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;
}

View File

@ -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

View File

@ -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<String> 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) {

View File

@ -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;
}
}

View File

@ -4,6 +4,7 @@
"package": "net.playeranalytics.plan.gathering.listeners.events.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ClientToServerHandshakePacketMixin",
"KickCommandMixin",
"PlayerManagerMixin",
"ServerCommandSourceMixin",