Skip to content

Commit

Permalink
Major core rewrite - efficiency and cleverness boost all over
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 25, 2018
1 parent f7179f7 commit 028f7d3
Show file tree
Hide file tree
Showing 46 changed files with 2,749 additions and 1,632 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ public interface DenizenImplementation {
*/
public abstract List<YamlConfiguration> getOutsideScripts();

public abstract void handleCommandSpecialCases(ScriptEntry entry);

public abstract void debugCommandHeader(ScriptEntry entry);

public abstract TagContext getTagContextFor(ScriptEntry entry, boolean instant);
Expand Down Expand Up @@ -146,4 +144,12 @@ public interface DenizenImplementation {
public abstract boolean allowedToWebget();

public abstract void preTagExecute();

public abstract boolean needsHandleArgPrefix(String prefix);

public abstract boolean shouldDebug(Debuggable debug);

public abstract void debugQueueExecute(ScriptEntry entry, String queue, String execute);

public abstract void debugTagFill(ScriptEntry entry, String tag, String result);
}
55 changes: 40 additions & 15 deletions src/main/java/net/aufdemrand/denizencore/events/ScriptEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.aufdemrand.denizencore.scripts.ScriptBuilder;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.ScriptEntrySet;
import net.aufdemrand.denizencore.scripts.commands.core.DetermineCommand;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
Expand Down Expand Up @@ -53,6 +54,7 @@ public static class ScriptPath {
ScriptContainer container;
String event;
int priority = 0;
ScriptEntrySet set;

public ScriptPath(ScriptContainer container, String event) {
this.container = container;
Expand Down Expand Up @@ -198,20 +200,31 @@ public static String getSwitch(String event, String switcher) {
return null;
}

public boolean applyDetermination(ScriptContainer container, dObject determination) {
return applyDetermination(container, determination.identify());
}

public boolean applyDetermination(ScriptContainer container, String determination) {
if (determination.equalsIgnoreCase("cancelled")) {
String low = CoreUtilities.toLowerCase(determination);
if (low.equals("cancelled")) {
dB.echoDebug(container, "Event cancelled!");
cancelled = true;
return true;
}
else if (low.equals("cancelled:true")) {
dB.echoDebug(container, "Event cancelled!");
cancelled = true;
return true;
}
else if (determination.equalsIgnoreCase("cancelled:false")) {
else if (low.equals("cancelled:false")) {
dB.echoDebug(container, "Event uncancelled!");
cancelled = false;
return true;
}
else {
dB.echoError("Unknown determination '" + determination + "'");
return false;
}
return true;
}

public HashMap<String, dObject> getContext() { // TODO: Delete
Expand All @@ -234,10 +247,14 @@ public void reset() {

public void fire() {
fires++;
ScriptEvent dupd = null;
for (ScriptPath path : eventPaths) {
try {
if (matchesScript(this, path.container, path.event)) {
run(path.container, path.event);
if (dupd == null) {
dupd = clone();
}
dupd.run(path.container, path.event);
}
}
catch (Exception e) {
Expand All @@ -250,19 +267,27 @@ public void fire() {
private String currentEvent;

public void run(ScriptContainer script, String event) throws CloneNotSupportedException {
}

public void run(ScriptPath path) {
scriptFires++;
HashMap<String, dObject> context = getContext();
dB.echoDebug(script, "<Y>Running script event '<A>" + getName() + "<Y>', event='<A>" + event + "<Y>'"
+ " for script '<A>" + script.getName() + "<Y>'");
for (Map.Entry<String, dObject> obj : context.entrySet()) {
dB.echoDebug(script, "<Y>Context '<A>" + obj.getKey() + "<Y>' = '<A>" + obj.getValue().identify() + "<Y>'");
if (path.container.shouldDebug()) {
dB.echoDebug(path.container, "<Y>Running script event '<A>" + getName() + "<Y>', event='<A>" + path.event + "<Y>'"
+ " for script '<A>" + path.container.getName() + "<Y>'");
for (Map.Entry<String, dObject> obj : context.entrySet()) {
dB.echoDebug(path.container, "<Y>Context '<A>" + obj.getKey() + "<Y>' = '<A>" + obj.getValue().identify() + "<Y>'");
}
}
if (path.set == null) {
path.set = path.container.getSetFor("events.on " + path.event);
}
List<ScriptEntry> entries = script.getEntries(getScriptEntryData(), "events.on " + event);
List<ScriptEntry> entries = ScriptContainer.cleanDup(getScriptEntryData(), path.set);
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getName())).addEntries(entries).setReqId(id);
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(path.container.getName())).addEntries(entries).setReqId(id);
HashMap<String, dObject> oldStyleContext = getContext();
currentEvent = event;
currentEvent = path.event;
if (oldStyleContext.size() > 0) {
OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
oecs.contexts = oldStyleContext;
Expand All @@ -271,14 +296,14 @@ public void run(ScriptContainer script, String event) throws CloneNotSupportedEx
queue.setContextSource(oecs);
}
else {
queue.setContextSource(this.clone());
queue.setContextSource(this);
}
queue.start();
nanoTimes += System.nanoTime() - queue.startTime;
List<String> determinations = DetermineCommand.getOutcome(id);
List<dObject> determinations = DetermineCommand.getOutcome(id).objectForms;
if (determinations != null) {
for (String determination : determinations) {
applyDetermination(script, determination);
for (dObject determination : determinations) {
applyDetermination(path.container, determination);
}
}
}
Expand Down
63 changes: 46 additions & 17 deletions src/main/java/net/aufdemrand/denizencore/objects/CustomObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.debugging.dB;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

public class CustomObject implements dObject, Adjustable {
public class CustomObject implements dObject, dObject.ObjectAttributable, Adjustable {

@Fetchable("custom")
public static CustomObject valueOf(String string, TagContext context) {
Expand Down Expand Up @@ -47,14 +46,18 @@ public static CustomObject valueOf(String string, TagContext context) {
return new CustomObject((CustomScriptContainer) sc, ((CustomScriptContainer) sc).getVars());
}

public static CustomObject getFor(dObject obj, TagContext context) {
return obj instanceof CustomObject ? (CustomObject) obj : valueOf(obj.toString(), context);
}

public static boolean matches(String string) {
return string.startsWith("custom@");
}

public CustomScriptContainer container;
public Map<String, String> vars;
public Map<String, dObject> vars;

public CustomObject(CustomScriptContainer type, Map<String, String> values) {
public CustomObject(CustomScriptContainer type, Map<String, dObject> values) {
container = type;
vars = values;
}
Expand All @@ -69,8 +72,8 @@ public String getObjectType() {
@Override
public String identify() {
StringBuilder outp = new StringBuilder();
for (Map.Entry<String, String> var : vars.entrySet()) {
outp.append(var.getKey() + "=" + var.getValue().replace(';', (char) 0x2011) + ";");
for (Map.Entry<String, dObject> var : vars.entrySet()) {
outp.append(var.getKey() + "=" + var.getValue().toString().replace(';', (char) 0x2011) + ";");
}
return "custom@" + container.getName() + "[" + (outp.length() > 0 ? outp.substring(0, outp.length() - 1) : "") + "]";
}
Expand Down Expand Up @@ -108,25 +111,48 @@ public boolean isUnique() {

@Override
public String getAttribute(Attribute attribute) {
return CoreUtilities.stringifyNullPass(getObjectAttribute(attribute));
}

@Override
public <T extends dObject> T asObjectType(Class<T> type, TagContext context) {
return null;
}

@Override
public boolean canPossiblyBeType(Class<? extends dObject> type) {
if (type == CustomObject.class) {
return true;
}
return false;
}


@Override
public dObject getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return "null";
return null;
}

String res = vars.get(attribute.getAttribute(1));
if (attribute.isComplete()) {
return this;
}

dObject res = vars.get(attribute.getAttribute(1));
if (res == null) {
String taggo = attribute.getAttributeWithoutContext(1);
if (container.hasPath("tags." + taggo)) {
long ID = container.runTagScript(taggo, attribute.getContext(1), this,
long ID = container.runTagScript(taggo, attribute.getContextObject(1), this,
attribute.getScriptEntry() != null ? attribute.getScriptEntry().entryData : null);
List<String> outcomes = DetermineCommand.getOutcome(ID);
dList outcomes = DetermineCommand.getOutcome(ID);
if (outcomes == null) {
return null;
}
return ObjectFetcher.pickObjectFor(outcomes.get(0)).getAttribute(attribute.fulfill(1));
return CoreUtilities.autoAttribTyped(outcomes.getObject(0), attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
return new Element(identify()).getObjectAttribute(attribute);
}
return ObjectFetcher.pickObjectFor(res).getAttribute(attribute.fulfill(1));
return CoreUtilities.autoAttribTyped(res, attribute.fulfill(1));
}

@Override
Expand All @@ -137,19 +163,22 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {
String name = CoreUtilities.toLowerCase(mechanism.getName());
String value = mechanism.getValue().asString();
if (!mechanism.hasValue()) {
vars.remove(name);
return;
}
dObject value = mechanism.getValue();
if (container.hasPath("mechanisms." + name)) {
long ID = container.runMechScript(name, this, value);
List<String> outcomes = DetermineCommand.getOutcome(ID);
dList outcomes = DetermineCommand.getOutcome(ID);
if (outcomes == null) {
return;
}
CustomObject co = CustomObject.valueOf(outcomes.get(0), null);
CustomObject co = CustomObject.getFor(outcomes.getObject(0), null);
container = co.container;
vars = co.vars;
}
else {
vars.remove(name);
vars.put(name, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public String getAttribute(Attribute attribute) {
}

// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
for (Property property : PropertyParser.getProperties(this, attrLow)) {
String returned = property.getAttribute(attribute);
if (returned != null) {
return returned;
Expand Down
Loading

0 comments on commit 028f7d3

Please sign in to comment.