Citizens2/src/net/citizensnpcs/Citizens.java

55 lines
1.6 KiB
Java
Raw Normal View History

2012-01-15 00:51:37 +01:00
package net.citizensnpcs;
import net.citizensnpcs.api.CitizensAPI;
2012-01-18 05:04:08 +01:00
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
2012-01-18 11:35:15 +01:00
import net.citizensnpcs.listener.EntityListen;
2012-01-18 05:04:08 +01:00
import net.citizensnpcs.listener.WorldListen;
2012-01-15 00:51:37 +01:00
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.util.Messaging;
2012-01-15 00:51:37 +01:00
2012-01-18 05:04:08 +01:00
import org.bukkit.Bukkit;
2012-01-18 11:35:15 +01:00
import org.bukkit.plugin.PluginManager;
2012-01-15 00:51:37 +01:00
import org.bukkit.plugin.java.JavaPlugin;
public class Citizens extends JavaPlugin {
2012-01-18 05:04:08 +01:00
private CitizensNPCManager npcManager;
2012-01-15 00:51:37 +01:00
@Override
public void onDisable() {
Messaging.log("v" + getDescription().getVersion() + " disabled.");
2012-01-15 00:51:37 +01:00
}
@Override
public void onEnable() {
2012-01-18 05:04:08 +01:00
npcManager = new CitizensNPCManager();
CitizensAPI.setNPCManager(npcManager);
2012-01-18 11:35:15 +01:00
registerEvents(getServer().getPluginManager());
Messaging.log("v" + getDescription().getVersion() + " enabled.");
2012-01-18 05:04:08 +01:00
// Setup NPCs after all plugins have been enabled (allows for multiworld
// support and for NPCs to properly register external settings)
if (Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
setupNPCs();
}
}, 100) == -1)
Messaging.log("Issue enabling plugin. Disabling.");
}
private void setupNPCs() {
// TODO set up saving
for (NPC npc : npcManager.getNPCs()) {
npc.spawn(((LocationTrait) npc.getTrait("location")).getLocation());
}
Messaging.log("Loaded " + npcManager.getNPCs().size() + " NPCs.");
}
2012-01-18 11:35:15 +01:00
private void registerEvents(PluginManager pm) {
pm.registerEvents(new EntityListen(), this);
pm.registerEvents(new WorldListen(), this);
2012-01-15 00:51:37 +01:00
}
}