PlayerLogInOut.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package me.km.playerbank;
  2. import me.km.KajetansMod;
  3. import me.km.api.Module;
  4. import me.km.api.ModuleListener;
  5. import me.km.api.Utils;
  6. import me.km.commands.CommandSilent;
  7. import me.km.commands.CommandTeleportAccept;
  8. import me.km.events.PlayerJoinMessageEvent;
  9. import me.km.events.PlayerLeaveMessageEvent;
  10. import me.km.permissions.Permissions;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.player.EntityPlayerMP;
  13. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  14. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  15. import net.minecraftforge.fml.common.gameevent.PlayerEvent;
  16. public class PlayerLogInOut extends ModuleListener
  17. {
  18. public PlayerLogInOut(Module m)
  19. {
  20. super(m);
  21. }
  22. @SubscribeEvent(priority = EventPriority.HIGH)
  23. public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent e)
  24. {
  25. EntityPlayer p = e.player;
  26. if(p == null)
  27. {
  28. return;
  29. }
  30. if(!Utils.hasPlayedBefore(p)) // first join
  31. {
  32. Utils.teleportEntity(p, Utils.getSpawn());
  33. }
  34. PlayerBank pb = KajetansMod.playerbank.getDataBank();
  35. if(!pb.contains(p))
  36. {
  37. pb.add(p.getGameProfile());
  38. this.getModule().sendToConsole(p.getName() + " wurde hinzugefügt.");
  39. }
  40. else
  41. {
  42. this.getModule().sendToConsole(p.getName() + " ist bereits vorhanden.");
  43. if(pb.getName(p.getUniqueID().toString()).equals(p.getName()))
  44. {
  45. this.getModule().sendToConsole(p.getName() + " hat noch den gleichen Namen.");
  46. }
  47. else
  48. {
  49. this.getModule().sendToConsole(p.getName() + " hat seinen Namen geändert.");
  50. pb.changeName(p);
  51. }
  52. }
  53. }
  54. @SubscribeEvent(priority = EventPriority.LOW)
  55. public void silentJoin(PlayerJoinMessageEvent e)
  56. {
  57. if(KajetansMod.perms.has(e.getEntityPlayer(), Permissions.SILENT) &&
  58. KajetansMod.generalCommands.getCommand(CommandSilent.class).silentjoin)
  59. {
  60. e.setCanceled(true);
  61. }
  62. }
  63. @SubscribeEvent(priority = EventPriority.LOW)
  64. public void onPlayerLeaveCleanup(PlayerLeaveMessageEvent e)
  65. {
  66. EntityPlayer p = e.getEntityPlayer();
  67. KajetansMod.generalCommands.getCommand(CommandTeleportAccept.class).tpaccept.remove(p.getUniqueID());
  68. KajetansMod.playerbank.removeData(p);
  69. }
  70. @SubscribeEvent
  71. public void changeConnectionOnJoin(PlayerEvent.PlayerLoggedInEvent e)
  72. {
  73. if(e.player != null && e.player instanceof EntityPlayerMP)
  74. {
  75. EntityPlayerMP p = (EntityPlayerMP) e.player;
  76. // new handler sets connection with player in constructor, doing it twice
  77. p.connection = new ModNetHandlerPlayServer(p.mcServer, p.connection.netManager, p);
  78. }
  79. }
  80. }