GameLocation.java


SUBMITTED BY: Guest

DATE: April 20, 2014, 9:28 p.m.

FORMAT: Java

SIZE: 2.5 kB

HITS: 1195

  1. package de.codebucket.witchmania.util;
  2. import org.bukkit.Bukkit;
  3. import org.bukkit.Location;
  4. public class GameLocation
  5. {
  6. private String world;
  7. private Double x;
  8. private Double y;
  9. private Double z;
  10. private Float yaw;
  11. private Float pitch;
  12. private LocationType type;
  13. public GameLocation(String world, Double x, Double y, Double z)
  14. {
  15. this.world = world;
  16. this.x = x;
  17. this.y = y;
  18. this.z = z;
  19. this.type = LocationType.ENTITY;
  20. }
  21. public GameLocation(String world, Double x, Double y, Double z, Float yaw, Float pitch)
  22. {
  23. this.world = world;
  24. this.x = x;
  25. this.y = y;
  26. this.z = z;
  27. this.yaw = yaw;
  28. this.pitch = pitch;
  29. this.type = LocationType.PLAYER;
  30. }
  31. public String getWorld()
  32. {
  33. return world;
  34. }
  35. public void setWorld(String world)
  36. {
  37. this.world = world;
  38. }
  39. public Double getX()
  40. {
  41. return x;
  42. }
  43. public void setX(Double x)
  44. {
  45. this.x = x;
  46. }
  47. public Double getY()
  48. {
  49. return y;
  50. }
  51. public void setY(Double y)
  52. {
  53. this.y = y;
  54. }
  55. public Double getZ()
  56. {
  57. return z;
  58. }
  59. public void setZ(Double z)
  60. {
  61. this.z = z;
  62. }
  63. public Float getYaw()
  64. {
  65. return yaw;
  66. }
  67. public void setYaw(Float yaw)
  68. {
  69. this.yaw = yaw;
  70. }
  71. public Float getPitch()
  72. {
  73. return pitch;
  74. }
  75. public void setPitch(Float pitch)
  76. {
  77. this.pitch = pitch;
  78. }
  79. public Location serialize()
  80. {
  81. if(type == LocationType.ENTITY)
  82. {
  83. return new Location(Bukkit.getWorld(world), x, y, z);
  84. new Loc
  85. }
  86. else if(type == LocationType.PLAYER)
  87. {
  88. return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
  89. }
  90. return null;
  91. }
  92. public void deserialize(Location location)
  93. {
  94. this.world = location.getWorld().getName();
  95. this.x = location.getX();
  96. this.y = location.getY();
  97. this.z = location.getZ();
  98. this.yaw = location.getYaw();
  99. this.pitch = location.getPitch();
  100. }
  101. public GameLocation clone()
  102. {
  103. if(type == LocationType.ENTITY)
  104. {
  105. return new GameLocation(world, x, y, z);
  106. }
  107. else if(type == LocationType.PLAYER)
  108. {
  109. return new GameLocation(world, x, y, z, yaw, pitch);
  110. }
  111. return null;
  112. }
  113. public enum LocationType
  114. {
  115. ENTITY,
  116. PLAYER;
  117. }
  118. }

comments powered by Disqus