From eec369ea4f1c538817b49fa89a3651d5a556807f Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Thu, 19 Nov 2020 21:53:27 +0100 Subject: [PATCH] Improve tab completion, adjust permissions and more v6 changes --- Bukkit/src/main/resources/plugin.yml | 4 ++- .../plotsquared/core/command/Download.java | 26 +++++++++++++++++ .../plotsquared/core/command/FlagCommand.java | 6 ++-- .../com/plotsquared/core/command/Inbox.java | 29 +++++++++++++++++++ .../com/plotsquared/core/command/Like.java | 2 +- .../com/plotsquared/core/command/Rate.java | 29 ++++++++++++++++++- .../core/permissions/Permission.java | 2 +- 7 files changed, 91 insertions(+), 7 deletions(-) diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index bd5328e27..a600a5490 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -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 diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index 4a93c309d..457b62eca 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -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 tab(final PlotPlayer player, final String[] args, final boolean space) { + if (args.length == 1) { + final List completions = new LinkedList<>(); + if (Permissions.hasPermission(player, "plots.download")) { + completions.add("schem"); + } + if (Permissions.hasPermission(player, "plots.download.world")) { + completions.add("world"); + } + final List 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()); + } } diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java index 6ccd97256..83621638a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -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 = diff --git a/Core/src/main/java/com/plotsquared/core/command/Inbox.java b/Core/src/main/java/com/plotsquared/core/command/Inbox.java index 33ff92b33..5c2235654 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java +++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java @@ -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 | clear | page]", @@ -264,4 +270,27 @@ public class Inbox extends SubCommand { } return true; } + @Override + public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { + if (args.length == 1) { + final List 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 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()); + } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Like.java b/Core/src/main/java/com/plotsquared/core/command/Like.java index 199bd09e3..f4b91a0a0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Like.java +++ b/Core/src/main/java/com/plotsquared/core/command/Like.java @@ -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(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Rate.java b/Core/src/main/java/com/plotsquared/core/command/Rate.java index 035ed41d3..d40b1239c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Rate.java +++ b/Core/src/main/java/com/plotsquared/core/command/Rate.java @@ -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 tab(final PlotPlayer player, final String[] args, final boolean space) { + if (args.length == 1) { + final List 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 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()); + } } diff --git a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java index 234d7135b..0237ba468 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java @@ -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"),