PlayerLogInOut.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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(PlayerJoinMessageEvent e)
  24. {
  25. EntityPlayer p = e.getEntityPlayer();
  26. if(Utils.hasPlayedBefore(p)) // first join
  27. {
  28. Utils.teleportEntity(p, Utils.getSpawn());
  29. }
  30. PlayerBank pb = KajetansMod.playerbank.getDataBank();
  31. if(!pb.contains(p))
  32. {
  33. pb.add(p.getGameProfile());
  34. this.getModule().sendToConsole(p.getName() + " wurde hinzugefügt.");
  35. }
  36. else
  37. {
  38. this.getModule().sendToConsole(p.getName() + " ist bereits vorhanden.");
  39. if(pb.getName(p.getUniqueID().toString()).equals(p.getName()))
  40. {
  41. this.getModule().sendToConsole(p.getName() + " hat noch den gleichen Namen.");
  42. }
  43. else
  44. {
  45. this.getModule().sendToConsole(p.getName() + " hat seinen Namen geändert.");
  46. pb.changeName(p);
  47. }
  48. }
  49. }
  50. @SubscribeEvent(priority = EventPriority.LOW)
  51. public void silentJoin(PlayerJoinMessageEvent e)
  52. {
  53. if(KajetansMod.perms.has(e.getEntityPlayer(), Permissions.SILENT) &&
  54. KajetansMod.generalCommands.getCommand(CommandSilent.class).silentjoin)
  55. {
  56. e.setCanceled(true);
  57. }
  58. }
  59. @SubscribeEvent(priority = EventPriority.LOW)
  60. public void onPlayerLeaveCleanup(PlayerLeaveMessageEvent e)
  61. {
  62. EntityPlayer p = e.getEntityPlayer();
  63. KajetansMod.generalCommands.getCommand(CommandTeleportAccept.class).tpaccept.remove(p.getUniqueID());
  64. KajetansMod.playerbank.removeData(p);
  65. }
  66. @SubscribeEvent
  67. public void changeConnectionOnJoin(PlayerEvent.PlayerLoggedInEvent e)
  68. {
  69. if(e.player != null && e.player instanceof EntityPlayerMP)
  70. {
  71. EntityPlayerMP p = (EntityPlayerMP) e.player;
  72. // new handler sets connection with player in constructor, doing it twice
  73. p.connection = new ModNetHandlerPlayServer(p.mcServer, p.connection.netManager, p);
  74. }
  75. }
  76. }