Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
344 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 96 additions & 8 deletions
104
src/main/java/net/aufdemrand/denizen/objects/Mechanism.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,115 @@ | ||
package net.aufdemrand.denizen.objects; | ||
|
||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
|
||
public class Mechanism { | ||
|
||
boolean fulfilled; | ||
String raw_mechanism; | ||
String outcome = null; | ||
private boolean fulfilled; | ||
private String raw_mechanism; | ||
private Element value; | ||
private String outcome = null; | ||
|
||
public Mechanism(String string) { | ||
public Mechanism(Element mechanism, Element value) { | ||
fulfilled = false; | ||
raw_mechanism = string; | ||
raw_mechanism = mechanism.asString(); | ||
this.value = value; | ||
} | ||
|
||
public void fulfill(String _outcome) { | ||
fulfilled = true; | ||
outcome = _outcome; | ||
outcome = _outcome; // TODO: Return outcome somewhere? | ||
} | ||
|
||
public boolean fulfilled() { | ||
return fulfilled; | ||
} | ||
|
||
public Element getValue() { | ||
return value; | ||
} | ||
|
||
public boolean matches(String string) { | ||
return (string.equalsIgnoreCase(raw_mechanism)); | ||
} | ||
|
||
public boolean fulfilled() { | ||
return fulfilled; | ||
public boolean requireBoolean() { | ||
return requireBoolean("Invalid boolean. Must specify TRUE or FALSE."); | ||
} | ||
|
||
public boolean requireDouble() { | ||
return requireDouble("Invalid double specified."); | ||
} | ||
|
||
public boolean requireEnum(boolean allowInt, Enum<?>... values) { | ||
return requireEnum("Invalid " + values[0].getDeclaringClass().getName() + "." | ||
+ " Must specify valid name" + (allowInt ? " or number" : "") + ".", allowInt, values); | ||
} | ||
|
||
public boolean requireFloat() { | ||
return requireFloat("Invalid float specified."); | ||
} | ||
|
||
public boolean requireInteger() { | ||
return requireInteger("Invalid integer specified."); | ||
} | ||
|
||
public <T extends dObject> boolean requireObject(Class<T> type) { | ||
return requireObject("Invalid " + type.getName() + " specified.", type); | ||
} | ||
|
||
public boolean requireBoolean(String error) { | ||
fulfill(""); | ||
if (value.isBoolean()) | ||
return true; | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
public boolean requireDouble(String error) { | ||
fulfill(""); | ||
if (value.isDouble()) | ||
return true; | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
public boolean requireEnum(String error, boolean allowInt, Enum<?>... values) { | ||
fulfill(""); | ||
if (allowInt && value.isInt() && value.asInt() < values.length) | ||
return true; | ||
if (value.isString()) { | ||
String raw_value = value.asString().toUpperCase(); | ||
for (Enum<?> check_value : values) { | ||
if (raw_value.equals(check_value.name())) | ||
return true; | ||
} | ||
} | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
public boolean requireFloat(String error) { | ||
fulfill(""); | ||
if (value.isFloat()) | ||
return true; | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
public boolean requireInteger(String error) { | ||
fulfill(""); | ||
if (value.isInt()) | ||
return true; | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
public <T extends dObject> boolean requireObject(String error, Class<T> type) { | ||
fulfill(""); | ||
if (value.matchesType(type)) | ||
return true; | ||
dB.echoError(error); | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.