PlayerMoveData.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package me.km.events;
  2. import java.util.function.BiPredicate;
  3. import me.hammerle.snuviscript.code.Script;
  4. import me.km.KajetansMod;
  5. import me.km.api.Location;
  6. import me.km.snuviscript.ScriptEvents;
  7. import net.minecraft.entity.player.EntityPlayerMP;
  8. import net.minecraft.world.World;
  9. public class PlayerMoveData
  10. {
  11. private final Script sc;
  12. private final BiPredicate<EntityPlayerMP, Object> c;
  13. private final int coolDown;
  14. private int ticks;
  15. private int livingTime;
  16. private Object data;
  17. private final World w;
  18. private final double minX;
  19. private final double minY;
  20. private final double minZ;
  21. private final double maxX;
  22. private final double maxY;
  23. private final double maxZ;
  24. private PlayerMoveData(Script sc, BiPredicate<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
  25. {
  26. this.sc = sc;
  27. this.c = c;
  28. this.coolDown = cooldown;
  29. this.ticks = cooldown;
  30. this.livingTime = livingTime;
  31. this.w = l1.getWorld();
  32. this.minX = Math.min(l1.getX(), l2.getX());
  33. this.minY = Math.min(l1.getY(), l2.getY());
  34. this.minZ = Math.min(l1.getZ(), l2.getZ());
  35. this.maxX = Math.max(l1.getX(), l2.getX());
  36. this.maxY = Math.max(l1.getY(), l2.getY());
  37. this.maxZ = Math.max(l1.getZ(), l2.getZ());
  38. this.data = data;
  39. //System.out.println("X DATA FROM " + minX +" TO " + maxX);
  40. //System.out.println("Y DATA FROM " + minY +" TO " + maxY);
  41. //System.out.println("Z DATA FROM " + minZ +" TO " + maxZ);
  42. }
  43. public PlayerMoveData(Script sc, Location l1, Location l2, int cooldown, int livingTime)
  44. {
  45. this(sc, null, l1, l2, cooldown, livingTime, null);
  46. }
  47. public PlayerMoveData(BiPredicate<EntityPlayerMP, Object> c, Location l1, Location l2, int cooldown, int livingTime, Object data)
  48. {
  49. this(null, c, l1, l2, cooldown, livingTime, data);
  50. }
  51. public boolean isSameScript(Script sc)
  52. {
  53. return this.sc == sc;
  54. }
  55. public Object getData()
  56. {
  57. return data;
  58. }
  59. public boolean tickLiving()
  60. {
  61. if(livingTime == -1)
  62. {
  63. return false;
  64. }
  65. livingTime--;
  66. return livingTime < 0;
  67. }
  68. public boolean tick()
  69. {
  70. ticks--;
  71. if(ticks > 0)
  72. {
  73. return true;
  74. }
  75. ticks = coolDown;
  76. return false;
  77. }
  78. public boolean check(EntityPlayerMP p)
  79. {
  80. if(p.world != w || p.posX < minX || p.posX > maxX || p.posZ < minZ || p.posZ > maxZ || p.posY < minY || p.posY > maxY)
  81. {
  82. return false;
  83. }
  84. if(sc != null)
  85. {
  86. KajetansMod.scripts.getEvent(ScriptEvents.class).onPlayerMove(p);
  87. }
  88. if(c != null)
  89. {
  90. if(c.test(p, data))
  91. {
  92. return true;
  93. }
  94. }
  95. return coolDown == -1;
  96. }
  97. }