Search in sources :

Example 1 with Denizen

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?");
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) Denizen(net.aufdemrand.denizen.Denizen) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Denizen

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);
}
Also used : Denizen(net.aufdemrand.denizen.Denizen) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Denizen

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);
    }
}
Also used : Denizen(net.aufdemrand.denizen.Denizen)

Aggregations

Denizen (net.aufdemrand.denizen.Denizen)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)1 EventHandler (org.bukkit.event.EventHandler)1