From 2880f6c7a5a19fc78b0bf17426506356a8d4c9ca Mon Sep 17 00:00:00 2001 From: DaMachinator Date: Tue, 23 Jan 2018 13:04:10 -0500 Subject: [PATCH] Add join/leave handler --- .../civilengineering/CivilEngineering.kt | 6 ++-- .../eventhandlers/JoinLeaveHandler.kt | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt diff --git a/src/main/kotlin/civilengineering/CivilEngineering.kt b/src/main/kotlin/civilengineering/CivilEngineering.kt index f33f63a..7775d41 100644 --- a/src/main/kotlin/civilengineering/CivilEngineering.kt +++ b/src/main/kotlin/civilengineering/CivilEngineering.kt @@ -3,10 +3,7 @@ package civilengineering import civilengineering.bridge.MessageHandler import civilengineering.bridge.ServerChatHelper import civilengineering.command.BridgeCommand -import civilengineering.eventhandlers.AdvancementEventHandler -import civilengineering.eventhandlers.ChatMessageHandler -import civilengineering.eventhandlers.DeathEventHandler -import civilengineering.eventhandlers.CommandEventHandler +import civilengineering.eventhandlers.* import net.minecraft.advancements.Advancement import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod @@ -63,6 +60,7 @@ object CivilEngineering { MinecraftForge.EVENT_BUS.register(DeathEventHandler()) MinecraftForge.EVENT_BUS.register(CommandEventHandler()) MinecraftForge.EVENT_BUS.register(AdvancementEventHandler()) + MinecraftForge.EVENT_BUS.register(JoinLeaveHandler()) } @Mod.EventHandler diff --git a/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt b/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt new file mode 100644 index 0000000..a3bef68 --- /dev/null +++ b/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt @@ -0,0 +1,32 @@ +package civilengineering.eventhandlers + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.PlayerEvent +import civilengineering.Util.antiping +import civilengineering.bridge.ApiMessage +import civilengineering.bridge.MessageHandler +import civilengineering.cfg + +class JoinLeaveHandler { + @SubscribeEvent + fun handleJoinEvent(event: PlayerEvent.PlayerLoggedInEvent) { + if(cfg!!.relay.joinLeave) { + val player:String = event.player.name.antiping() + MessageHandler.transmit(ApiMessage( + username = "Server", + text = "$player has connected to the server." + )) + } + } + + @SubscribeEvent + fun handleLeaveEvent(event: PlayerEvent.PlayerLoggedOutEvent) { + if(cfg!!.relay.joinLeave) { + val player:String = event.player.name.antiping() + MessageHandler.transmit(ApiMessage( + username = "Server", + text = "$player has disconnected from the server." + )) + } + } +} \ No newline at end of file