testing new Bukkit events

This commit is contained in:
aPunch 2012-01-17 22:04:08 -06:00
parent 367dba47fb
commit 21e985dc5d
3 changed files with 51 additions and 3 deletions

Binary file not shown.

View File

@ -1,12 +1,17 @@
package net.citizensnpcs; package net.citizensnpcs;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.trait.trait.LocationTrait;
import net.citizensnpcs.listener.WorldListen;
import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Citizens extends JavaPlugin { public class Citizens extends JavaPlugin {
private CitizensNPCManager npcManager;
@Override @Override
public void onDisable() { public void onDisable() {
@ -15,10 +20,33 @@ public class Citizens extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
CitizensAPI.setNPCManager(new CitizensNPCManager()); npcManager = new CitizensNPCManager();
CitizensAPI.setNPCManager(npcManager);
registerEvents();
// TODO wait to load until after all plugins using CitizensAPI are
// loaded
Messaging.log("v" + getDescription().getVersion() + " enabled."); Messaging.log("v" + getDescription().getVersion() + " enabled.");
// 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.");
}
private void registerEvents() {
getServer().getPluginManager().registerEvents(new WorldListen(), this);
} }
} }

View File

@ -0,0 +1,20 @@
package net.citizensnpcs.listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
public class WorldListen implements Listener {
@EventHandler(event = ChunkLoadEvent.class, priority = EventPriority.NORMAL)
public void onChunkLoad(ChunkLoadEvent event) {
}
@EventHandler(event = ChunkLoadEvent.class, priority = EventPriority.NORMAL)
public void onChunkUnload(ChunkUnloadEvent event) {
}
}