Add join/leave handler

This commit is contained in:
DaMachinator 2018-01-23 13:04:10 -05:00 committed by Arcanitor
parent 6fa058e834
commit 2880f6c7a5
2 changed files with 34 additions and 4 deletions

View File

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

View File

@ -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."
))
}
}
}