package me.km.playerbank; import me.km.KajetansMod; import me.km.api.Module; import me.km.api.ModuleListener; import me.km.api.Utils; import me.km.commands.CommandSilent; import me.km.commands.CommandTeleportAccept; import me.km.events.PlayerJoinMessageEvent; import me.km.events.PlayerLeaveMessageEvent; import me.km.permissions.Permissions; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent; public class PlayerLogInOut extends ModuleListener { public PlayerLogInOut(Module m) { super(m); } @SubscribeEvent(priority = EventPriority.HIGH) public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent e) { EntityPlayer p = e.player; if(p == null) { return; } if(!Utils.hasPlayedBefore(p)) // first join { Utils.teleportEntity(p, Utils.getSpawn()); } PlayerBank pb = KajetansMod.playerbank.getDataBank(); if(!pb.contains(p)) { pb.add(p.getGameProfile()); this.getModule().sendToConsole(p.getName() + " wurde hinzugefügt."); } else { this.getModule().sendToConsole(p.getName() + " ist bereits vorhanden."); if(pb.getName(p.getUniqueID().toString()).equals(p.getName())) { this.getModule().sendToConsole(p.getName() + " hat noch den gleichen Namen."); } else { this.getModule().sendToConsole(p.getName() + " hat seinen Namen geändert."); pb.changeName(p); } } } @SubscribeEvent(priority = EventPriority.LOW) public void silentJoin(PlayerJoinMessageEvent e) { if(KajetansMod.perms.has(e.getEntityPlayer(), Permissions.SILENT) && KajetansMod.generalCommands.getCommand(CommandSilent.class).silentjoin) { e.setCanceled(true); } } @SubscribeEvent(priority = EventPriority.LOW) public void onPlayerLeaveCleanup(PlayerLeaveMessageEvent e) { EntityPlayer p = e.getEntityPlayer(); KajetansMod.generalCommands.getCommand(CommandTeleportAccept.class).tpaccept.remove(p.getUniqueID()); KajetansMod.playerbank.removeData(p); } @SubscribeEvent public void changeConnectionOnJoin(PlayerEvent.PlayerLoggedInEvent e) { if(e.player != null && e.player instanceof EntityPlayerMP) { EntityPlayerMP p = (EntityPlayerMP) e.player; // new handler sets connection with player in constructor, doing it twice p.connection = new ModNetHandlerPlayServer(p.mcServer, p.connection.netManager, p); } } }