Skip to content

Commit

Permalink
Add server.match_offline_player
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 21, 2015
1 parent ddc2e2f commit 203702a
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main/java/net/aufdemrand/denizen/tags/core/ServerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,35 @@ else if (player.getName().toLowerCase().contains(matchInput) && matchPlayer == n
}
}

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

return;
}

// <--[tag]
// @attribute <server.match_offline_player[<name>]>
// @returns dPlayer
// @description
// Returns any player (online or offline) 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("match_offline_player") && attribute.hasContext(1)) {
UUID matchPlayer = null;
String matchInput = attribute.getContext(1).toLowerCase();
for (Map.Entry<String, UUID> entry: dPlayer.getAllPlayers().entrySet()) {
if (entry.getKey().toLowerCase().equals(matchInput)) {
matchPlayer = entry.getValue();
break;
}
else if (entry.getKey().toLowerCase().contains(matchInput) && matchPlayer == null) {
matchPlayer = entry.getValue();
}
}

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

Expand Down

0 comments on commit 203702a

Please sign in to comment.