Skip to content

Commit

Permalink
Fixed players and caseSensitive commands
Browse files Browse the repository at this point in the history
  • Loading branch information
divios committed Feb 18, 2022
1 parent d6fbcd0 commit 1220d44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/main/java/io/github/divios/jcommands/JCommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,23 @@ private ValueMap wrapArgs(JCommand command, String[] args) {
Map<String, Value> valueMap = new LinkedHashMap<>();
List<Argument> arguments = command.getArguments();

String[] validArgs = Arrays.copyOfRange(args, ArrayUtils.indexOf(args, command.getName()) + 1, args.length);
String[] validArgs = Arrays.copyOfRange(args, indexOf(args, command.getName()) + 1, args.length);

for (int i = 0; i < arguments.size(); i++)
valueMap.put(arguments.get(i).getName(), Value.ofString(validArgs[i]));

return ValueMap.of(valueMap);
}

private int indexOf(String[] args, String s) {
int i = 0;
for (String arg : args) {
if (arg.equalsIgnoreCase(s))
return i;
i++;
}

return -1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static boolean getAsBoolean(String s) {

public static boolean isPlayer(String s) {
return Bukkit.getOnlinePlayers().stream()
.anyMatch(player -> ChatColor.stripColor(player.getDisplayName()).equalsIgnoreCase(s));
.anyMatch(player -> player.getName().equalsIgnoreCase(s));
}

public static Player getAsPlayer(String s) {
Expand Down

0 comments on commit 1220d44

Please sign in to comment.