Skip to content

Commit

Permalink
if command operators redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 15, 2021
1 parent f0e9b5b commit 5c472c5
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 405 deletions.
Expand Up @@ -133,8 +133,6 @@ public interface DenizenImplementation {

String cleanseLogString(String str);

boolean matchesType(String comparable, String comparedTo);

boolean allowedToWebget();

void preTagExecute();
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizencore.scripts.commands.Comparable;
import com.denizenscript.denizencore.tags.*;
import com.denizenscript.denizencore.utilities.AsciiMatcher;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -396,75 +395,6 @@ public static void registerTags() {
// CONVERSION ATTRIBUTES
/////////////////

registerTag("is", (attribute, object) -> {
// <--[tag]
// @attribute <ElementTag.is[<operator>].to[<element>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Takes an operator, and compares the value of the element to the supplied
// element. Returns the outcome of the comparable, either true or false. For
// information on operators, see <@link language operator>.
// Equivalent to <@link tag ElementTag.is[<operator>].than[<element>]>
// -->

// <--[tag]
// @attribute <ElementTag.is[<operator>].than[<element>]>
// @returns ElementTag(Boolean)
// @group comparison
// @description
// Takes an operator, and compares the value of the element to the supplied
// element. Returns the outcome of the comparable, either true or false. For
// information on operators, see <@link language operator>.
// Equivalent to <@link tag ElementTag.is[<operator>].to[<element>]>
// -->
if (attribute.hasContext(1) && (attribute.startsWith("to", 2) || attribute.startsWith("than", 2)) && attribute.hasContext(2)) {

// Use the Comparable object as implemented for the IF command. First, a new Comparable!
Comparable com = new Comparable();
com.context = attribute.context;

// Check for negative logic
String operator;
if (attribute.getContext(1).startsWith("!")) {
operator = attribute.getContext(1).substring(1);
com.setNegativeLogic();
}
else {
operator = attribute.getContext(1);
}

// Operator is the value of the .is[] context. Valid are Comparable.Operators, same
// as used by the IF command.
Comparable.Operator comparableOperator = null;
try {
comparableOperator = Comparable.Operator.valueOf(operator.replace("==", "EQUALS")
.replace(">=", "OR_MORE").replace("<=", "OR_LESS").replace("<", "LESS")
.replace(">", "MORE").replace("=", "EQUALS").toUpperCase());
}
catch (IllegalArgumentException e) {
}

if (comparableOperator != null) {
com.setOperator(comparableOperator);

// Comparable is the value of this element
com.setComparable(object.toString());
// Compared_to is the value of the .to[] context.
com.setComparedto(attribute.getContext(2));

attribute.fulfill(1);

return new ElementTag(com.determineOutcome());
}
else {
attribute.echoError("Unknown operator '" + operator + "'.");
}
}

return null;
});

// <--[tag]
// @attribute <ElementTag.equals[<element>]>
// @returns ElementTag(Boolean)
Expand Down
Expand Up @@ -72,7 +72,7 @@ public static void debugSingleExecution(ScriptEntry scriptEntry) {
// The most useful place to have this is a 'stop' command, to quickly stop a script if a condition is true (a player has a flag, lacks a permission, is outside a region, or whatever else).
//
// If you need more complex matching, especially using '&&', '||', '==', etc. you should probably just do an 'if' command rather than using the argument.
// Though if you really want to, you can use tags here like <@link tag elementtag.is.to> or <@link tag elementtag.and> or <@link tag elementtag.or>.
// Though if you really want to, you can use tags here like <@link tag objecttag.is.to> or <@link tag elementtag.and> or <@link tag elementtag.or>.
// -->

public boolean execute(ScriptEntry scriptEntry) {
Expand Down

0 comments on commit 5c472c5

Please sign in to comment.