Make use of Permission class in tab completion

Plus document a few more permission nodes
This commit is contained in:
N0tMyFaultOG 2020-11-19 22:29:44 +01:00
parent a8495c67d4
commit be9d9264ae
12 changed files with 114 additions and 53 deletions

View File

@ -95,6 +95,30 @@ permissions:
default: false
plots.set.flag.other:
default: false
plots.set:
default: false
plots.set.biome:
default: false
plots.set.alias:
default: false
plots.set.home:
default: false
plots.set.main:
default: false
plots.set.floor:
default: false
plots.set.air:
default: false
plots.set.all:
default: false
plots.set.border:
default: false
plots.set.wall:
default: false
plots.set.outline:
default: false
plots.set.middle:
default: false
plots.set.flag:
default: false
plots.flag.remove:
@ -107,6 +131,8 @@ permissions:
default: false
plots.list.shared:
default: false
plots.target:
default: false
plots.list.world:
default: false
plots.list.top:
@ -157,6 +183,12 @@ permissions:
default: false
plots.rate:
default: false
plots.template.export:
default: false
plots.template.import:
default: false
plots.template:
default: false
plots.admin:
default: false

View File

@ -684,25 +684,25 @@ public class Area extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.area.create")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
completions.add("create");
}
if (Permissions.hasPermission(player, "plots.area.create")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
completions.add("single");
}
if (Permissions.hasPermission(player, "plots.area.list")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_LIST)) {
completions.add("list");
}
if (Permissions.hasPermission(player, "plots.area.info")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_INFO)) {
completions.add("info");
}
if (Permissions.hasPermission(player, "plots.area.tp")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
completions.add("tp");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.area") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -823,43 +823,43 @@ public class Cluster extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.cluster.list")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_LIST)) {
completions.add("list");
}
if (Permissions.hasPermission(player, "plots.cluster.create")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_CREATE)) {
completions.add("create");
}
if (Permissions.hasPermission(player, "plots.cluster.delete")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_DELETE)) {
completions.add("delete");
}
if (Permissions.hasPermission(player, "plots.cluster.resize")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_RESIZE)) {
completions.add("resize");
}
if (Permissions.hasPermission(player, "plots.cluster.invite")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_INVITE)) {
completions.add("invite");
}
if (Permissions.hasPermission(player, "plots.cluster.kick")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_KICK)) {
completions.add("kick");
}
if (Permissions.hasPermission(player, "plots.cluster.leave")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_KICK)) {
completions.add("leave");
}
if (Permissions.hasPermission(player, "plots.cluster.members")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_HELPERS)) {
completions.add("members");
}
if (Permissions.hasPermission(player, "plots.cluster.info")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_INFO)) {
completions.add("info");
}
if (Permissions.hasPermission(player, "plots.cluster.tp")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_TP)) {
completions.add("tp");
}
if (Permissions.hasPermission(player, "plots.cluster.sethome")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER_SETHOME)) {
completions.add("sethome");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.cluster") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -157,16 +157,16 @@ public class Download extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.download")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD)) {
completions.add("schem");
}
if (Permissions.hasPermission(player, "plots.download.world")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD_WORLD)) {
completions.add("world");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.download") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -144,16 +144,16 @@ public class Grant extends Command {
@Override public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.grant.add")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_ADD)) {
completions.add("add");
}
if (Permissions.hasPermission(player, "plots.grant.check")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_CHECK)) {
completions.add("check");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.grant") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_SINGLE) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -28,6 +28,7 @@ package com.plotsquared.core.command;
import com.google.inject.TypeLiteral;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.MetaDataAccess;
import com.plotsquared.core.player.MetaDataKey;
import com.plotsquared.core.player.PlotPlayer;
@ -274,19 +275,19 @@ public class Inbox extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.inbox.read.owner")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX_READ_OWNER)) {
completions.add("owner");
}
if (Permissions.hasPermission(player, "plots.inbox.read.public")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX_READ_PUBLIC)) {
completions.add("public");
}
if (Permissions.hasPermission(player, "plots.inbox.read.report")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX_READ_REPORT)) {
completions.add("report");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.CHAT) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.inbox") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -293,16 +293,16 @@ public class Rate extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.rate")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE)) {
completions.add("1 - 10");
}
if (Permissions.hasPermission(player, "plots.admin.command.purge.ratings")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS)) {
completions.add("purge");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.rate") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -280,19 +280,19 @@ public class SchematicCmd extends SubCommand {
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.schematic.save")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC_SAVE)) {
completions.add("save");
}
if (Permissions.hasPermission(player, "plots.schematic.list")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC_LIST)) {
completions.add("list");
}
if (Permissions.hasPermission(player, "plots.schematic.paste")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC_PASTE)) {
completions.add("paste");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.schematic") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -227,44 +227,44 @@ public class Set extends SubCommand {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.set.biome")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_BIOME)) {
completions.add("biome");
}
if (Permissions.hasPermission(player, "plots.set.alias")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_ALIAS)) {
completions.add("alias");
}
if (Permissions.hasPermission(player, "plots.set.home")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_HOME)) {
completions.add("home");
}
if (Permissions.hasPermission(player, "plots.set.main")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_MAIN)) {
completions.add("main");
}
if (Permissions.hasPermission(player, "plots.set.floor")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_FLOOR)) {
completions.add("floor");
}
if (Permissions.hasPermission(player, "plots.set.air")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_AIR)) {
completions.add("air");
}
if (Permissions.hasPermission(player, "plots.set.all")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_ALL)) {
completions.add("all");
}
if (Permissions.hasPermission(player, "plots.set.border")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_BORDER)) {
completions.add("border");
}
if (Permissions.hasPermission(player, "plots.set.wall")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_WALL)) {
completions.add("wall");
}
if (Permissions.hasPermission(player, "plots.set.outline")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_OUTLINE)) {
completions.add("outline");
}
if (Permissions.hasPermission(player, "plots.set.middle")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET_MIDDLE)) {
completions.add("middle");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.APPEARANCE) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.set") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_SET) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -85,10 +85,10 @@ public class Target extends SubCommand {
player.sendMessage(TranslatableCaption.of("compass.compass_target"));
return true;
}
@Override public Collection<Command> tab(final PlotPlayer player, String[] args, boolean space) {
@Override public Collection<Command> tab(final PlotPlayer<?> player, String[] args, boolean space) {
return Stream.of("<X;Z>", "nearest")
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
.map(value -> new Command(null, false, value, "plots.target", RequiredType.NONE, null) {
.map(value -> new Command(null, false, value, "plots.target", RequiredType.PLAYER, null) {
}).collect(Collectors.toList());
}
}

View File

@ -37,6 +37,7 @@ import com.plotsquared.core.configuration.InvalidConfigurationException;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.permissions.Permission;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
@ -272,16 +273,16 @@ public class Template extends SubCommand {
@Override public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
if (args.length == 1) {
final List<String> completions = new LinkedList<>();
if (Permissions.hasPermission(player, "plots.template.export")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE_EXPORT)) {
completions.add("export");
}
if (Permissions.hasPermission(player, "plots.template.import")) {
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE_IMPORT)) {
completions.add("import");
}
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
}).collect(Collectors.toCollection(LinkedList::new));
if (Permissions.hasPermission(player, "plots.template") && args[0].length() > 0) {
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;

View File

@ -84,6 +84,7 @@ public enum Permission {
PERMISSION_AREA_LIST("plots.area.list"),
PERMISSION_AREA_REGEN("plots.area.regen"),
PERMISSION_AREA_TP("plots.area.tp"),
PERMISSION_AREA("plots.area"),
PERMISSION_AUTO_MEGA("plots.auto.mega"),
PERMISSION_CLAIM_SCHEMATIC("plots.claim.%s"),
PERMISSION_ADMIN_COMMAND_SCHEMATIC("plots.admin.command.schematic"),
@ -117,16 +118,36 @@ public enum Permission {
PERMISSION_DENY_EVERYONE("plots.deny.everyone"),
PERMISSION_ADMIN_COMMAND_DONE("plots.admin.command.done"),
PERMISSION_ADMIN_COMMAND_DOWNLOAD("plots.admin.command.download"),
PERMISSION_DOWNLOAD("plots.download"),
PERMISSION_DOWNLOAD_WORLD("plots.download.world"),
PERMISSION_SET_FLAG_OTHER("plots.set.flag.other"),
PERMISSION_SET_FLAG("plots.set.flag"),
PERMISSION_SET_FLAG_KEY("plots.set.flag.%s"),
PERMISSION_SET_FLAG_KEY_VALUE("plots.set.flag.%s.%s"),
PERMISSION_SET("plots.set"),
PERMISSION_SET_BIOME("plots.set.biome"),
PERMISSION_SET_ALIAS("plots.set.alias"),
PERMISSION_SET_HOME("plots.set.home"),
PERMISSION_SET_MAIN("plots.set.main"),
PERMISSION_SET_FLOOR("plots.set.floor"),
PERMISSION_SET_AIR("plots.set.air"),
PERMISSION_SET_ALL("plots.set.all"),
PERMISSION_SET_BORDER("plots.set.border"),
PERMISSION_SET_WALL("plots.set.wall"),
PERMISSION_SET_OUTLINE("plots.set.outline"),
PERMISSION_SET_MIDDLE("plots.set.middle"),
PERMISSION_TARGET("plots.target"),
PERMISSION_TEMPLATE("plots.template"),
PERMISSION_TEMPLATE_IMPORT("plots.template.import"),
PERMISSION_TEMPLATE_EXPORT("plots.template.import"),
PERMISSION_FLAG_REMOVE("plots.flag.remove"),
PERMISSION_FLAG_ADD("plots.flag.add"),
PERMISSION_FLAG_LIST("plots.flag.list"),
PERMISSION_ADMIN_COMMAND_KICK("plots.admin.command.kick"),
PERMISSION_GRANT_SINGLE("plots.grant"),
PERMISSION_GRANT("plots.grant.%s"),
PERMISSION_GRANT_ADD("plots.grant.add"),
PERMISSION_GRANT_CHECK("plots.grant.check"),
PERMISSION_LIST_FOR_SALE("plots.list.forsale"),
PERMISSION_LIST_MINE("plots.list.mine"),
PERMISSION_LIST_SHARED("plots.list.shared"),
@ -144,9 +165,14 @@ public enum Permission {
PERMISSION_ADMIN_COMMAND_MERGE("plots.admin.command.merge"),
PERMISSION_ADMIN_COMMAND_SET_OWNER("plots.admin.command.setowner"),
PERMISSION_COMMENT("plots.comment"),
PERMISSION_INBOX("plots.inbox"),
PERMISSION_INBOX_READ_OWNER("plots.inbox.read.owner"),
PERMISSION_INBOX_READ_PUBLIC("plots.inbox.read.public"),
PERMISSION_INBOX_READ_REPORT("plots.inbox.read.report"),
PERMISSION_ADMIN_COMMAND_REMOVE("plots.admin.command.remove"),
PERMISSION_ADMIN_COMMAND_SAVE("plots.admin.command.save"),
PERMISSION_ADMIN_COMMAND_SCHEMATIC_PASTE("plots.admin.command.schematic.paste"),
PERMISSION_SCHEMATIC("plots.schematic.paste"),
PERMISSION_SCHEMATIC_PASTE("plots.schematic.paste"),
PERMISSION_SCHEMATIC_LIST("plots.schematic.list"),
PERMISSION_SCHEMATIC_SAVE("plots.schematic.save"),
@ -171,7 +197,8 @@ public enum Permission {
PERMISSION_BACKUP_LOAD("plots.backup.load"),
PERMISSION_ADMIN_BACKUP_OTHER("plots.admin.backup.other"),
PERMISSION_ADMIN_ALLOW_UNSAFE("plots.admin.unsafe"),
PERMISSION_ADMIN_DEBUG_OTHER("plots.admin.debug.other");
PERMISSION_ADMIN_DEBUG_OTHER("plots.admin.debug.other"),
PERMISSION_RATE("plots.rate");
//</editor-fold>
private final String text;