PlayerMoveData.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package me.km.events;
  2. import java.util.UUID;
  3. import me.hammerle.snuviscript.code.Script;
  4. import me.km.Server;
  5. import me.km.utils.Location;
  6. import net.minecraft.entity.player.ServerPlayerEntity;
  7. import net.minecraft.world.IWorld;
  8. public class PlayerMoveData
  9. {
  10. private static int idCounter = 0;
  11. private final Script sc;
  12. private final int coolDown;
  13. private int ticks;
  14. private int livingTime;
  15. private final IWorld w;
  16. private final double minX;
  17. private final double minY;
  18. private final double minZ;
  19. private final double maxX;
  20. private final double maxY;
  21. private final double maxZ;
  22. private final int id = idCounter++;
  23. private final UUID uuid;
  24. public PlayerMoveData(Script sc, Location l1, Location l2, int cooldown, int livingTime, UUID uuid)
  25. {
  26. this.sc = sc;
  27. this.coolDown = cooldown;
  28. this.ticks = cooldown;
  29. this.livingTime = livingTime;
  30. this.w = l1.getWorld();
  31. this.minX = Math.min(l1.getX(), l2.getX());
  32. this.minY = Math.min(l1.getY(), l2.getY());
  33. this.minZ = Math.min(l1.getZ(), l2.getZ());
  34. this.maxX = Math.max(l1.getX(), l2.getX());
  35. this.maxY = Math.max(l1.getY(), l2.getY());
  36. this.maxZ = Math.max(l1.getZ(), l2.getZ());
  37. this.uuid = uuid;
  38. }
  39. public int getId()
  40. {
  41. return id;
  42. }
  43. public boolean isSameScript(Script sc)
  44. {
  45. return this.sc == sc;
  46. }
  47. public boolean tickLiving()
  48. {
  49. if(livingTime == -1)
  50. {
  51. return false;
  52. }
  53. livingTime--;
  54. return livingTime < 0;
  55. }
  56. public boolean tick()
  57. {
  58. ticks--;
  59. if(ticks > 0)
  60. {
  61. return true;
  62. }
  63. ticks = coolDown;
  64. return false;
  65. }
  66. public boolean check(ServerPlayerEntity p)
  67. {
  68. double posX = p.getPosX();
  69. double posY = p.getPosY();
  70. double posZ = p.getPosZ();
  71. if(p.world != w || posX < minX || posX > maxX || posZ < minZ || posZ > maxZ || posY < minY || posY > maxY)
  72. {
  73. return false;
  74. }
  75. boolean b = (uuid == null || p.getUniqueID().equals(uuid));
  76. if(sc != null && b)
  77. {
  78. Server.scriptEvents.onPlayerMove(p, id);
  79. }
  80. return coolDown == -1 && b;
  81. }
  82. }