Improve tab completion, adjust permissions and more v6 changes

This commit is contained in:
N0tMyFaultOG 2020-11-19 21:53:27 +01:00
parent abed07b613
commit eec369ea4f
7 changed files with 91 additions and 7 deletions

View File

@ -155,6 +155,8 @@ permissions:
default: false
plots.backup.load:
default: false
plots.rate:
default: false
plots.admin:
default: false
@ -240,7 +242,7 @@ permissions:
default: false
plots.admin.build.heightlimit:
default: false
plots.admin.command.rate:
plots.admin.command.purge.ratings:
default: false
plots.admin.command.trust:
default: false

View File

@ -37,6 +37,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.sk89q.jnbt.CompoundTag;
@ -44,6 +45,11 @@ import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@CommandDeclaration(usage = "/plot download [schematic | world]",
command = "download",
@ -147,4 +153,24 @@ public class Download extends SubCommand {
player.sendMessage(TranslatableCaption.of("web.generating_link"));
return true;
}
@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.download")) {
completions.add("schem");
}
if (Permissions.hasPermission(player, "plots.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) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;
}
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -227,18 +227,18 @@ public final class FlagCommand extends Command {
final boolean space) {
if (args.length == 1) {
return Stream
.of("s", "set", "add", "a", "remove", "r", "delete", "info", "i", "list", "l")
.of("set", "add", "remove", "delete", "info", "list")
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
}).collect(Collectors.toList());
} else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete", "info", "i")
} else if (Arrays.asList("set", "add", "remove", "delete", "info")
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 2) {
return GlobalFlagContainer.getInstance().getRecognizedPlotFlags().stream()
.filter(flag -> !(flag instanceof InternalFlag))
.filter(flag -> flag.getName().startsWith(args[1].toLowerCase(Locale.ENGLISH)))
.map(flag -> new Command(null, false, flag.getName(), "", RequiredType.NONE, null) {
}).collect(Collectors.toList());
} else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete")
} else if (Arrays.asList("set", "add", "remove", "delete")
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 3) {
try {
final PlotFlag<?, ?> flag =

View File

@ -35,13 +35,19 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.comment.CommentInbox;
import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.comment.PlotComment;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.Template;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@CommandDeclaration(command = "inbox",
usage = "/plot inbox [inbox] [delete <index> | clear | page]",
@ -264,4 +270,27 @@ public class Inbox extends SubCommand {
}
return true;
}
@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.inbox.read.owner")) {
completions.add("owner");
}
if (Permissions.hasPermission(player, "plots.inbox.read.public")) {
completions.add("public");
}
if (Permissions.hasPermission(player, "plots.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) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;
}
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -95,7 +95,7 @@ public class Like extends SubCommand {
return false;
}
if (!Permissions
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_RATE, true)) {
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
return false;
}
plot.clearRatings();

View File

@ -42,15 +42,21 @@ import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.stream.Collectors;
@CommandDeclaration(command = "rate",
permission = "plots.rate",
@ -113,7 +119,7 @@ public class Rate extends SubCommand {
return false;
}
if (!Permissions
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_RATE, true)) {
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_PURGE_RATINGS, true)) {
return false;
}
plot.clearRatings();
@ -282,4 +288,25 @@ public class Rate extends SubCommand {
this.value += v.intValue();
}
}
@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.rate")) {
completions.add("1 - 10");
}
if (Permissions.hasPermission(player, "plots.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) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;
}
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -75,7 +75,7 @@ public enum Permission {
PERMISSION_ADMIN_INTERACT_UNOWNED("plots.admin.interact.unowned"),
PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other"),
PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT("plots.admin.build.heightlimit"),
PERMISSION_ADMIN_COMMAND_RATE("plots.admin.command.rate"),
PERMISSION_ADMIN_COMMAND_PURGE_RATINGS("plots.admin.command.purge.ratings"),
PERMISSION_ADMIN_COMMAND_TRUST("plots.admin.command.trust"),
PERMISSION_TRUST_EVERYONE("plots.trust.everyone"),
PERMISSION_AREA_CREATE("plots.area.create"),