Skip to content

Commit

Permalink
Fix ChunkLoad event registration without Citizens2
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Nov 30, 2014
1 parent bff740f commit 3c5bfdf
Showing 1 changed file with 22 additions and 14 deletions.
Expand Up @@ -3,8 +3,10 @@
import java.util.HashMap;
import java.util.Map;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand All @@ -22,7 +24,11 @@ public class ChunkLoadCommand extends AbstractCommand implements Listener {

@Override
public void onEnable() {
DenizenAPI.getCurrentInstance().getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance());
Denizen denizen = DenizenAPI.getCurrentInstance();
denizen.getServer().getPluginManager().registerEvents(this, denizen);
if (Depends.citizens != null) {
denizen.getServer().getPluginManager().registerEvents(new ChunkLoadCommandNPCEvents(), denizen);
}
}

/*
Expand Down Expand Up @@ -127,21 +133,23 @@ else if(System.currentTimeMillis() < chunkDelays.get(chunkString))
}
}

@EventHandler
public void stopDespawn(NPCDespawnEvent e) {
if (e.getNPC() == null || !e.getNPC().isSpawned())
return;
Chunk chnk = e.getNPC().getEntity().getLocation().getChunk();
String chunkString = chnk.getX()+", "+ chnk.getZ();
if(chunkDelays.containsKey(chunkString)) {
if(chunkDelays.get(chunkString) == 0)
e.setCancelled(true);
public class ChunkLoadCommandNPCEvents implements Listener {
@EventHandler
public void stopDespawn(NPCDespawnEvent e) {
if (e.getNPC() == null || !e.getNPC().isSpawned())
return;
Chunk chnk = e.getNPC().getEntity().getLocation().getChunk();
String chunkString = chnk.getX()+", "+ chnk.getZ();
if(chunkDelays.containsKey(chunkString)) {
if(chunkDelays.get(chunkString) == 0)
e.setCancelled(true);

else if(System.currentTimeMillis() < chunkDelays.get(chunkString))
e.setCancelled(true);
else if(System.currentTimeMillis() < chunkDelays.get(chunkString))
e.setCancelled(true);

else
chunkDelays.remove(chunkString);
else
chunkDelays.remove(chunkString);
}
}
}
}

0 comments on commit 3c5bfdf

Please sign in to comment.