diff --git a/Plan/fabric/build.gradle b/Plan/fabric/build.gradle index 129e1c1a8..a082a1429 100644 --- a/Plan/fabric/build.gradle +++ b/Plan/fabric/build.gradle @@ -8,10 +8,10 @@ dependencies { shadow "net.playeranalytics:platform-abstraction-layer-api:$palVersion" - minecraft "com.mojang:minecraft:1.19" - mappings "net.fabricmc:yarn:1.19+build.1:v2" - modImplementation "net.fabricmc:fabric-loader:0.14.7" - modImplementation('me.lucko:fabric-permissions-api:0.1-SNAPSHOT') + minecraft "com.mojang:minecraft:1.19.1" + mappings "net.fabricmc:yarn:1.19.1+build.1:v2" + modImplementation "net.fabricmc:fabric-loader:0.14.8" + modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT') // Fabric API Set apiModules = [ @@ -19,18 +19,19 @@ dependencies { 'fabric-command-api-v2', 'fabric-entity-events-v1', 'fabric-lifecycle-events-v1', - 'fabric-networking-api-v1' + 'fabric-networking-api-v1', + 'fabric-message-api-v1' ] apiModules.forEach { - modImplementation(fabricApi.module(it, "0.55.3+1.19")) + modImplementation(fabricApi.module(it, "0.58.5+1.19.1")) } testImplementation project(path: ":common", configuration: 'testArtifacts') } tasks.withType(JavaCompile).configureEach { - options.release = 17 + options.release.set(17) } processResources { @@ -77,8 +78,6 @@ shadowJar { exclude "jakarta/xml/**/*" exclude "javassist/**/*" - relocate 'org.slf4j', 'plan.org.slf4j' - relocate('org.apache', 'plan.org.apache') { exclude 'org/apache/logging/**' } diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/PlanFabricEvents.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/PlanFabricEvents.java index 9f22980e3..b260b8da7 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/PlanFabricEvents.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/PlanFabricEvents.java @@ -42,9 +42,9 @@ public class PlanFabricEvents { } }); - public static final Event ON_CHAT = EventFactory.createArrayBacked(OnChat.class, callbacks -> (handler, message) -> { - for (OnChat callback : callbacks) { - callback.onChat(handler, message); + public static final Event ON_COMMAND = EventFactory.createArrayBacked(OnCommand.class, callbacks -> (handler, command) -> { + for (OnCommand callback : callbacks) { + callback.onCommand(handler, command); } }); @@ -113,14 +113,14 @@ public class PlanFabricEvents { } @FunctionalInterface - public interface OnChat { + public interface OnCommand { /** * Called when a player sends a chat message / command * * @param handler the handler of the sending player * @param message the message sent (starts with "/" if it is a command) */ - void onChat(ServerPlayNetworkHandler handler, String message); + void onCommand(ServerPlayNetworkHandler handler, String message); } @FunctionalInterface diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/EntityMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/EntityMixin.java deleted file mode 100644 index 1b66dd990..000000000 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/EntityMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package net.playeranalytics.plan.gathering.listeners.events.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.server.world.ServerWorld; -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.CallbackInfoReturnable; - -@Mixin(Entity.class) -public class EntityMixin { - - @Inject(method = "onKilledOther", at = @At(value = "TAIL")) - public void onDeath(ServerWorld world, LivingEntity other, CallbackInfoReturnable cir) { - PlanFabricEvents.ON_KILLED.invoker().onKilled(other, (Entity) (Object) this); - } - -} diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/PlayerEntityMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/PlayerEntityMixin.java deleted file mode 100644 index ce82e6368..000000000 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/PlayerEntityMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package net.playeranalytics.plan.gathering.listeners.events.mixin; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.world.ServerWorld; -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.CallbackInfoReturnable; - -@Mixin(PlayerEntity.class) -public class PlayerEntityMixin { - - @Inject(method = "onKilledOther", at = @At("TAIL")) - public void onDeath(ServerWorld world, LivingEntity other, CallbackInfoReturnable cir) { - PlanFabricEvents.ON_KILLED.invoker().onKilled(other, (PlayerEntity) (Object) this); - } - -} diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayNetworkHandlerMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayNetworkHandlerMixin.java index 1e995527b..98482ae9b 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayNetworkHandlerMixin.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerPlayNetworkHandlerMixin.java @@ -16,7 +16,7 @@ */ package net.playeranalytics.plan.gathering.listeners.events.mixin; -import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; +import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; @@ -28,9 +28,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayNetworkHandler.class) public class ServerPlayNetworkHandlerMixin { - @Inject(method = "onChatMessage", at = @At("TAIL")) - public void onChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) { - PlanFabricEvents.ON_CHAT.invoker().onChat((ServerPlayNetworkHandler) (Object) this, packet.getChatMessage()); + @Inject(method = "onCommandExecution", at = @At("TAIL")) + public void onCommand(CommandExecutionC2SPacket packet, CallbackInfo ci) { + PlanFabricEvents.ON_COMMAND.invoker().onCommand((ServerPlayNetworkHandler) (Object) this, packet.command()); } @Inject(method = "onPlayerMove", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getWorld()Lnet/minecraft/server/world/ServerWorld;")) 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 913941575..19522e381 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 @@ -23,10 +23,9 @@ import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction; import com.djrapitops.plan.utilities.logging.ErrorContext; import com.djrapitops.plan.utilities.logging.ErrorLogger; -import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.minecraft.server.network.ServerPlayerEntity; import net.playeranalytics.plan.gathering.listeners.FabricListener; -import net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents; import javax.inject.Inject; import java.util.UUID; @@ -59,18 +58,17 @@ public class ChatListener implements FabricListener { this.errorLogger = errorLogger; } - public void onChat(ServerPlayNetworkHandler handler, String message) { + public void onChat(ServerPlayerEntity player, String message) { try { - actOnChatEvent(handler); + actOnChatEvent(player); } catch (Exception e) { - errorLogger.error(e, ErrorContext.builder().related(handler, message).build()); + errorLogger.error(e, ErrorContext.builder().related(player, message).build()); } } - private void actOnChatEvent(ServerPlayNetworkHandler handler) { + private void actOnChatEvent(ServerPlayerEntity player) { long time = System.currentTimeMillis(); - ServerPlayerEntity player = handler.player; UUID uuid = player.getUuid(); String displayName = player.getDisplayName().getString(); @@ -82,12 +80,11 @@ public class ChatListener implements FabricListener { @Override public void register() { - PlanFabricEvents.ON_CHAT.register((handler, message) -> { + ServerMessageEvents.CHAT_MESSAGE.register((message, sender, params) -> { if (!isEnabled) { return; } - onChat(handler, message); - + onChat(sender, message.getContent().getString()); }); this.enable(); 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 3544b5fef..647c77fef 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 @@ -26,6 +26,7 @@ import com.djrapitops.plan.processing.processors.player.MobKillProcessor; import com.djrapitops.plan.processing.processors.player.PlayerKillProcessor; import com.djrapitops.plan.utilities.logging.ErrorContext; import com.djrapitops.plan.utilities.logging.ErrorLogger; +import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.projectile.ProjectileEntity; @@ -58,6 +59,9 @@ public class DeathEventListener implements FabricListener { @Override public void register() { + ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, killer, killedEntity) -> { + PlanFabricEvents.ON_KILLED.invoker().onKilled(killedEntity, killer); + }); PlanFabricEvents.ON_KILLED.register((victim, killer) -> { if (!this.isEnabled) { return; 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 7cc308ca2..190e98878 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 @@ -21,6 +21,7 @@ import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.utilities.logging.ErrorContext; import com.djrapitops.plan.utilities.logging.ErrorLogger; import me.lucko.fabric.api.permissions.v0.Permissions; +import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.server.network.ServerPlayerEntity; import net.playeranalytics.plan.commands.CommandManager; @@ -85,12 +86,18 @@ public class FabricAFKListener implements FabricListener { @Override public void register() { this.enable(); - PlanFabricEvents.ON_CHAT.register((handler, message) -> { + ServerMessageEvents.CHAT_MESSAGE.register((message, sender, params) -> { + if (!isEnabled) { + return; + } + event(sender); + }); + PlanFabricEvents.ON_COMMAND.register((handler, command) -> { if (!isEnabled) { return; } event(handler.player); - boolean isAfkCommand = message.substring(1).toLowerCase().startsWith("afk"); + boolean isAfkCommand = command.toLowerCase().startsWith("afk"); if (isAfkCommand) { UUID uuid = handler.player.getUuid(); afkTracker.usedAfkCommand(uuid, System.currentTimeMillis()); diff --git a/Plan/fabric/src/main/resources/fabric.mod.json b/Plan/fabric/src/main/resources/fabric.mod.json index 05ec25a74..8875da989 100644 --- a/Plan/fabric/src/main/resources/fabric.mod.json +++ b/Plan/fabric/src/main/resources/fabric.mod.json @@ -19,7 +19,8 @@ "fabric-command-api-v2": "*", "fabric-entity-events-v1": "*", "fabric-lifecycle-events-v1": "*", - "fabric-networking-v0": "*" + "fabric-networking-v0": "*", + "fabric-message-api-v1": "*" }, "suggests": { "fabric-permissions-api-v0": "*" diff --git a/Plan/fabric/src/main/resources/plan.mixins.json b/Plan/fabric/src/main/resources/plan.mixins.json index 478167ae1..829d07635 100644 --- a/Plan/fabric/src/main/resources/plan.mixins.json +++ b/Plan/fabric/src/main/resources/plan.mixins.json @@ -4,9 +4,7 @@ "package": "net.playeranalytics.plan.gathering.listeners.events.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityMixin", "KickCommandMixin", - "PlayerEntityMixin", "PlayerManagerMixin", "ServerCommandSourceMixin", "ServerPlayerEntityMixin",