Skip to content

Commit

Permalink
Add notable cuboid events.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Oct 24, 2013
1 parent df390ba commit 323e8d2
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 69 deletions.
19 changes: 12 additions & 7 deletions src/main/java/net/aufdemrand/denizen/npc/dNPCRegistry.java
Expand Up @@ -118,16 +118,22 @@ public void onSpawn(NPCSpawnEvent event) {
getDenizen(event.getNPC()).action("spawn", null);
}


// <--[action]
// @Actions
// despawn
//
// @Triggers when the NPC is despawned.
// This can be because a command was issues, or a chunk has been unloaded.
//
// @Context
// None
//
// <npc> The NPC involved.
// -->

/**
* Fires a world script event and then NPC action when the NPC despawns.
*
* @param event NPCDespawnEvent
*/
@EventHandler
public void despawn(NPCDespawnEvent event) {
// Do world script event 'On NPC Completes Navigation'
Expand All @@ -138,21 +144,20 @@ public void despawn(NPCDespawnEvent event) {
getDenizen(event.getNPC()).action("despawn", null);
}


// <--[action]
// @Actions
// remove
//
// @Triggers when the NPC is removed.
//
// @Context
// None
//
// <npc> The NPC involved.
// -->

/**
* Removes an NPC from the Registry when removed from Citizens.
*
* @param event NPCRemoveEvent
*
*/
@EventHandler
public void onRemove(NPCRemoveEvent event) {
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -24,7 +25,14 @@ public class dCuboid implements dObject, Notable {
// STATIC METHODS
/////////////////

public static List<dCuboid> getNotableCuboidsContaining(Location location) {
List<dCuboid> cuboids = new ArrayList<dCuboid>();
for (dObject notable : NotableManager.getAllType(dCuboid.class))
if (((dCuboid) notable).isInsideCuboid(location))
cuboids.add((dCuboid) notable);

return cuboids;
}


//////////////////
Expand Down Expand Up @@ -321,8 +329,8 @@ public dList getSpawnableBlocks() {
.add(x, y, z));

if (SafeBlock.blockIsSafe(loc.getBlock().getType())
&& SafeBlock.blockIsSafe(loc.clone().add(0, 1, 0).getBlock().getType())
&& loc.clone().add(0, -1, 0).getBlock().getType().isSolid()) {
&& SafeBlock.blockIsSafe(loc.clone().add(0, 1, 0).getBlock().getType())
&& loc.clone().add(0, -1, 0).getBlock().getType().isSolid()) {
// Get the center of the block, so the entity won't suffocate
// inside the edges for a couple of seconds
loc.add(0.5, 0, 0.5);
Expand Down Expand Up @@ -351,11 +359,11 @@ public boolean isUnique() {
@Override
@Note("cuboid")
public String getSaveObject() {
return loc_1.getBlockX() + "," + loc_1.getBlockY()
+ "," + loc_1.getBlockZ() + "," + loc_1.getWorld().getName()
+ "|"
+ loc_2.getBlockX() + "," + loc_2.getBlockY()
+ "," + loc_2.getBlockZ() + "," + loc_2.getWorld().getName();
return loc_1.getBlockX() + ',' + loc_1.getBlockY()
+ ',' + loc_1.getBlockZ() + ',' + loc_1.getWorld().getName()
+ '|'
+ loc_2.getBlockX() + ',' + loc_2.getBlockY()
+ ',' + loc_2.getBlockZ() + ',' + loc_2.getWorld().getName();
}

@Override
Expand All @@ -376,7 +384,7 @@ public void forget() {
////////////////////


String prefix = "Cuboid";
String prefix = "Cuboid";


@Override
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
Expand All @@ -12,6 +13,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -60,7 +62,7 @@ public static Notable getSavedObject(String id) {

public static String getSavedId(Notable object) {
if (reverseObjects.containsKey(object))
return reverseObjects.get(reverseObjects);
return reverseObjects.get(object);
return null;
}

Expand Down Expand Up @@ -92,6 +94,17 @@ public static void remove(Notable obj) {
typeTracker.remove(id.toLowerCase());
}

public static List<dObject> getAllType(Class<? extends dObject> type) {
List<dObject> objects = new ArrayList<dObject>();
for (Map.Entry<String, Notable> notable : notableObjects.entrySet()) {
dB.log(notable.toString());
if (isType(notable.getKey(), type))
objects.add((dObject) notable.getValue());
}

return objects;
}



/*
Expand Down

0 comments on commit 323e8d2

Please sign in to comment.