Skip to content

Commit

Permalink
Address Review
Browse files Browse the repository at this point in the history
  • Loading branch information
AyhamAl-Ali committed Aug 2, 2023
1 parent 27c7515 commit d27a853
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,10 @@ public String toVariableNameString(final Inventory i) {
"The first requires that the player is online and also accepts only part of the name, " +
"while the latter doesn't require that the player is online, but the player's name has to be entered exactly.")
.usage("")
.examples("set {_p} to \"Notch\" parsed as a player # returns <none> unless Notch is actually online")
.since("1.0")
.examples(
"set {_p} to \"Notch\" parsed as a player # returns <none> unless Notch is actually online",
"set {_p} to \"N\" parsed as a player # returns Notch if Notch is online because their name starts with 'N' (case insensitive) however, it would return nothing if no player whose name starts with 'N' is online."
).since("1.0")
.defaultExpression(new EventValueExpression<>(Player.class))
.after("string", "world")
.parser(new Parser<Player>() {
Expand All @@ -679,13 +681,15 @@ public Player parse(String string, ParseContext context) {
if (UUID_PATTERN.matcher(string).matches())
return Bukkit.getPlayer(UUID.fromString(string));
String name = string.toLowerCase(Locale.ENGLISH);
int nameLength = name.length();
List<Player> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
String lowerName = player.getName().toLowerCase(Locale.ENGLISH);
if (lowerName.equals(name))
return player;
if (lowerName.startsWith(name))
if (lowerName.startsWith(name)) {
if (lowerName.length() == nameLength)
return player;
players.add(player);
}
}
if (players.size() == 1)
return players.get(0);
Expand Down

0 comments on commit d27a853

Please sign in to comment.