Skip to content

Commit

Permalink
Make /ex command work form console (remember: no player or npc attach…
Browse files Browse the repository at this point in the history
…ed!). Add <element.replace[…].with[…]>
  • Loading branch information
aufdemrand committed Jul 23, 2013
1 parent 1da7249 commit a00c46d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 40 deletions.
31 changes: 0 additions & 31 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -963,37 +963,6 @@ public void text(CommandContext args, CommandSender sender, NPC npc) throws Comm
trait.report();
}


/*
* DENIZEN TEST, always a new flavor
*/
@Command(
aliases = { "denizen" }, usage = "ex",
desc = "For bob.", modifiers = { "ex" },
min = 1, max = 20, permission = "denizen.basic")
public void ex(CommandContext args, CommandSender sender, NPC npc) throws CommandException {

List<String> entries = new ArrayList<String>();
String entry = args.getJoinedStrings(1);

dB.log(entry);

entries.add(entry);

InstantQueue queue = InstantQueue.getQueue(null);

List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null,
(sender instanceof Player) ? dPlayer.mirrorBukkitPlayer((Player) sender) : null,
npc != null ? dNPC.mirrorCitizensNPC(npc) : null);

queue.addEntries(scriptEntries);

queue.start();


}


@Command(
aliases = { "notable" }, usage = "add",
desc = "Adds a new notable to your current location", modifiers = { "add", "save" },
Expand Down
46 changes: 39 additions & 7 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -11,11 +13,10 @@
import net.aufdemrand.denizen.npc.traits.*;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.scripts.ScriptEngine;
import net.aufdemrand.denizen.scripts.ScriptHelper;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.*;
import net.aufdemrand.denizen.scripts.commands.CommandRegistry;
import net.aufdemrand.denizen.scripts.containers.core.WorldScriptHelper;
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.scripts.requirements.RequirementRegistry;
import net.aufdemrand.denizen.scripts.triggers.TriggerRegistry;
import net.aufdemrand.denizen.tags.ObjectFetcher;
Expand Down Expand Up @@ -52,8 +53,8 @@ public class Denizen extends JavaPlugin {
public CommandHandler getCommandHandler() {
return commandHandler;
}


/*
* Denizen Engines
*/
Expand All @@ -63,7 +64,7 @@ public ScriptEngine getScriptEngine() {
return scriptEngine;
}


/*
* Denizen Registries
*/
Expand Down Expand Up @@ -309,9 +310,40 @@ public void saveSaves() {
}
}

Citizens citizens;

@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
Citizens citizens = (Citizens) getServer().getPluginManager().getPlugin("Citizens");
if (citizens == null) citizens = (Citizens) getServer().getPluginManager().getPlugin("Citizens");

dB.log("" + (sender instanceof Player));

if (!(sender instanceof Player) &&
cmdName.equalsIgnoreCase("ex")) {

List<String> entries = new ArrayList<String>();

String entry = "";
for (String arg : args)
entry = entry + arg + " ";

dB.log(entry);

entries.add(entry);

InstantQueue queue = InstantQueue.getQueue(null);

List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null,
null, null);

queue.addEntries(scriptEntries);

queue.start();

return true;

}

return citizens.onCommand(sender, cmd, cmdName, args);
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -295,6 +295,14 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("replace")
&& attribute.hasContext(1) && attribute.getAttribute(2).startsWith("with")
&& attribute.hasContext(2)) {
return new Element(element.replace(attribute.getContext(1), attribute.getContext(2)))
.getAttribute(attribute.fulfill(2));
}


if (attribute.startsWith("length")) {
return new Element(element.length())
.getAttribute(attribute.fulfill(1));
Expand Down
55 changes: 54 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -259,14 +259,27 @@ public String getAttribute(Attribute attribute) {

if (attribute == null) return "null";


// <--
// <npc.name.nickname> -> Element
// returns the NPC's nickname provided by the nickname trait, or null if the npc does not have the nickname trait.
// -->
if (attribute.startsWith("name.nickname"))
return new Element(getCitizen().hasTrait(NicknameTrait.class) ? getCitizen().getTrait(NicknameTrait.class)
.getNickname() : getName()).getAttribute(attribute.fulfill(2));

// <--
// <npc.name> -> Element
// returns the player's nickname provided by the nickname trait, or null if the NPC does not have a nickname
// -->
if (attribute.startsWith("name"))
return new Element(ChatColor.stripColor(getName()))
.getAttribute(attribute.fulfill(1));

// <--
// <npc.anchor.list> -> dList
// returns a dList of anchor names currently assigned to the NPC.
// -->
if (attribute.startsWith("anchor.list")
|| attribute.startsWith("anchors.list")) {
List<String> list = new ArrayList<String>();
Expand All @@ -275,11 +288,19 @@ public String getAttribute(Attribute attribute) {
return new dList(list).getAttribute(attribute.fulfill(1));
}

// <--
// <npc.has_anchors> -> Element(boolean)
// returns true if the NPC has anchors assigned, false otherwise.
// -->
if (attribute.startsWith("has_anchors")) {
return (new Element(String.valueOf(getCitizen().getTrait(Anchors.class).getAnchors().size() > 0)))
.getAttribute(attribute.fulfill(1));
}

// <--
// <npc.anchor[name]> -> dLocation
// returns a dLocation associated with the specified anchor, or 'null' if it doesn't exist.
// -->
if (attribute.startsWith("anchor")) {
if (attribute.hasContext(1)
&& getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != null)
Expand All @@ -288,7 +309,11 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("flag")) {
// <--
// <npc.flag[flag_name]> -> Flag dList
// returns 'flag dList' of the NPC's flag_name specified.
// -->
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
Expand All @@ -306,27 +331,55 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
else return "null";
}

// <--
// <npc.id> -> Element(number)
// returns the NPC's 'npcid' provided by Citizens.
// -->
if (attribute.startsWith("id"))
return new Element(String.valueOf(getId())).getAttribute(attribute.fulfill(1));

// <--
// <npc.owner> -> Element
// returns the owner of the NPC.
// -->
if (attribute.startsWith("owner"))
return new Element(getOwner()).getAttribute(attribute.fulfill(1));

// <--
// <npc.is_spawned> -> Element(boolean)
// returns 'true' if the NPC is spawned, otherwise 'false'.
// -->
if (attribute.startsWith("is_spawned"))
return new Element(String.valueOf(isSpawned())).getAttribute(attribute.fulfill(1));

// <--
// <npc.location.previous_location> -> dLocation
// returns the NPC's previous navigated location.
// -->
if (attribute.startsWith("location.previous_location"))
return (NPCTags.previousLocations.containsKey(getId())
? NPCTags.previousLocations.get(getId()).getAttribute(attribute.fulfill(2))
: "null");

// <--
// <npc.navigator.is_navigating> -> Element(boolean)
// returns true if the NPC is currently navigating, false otherwise.
// -->
if (attribute.startsWith("navigator.is_navigating"))
return new Element(String.valueOf(getNavigator().isNavigating())).getAttribute(attribute.fulfill(2));

// <--
// <npc.navigator.speed> -> Element(number)
// returns the current speed of the NPC.
// -->
if (attribute.startsWith("navigator.speed"))
return new Element(String.valueOf(getNavigator().getLocalParameters().speed()))
.getAttribute(attribute.fulfill(2));

// <--
// <npc.navigator.range> -> Element(number)
// returns the maximum 'pathfinding range'
// -->
if (attribute.startsWith("navigator.range"))
return new Element(String.valueOf(getNavigator().getLocalParameters().range()))
.getAttribute(attribute.fulfill(2));
Expand Down
Expand Up @@ -301,7 +301,6 @@ private void doCommand(ScriptEntry scriptEntry, String mapName) {
// Put tracked objects into new script entries.
for (String tracked_object : scriptEntry.tracked_objects) {
ScriptBuilder.addObjectToEntries(entries, tracked_object, scriptEntry.getObject(tracked_object));
dB.log(tracked_object);
}

scriptEntry.getResidingQueue().injectEntries(entries, 0);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/util.dscript
Expand Up @@ -71,6 +71,7 @@ _util_dtime_command:

events:
on ex command:
- if <player> == null queue clear
- if !<player.is_op> queue clear
- define command_name <c.args.get[1]>
- flag npc:<player.selected_npc> "list:|:<c.args>"
Expand Down

0 comments on commit a00c46d

Please sign in to comment.