PlayerLogInOut.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package me.km.playerbank;
  2. import me.kcm.events.PlayerConnectionEvent;
  3. import me.km.KajetansMod;
  4. import me.km.api.Module;
  5. import me.km.api.ModuleListener;
  6. import me.km.api.Utils;
  7. import me.km.chatchannel.ChatChannel;
  8. import me.km.commands.CommandTeleportAccept;
  9. import me.km.dimensions.ModDimensions;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  12. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  13. import net.minecraftforge.fml.common.gameevent.PlayerEvent;
  14. public class PlayerLogInOut extends ModuleListener
  15. {
  16. public PlayerLogInOut(Module m)
  17. {
  18. super(m);
  19. }
  20. @SubscribeEvent(priority = EventPriority.HIGH)
  21. public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent e)
  22. {
  23. EntityPlayer p = e.player;
  24. if(p == null)
  25. {
  26. return;
  27. }
  28. if(!Utils.hasPlayedBefore(p)) // first join
  29. {
  30. Utils.teleportEntity(p, Utils.getSpawn());
  31. }
  32. PlayerBank pb = KajetansMod.playerbank.getDataBank();
  33. if(!pb.contains(p))
  34. {
  35. pb.add(p.getGameProfile());
  36. this.getModule().sendToConsole(p.getName() + " wurde hinzugefügt.");
  37. }
  38. else
  39. {
  40. this.getModule().sendToConsole(p.getName() + " ist bereits vorhanden.");
  41. if(pb.getName(p.getUniqueID().toString()).equals(p.getName()))
  42. {
  43. this.getModule().sendToConsole(p.getName() + " hat noch den gleichen Namen.");
  44. }
  45. else
  46. {
  47. this.getModule().sendToConsole(p.getName() + " hat seinen Namen geändert.");
  48. pb.changeName(p);
  49. }
  50. }
  51. ChatChannel.onPlayerLogIn(p);
  52. }
  53. @SubscribeEvent(priority = EventPriority.LOW)
  54. public void onPlayerLeaveCleanup(PlayerEvent.PlayerLoggedOutEvent e)
  55. {
  56. EntityPlayer p = e.player;
  57. KajetansMod.generalCommands.getCommand(CommandTeleportAccept.class).tpaccept.remove(p.getUniqueID());
  58. KajetansMod.scoreboard.removeScoreboard(p.getUniqueID());
  59. ChatChannel.onPlayerLogOut(p);
  60. }
  61. @SubscribeEvent
  62. public void onPlayerConnection(PlayerConnectionEvent e)
  63. {
  64. ModDimensions.sendNotificationsForDimensions(e.getEntityPlayer());
  65. }
  66. }