Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package ngx;
  2.  
  3. import API.APIconfig;
  4. import Core.MainClass;
  5. import Loader.NGXaddon;
  6. import ngx.Commands.Quests;
  7. import ngx.Commands.SetNPC;
  8. import ngx.Listeners.onInteract;
  9. import org.bukkit.Chunk;
  10. import org.bukkit.Location;
  11. import org.bukkit.World;
  12. import org.bukkit.entity.Entity;
  13. import org.bukkit.entity.LivingEntity;
  14. import org.bukkit.entity.Villager;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.UUID;
  19.  
  20. public class Addon extends NGXaddon {
  21.     public MainClass core;
  22.     public Addon m;
  23.  
  24.     public APIconfig Messages;
  25.     public APIconfig EntityData;
  26.     public APIconfig Quests;
  27.  
  28.     public List<LivingEntity> villagers = new ArrayList<LivingEntity>();
  29.  
  30.     public void preLoad() {
  31.         core = MainClass.getCore();
  32.         m = this;
  33.         setupConfigs();
  34.     }
  35.  
  36.     public void onLoad() {
  37.         preLoad();
  38.         spawnVillagers();
  39.         loadVillagers();
  40.         registerListener(new onInteract(m, core));
  41.         registerCommand(new SetNPC(m, core));
  42.         registerCommand(new Quests(m, core));
  43.     }
  44.  
  45.     public void onUnload() {
  46.         PrintConsole("Fire");
  47.         try {
  48.             for (LivingEntity e : villagers) {
  49.                 e.getLocation().getWorld().loadChunk(e.getLocation().getChunk());
  50.                 e.damage(999999);
  51.             }
  52.         } catch (Exception e) {
  53.             e.printStackTrace();
  54.         }
  55.         PrintConsole("Fire");
  56.         villagers.clear();
  57.         core = null;
  58.         m = null;
  59.     }
  60.  
  61.     public void setupConfigs() {
  62.         EntityData = core.APIcfgm.getNewConfig("Entitydata.yml");
  63.         Quests = core.APIcfgm.getNewConfig("Quests.yml");
  64.     }
  65.  
  66.     @SuppressWarnings("deprecation")
  67.     public void spawnVillagers() {
  68.         if (EntityData.getConfigurationSection("villagers") == null)
  69.             return;
  70.         if (EntityData.getConfigurationSection("villagers").getKeys(false).isEmpty())
  71.             return;
  72.         for (String s : EntityData.getConfigurationSection("villagers").getKeys(false)) {
  73.             PrintConsole("" + UUID.fromString(s));
  74.             World world = core.getServer().getWorld(EntityData.getString("villagers." + UUID.fromString(s) + ".loc." + "world"));
  75.             double x = EntityData.getDouble("villagers." + UUID.fromString(s) + ".loc." + "x");
  76.             double y = EntityData.getDouble("villagers." + UUID.fromString(s) + ".loc." + "y");
  77.             double z = EntityData.getDouble("villagers." + UUID.fromString(s) + ".loc." + "z");
  78.             float yaw = EntityData.getInt("villagers." + UUID.fromString(s) + ".loc." + "yaw");
  79.             float pitch = EntityData.getInt("villagers." + UUID.fromString(s) + ".loc." + "pitch");
  80.             Location loc = new Location(world, x, y, z, yaw, pitch);
  81.  
  82.             Villager villager = loc.getWorld().spawn(loc, Villager.class);
  83.             villager.setProfession(Villager.Profession.getProfession(EntityData.getInt("villagers." + s + ".type")));
  84.             villager.setCustomName(EntityData.getString("villagers." + s + ".name"));
  85.             villager.setCustomNameVisible(false);
  86.             m.villagers.add(villager);
  87.             core.APIrAI.removeAI(villager.getUniqueId());
  88.         }
  89.     }
  90.  
  91.     public void loadVillagers() {
  92.         for (String s : EntityData.getStringList("villagers")) {
  93.             villagers.add(core.APIefuuid.getLivingEntity(UUID.fromString(s)));
  94.         }
  95.     }
  96.  
  97.     public String PLAYER_ONLY = "Error: You can't use this command inside the console!";
  98.     public String USAGE = "&4Error&f: &cProper usage is: ";
  99.     public String INVALID_ARGS = "&4Error&f: &cInvalid arguments.";
  100.     public String NO_PERMISSION = "&4Error&f: &cNo permission!";
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement