Lisenochek

Untitled

Dec 18th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 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 addNPCToConfig() {
  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.  
  35. try {
  36. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40. }
  41.  
  42. public static void addCommandToNPC(String name) {
  43.  
  44. for (String s : CreatorNPC.entityCommand.values()) y.set("NPC." + name + ".command", s);
  45.  
  46. try {
  47. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  48. } catch (IOException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. public static void addFromConfigToHashMap() {
  54.  
  55. if (!y.isConfigurationSection("NPC")) return;
  56.  
  57. for (String s : y.getConfigurationSection("NPC").getKeys(false)) {
  58.  
  59. World w = Bukkit.getWorld(y.getString("NPC." + s + ".world"));
  60. double x = y.getDouble("NPC." + s + ".x");
  61. double Y = y.getDouble("NPC." + s + ".y");
  62. double z = y.getDouble("NPC." + s + ".z");
  63. float yaw = y.getInt("NPC." + s + ".yaw");
  64. float pitch = y.getInt("NPC." + s + ".pitch");
  65. String cmd = y.getString("NPC." + s + ".command");
  66.  
  67. Location loc = new Location(w, x, Y, z, yaw, pitch);
  68.  
  69. for (Entity ent : w.getNearbyEntities(loc, 0.1, 0.1, 0.1)) {
  70. CreatorNPC.entitySave.put(s, ent);
  71. CreatorNPC.entityCommand.put(ent, cmd);
  72. }
  73. }
  74. }
  75.  
  76. public static void deleteFromDisc(String name) {
  77.  
  78. y.set("NPC." + name, null);
  79.  
  80. try {
  81. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  82. } catch (IOException e) {
  83. e.printStackTrace();
  84. }
  85. }
  86.  
  87. public static void deleteCommandFromDisc(String name) {
  88.  
  89. y.set("NPC." + name + ".command", null);
  90.  
  91. try {
  92. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  93. } catch (IOException e) {
  94. e.printStackTrace();
  95. }
  96. }
  97. }
Add Comment
Please, Sign In to add comment