Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. package auki.commands.holographic;
  2.  
  3. import auki.commands.user;
  4. import auki.config.chologram;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.World;
  9. import org.bukkit.entity.ArmorStand;
  10. import org.bukkit.entity.EntityType;
  11.  
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. public class Hologram {
  16. public String name;
  17. public List<ArmorStand> physicalEntities;
  18. private List<String> content, commands;
  19. private Location hologramLocation;
  20.  
  21.  
  22. public static String format(String string) {
  23. return ChatColor.translateAlternateColorCodes('&', string);
  24. }
  25.  
  26. public static String format(List<String> list) {
  27. String str = "";
  28. for (String content : list) {
  29. if (str.equals("")) {
  30. str = content;
  31. } else {
  32. str = str + ", " + content;
  33. }
  34. }
  35. return str;
  36. }
  37.  
  38.  
  39. public Hologram(String name, Location location, String content) {
  40. this.name = name;
  41. this.content = new ArrayList<>();
  42. this.physicalEntities = new ArrayList<>();
  43. this.commands = new ArrayList<>();
  44. this.content.add(content);
  45. spawn(location);
  46. }
  47.  
  48.  
  49. public Hologram(String name) {
  50. this.name = name;
  51. this.physicalEntities = new ArrayList<>();
  52. this.commands = new ArrayList<>();
  53. this.commands = chologram.get.getFile().getStringList("holograms." + name + ".commands");
  54. this.content = new ArrayList<>();
  55.  
  56. for (String key : chologram.get.getFile().getConfigurationSection("holograms." + name + ".content").getKeys(false)) {
  57. this.content.add(format(chologram.get.getFile().getString("holograms." + name + ".content." + key)));
  58. }
  59.  
  60. World world = Bukkit.getWorld(chologram.get.getFile().getString("holograms." + name + ".location.world"));
  61. double x = chologram.get.getFile().getDouble("holograms." + name + ".location.x"), y = chologram.get.getFile().getDouble("holograms." + name + ".location.y"), z = chologram.get.getFile().getDouble("holograms." + name + ".location.z");
  62. float yaw = Float.parseFloat(chologram.get.getFile().getString("holograms." + name + ".location.yaw")), pitch = Float.parseFloat(chologram.get.getFile().getString("holograms." + name + ".location.pitch"));
  63. if (world == null) return;
  64. Location location = new Location(world, x, y, z, yaw, pitch);
  65. spawn(location);
  66. }
  67.  
  68. private void spawn(Location location) {
  69. this.hologramLocation = location;
  70. int cycle = 0;
  71. for (String str : content) {
  72. cycle++;
  73. location.subtract(0, 0.3, 0);
  74. ArmorStand physicalEntity = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
  75. physicalEntity.setVisible(false);
  76. physicalEntity.setGravity(false);
  77. physicalEntity.setCustomNameVisible(true);
  78. physicalEntity.setCustomName(format(str));
  79. physicalEntity.setInvulnerable(true);
  80. physicalEntities.add(physicalEntity);
  81. }
  82. }
  83.  
  84. public boolean isTouchscreen() {
  85. return commands != null && commands.size() > 0;
  86. }
  87.  
  88. public void executeCommands(user user) {
  89. if (isTouchscreen()) {
  90. return;
  91. }
  92. for (String command : commands) {
  93. if (user.isplayer()) {
  94. boolean status = user.access().performCommand("/" + command.replaceAll("player%", user.access().getName()));
  95. if (!status) {
  96. user.send("Failed to run command " + command);
  97. }
  98. }
  99. }
  100. }
  101.  
  102. public void addCommand(String command) {
  103. commands.add(command);
  104. }
  105.  
  106. public void remove() {
  107. for(ArmorStand armorStand : physicalEntities) {
  108. armorStand.remove();
  109. }
  110. }
  111.  
  112. public void addline(String line) {
  113. content.add(format(line));
  114. this.remove();
  115. this.spawn(hologramLocation);
  116. }
  117.  
  118. public void serialize() {
  119. Location location = this.hologramLocation;
  120. chologram.get.setPath("holograms." + name + ".location.world", location.getWorld().getName());
  121. chologram.get.setPath("holograms." + name + ".location.x", location.getX());
  122. chologram.get.setPath("holograms." + name + ".location.y", location.getY());
  123. chologram.get.setPath("holograms." + name + ".location.z", location.getZ());
  124. chologram.get.setPath("holograms." + name + ".location.yaw", location.getYaw());
  125. chologram.get.setPath("holograms." + name + ".location.pitch", location.getPitch());
  126. chologram.get.setPath("holograms." + name + ".commands", commands);
  127. for (int x = 0; x < content.size(); x++) {
  128. chologram.get.setDefault("holograms." + name + ".content." + x, String.valueOf(content.get(x)));
  129. }
  130.  
  131. for (ArmorStand armorStand : physicalEntities) {
  132. armorStand.remove();
  133. }
  134.  
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement