Skip to content

Commit

Permalink
Finish mending the Great Schism of 2013. Pope Francis, ask Auf for my…
Browse files Browse the repository at this point in the history
… number if you need my expertise with the Great Schism of 1054 next.
  • Loading branch information
davidcernat committed Jun 26, 2013
1 parent 46d739e commit 1562e84
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>net.aufdemrand</groupId>
<artifactId>denizen</artifactId>
<packaging>jar</packaging>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
<name>Denizen</name>
<description>Scriptable NPCs for Citizens2</description>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/aH.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ public static boolean matchesValueArg(String names, String string_arg, ArgumentT

case String:
return true;

case Custom:
return true;

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public String getAttribute(Attribute attribute) {
return new Element(Depends.economy.currencyNameSingular())
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("money.currency_plural"))
if (attribute.startsWith("money.currency"))
return new Element(Depends.economy.currencyNamePlural())
.getAttribute(attribute.fulfill(2));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.aufdemrand.denizen.scripts.commands.core;

import java.lang.*;
import java.util.*;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
Expand All @@ -14,7 +13,7 @@
import org.bukkit.ChatColor;

/**
* Core dScript IF command.
* Core dScript If command.
*
* @author Jeremy Schroeder, David Cernat
*/
Expand All @@ -30,28 +29,29 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
comparables.add(new Comparable());

// Indicate that comparables are building
boolean building_comparables = true;
boolean buildingComparables = true;

// What to do depending on the logic of the comparables
// is stored in two strings
TreeMap<Integer, ArrayList<String>> then_outcome = new TreeMap<Integer, ArrayList<String>>();
TreeMap<Integer, ArrayList<String>> else_outcome = new TreeMap<Integer, ArrayList<String>>();
// Need this for building the outcomes
boolean then_used = false;
// is stored in two tree maps
TreeMap<Integer, ArrayList<String>> thenOutcome = new TreeMap<Integer, ArrayList<String>>();
TreeMap<Integer, ArrayList<String>> elseOutcome = new TreeMap<Integer, ArrayList<String>>();

// Keep tracking of whether we're inside the Else part of the statement or not
boolean insideElse = false;

// Keep track of this to avoid Denizen overlooking comparedTo when an operator is used
// with a value that matches the name of a command. (Good find dimensionZ!)
boolean used_operator = false;
boolean usedOperator = false;

// Track whether we are adding a new command or not
boolean newCommand = false;

// Track whether we are inside recursive brackets whose contents
// Track whether we are inside nested brackets whose contents
// should be added as arguments to our current If, not as commands
int bracketsEntered = 0;

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (building_comparables) {
if (buildingComparables) {

// Set logic to NEGATIVE
if (arg.startsWith("!")) {
Expand All @@ -77,7 +77,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
else if (arg.matchesEnum(Comparable.Operator.values())) {
comparables.get(comparables.size() - 1).operator =
Comparable.Operator.valueOf(arg.getValue().toUpperCase());
used_operator = true;
usedOperator = true;
}

// Set comparable
Expand All @@ -86,24 +86,25 @@ else if (comparables.get(comparables.size() - 1).comparable == null) {
comparables.get(comparables.size() - 1).setComparable(arg.getValue());
}

else if (!used_operator && arg.matches("{"))
building_comparables = false;
else if (!usedOperator && arg.matches("{")) {
buildingComparables = false;
}

// Check if filling comparables are done by checking the command registry for valid commands.
// If using an operator though, skip on to compared-to!
else if (!used_operator && denizen.getCommandRegistry()
else if (!usedOperator && denizen.getCommandRegistry()
.get(arg.getValue().replace("^", "")) != null) {
building_comparables = false;
buildingComparables = false;
}

// Set compared-to
else {
comparables.get(comparables.size() - 1).setComparedto(arg.getValue());
used_operator = false;
usedOperator = false;
}
}

if (!building_comparables) {
if (!buildingComparables) {

// Read "-" as meaning we are moving to a new command, unless we
// are inside nested brackets (i.e. bracketsEntered of at least 2)
Expand All @@ -112,85 +113,97 @@ else if (!used_operator && denizen.getCommandRegistry()
newCommand = true;
}

else if (arg.matches("else")) then_used = true;

else if (!then_used) {
if (arg.matches("{")) {
else if (!insideElse) {

// Move to else commands if we read an "else" and we're not
// currently going through nested arguments
if (arg.matches("else") && bracketsEntered == 0) {
insideElse = true;
}

// If we find a bracket, and we're already inside
// nested brackets, add the bracket to the current
// command's arguments
else if (arg.matches("{")) {
bracketsEntered++;
if (bracketsEntered > 1)
then_outcome.get(then_outcome.lastKey()).add(arg.getValue());

if (bracketsEntered > 1) {
thenOutcome.get(thenOutcome.lastKey()).add(arg.getValue());
}
}

else if (arg.matches("}")) {
bracketsEntered--;
if (bracketsEntered > 0)
then_outcome.get(then_outcome.lastKey()).add(arg.getValue());
}

else if (then_outcome.size() == 0) {
then_outcome.put(then_outcome.size(), new ArrayList<String>());
then_outcome.get(then_outcome.lastKey()).add(arg.getValue());
newCommand = false;
if (bracketsEntered > 0) {
thenOutcome.get(thenOutcome.lastKey()).add(arg.getValue());
}
}

else if (newCommand == true) {
// Add new outcome command if the last argument was a non-nested "-"
// or if there are no outcome commands yet
else if (newCommand == true || thenOutcome.size() == 0) {
thenOutcome.put(thenOutcome.size(), new ArrayList<String>());
thenOutcome.get(thenOutcome.lastKey()).add(arg.getValue());
newCommand = false;
then_outcome.put(then_outcome.size(), new ArrayList<String>());
then_outcome.get(then_outcome.lastKey()).add(arg.getValue());
}

// Add new outcome argument
else {
then_outcome.get(then_outcome.lastKey()).add(arg.getValue());
thenOutcome.get(thenOutcome.lastKey()).add(arg.getValue());
}
}

else if (then_used) {
else if (insideElse) {

// If we find a bracket, and we're already inside
// nested brackets, add the bracket to the current
// command's arguments
if (arg.matches("{")) {
bracketsEntered++;

if (bracketsEntered > 1) {
else_outcome.get(else_outcome.lastKey()).add(arg.getValue());
elseOutcome.get(elseOutcome.lastKey()).add(arg.getValue());
}
}

else if (arg.matches("}")) {
bracketsEntered--;

if (bracketsEntered > 0) {
else_outcome.get(else_outcome.lastKey()).add(arg.getValue());
elseOutcome.get(elseOutcome.lastKey()).add(arg.getValue());
}
}

// Add new else command if the last argument was a non-nested "-"
// or if it was "else" and we have no else commands yet
else if (newCommand == true || else_outcome.size() == 0) {
else if (newCommand == true || elseOutcome.size() == 0) {
newCommand = false;
else_outcome.put(else_outcome.size(), new ArrayList<String>());
else_outcome.get(else_outcome.lastKey()).add(arg.getValue());
elseOutcome.put(elseOutcome.size(), new ArrayList<String>());
elseOutcome.get(elseOutcome.lastKey()).add(arg.getValue());

// Important!
//
// If we find an "if", act like we entered a set of
// brackets, so we treat the if's commands as arguments
// and don't add them to our current else commands
// if (arg.matches("if")) {
// bracketsEntered++;
// }
if (arg.matches("if")) {
bracketsEntered++;
}
}

// Add new else argument
else {
else_outcome.get(else_outcome.lastKey()).add(arg.getValue());
elseOutcome.get(elseOutcome.lastKey()).add(arg.getValue());
}
}
}
}

// Stash objects required to execute() into the ScriptEntry
scriptEntry.addObject("comparables", comparables)
.addObject("then-outcome", then_outcome)
.addObject("else-outcome", else_outcome);
.addObject("then-outcome", thenOutcome)
.addObject("else-outcome", elseOutcome);
}


Expand Down Expand Up @@ -251,11 +264,11 @@ else if (andcount == andmet && comparables.get(0).outcome == true)
}


private void doCommand(ScriptEntry scriptEntry, String map) {
private void doCommand(ScriptEntry scriptEntry, String mapName) {
TreeMap<Integer, ArrayList<String>> commandMap =
(TreeMap<Integer, ArrayList<String>>) scriptEntry.getObject(map);
(TreeMap<Integer, ArrayList<String>>) scriptEntry.getObject(mapName);

if (map == null || map.length() == 0) return;
if (commandMap == null || commandMap.size() == 0) return;

List<ScriptEntry> entries = new ArrayList<ScriptEntry>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
player = Bukkit.getServer().getPlayer(aH.getStringFrom("player"));
type = Type.PLAYER;

} else if (aH.matchesValueArg("weather", arg, ArgumentType.Custom)) {
} else if (aH.matchesValueArg("weather", arg, ArgumentType.String)) {
action = Action.WEATHER;
sub = SubAction.valueOf(aH.getStringFrom("weather"));
Bukkit.broadcastMessage("Got inside weather!");
sub = SubAction.valueOf(aH.getStringFrom(arg).toUpperCase());
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for WEATHER!");

} else if (aH.matchesValueArg("time", arg, ArgumentType.Custom)) {
} else if (aH.matchesValueArg("time", arg, ArgumentType.String)) {
action = Action.TIME;
Bukkit.broadcastMessage("Got inside time!");
sub = SubAction.valueOf(aH.getStringFrom(arg).toUpperCase());
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for TIME!");

Expand Down
Loading

0 comments on commit 1562e84

Please sign in to comment.