Skip to content

Commit

Permalink
Add list[] and cuboid[] tag base units
Browse files Browse the repository at this point in the history
A way to easily get a cuboid or list from random tagged input, also a
few corrections.
  • Loading branch information
mcmonkey4eva committed Sep 22, 2014
1 parent c68b743 commit 311bb2a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -33,12 +33,14 @@ public TagManager(Denizen denizen) {

public void registerCoreTags() {
// Objects
new CuboidTags(denizen);
new EntityTags(denizen);
new PlayerTags(denizen);
new NPCTags(denizen);
new ListTags(denizen);
new LocationTags(denizen);
new ScriptTags(denizen);
new NPCTags(denizen);
new PlayerTags(denizen);
new QueueTags(denizen);
new ScriptTags(denizen);

// Utilities
new UtilTags(denizen);
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/CuboidTags.java
@@ -0,0 +1,45 @@
package net.aufdemrand.denizen.tags.core;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.bukkit.ReplaceableTagEvent;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dList;
import net.aufdemrand.denizen.tags.Attribute;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;


/**
* Location tag is a starting point for getting attributes for a
*
*/

public class CuboidTags implements Listener {

public CuboidTags(Denizen denizen) {
denizen.getServer().getPluginManager().registerEvents(this, denizen);
}

@EventHandler
public void locationTags(ReplaceableTagEvent event) {

if (!event.matches("cuboid") || event.replaced()) return;

dCuboid cuboid = null;

String context = event.getNameContext();
if (event.hasNameContext() && dCuboid.matches(context))
cuboid = dCuboid.valueOf(context);

// Check if cuboid is null, return null if it is
if (cuboid == null) {
event.setReplaced("null");
return;
}

// Build and fill attributes
Attribute attribute = event.getAttributes();
event.setReplaced(cuboid.getAttribute(attribute.fulfill(1)));

}
}
44 changes: 44 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/ListTags.java
@@ -0,0 +1,44 @@
package net.aufdemrand.denizen.tags.core;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.bukkit.ReplaceableTagEvent;
import net.aufdemrand.denizen.objects.dList;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.tags.Attribute;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;


/**
* Location tag is a starting point for getting attributes for a
*
*/

public class ListTags implements Listener {

public ListTags(Denizen denizen) {
denizen.getServer().getPluginManager().registerEvents(this, denizen);
}

@EventHandler
public void locationTags(ReplaceableTagEvent event) {

if (!event.matches("list") || event.replaced()) return;

dList list = null;

if (event.hasNameContext())
list = dList.valueOf(event.getNameContext());

// Check if list is null, return null if it is
if (list == null) {
event.setReplaced("null");
return;
}

// Build and fill attributes
Attribute attribute = event.getAttributes();
event.setReplaced(list.getAttribute(attribute.fulfill(1)));

}
}
12 changes: 8 additions & 4 deletions src/main/java/net/aufdemrand/denizen/tags/core/LocationTags.java
Expand Up @@ -30,16 +30,20 @@ public void locationTags(ReplaceableTagEvent event) {

// Check name context for a specified location, or check
// the ScriptEntry for a 'location' context
if (event.hasNameContext() && dLocation.matches(event.getNameContext()))
loc = dLocation.valueOf(event.getNameContext());
String context = event.getNameContext();
if (event.hasNameContext() && dLocation.matches(context))
loc = dLocation.valueOf(context);
else if (event.getScriptEntry().hasObject("location"))
loc = (dLocation) event.getScriptEntry().getObject("location");

// Check if location is null, return null if it is
if (loc == null) { event.setReplaced("null"); return; }
if (loc == null) {
event.setReplaced("null");
return;
}

// Build and fill attributes
Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
Attribute attribute = event.getAttributes();
event.setReplaced(loc.getAttribute(attribute.fulfill(1)));

}
Expand Down

0 comments on commit 311bb2a

Please sign in to comment.