Skip to content

Commit

Permalink
add server.get_player
Browse files Browse the repository at this point in the history
Can't test too closely due to lack of test subjects will similar names.
  • Loading branch information
mcmonkey4eva committed Oct 26, 2013
1 parent ce93141 commit cf0c7e1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Expand Up @@ -191,6 +191,35 @@ public void serverTags(ReplaceableTagEvent event) {
return;
}

// <--[tag]
// @attribute <server.get_player[<name>]>
// @returns dPlayer
// @description
// Returns the online player that best matches the input name.
// (EG, in a group of 'bo', 'bob', and 'bobby'... input 'bob' returns p@bob,
// input 'bobb' returns p@bobby, and input 'b' returns p@bo.)
// -->
if (attribute.startsWith("get_player") && attribute.hasContext(1)) {
Player matchPlayer = null;
String matchInput = attribute.getContext(1).toLowerCase();
for (Player player: Bukkit.getOnlinePlayers()) {
if (player.getName().toLowerCase().equals(matchInput)) {
matchPlayer = player;
break;
}
else if (player.getName().contains(matchInput) && matchPlayer == null) {
matchPlayer = player;
}
}
if (matchPlayer == null) {
event.setReplaced("null");
}
else {
event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
}
return;
}

// <--[tag]
// @attribute <server.list_npcs>
// @returns dList(dNPC)
Expand Down

0 comments on commit cf0c7e1

Please sign in to comment.