Commit a4cd48c4 authored by Nico Eckes's avatar Nico Eckes

Added /perm test

parent 627fa7ef
Pipeline #715 passed with stage
in 2 minutes and 48 seconds
......@@ -22,7 +22,7 @@ public class CmdPermission extends CommandNode {
protected List<ICommand> subCommands() {
return Arrays.asList(new CmdUser(), new CmdGroup(), new CmdReload(), new CmdAddperm(), new CmdRemovePerm(), new CmdPrefix(), new CmdInfo(), new CmdDebug());
return Arrays.asList(new CmdUser(), new CmdGroup(), new CmdReload(), new CmdAddperm(), new CmdRemovePerm(), new CmdPrefix(), new CmdInfo(), new CmdDebug(), new CmdTestPerm());
package com.unitedworldminers.PermIO.commands.general;
import com.unitedworldminers.BaseIO.util.MessageUtils;
import com.unitedworldminers.BaseIO.util.SimpleCommand;
import com.unitedworldminers.PermIO.api.IGroup;
import com.unitedworldminers.PermIO.api.IPermissionHolder;
import com.unitedworldminers.PermIO.commands.CmdPermission;
import com.unitedworldminers.PermIO.permissions.Permissions;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class CmdTestPerm extends SimpleCommand {
public String commandUsage(ICommandSender sender) {
return "commands.testperm.usage";
public List<String> commandNames() {
return Arrays.asList("test", "testperm", "testfor");
public void run(ICommandSender sender, String[] args, Map<String, String[]> options) throws CommandException {
if (args.length < 2) {
MessageUtils.messageToSender(sender, getCommandUsage(sender));
IPermissionHolder node = CmdPermission.getHolder(sender, args[0]);
if (node != null) {
boolean hasPermission = node.hasPermission(args[1]);
MessageUtils.messageToSender(sender, "commands.testperm." + (hasPermission ? "yes" : "no"), args[0], args[1]);
if (!hasPermission) //noinspection ConstantConditions
throw new CommandException(null);
public boolean checkPermission(@NotNull MinecraftServer server, @NotNull ICommandSender sender) {
return Permissions.INSTANCE.getPlayer(sender).hasPermission("commands.testperm");
protected Collection<String> customTabCompletions(String tag, List<String> current, ICommandSender sender, String[] args) {
return Permissions.INSTANCE.getGroups().stream().map(IGroup::getGroupId).collect(Collectors.toList());
protected String tabCompletions() {
return "%p|%g";
......@@ -36,4 +36,7 @@ commands.removeperm.success=Removed perm %s from %s
commands.rename.usage=/perm group rename <group> <newname>
commands.rename.success=Renamed group %s to %s.
commands.remove.success=Successfully removed group %s.
commands.remove.usage=/perm group remove <groupid>
\ No newline at end of file
commands.remove.usage=/perm group remove <groupid>
commands.testperm.usage=/perm test <group|user> <perm>
commands.testperm.yes=§aPlayer %s has permission %s.§4Player %s doesn't have permission %s.
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment