Greenadine

ScareCrow.java

Sep 17th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package me.greenadine.scarecrow;
  2.  
  3. import org.bukkit.Chunk;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.entity.ArmorStand;
  7. import org.bukkit.entity.Entity;
  8.  
  9. public class ScareCrow {
  10.  
  11. private Main main;
  12.  
  13. private String id;
  14.  
  15. private ArmorStand armorstand = null;
  16. private Location location;
  17. private double x, y, z;
  18.  
  19. public ScareCrow(Main main, ArmorStand armorstand) {
  20. this.main = main;
  21. this.armorstand = armorstand;
  22. location = armorstand.getLocation();
  23. x = armorstand.getLocation().getX();
  24. y = armorstand.getLocation().getY();
  25. z = armorstand.getLocation().getZ();
  26.  
  27. String id = location.getWorld() + "@" + x + ";" + y + ";" + z;
  28. this.id = id;
  29.  
  30. main.getScarecrows().add(this);
  31. }
  32.  
  33. public void create(Location loc) {
  34. World w = loc.getWorld();
  35.  
  36. try {
  37. w.spawn(loc, ArmorStand.class);
  38. } catch(Exception e) {
  39. return;
  40. }
  41.  
  42. Chunk c = loc.getChunk();
  43.  
  44. Entity[] entities = c.getEntities();
  45.  
  46. for(Entity e : entities) {
  47. if(e instanceof ArmorStand) {
  48. ArmorStand am = (ArmorStand) e;
  49. int blockX = am.getLocation().getBlockX();
  50. int blockY = am.getLocation().getBlockY();
  51. int blockZ = am.getLocation().getBlockZ();
  52.  
  53. if(loc.getBlockX() == blockX && loc.getBlockY() == blockY && loc.getBlockZ() == blockZ) {
  54. ScareCrow sc = new ScareCrow(main, am);
  55. return;
  56. } else {
  57. return;
  58. }
  59. } else {
  60. return;
  61. }
  62. }
  63. }
  64.  
  65. public String getID() {
  66. return id;
  67. }
  68.  
  69. public ArmorStand getStand() {
  70. return armorstand;
  71. }
  72.  
  73. public Location getLocation() {
  74. return location;
  75. }
  76.  
  77. public double getX() {
  78. return x;
  79. }
  80.  
  81. public double gety() {
  82. return y;
  83. }
  84.  
  85. public double getz() {
  86. return z;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment