Add /lp check <user> <permission> command

This commit is contained in:
Luck 2017-01-23 21:03:58 +00:00
parent 7d1a3d32e9
commit 69dc02b2c2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 93 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.group.GroupMainCommand;
import me.lucko.luckperms.common.commands.group.ListGroups;
import me.lucko.luckperms.common.commands.log.LogMainCommand;
import me.lucko.luckperms.common.commands.migration.MigrationMainCommand;
import me.lucko.luckperms.common.commands.misc.CheckCommand;
import me.lucko.luckperms.common.commands.misc.ExportCommand;
import me.lucko.luckperms.common.commands.misc.ImportCommand;
import me.lucko.luckperms.common.commands.misc.InfoCommand;
@ -89,6 +90,7 @@ public class CommandManager {
.add(new InfoCommand())
.add(new VerboseCommand())
.add(new SearchCommand())
.add(new CheckCommand())
.add(new NetworkSyncCommand())
.add(new ImportCommand())
.add(new ExportCommand())

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.misc;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.UUID;
public class CheckCommand extends SingleCommand {
public CheckCommand() {
super("Check", "Perform a standard permission check on an online player",
"/%s search <user> <permission>", Permission.CHECK, Predicates.not(2),
Arg.list(
Arg.create("user", true, "the user to check"),
Arg.create("permission", true, "the permission to check for")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
String target = args.get(0);
String permission = args.get(1);
User user;
UUID u = Util.parseUuid(target);
if (u != null) {
user = plugin.getUserManager().get(u);
} else {
user = plugin.getUserManager().getByUsername(target);
}
if (user == null) {
Message.USER_NOT_ONLINE.send(sender, target);
return CommandResult.STATE_ERROR;
}
UserCache data = user.getUserData();
if (data == null) {
Message.USER_NO_DATA.send(sender, user.getName());
return CommandResult.STATE_ERROR;
}
Tristate tristate = data.getPermissionData(plugin.getContextForUser(user)).getPermissionValue(permission);
Message.CHECK_RESULT.send(sender, user.getName(), permission, Util.formatTristate(tristate));
return CommandResult.SUCCESS;
}
}

View File

@ -64,6 +64,8 @@ public enum Message {
* Loading / Saving
*/
USER_NOT_FOUND("&bUser could not be found.", true),
USER_NOT_ONLINE("&bUser &a{0}&b is not online.", true),
USER_NO_DATA("&bUser &a{0}&b does not have any data loaded.", true),
USER_SAVE_SUCCESS("&7(User data was saved to storage)", true),
USER_SAVE_ERROR("There was an error whilst saving the user.", true),
USER_CREATE_FAIL("There was an error whilst creating a new user.", true),
@ -106,6 +108,8 @@ public enum Message {
SEARCH_SHOWING_USERS_WITH_PAGE("&bShowing user entries: {0}", true),
SEARCH_SHOWING_GROUPS_WITH_PAGE("&bShowing group entries: {0}", true),
CHECK_RESULT("&aPermission check result for user &b{0}&a for permission &b{1}&a in current contexts: &f{2}", true),
CREATE_SUCCESS("&b{0}&a was successfully created.", true),
DELETE_SUCCESS("&b{0}&a was successfully deleted.", true),
RENAME_SUCCESS("&b{0}&a was successfully renamed to &b{1}&a.", true),

View File

@ -37,8 +37,9 @@ public enum Permission {
SYNC(list("sync"), Type.NONE),
INFO(list("info"), Type.NONE),
SEARCH(list("search"), Type.NONE),
VERBOSE(list("verbose"), Type.NONE),
SEARCH(list("search"), Type.NONE),
CHECK(list("check"), Type.NONE),
IMPORT(list("import"), Type.NONE),
EXPORT(list("export"), Type.NONE),
RELOAD_CONFIG(list("reloadconfig"), Type.NONE),

View File

@ -25,6 +25,8 @@ does-not-have-temp-permission: "{0} does not have this permission set temporaril
user-not-found: "&bUser could not be found."
user-not-online: "&bUser &a{0}&b is not online."
user-no-data: "&bUser &a{0}&b does not have any data loaded."
user-save-success: "&7(User data was saved to storage)"
user-save-error: "There was an error whilst saving the user."
user-create-fail: "There was an error whilst creating a new user."
@ -64,6 +66,8 @@ search-showing-groups: "&bShowing group entries:"
search-showing-users-with-page: "&bShowing user entries: {0}"
search-showing-groups-with-page: "&bShowing group entries: {0}"
check-result: "&aPermission check result for user &b{0}&a for permission &b{1}&a in current contexts: &f{2}"
create-success: "&b{0}&a was successfully created."
delete-success: "&b{0}&a was successfully deleted."
rename-success: "&b{0}&a was successfully renamed to &b{1}&a."