PlayerMoveData.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, UUID uuid) {
  24. this.sc = sc;
  25. this.coolDown = cooldown;
  26. this.ticks = cooldown;
  27. this.livingTime = livingTime;
  28. this.w = l1.getWorld();
  29. this.minX = Math.min(l1.getX(), l2.getX());
  30. this.minY = Math.min(l1.getY(), l2.getY());
  31. this.minZ = Math.min(l1.getZ(), l2.getZ());
  32. this.maxX = Math.max(l1.getX(), l2.getX());
  33. this.maxY = Math.max(l1.getY(), l2.getY());
  34. this.maxZ = Math.max(l1.getZ(), l2.getZ());
  35. this.uuid = uuid;
  36. }
  37. public int getId() {
  38. return id;
  39. }
  40. public boolean isSameScript(Script sc) {
  41. return this.sc == sc;
  42. }
  43. public boolean tickLiving() {
  44. if(livingTime == -1) {
  45. return false;
  46. }
  47. livingTime--;
  48. return livingTime < 0;
  49. }
  50. public boolean tick() {
  51. ticks--;
  52. if(ticks > 0) {
  53. return true;
  54. }
  55. ticks = coolDown;
  56. return false;
  57. }
  58. public boolean check(ServerPlayerEntity p) {
  59. double posX = p.getPosX();
  60. double posY = p.getPosY();
  61. double posZ = p.getPosZ();
  62. if(p.world != w || posX < minX || posX > maxX || posZ < minZ || posZ > maxZ || posY < minY || posY > maxY) {
  63. return false;
  64. }
  65. boolean b = (uuid == null || p.getUniqueID().equals(uuid));
  66. if(sc != null && b) {
  67. Server.scriptEvents.onPlayerMove(p, id);
  68. }
  69. return coolDown == -1 && b;
  70. }
  71. }