Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jul 13, 2013
1 parent ff5ab8a commit a56056b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 13 deletions.
Expand Up @@ -176,7 +176,6 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
break;
case SPLIT:
flag.split(value);
dB.echoDebug(flag.toString());
break;
case DELETE:
flag.clear();
Expand Down
Expand Up @@ -2,10 +2,7 @@

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.ScriptQueue;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
Expand All @@ -29,6 +26,20 @@ enum Type {LOCATION, LIST_ITEM}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("iterable")
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("iterable", arg.asType(dLocation.class));

else if (!scriptEntry.hasObject("iterable")
&& arg.matchesArgumentType(dList.class))
scriptEntry.addObject("iterable", arg.asType(dList.class));



}

Type type = null;
dScript script = null;
dLocation location_1 = null;
Expand Down
Expand Up @@ -285,6 +285,8 @@ private void doCommand(ScriptEntry scriptEntry, String mapName) {
.setNPC(scriptEntry.getNPC()).setInstant(true)
.addObject("reqId", scriptEntry.getObject("reqId"));

entry.setSendingQueue(scriptEntry.getResidingQueue());

// Put tracked objects into new script entries.
for (String tracked_object : scriptEntry.tracked_objects)
entry.addObject(tracked_object, scriptEntry.getObject(tracked_object));
Expand Down
Expand Up @@ -147,8 +147,6 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}
}

dB.log(queue.getQueueSize() + " " + entries.size());

// OK, GO!
queue.start();
}
Expand Down
60 changes: 54 additions & 6 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -3,14 +3,19 @@
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.ReplaceableTagEvent;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.tags.core.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand All @@ -23,29 +28,72 @@
*
*/

public class TagManager {
public class TagManager implements Listener {

public Denizen denizen;

public TagManager(Denizen denizen) {
this.denizen = denizen;

}

public void registerCoreTags() {
new PlayerTags(denizen);
new UtilTags(denizen);
// For compatibility
new AnchorTags(denizen);
new FlagTags(denizen);
new ConstantTags(denizen);
new ProcedureScriptTag(denizen);

new PlayerTags(denizen);
new NPCTags(denizen);
new AnchorTags(denizen);
new LocationTags(denizen);

new UtilTags(denizen);
new ProcedureScriptTag(denizen);
new NotableLocationTags(denizen);
new ContextTags(denizen);
new LocationTags(denizen);
new SpecialCharacterTags(denizen);
new TextTags(denizen);

denizen.getServer().getPluginManager().registerEvents(this, denizen);
}

@EventHandler
public void fetchObject(ReplaceableTagEvent event) {
if (!event.getName().contains("@")) return;

String object_type = event.getName().split("@")[0].toLowerCase();
Class object_class = ObjectFetcher.getObjectClass(object_type);

if (object_class == null) {
dB.echoError("Invalid object type! Could not fetch '" + object_type + "'!");
event.setReplaced("null");
return;
}

dObject arg;
try {

if ((Boolean) object_class.getMethod("matches", String.class)
.invoke(null, event.getName()) == false) {
dB.echoDebug("Returning null. '" + event.getName()
+ "' is an invalid " + object_class.getSimpleName() + ".");
event.setReplaced("null");
return;
}

arg = (dObject) object_class.getMethod("valueOf", String.class)
.invoke(null, event.getName());

Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
event.setReplaced(arg.getAttribute(attribute.fulfill(1)));
} catch (Exception e) {
dB.echoError("Uh oh! Report this to aufdemrand! Err: TagManagerObjectReflection");
}

return;
}


public static String tag(dPlayer player, dNPC npc, String arg) {
return tag(player, npc, arg, false, null);
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.TagManager;

import net.aufdemrand.denizen.utilities.depends.Depends;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down

0 comments on commit a56056b

Please sign in to comment.