Skip to content

Commit

Permalink
Fix potential problem in flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Oct 12, 2013
1 parent 132f3a1 commit 5dc3009
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Duration.java
Expand Up @@ -68,7 +68,7 @@ public class Duration implements dObject {
// <--[language]
// @name d@
// @description
// d@ refers to the object type of a 'Duration'. The 'd@' is notation for Denizen's Object
// d@ refers to the 'object identifier' of a 'Duration'. The 'd@' is notation for Denizen's Object
// Fetcher. Durations must be a positive number or range of numbers followed optionally by
// a unit of time, and prefixed by d@. Examples: d@3s, d@1d, d@10s-20s.
//
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -42,6 +42,7 @@ public class Element implements dObject {

public final static Element TRUE = new Element(Boolean.TRUE);
public final static Element FALSE = new Element(Boolean.FALSE);
public final static Element SERVER = new Element("server");

final static Pattern VALUE_PATTERN =
Pattern.compile("el@val(?:ue)?\\[([^\\[\\]]+)\\].*",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -42,7 +42,7 @@ public static dPlayer mirrorBukkitPlayer(OfflinePlayer player) {
// <--[language]
// @name p@
// @description
// p@ refers to the object type of a dPlayer. The 'p@' is notation for Denizen's Object
// p@ refers to the 'object identifier' of a dPlayer. The 'p@' is notation for Denizen's Object
// Fetcher. The only valid constructor for a dPlayer is the name of the player the object should be
// associated with. For example, to reference the player named 'mythan', use p@mythan. Player names
// are case insensitive.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dScript.java
Expand Up @@ -53,7 +53,7 @@ public class dScript implements dObject {
// <--[language]
// @name s@
// @description
// s@ refers to the object type of a dScript. The 's@' is notation for Denizen's Object
// s@ refers to the 'object identifier' of a dScript. The 's@' is notation for Denizen's Object
// Fetcher. The only valid constructor for a dScript is the name of the script container that it should be
// associated with. For example, if my script container is called 'cool_script', the dScript object for that script
// would be able to be referenced (fetched) with s@cool_script.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dWorld.java
Expand Up @@ -37,7 +37,7 @@ public static dWorld mirrorBukkitWorld(World world) {
// <--[language]
// @name w@
// @description
// w@ refers to the object type of a dWorld. The 'w@' is notation for Denizen's Object
// w@ refers to the 'object identifier' of a dWorld. The 'w@' is notation for Denizen's Object
// Fetcher. The only valid constructor for a dWorld is the name of the world it should be
// associated with. For example, to reference the world named 'world1', use w@world1.
// World names are case insensitive.
Expand Down
Expand Up @@ -21,6 +21,12 @@

public class FlagCommand extends AbstractCommand implements Listener {

// <--[example]
//
//
//
//

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

Expand All @@ -45,40 +51,43 @@ else if (!scriptEntry.hasObject("flag_target")
} else if (!scriptEntry.hasObject("flag_target")
&& arg.matches("global, server")) {
specified_target = true;
scriptEntry.addObject("flag_target", new Element("server"));
scriptEntry.addObject("flag_target", Element.SERVER);

} else if (!scriptEntry.hasObject("flag_target")
&& arg.matches("player")) {
specified_target = true;
scriptEntry.addObject("flag_target", scriptEntry.getPlayer());
}

// Allow a p@player or n@npc entity to specify the target
// to be flagged
// Allow a p@player or n@npc entity to specify the target to be flagged.
// Don't check if the player/npc is valid until after the argument
// is being process to make sure the objects don't accidently get set
// as the name of the flag..
else if (!scriptEntry.hasObject("flag_target")
&& arg.matchesArgumentType(dNPC.class)
&& arg.startsWith("n@")) {
if (dNPC.valueOf(arg.getValue()) == null)
throw new InvalidArgumentsException("Invalid NPC target.");
specified_target = true;
scriptEntry.addObject("flag_target", arg.asType(dNPC.class));

} else if (!scriptEntry.hasObject("flag_target")
&& arg.matchesArgumentType(dPlayer.class)
&& arg.startsWith("p@")) {
if (dPlayer.valueOf(arg.getValue()) == null)
throw new InvalidArgumentsException("Invalid Player target.");
specified_target = true;
scriptEntry.addObject("flag_target", arg.asType(dPlayer.class));
}


// Check if setting a boolean
else if (!scriptEntry.hasObject("action")
&& arg.raw_value.split(":", 3).length == 1) {
else if (arg.raw_value.split(":", 3).length == 1) {
scriptEntry.addObject("action", FlagManager.Action.SET_BOOLEAN);
scriptEntry.addObject("value", Element.TRUE);
scriptEntry.addObject("flag_name", arg.asElement());
}

// Check for flag_name:value/action
else if (!scriptEntry.hasObject("action")
&& arg.raw_value.split(":", 3).length == 2) {
else if (arg.raw_value.split(":", 3).length == 2) {

String[] flagArgs = arg.raw_value.split(":", 2);
scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
Expand Down Expand Up @@ -107,8 +116,7 @@ else if (flagArgs[1].equals("<-")) {
}

// Check for flag_name:action:value
else if (!scriptEntry.hasObject("action")
&& arg.raw_value.split(":", 3).length == 3) {
else if (arg.raw_value.split(":", 3).length == 3) {
String[] flagArgs = arg.raw_value.split(":", 3);
scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
scriptEntry.addObject("value", new Element(flagArgs[2]));
Expand All @@ -135,7 +143,7 @@ else if (flagArgs[1].startsWith("/"))
scriptEntry.addObject("action", FlagManager.Action.DIVIDE);
}

else dB.echoDebug("Unhandled argument: " + arg.raw_value);
else arg.reportUnhandled();
}

// Set defaults
Expand Down

0 comments on commit 5dc3009

Please sign in to comment.