Skip to content

Commit

Permalink
improve core events setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 18, 2019
1 parent 1357563 commit 37c7932
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
18 changes: 18 additions & 0 deletions src/main/java/net/aufdemrand/denizencore/events/ScriptEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ public static class ScriptPath {
public String[] eventArgs;
public String[] eventArgsLower;

public String eventArgAt(int index) {
return index < eventArgs.length ? eventArgs[index] : "";
}

public String eventArgLowerAt(int index) {
return index < eventArgsLower.length ? eventArgsLower[index] : "";
}

public boolean checkSwitch(String key, String value) {
String pathValue = switches.get(key);
if (pathValue == null) {
return false;
}
return CoreUtilities.toLowerCase(pathValue).equals(value);
}

public ScriptPath(ScriptContainer container, String event) {
this.container = container;
this.event = event;
Expand Down Expand Up @@ -199,6 +215,7 @@ public void init() {
public void destroy() {
}

@Deprecated
public static boolean checkSwitch(String event, String switcher, String value) {
for (String possible : CoreUtilities.split(event, ' ')) {
List<String> split = CoreUtilities.split(possible, ':', 2);
Expand All @@ -209,6 +226,7 @@ public static boolean checkSwitch(String event, String switcher, String value) {
return true;
}

@Deprecated
public static String getSwitch(String event, String switcher) {
for (String possible : CoreUtilities.split(event, ' ')) {
List<String> split = CoreUtilities.split(possible, ':', 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public boolean couldMatch(ScriptContainer script, String event) {
return event.startsWith("delta time");
}

public boolean matches(ScriptContainer script, String event) {
String time = CoreUtilities.getXthArg(2, event);
public boolean matches(ScriptPath path) {
String time = path.eventArgLowerAt(2);
long seconds = DenizenCore.serverTimeMillis / 1000;
return time.equals("secondly") || (seconds % 60 == 0 && time.equals("minutely")) || (seconds % 3600 == 0 && time.equals("hourly"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public boolean couldMatch(ScriptContainer script, String event) {
}

@Override
public boolean matches(ScriptContainer script, String event) {
return checkSwitch(event, "haderror", hadError ? "true" : "false")
&& checkSwitch(event, "sender", sender.equalsIgnoreCase("console") ? "server" : "player")
&& checkSwitch(event, "all", all ? "true" : "false");
public boolean matches(ScriptPath path) {
return path.checkSwitch("haderror", hadError ? "true" : "false")
&& path.checkSwitch("sender", sender.equalsIgnoreCase("console") ? "server" : "player")
&& path.checkSwitch("all", all ? "true" : "false");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public ScriptEntryData getScriptEntryData() {
}

@Override
public boolean matches(ScriptContainer script, String event) {
String time = CoreUtilities.getXthArg(2, event);
public boolean matches(ScriptPath path) {
String time = path.eventArgLowerAt(2);
return time.equals("minutely") || time.equals(hour.asString() + ":" + minute.asString()) || (minute.asString().equals("00") && time.equals("hourly"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {
}

@Override
public boolean matches(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
return lower.endsWith("example")
&& checkSwitch(s, "example", "value");
public boolean matches(ScriptPath path) {
return path.eventLower.startsWith("template example")
&& path.checkSwitch("example", "value");
}

@Override
Expand All @@ -55,7 +54,7 @@ public void destroy() {
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
// Apply an input determination here.
// Return true if sucessful, false if there was an error.
// Return true if successful, false if there was an error.
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("example:")) {
objectOne = new Element(determination.substring(2));
Expand Down

0 comments on commit 37c7932

Please sign in to comment.