use of net.aufdemrand.denizen.Denizen in project Denizen-For-Bukkit by DenizenScript.
the class ListenerRegistry method playerJoin.
@EventHandler
public void playerJoin(PlayerJoinEvent event) {
Denizen denizen = DenizenAPI.getCurrentInstance();
dPlayer player = new dPlayer(event.getPlayer());
// Any saves quest listeners in progress?
if (!denizen.getSaves().contains("Listeners." + player.getSaveName())) {
return;
}
Set<String> inProgress = denizen.getSaves().getConfigurationSection("Listeners." + player.getSaveName()).getKeys(false);
// If empty, no quest listeners to load.
if (inProgress.isEmpty()) {
return;
}
// TODO: Players.SAVENAME.Listeners?
String path = "Listeners." + player.getSaveName() + ".";
// If not empty, let's do the loading process for each.
for (String listenerId : inProgress) {
// People tend to worry when they see long-ass stacktraces.. let's catch them.
try {
String type = denizen.getSaves().getString(path + listenerId + ".Listener Type");
dNPC npc = null;
if (denizen.getSaves().contains(path + listenerId + ".Linked NPCID")) {
npc = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getById(denizen.getSaves().getInt(path + listenerId + ".Linked NPCID")));
}
if (get(type) == null) {
return;
}
dB.log(event.getPlayer().getName() + " has a LISTENER in progress. Loading '" + listenerId + "'.");
get(type).createInstance(dPlayer.mirrorBukkitPlayer(event.getPlayer()), listenerId).load(dPlayer.mirrorBukkitPlayer(event.getPlayer()), npc, listenerId, type);
} catch (Exception e) {
dB.log(event.getPlayer() + " has a saved listener named '" + listenerId + "' that may be corrupt. Skipping for now, but perhaps check the contents of your saves.yml for problems?");
}
}
}
use of net.aufdemrand.denizen.Denizen in project Denizen-For-Bukkit by DenizenScript.
the class ListenerRegistry method deconstructPlayer.
public void deconstructPlayer(dPlayer player) {
Denizen denizen = DenizenAPI.getCurrentInstance();
// Clear previous MemorySection in saves
denizen.getSaves().set("Listeners." + player.getSaveName(), null);
// If no quest listeners in progress, nothing else to do.
if (!listeners.containsKey(player.getName())) {
return;
}
// If there are quest listeners, invoke save() for each of them.
for (Map.Entry<String, AbstractListener> entry : getListenersFor(player).entrySet()) {
dB.log(player.getName() + " has a LISTENER in progress. Saving '" + entry.getKey() + "'.");
entry.getValue().save();
}
// Remove all listeners from memory for Player
// TODO: this seems invalid
listeners.remove(player);
}
use of net.aufdemrand.denizen.Denizen in project Denizen-For-Bukkit by DenizenScript.
the class ChunkLoadCommand method onEnable.
@Override
public void onEnable() {
Denizen denizen = DenizenAPI.getCurrentInstance();
denizen.getServer().getPluginManager().registerEvents(this, denizen);
if (Depends.citizens != null) {
denizen.getServer().getPluginManager().registerEvents(new ChunkLoadCommandNPCEvents(), denizen);
}
}
Aggregations