Added permission information to help command (#1427)

Original commits:
* Added command CommandPermissionCommand. Added permission information in HelpCommand.

* Removed command CommandPermissionCommand

* Display permission for single command when use help.

* Display permission targeted when use help.
This commit is contained in:
Someone999
2022-07-04 12:21:41 +08:00
committed by GitHub
parent b92cc6a882
commit fe50a42a3c
4 changed files with 62 additions and 4 deletions

View File

@@ -46,8 +46,24 @@ public final class HelpCommand implements CommandHandler {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
}
else {
builder.append(annotation.permission());
}
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) {
builder.append("\n Warning: You do not have permission to run this command.");
builder.append("\n ");
builder.append(translate(player, "commands.help.warn_player_has_no_permission"));
}
}
@@ -68,6 +84,20 @@ public final class HelpCommand implements CommandHandler {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
}
else {
builder.append(annotation.permission());
}
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
builder.append("\n");
});
@@ -85,6 +115,21 @@ public final class HelpCommand implements CommandHandler {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.no_permission"));
}
else {
builder.append(annotation.permission());
}
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
CommandHandler.sendMessage(player, builder.toString());
});