Advertisement
Lisenochek

Untitled

Dec 17th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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 NPCSettings {
  16.  
  17. private static YamlConfiguration y = YamlConfiguration.loadConfiguration(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  18.  
  19. public static void addToConfig() {
  20.  
  21. for (HashMap.Entry<String, Entity> map : CreatorNPC.entitySave.entrySet()) {
  22.  
  23. String name = map.getKey();
  24. Entity ent = map.getValue();
  25.  
  26. y.set("NPC." + name + ".world", ent.getLocation().getWorld().getName());
  27. y.set("NPC." + name + ".x", ent.getLocation().getX());
  28. y.set("NPC." + name + ".y", ent.getLocation().getY());
  29. y.set("NPC." + name + ".z", ent.getLocation().getZ());
  30. y.set("NPC." + name + ".yaw", ent.getLocation().getYaw());
  31. y.set("NPC." + name + ".pitch", ent.getLocation().getPitch());
  32. }
  33.  
  34. try {
  35. y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. public static void addToList() {
  42.  
  43. for (String s : y.getConfigurationSection("NPC").getKeys(false)) {
  44.  
  45. World w = Bukkit.getWorld(y.getString(s + ".world"));
  46. double x = y.getDouble(s + ".x");
  47. double Y = y.getDouble(s + ".y");
  48. double z = y.getDouble(s + ".z");
  49. float yaw = y.getInt(s + ".yaw");
  50. float pitch = y.getInt(s + ".pitch");
  51.  
  52. Location loc = new Location(w, x, Y, z, yaw, pitch);
  53.  
  54. for (Entity ent : w.getNearbyEntities(loc, 100.0, 100.0, 100.0)) CreatorNPC.entitySave(s, ent);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement