Skip to content

Commit

Permalink
Add .has_flag[flag_name] attributes to Server, dPlayer, dNPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Oct 31, 2013
1 parent 471e79b commit d8bdd03
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -381,6 +381,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdName, Stri

// <--[language]
// @name /ex command
// @group Console Commands
// @description
// The '/ex' command is an easy way to run a single denizen script command in-game. Its syntax,
// aside from '/ex' is exactly the same as any other command. When running a command, some context
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -364,6 +364,19 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <n@npc.has_flag[flag_name]>
// @returns Element(boolean)
// @description
// returns true if the NPC has the specified flag, otherwise returns false.
// -->
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
return new Element(FlagManager.npcHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <npc.flag[flag_name]>
// @returns Flag dList
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -211,9 +211,9 @@ public String getAttribute(Attribute attribute) {

if (player_name == null) return "null";

/////////////////////
// OFFLINE ATTRIBUTES
/////////////////
/////////////////////
// OFFLINE ATTRIBUTES
/////////////////

/////////////////////
// DEBUG ATTRIBUTES
Expand Down Expand Up @@ -320,6 +320,19 @@ else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1)
else return "null";
}

// <--[tag]
// @attribute <p@player.has_flag[flag_name]>
// @returns Element(boolean)
// @description
// returns true if the Player has the specified flag, otherwise returns false.
// -->
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
return new Element(FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}


/////////////////////
// ECONOMY ATTRIBUTES
Expand Down Expand Up @@ -537,9 +550,9 @@ else if (attribute.startsWith("list.offline")) {
.getAttribute(attribute.fulfill(1));


/////////////////////
// ONLINE ATTRIBUTES
/////////////////
/////////////////////
// ONLINE ATTRIBUTES
/////////////////

// Player is required to be online after this point...
if (!isOnline()) return new Element(identify()).getAttribute(attribute);
Expand All @@ -559,7 +572,7 @@ else if (attribute.startsWith("list.offline")) {
if (attribute.startsWith("selected_npc")) {
if (getPlayerEntity().hasMetadata("selected"))
return getSelectedNPC()
.getAttribute(attribute.fulfill(1));
.getAttribute(attribute.fulfill(1));
else return "null";
}

Expand Down Expand Up @@ -591,7 +604,7 @@ else if (attribute.startsWith("list.offline")) {
// returns the player's IP address.
// -->
if (attribute.startsWith("ip") ||
attribute.startsWith("host_name"))
attribute.startsWith("host_name"))
return new Element(getPlayerEntity().getAddress().getHostName())
.getAttribute(attribute.fulfill(1));

Expand Down Expand Up @@ -732,7 +745,7 @@ else if (attribute.getAttribute(2).startsWith("world"))
return new Element(Depends.permissions.playerInGroup((World) null, player_name, group))
.getAttribute(attribute.fulfill(2));

// Permission in certain world
// Permission in certain world
else if (attribute.getAttribute(2).startsWith("world"))
return new Element(Depends.permissions.playerInGroup(attribute.getContext(2), player_name, group))
.getAttribute(attribute.fulfill(2));
Expand Down
Expand Up @@ -53,7 +53,7 @@ public <T extends RegistrationableInstance> T get(Class<T> clazz) {

// <--[language]
// @Name Command Syntax
// @group Getting Started
// @group Script Command System
// @Description
// Almost every Denizen command and requirement has arguments after the command itself.
// These arguments are just snippets of text showing what exactly the command should do,
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Expand Up @@ -121,6 +121,22 @@ public void serverTags(ReplaceableTagEvent event) {
Attribute attribute =
new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

// <--[tag]
// @attribute <server.has_flag[flag_name]>
// @returns Element(boolean)
// @description
// returns true if the Player has the specified flag, otherwise returns false.
// -->
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else {
event.setReplaced("null");
return;
}
event.setReplaced(new Element(FlagManager.serverHasFlag(flag_name)).getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.flag[<name>]>
// @returns Flag dList
Expand Down Expand Up @@ -211,12 +227,13 @@ else if (player.getName().contains(matchInput) && matchPlayer == null) {
matchPlayer = player;
}
}

if (matchPlayer == null) {
event.setReplaced("null");
}
else {
} else {
event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
}

return;
}

Expand Down

0 comments on commit d8bdd03

Please sign in to comment.