PlayerMoveData.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. private static int idCounter = 0;
  10. private final Script sc;
  11. private final int coolDown;
  12. private int ticks;
  13. private int livingTime;
  14. private final IWorld w;
  15. private final double minX;
  16. private final double minY;
  17. private final double minZ;
  18. private final double maxX;
  19. private final double maxY;
  20. private final double maxZ;
  21. private final int id = idCounter++;
  22. private final UUID uuid;
  23. public PlayerMoveData(Script sc, Location l1, Location l2, int cooldown, int livingTime,
  24. UUID uuid) {
  25. this.sc = sc;
  26. this.coolDown = cooldown;
  27. this.ticks = cooldown;
  28. this.livingTime = livingTime;
  29. this.w = l1.getWorld();
  30. this.minX = Math.min(l1.getX(), l2.getX());
  31. this.minY = Math.min(l1.getY(), l2.getY());
  32. this.minZ = Math.min(l1.getZ(), l2.getZ());
  33. this.maxX = Math.max(l1.getX(), l2.getX());
  34. this.maxY = Math.max(l1.getY(), l2.getY());
  35. this.maxZ = Math.max(l1.getZ(), l2.getZ());
  36. this.uuid = uuid;
  37. }
  38. public int getId() {
  39. return id;
  40. }
  41. public boolean isSameScript(Script sc) {
  42. return this.sc == sc;
  43. }
  44. public boolean tickLiving() {
  45. if(livingTime == -1) {
  46. return false;
  47. }
  48. livingTime--;
  49. return livingTime < 0;
  50. }
  51. public boolean tick() {
  52. ticks--;
  53. if(ticks > 0) {
  54. return true;
  55. }
  56. ticks = coolDown;
  57. return false;
  58. }
  59. public boolean check(ServerPlayerEntity p) {
  60. double posX = p.getX();
  61. double posY = p.getY();
  62. double posZ = p.getZ();
  63. if(p.level != w || posX < minX || posX > maxX || posZ < minZ || posZ > maxZ || posY < minY
  64. || posY > maxY) {
  65. return false;
  66. }
  67. boolean b = (uuid == null || p.getUUID().equals(uuid));
  68. if(sc != null && b) {
  69. Server.scriptEvents.onPlayerMove(p, id);
  70. }
  71. return coolDown == -1 && b;
  72. }
  73. }