Advertisement
Lisenochek

Untitled

Jan 4th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package ru.lisenochek.npc;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.World;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. import org.bukkit.entity.LivingEntity;
  9.  
  10. import java.io.File;
  11. import java.io.IOException;
  12.  
  13. public class Register {
  14.  
  15. public static void init() {
  16.  
  17. File f = new File(API.getInstance().getDataFolder(), "NPCbase.yml");
  18.  
  19. Bukkit.getPluginCommand("npc").setExecutor(new CommandAPI());
  20.  
  21. Bukkit.getPluginManager().registerEvents(new InteractListener(), API.getInstance());
  22. Bukkit.getPluginManager().registerEvents(new ChunkEntityListener(), API.getInstance());
  23. Bukkit.getScheduler().runTaskTimer(API.getInstance(), new RunnableClass(), 1, 20);
  24.  
  25. if (!f.exists()) {
  26. try {
  27. f.createNewFile();
  28. } catch (IOException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. YamlConfiguration y = ConfigManager.y;
  34. API.getInstance().saveDefaultConfig();
  35.  
  36. if (!y.isConfigurationSection("NPC")) return;
  37.  
  38. for (String s : y.getConfigurationSection("NPC").getKeys(false)) {
  39.  
  40. World w = Bukkit.getWorld(y.getString("NPC." + s + ".world"));
  41. double x = y.getDouble("NPC." + s + ".x");
  42. double Y = y.getDouble("NPC." + s + ".y");
  43. double z = y.getDouble("NPC." + s + ".z");
  44. String cmd = y.getString("NPC." + s + ".command");
  45.  
  46. Location loc = new Location(w, x, Y, z);
  47. loc.getChunk().load();
  48.  
  49. ChunkEntityListener.addEntity(new CustomEntity(loc, s, cmd), ChatColor.stripColor(s));
  50.  
  51. LivingEntity ent = (LivingEntity) ChunkEntityListener.getEntityByLocation(loc);
  52. ent.setCollidable(false);
  53. ent.setGravity(false);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement