Skip to content

Commit

Permalink
Simplify ScriptEntry to move coreward
Browse files Browse the repository at this point in the history
Still not ready to move, but we're another step closer
  • Loading branch information
mcmonkey4eva committed Dec 13, 2014
1 parent 1b5f53e commit e0b1454
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 131 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -39,6 +39,7 @@
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.DenizenImplementation;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.ScriptHelper;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.trait.TraitInfo;
Expand Down Expand Up @@ -745,6 +746,11 @@ public List<net.aufdemrand.denizencore.utilities.YamlConfiguration> getOutsideSc
}
return files;
}

@Override
public ScriptEntryData getEmptyScriptEntryData() {
return new BukkitScriptEntryData(null, null);
}
}


5 changes: 3 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
Expand Down Expand Up @@ -1266,8 +1267,8 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
}
else {
return new Element(format.getFormattedText(element,
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getNPC(): null,
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getPlayer(): null))
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(): null,
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(): null))
.getAttribute(attribute.fulfill(1));
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.aH.Argument;
import net.aufdemrand.denizen.objects.aH.PrimitiveType;
import net.aufdemrand.denizen.objects.notable.Notable;
Expand Down Expand Up @@ -1388,8 +1389,8 @@ public String getAttribute(Attribute attribute) {
&& attribute.hasContext(1)
&& dItem.matches(attribute.getContext(1))) {
dItem item = dItem.valueOf(attribute.getContext(1),
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getPlayer(): null,
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getNPC(): null);
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(): null,
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(): null);
item.setAmount(1);
int slot = -1;
for (int i = 0; i < inventory.getSize(); i++) {
Expand All @@ -1416,8 +1417,8 @@ public String getAttribute(Attribute attribute) {
&& attribute.hasContext(1)
&& dItem.matches(attribute.getContext(1))) {
dItem item = dItem.valueOf(attribute.getContext(1),
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getPlayer(): null,
attribute.getScriptEntry() != null ? attribute.getScriptEntry().getNPC(): null);
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(): null,
attribute.getScriptEntry() != null ? ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(): null);
item.setAmount(1);
int slot = -1;
for (int i = 0; i < inventory.getSize(); i++) {
Expand Down Expand Up @@ -1478,8 +1479,10 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("qty"))
if (attribute.hasContext(1) && dItem.matches(attribute.getContext(1)))
return new Element(count
(dItem.valueOf(attribute.getContext(1), attribute.getScriptEntry().getPlayer(), attribute.getScriptEntry().getNPC()).getItemStack(), false))
return new Element(count // TODO: Handle no-script-entry cases
(dItem.valueOf(attribute.getContext(1),
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC()).getItemStack(), false))
.getAttribute(attribute.fulfill(1));
else
return new Element(count(null, false))
Expand All @@ -1494,8 +1497,10 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("stacks"))
if (attribute.hasContext(1) && dItem.matches(attribute.getContext(1)))
return new Element(count
(dItem.valueOf(attribute.getContext(1), attribute.getScriptEntry().getPlayer(), attribute.getScriptEntry().getNPC()).getItemStack(), true))
return new Element(count // TODO: Handle no-script-entry cases
(dItem.valueOf(attribute.getContext(1),
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC()).getItemStack(), true))
.getAttribute(attribute.fulfill(1));
else
return new Element(count(null, true))
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/aufdemrand/denizen/objects/dScript.java
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
Expand Down Expand Up @@ -292,13 +293,13 @@ public String getAttribute(Attribute attribute) {
if (obj instanceof List) {
dList list = new dList();
for (Object each : (List<Object>) obj)
list.add(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), each.toString(), false, attribute.getScriptEntry()));
list.add(TagManager.tag(attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(), each.toString(), false, attribute.getScriptEntry()));
return list.getAttribute(attribute.fulfill(1));

}
else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), obj.toString(), false, attribute.getScriptEntry()))
else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(), obj.toString(), false, attribute.getScriptEntry()))
.getAttribute(attribute.fulfill(1));
}

Expand Down Expand Up @@ -326,13 +327,13 @@ else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null
if (obj instanceof List) {
dList list = new dList();
for (Object each : (List<Object>) obj)
list.add(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), each.toString(), false, attribute.getScriptEntry()));
list.add(TagManager.tag(attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(), each.toString(), false, attribute.getScriptEntry()));
return list.getAttribute(attribute.fulfill(1));

}
else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getPlayer(),
attribute.getScriptEntry() == null ? null: attribute.getScriptEntry().getNPC(), obj.toString(), false, attribute.getScriptEntry()))
else return new Element(TagManager.tag(attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer(),
attribute.getScriptEntry() == null ? null: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(), obj.toString(), false, attribute.getScriptEntry()))
.getAttribute(attribute.fulfill(1));
}

Expand Down
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.objects.properties.bukkit;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.scripts.commands.core.CooldownCommand;
Expand Down Expand Up @@ -40,7 +41,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("cooled_down")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid())
return new Element(CooldownCommand.checkCooldown(player, script.getContainer().getName()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -56,10 +57,10 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("requirements.check")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
if (attribute.hasContext(2))
return new Element(((InteractScriptContainer)script.getContainer()).checkRequirements(player,
attribute.getScriptEntry().getNPC(),
((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getNPC(),
attribute.getContext(2)))
.getAttribute(attribute.fulfill(2));
}
Expand All @@ -72,7 +73,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("cooldown")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());
return CooldownCommand.getCooldownDuration(player, script.getName())
.getAttribute(attribute.fulfill(1));

Expand All @@ -88,7 +89,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("step")) {
dPlayer player = (attribute.hasContext(1) ? dPlayer.valueOf(attribute.getContext(1))
: attribute.getScriptEntry().getPlayer());
: ((BukkitScriptEntryData)attribute.getScriptEntry().entryData).getPlayer());

if (player != null && player.isValid())
return new Element(InteractScriptHelper.getCurrentStep(player, script.getContainer().getName()))
Expand Down
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.List;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
Expand Down Expand Up @@ -64,7 +65,9 @@ public static List<ScriptEntry> buildScriptEntries(List<String> contents, Script
String[] args = aH.buildArgs(scriptEntry[1]);
if (dB.showScriptBuilder)
dB.echoDebug(parent, "Adding '" + scriptEntry[0] + "' Args: " + Arrays.toString(args));
ScriptEntry newEntry = new ScriptEntry(scriptEntry[0], args, parent).setPlayer(player).setNPC(npc);
ScriptEntry newEntry = new ScriptEntry(scriptEntry[0], args, parent);
((BukkitScriptEntryData)newEntry.entryData).setPlayer(player);
((BukkitScriptEntryData)newEntry.entryData).setNPC(npc);
scriptCommands.add(newEntry);
} catch (Exception e) {
dB.echoError(e);
Expand Down
81 changes: 4 additions & 77 deletions src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java
Expand Up @@ -2,14 +2,11 @@

import java.util.*;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.exceptions.ScriptEntryCreationException;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.scripts.commands.BracedCommand;
Expand Down Expand Up @@ -87,7 +84,7 @@ public ScriptEntry(String command, String[] arguments, ScriptContainer script) t
if (command == null)
throw new ScriptEntryCreationException("dCommand 'name' cannot be null!");

entryData = new BukkitScriptEntryData(null, null); // TODO: Make version-cross-compatible
entryData = DenizenCore.getImplementation().getEmptyScriptEntryData();

this.command = command.toUpperCase();

Expand Down Expand Up @@ -260,8 +257,7 @@ public void setData(Object result) {
}

public void copyFrom(ScriptEntry entry) {
setPlayer(((BukkitScriptEntryData)entry.entryData).getPlayer());
setNPC(((BukkitScriptEntryData)entry.entryData).getNPC());
entryData = entry.entryData.clone();
setSendingQueue(entry.getResidingQueue());
}

Expand Down Expand Up @@ -293,20 +289,6 @@ public <T extends dObject> T getdObject(String key) {
} catch (Exception e) { return null; }
}

@Deprecated
public <T extends dObject> T getdObjectAs(String key, Class<T> type) {
try {
// If an ENUM, return as an Element
Object gotten = objects.get(key.toLowerCase());
if (gotten instanceof Enum)
return (T) new Element(((Enum) gotten).name());
// Otherwise, just return the stored dObject
return (T) gotten;
// If not a dObject, return null
} catch (Exception e) { return null; }
}


public Element getElement(String key) {
try {
return (Element) objects.get(key.toLowerCase());
Expand All @@ -322,46 +304,6 @@ public boolean hasObject(String key) {
// CORE LINKED OBJECTS
///////

/**
* Gets a dNPC reference to any linked NPC set by the CommandExecuter.
*
* @return the NPC linked to this script entry
*/
@Deprecated
public dNPC getNPC() {
return ((BukkitScriptEntryData)entryData).getNPC();
}

@Deprecated
public boolean hasNPC() {
return ((BukkitScriptEntryData)entryData).hasNPC();
}


@Deprecated
public ScriptEntry setNPC(dNPC dNPC) {
((BukkitScriptEntryData)entryData).setNPC(dNPC);
return this;
}


@Deprecated
public dPlayer getPlayer() {
return ((BukkitScriptEntryData)entryData).getPlayer();
}

@Deprecated
public boolean hasPlayer() {
return ((BukkitScriptEntryData)entryData).hasPlayer();
}

@Deprecated
public ScriptEntry setPlayer(dPlayer player) {
((BukkitScriptEntryData)entryData).setPlayer(player);
return this;
}


public dScript getScript() {
return script;
}
Expand Down Expand Up @@ -415,6 +357,7 @@ public ScriptEntry setFinished(boolean finished) {
// so that IF can inject them into new entries.
// This is ugly, but it will keep from breaking
// previous versions of Denizen.
// TODO: Get rid of this
public List<String> tracked_objects = new ArrayList<String>();
public ScriptEntry trackObject(String key) {
tracked_objects.add(key.toLowerCase());
Expand All @@ -437,20 +380,4 @@ public boolean shouldDebug() throws Exception {
public boolean shouldFilter(String criteria) throws Exception {
return script.getName().equalsIgnoreCase(criteria.replace("s@", ""));
}

public String reportObject(String id) {
// If this script entry doesn't have the object being reported,
// just return nothing.
if (!hasObject(id))
return "";

// If the object is a dObject, there's a method for reporting them
// in the proper format.
if (getObject(id) instanceof dObject)
return getdObject(id).debug();

// If all else fails, fall back on the toString() method with the id of the
// object being passed to aH.report(...)
else return aH.debugObj(id, getObject(id));
}
}

0 comments on commit e0b1454

Please sign in to comment.