Advertisement
Lisenochek

Untitled

Dec 18th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package ru.lisenochek.npcandother.config.configSettings;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.configuration.file.YamlConfiguration;
  7. import org.bukkit.entity.Entity;
  8. import ru.lisenochek.npcandother.API;
  9. import ru.lisenochek.npcandother.NPC.CreatorNPC;
  10.  
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.util.HashMap;
  14.  
  15. public class NPC_DiscSettings {
  16.  
  17. private static File f = new File(API.getInstance().getDataFolder(), "NPCbase.yml");
  18. private static YamlConfiguration y = YamlConfiguration.loadConfiguration(f);
  19.  
  20. public static void addToConfig() {
  21.  
  22. for (HashMap.Entry<String, Entity> map : CreatorNPC.entitySave.entrySet()) {
  23.  
  24. String name = map.getKey();
  25. Entity ent = map.getValue();
  26.  
  27. y.set("NPC." + name + ".world", ent.getLocation().getWorld().getName());
  28. y.set("NPC." + name + ".x", ent.getLocation().getX());
  29. y.set("NPC." + name + ".y", ent.getLocation().getY());
  30. y.set("NPC." + name + ".z", ent.getLocation().getZ());
  31. y.set("NPC." + name + ".yaw", ent.getLocation().getYaw());
  32. y.set("NPC." + name + ".pitch", ent.getLocation().getPitch());
  33.  
  34. if (!CreatorNPC.entitySave.containsValue(ent)) y.set("NPC." + name, null);
  35. }
  36.  
  37. try {
  38. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  39. } catch (IOException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. public static void addCommandToConfig() {
  45.  
  46. for (HashMap.Entry<Entity, String> map : CreatorNPC.entityCommand.entrySet()) {
  47.  
  48. Entity ent = map.getKey();
  49. String cmd = map.getValue();
  50.  
  51. y.set("NPC." + ent.getName() + ".command", cmd);
  52. }
  53.  
  54. try {
  55. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  56. } catch (IOException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60.  
  61. public static void addToList() {
  62.  
  63. for (String s : y.getConfigurationSection("NPC").getKeys(false)) {
  64.  
  65. World w = Bukkit.getWorld(y.getString("NPC." + s + ".world"));
  66. double x = y.getDouble("NPC." + s + ".x");
  67. double Y = y.getDouble("NPC." + s + ".y");
  68. double z = y.getDouble("NPC." + s + ".z");
  69. float yaw = y.getInt("NPC." + s + ".yaw");
  70. float pitch = y.getInt("NPC." + s + ".pitch");
  71. String cmd = y.getString("NPC." + s + ".command");
  72.  
  73. Location loc = new Location(w, x, Y, z, yaw, pitch);
  74.  
  75. for (Entity ent : w.getNearbyEntities(loc, 1.0, 1.0, 1.0)) {
  76. CreatorNPC.entitySave.put(s, ent);
  77. CreatorNPC.entityCommand.put(ent, cmd);
  78. }
  79. }
  80. }
  81.  
  82. public static void deleteFromDisc(String name) {
  83.  
  84. y.set("NPC." + name, null);
  85.  
  86. try {
  87. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  88. } catch (IOException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92.  
  93. public static void deleteCommandFromDisc(String name) {
  94.  
  95. y.set("NPC." + name + ".command", null);
  96.  
  97. try {
  98. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  99. } catch (IOException e) {
  100. e.printStackTrace();
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement