diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/event/FabricBalmCommonEvents.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/event/FabricBalmCommonEvents.java index 4aad93a8..e55265e2 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/event/FabricBalmCommonEvents.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/event/FabricBalmCommonEvents.java @@ -99,7 +99,7 @@ public static void registerEvents(FabricBalmEvents events) { }); }); - events.registerEvent(PlayerLoginEvent.class, () -> ServerPlayConnectionEvents.JOIN.register((listener, sender, server) -> { + events.registerEvent(PlayerConnectedEvent.class, () -> ServerPlayConnectionEvents.JOIN.register((listener, sender, server) -> { final PlayerLoginEvent event = new PlayerLoginEvent(listener.player); events.fireEventHandlers(event); })); diff --git a/fabric/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java b/fabric/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java new file mode 100644 index 00000000..543fbc74 --- /dev/null +++ b/fabric/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java @@ -0,0 +1,21 @@ +package net.blay09.mods.balm.mixin; + +import net.blay09.mods.balm.api.Balm; +import net.blay09.mods.balm.api.event.PlayerLoginEvent; +import net.minecraft.network.Connection; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.players.PlayerList; +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(PlayerList.class) +public class PlayerListMixin { + @Inject(method = "placeNewPlayer", at = @At(value = "RETURN")) + private void handlePlayerConnection(Connection connection, ServerPlayer player, CommonListenerCookie commonListenerCookie, CallbackInfo callbackInfo) { + final PlayerLoginEvent event = new PlayerLoginEvent(player); + Balm.getEvents().fireEvent(event); + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/balm.mixins.json b/fabric/src/main/resources/balm.mixins.json index e67d76e8..5e1600b4 100644 --- a/fabric/src/main/resources/balm.mixins.json +++ b/fabric/src/main/resources/balm.mixins.json @@ -18,7 +18,8 @@ "ServerPlayerMixin", "SlotAccessor", "StemBlockMixin", - "MinecraftServerMixin" + "MinecraftServerMixin", + "PlayerListMixin" ], "client": [ "AbstractClientPlayerMixin", diff --git a/forge/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java b/forge/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java new file mode 100644 index 00000000..b93cca1d --- /dev/null +++ b/forge/src/main/java/net/blay09/mods/balm/mixin/PlayerListMixin.java @@ -0,0 +1,21 @@ +package net.blay09.mods.balm.mixin; + +import net.blay09.mods.balm.api.Balm; +import net.blay09.mods.balm.api.event.PlayerConnectedEvent; +import net.minecraft.network.Connection; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.players.PlayerList; +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(PlayerList.class) +public class PlayerListMixin { + @Inject(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundPlayerAbilitiesPacket;(Lnet/minecraft/world/entity/player/Abilities;)V")) + private void handlePlayerConnection(Connection connection, ServerPlayer player, CommonListenerCookie commonListenerCookie, CallbackInfo callbackInfo) { + final PlayerConnectedEvent event = new PlayerConnectedEvent(player); + Balm.getEvents().fireEvent(event); + } +} \ No newline at end of file diff --git a/forge/src/main/resources/balm.mixins.json b/forge/src/main/resources/balm.mixins.json index 8ab01373..25a06344 100644 --- a/forge/src/main/resources/balm.mixins.json +++ b/forge/src/main/resources/balm.mixins.json @@ -10,7 +10,8 @@ "ReloadableServerResourcesMixin", "SlotAccessor", "MinecraftServerMixin", - "EntityMixin" + "EntityMixin", + "PlayerListMixin" ], "client": [ "AbstractContainerScreenAccessor", diff --git a/shared/src/main/java/net/blay09/mods/balm/api/event/PlayerConnectedEvent.java b/shared/src/main/java/net/blay09/mods/balm/api/event/PlayerConnectedEvent.java new file mode 100644 index 00000000..eab1d8f3 --- /dev/null +++ b/shared/src/main/java/net/blay09/mods/balm/api/event/PlayerConnectedEvent.java @@ -0,0 +1,15 @@ +package net.blay09.mods.balm.api.event; + +import net.minecraft.server.level.ServerPlayer; + +public class PlayerConnectedEvent extends BalmEvent { + private final ServerPlayer player; + + public PlayerConnectedEvent(ServerPlayer player) { + this.player = player; + } + + public ServerPlayer getPlayer() { + return player; + } +}