From 5640a55d732f53e98351914427e7334d54c4a795 Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Sat, 22 Jun 2024 00:36:38 +1000 Subject: [PATCH] Update cloud-paper to 2.0.0-SNAPSHOT. Refactor commands to accomodate the new CommandSourceStack --- AreaShop/build.gradle.kts | 14 ++++---- .../areashop/commands/AddCommand.java | 20 +++++------ .../areashop/commands/AddFriendCommand.java | 12 ++++--- .../areashop/commands/AddSignCommand.java | 12 ++++--- .../areashop/commands/BuyCommand.java | 13 ++++--- .../areashop/commands/DelCommand.java | 14 +++----- .../areashop/commands/DelFriendCommand.java | 15 ++++---- .../areashop/commands/DelSignCommand.java | 10 +++--- .../areashop/commands/FindCommand.java | 10 +++--- .../areashop/commands/GroupAddCommand.java | 11 +++--- .../areashop/commands/GroupDelCommand.java | 11 +++--- .../areashop/commands/GroupInfoCommand.java | 7 ++-- .../areashop/commands/GroupListCommand.java | 7 ++-- .../areashop/commands/HelpCommand.java | 9 +++-- .../areashop/commands/ImportCommand.java | 7 ++-- .../areashop/commands/InfoBaseCommand.java | 7 ++-- .../areashop/commands/InfoCommand.java | 14 ++++---- .../areashop/commands/InfoPlayerCommand.java | 10 +++--- .../areashop/commands/InfoRegionCommand.java | 12 +++---- .../areashop/commands/LinkSignsCommand.java | 12 +++---- .../areashop/commands/MeCommand.java | 12 +++---- .../areashop/commands/MessageCommand.java | 18 +++------- .../areashop/commands/QuickBuyCommand.java | 14 ++++---- .../areashop/commands/QuickDeleteCommand.java | 10 +++--- .../areashop/commands/QuickRentCommand.java | 14 ++++---- .../areashop/commands/ReloadCommand.java | 7 ++-- .../areashop/commands/RentCommand.java | 13 ++++--- .../areashop/commands/ResellCommand.java | 18 +++++----- .../commands/SchematicEventCommand.java | 9 +++-- .../areashop/commands/SellCommand.java | 17 +++++---- .../areashop/commands/SetDurationCommand.java | 11 +++--- .../areashop/commands/SetLandlordCommand.java | 11 +++--- .../areashop/commands/SetOwnerCommand.java | 11 +++--- .../areashop/commands/SetPriceCommand.java | 11 +++--- .../areashop/commands/SetRestoreCommand.java | 13 ++++--- .../areashop/commands/SetTeleportCommand.java | 14 ++++---- .../areashop/commands/SetTransferCommand.java | 11 +++--- .../areashop/commands/StackCommand.java | 11 +++--- .../areashop/commands/StopResellCommand.java | 17 +++++---- .../areashop/commands/TeleportCommand.java | 12 +++---- .../areashop/commands/ToggleHomeCommand.java | 19 +++++----- .../areashop/commands/TransferCommand.java | 22 ++++++------ .../areashop/commands/UnrentCommand.java | 17 +++++---- .../commands/util/AreashopCommandBean.java | 12 +++---- .../commands/util/AreashopCommands.java | 23 +++++------- .../util/ArgumentParseExceptionHandler.java | 6 ++-- .../util/InvalidCommandSenderHandler.java | 10 +++--- .../commands/util/RegionCreationUtil.java | 8 ++--- .../commands/util/RegionParseUtil.java | 36 ++++++++++--------- .../commands/util/SignProfileUtil.java | 5 ++- .../util/ValidatedOfflinePlayerParser.java | 5 +++ .../areashop/commands/util/WorldFlagUtil.java | 11 +++--- .../commands/util/WorldGuardRegionParser.java | 10 +++--- .../util/commandsource/CommandSource.java | 16 +++++++++ .../commandsource/CommandSourceMapper.java | 27 ++++++++++++++ .../commandsource/CommandSourceWrapper.java | 15 ++++++++ .../commandsource/EntityCommandSource.java | 23 ++++++++++++ .../commandsource/GenericCommandSource.java | 31 ++++++++++++++++ .../commandsource/PlayerCommandSource.java | 23 ++++++++++++ 59 files changed, 468 insertions(+), 332 deletions(-) create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSource.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceMapper.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceWrapper.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/EntityCommandSource.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/GenericCommandSource.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/PlayerCommandSource.java diff --git a/AreaShop/build.gradle.kts b/AreaShop/build.gradle.kts index bbda7b1a..df735969 100644 --- a/AreaShop/build.gradle.kts +++ b/AreaShop/build.gradle.kts @@ -31,10 +31,10 @@ dependencies { api("com.google.inject.extensions:guice-assistedinject:7.0.0") { exclude("com.google.guava") } - implementation("org.incendo:cloud-paper:2.0.0-beta.5") { + implementation("org.incendo:cloud-paper:2.0.0-SNAPSHOT") { exclude("com.google.guava") } - implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.2") { + implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.3") { exclude("com.google.guava") } implementation("net.kyori:adventure-text-minimessage:4.16.0") @@ -132,15 +132,15 @@ tasks { // Configure the Minecraft version for our task. // This is the only required configuration besides applying the plugin. // Your plugin's jar (or shadowJar if present) will be used automatically. - minecraftVersion("1.20.4") + minecraftVersion("1.20.6") downloadPlugins { github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar") github("MilkBowl", "Vault", "1.7.3", "Vault.jar") - // WorldEdit 7.3.0 - url("https://mediafilez.forgecdn.net/files/5168/643/worldedit-bukkit-7.3.0.jar") - // WorldGuard 7.0.9 - url("https://mediafilez.forgecdn.net/files/4675/318/worldguard-bukkit-7.0.9-dist.jar") + // WorldEdit 7.3.3 + url("https://mediafilez.forgecdn.net/files/5400/331/worldedit-bukkit-7.3.3.jar") + // WorldGuard 7.0.10 + url("https://mediafilez.forgecdn.net/files/5344/377/worldguard-bukkit-7.0.10-dist.jar") } } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddCommand.java index 7ff10841..893698ae 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddCommand.java @@ -10,6 +10,8 @@ import me.wiefferink.areashop.commands.util.WorldFlagUtil; import me.wiefferink.areashop.commands.util.WorldGuardRegionParser; import me.wiefferink.areashop.commands.util.WorldSelection; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.events.ask.AddingRegionEvent; import me.wiefferink.areashop.events.ask.BuyingRegionEvent; import me.wiefferink.areashop.events.ask.RentingRegionEvent; @@ -28,13 +30,11 @@ import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.incendo.cloud.Command; import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; -import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.standard.EnumParser; import org.jetbrains.annotations.NotNull; @@ -92,31 +92,29 @@ public String getHelpKey(@NotNull CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { // /as add [region] [world] - ParserDescriptor wgRegionParser = ParserDescriptor.of(new WorldGuardRegionParser<>( - WorldFlagUtil.DEFAULT_WORLD_FLAG, - this.worldGuardInterface), ProtectedRegion.class); + var wgRegionParser = WorldGuardRegionParser.worldGuardRegionParser(WorldFlagUtil.DEFAULT_WORLD_FLAG, this.worldGuardInterface); return builder .literal("add") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class)) .optional(KEY_REGION, wgRegionParser) .flag(WorldFlagUtil.DEFAULT_WORLD_FLAG) .handler(this::handleCommand); } - private void handleCommand(CommandContext context) { - Player player = context.sender(); + private void handleCommand(CommandContext context) { + Player player = context.sender().sender(); final GeneralRegion.RegionType regionType = context.get(KEY_REGION_TYPE); - World world = WorldFlagUtil.parseOrDetectWorld(context); + World world = WorldFlagUtil.parseOrDetectWorld(context, player); Map regions; Optional inputRegion = context.optional(KEY_REGION); if (inputRegion.isPresent()) { regions = new HashMap<>(); regions.put(inputRegion.get().getId(), inputRegion.get()); } else { - WorldSelection selection = WorldSelection.fromPlayer(context.sender(), this.worldEditInterface); + WorldSelection selection = WorldSelection.fromPlayer(player, this.worldEditInterface); regions = Utils.getWorldEditRegionsInSelection(selection.selection()).stream() .collect(Collectors.toMap(ProtectedRegion::getId, region -> region)); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddFriendCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddFriendCommand.java index 8a894ae8..3a50f545 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddFriendCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddFriendCommand.java @@ -6,6 +6,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -55,21 +57,21 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("addfriend") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_FRIEND, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .flag(this.regionFlag) .handler(this::handleCommand); } - private void handleCommand(CommandContext context) { - Player sender = context.sender(); + private void handleCommand(CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) { this.messageBridge.message(sender, "addfriend-noPermission"); return; } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); OfflinePlayer friend = context.get(KEY_FRIEND); if (sender.hasPermission("areashop.addfriendall") && ((region instanceof RentRegion rentRegion && !rentRegion.isRented()) || (region instanceof BuyRegion buyRegion && !buyRegion.isSold()))) { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddSignCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddSignCommand.java index 76d8c797..a66fe797 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddSignCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/AddSignCommand.java @@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.GeneralRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.SignProfileUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.features.signs.RegionSign; import me.wiefferink.areashop.features.signs.SignManager; import me.wiefferink.areashop.managers.IFileManager; @@ -66,16 +68,16 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("addsign") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .flag(SignProfileUtil.DEFAULT_FLAG) .handler(this::handleCommand); } - private void handleCommand(@Nonnull CommandContext context) { - Player sender = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.addsign")) { throw new AreaShopCommandException("addsign-noPermission"); } @@ -93,7 +95,7 @@ private void handleCommand(@Nonnull CommandContext context) { return; } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, KEY_REGION); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, KEY_REGION); String profile = SignProfileUtil.getOrParseProfile(context, this.plugin); Optional optionalRegionSign = this.signManager.signFromLocation(block.getLocation()); if(optionalRegionSign.isPresent()) { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/BuyCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/BuyCommand.java index c5cd558e..ddc5518b 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/BuyCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/BuyCommand.java @@ -5,6 +5,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import org.bukkit.command.CommandSender; @@ -46,20 +48,21 @@ public String stringDescription() { @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder .literal("buy") .flag(this.buyRegionFlag) - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .handler(this::handleCommand); } - private void handleCommand(@Nonnull CommandContext context) { + private void handleCommand(@Nonnull CommandContext context) { if (!context.hasPermission("areashop.buy")) { throw new AreaShopCommandException("buy-noPermission"); } - BuyRegion region = RegionParseUtil.getOrParseBuyRegion(context, this.buyRegionFlag); - region.buy(context.sender()); + Player sender = context.sender().sender(); + BuyRegion region = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag); + region.buy(sender); } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelCommand.java index eaf9001e..80f19f6d 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelCommand.java @@ -8,6 +8,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; import me.wiefferink.areashop.commands.util.WorldSelection; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.events.ask.DeletingRegionEvent; import me.wiefferink.areashop.interfaces.WorldEditInterface; import me.wiefferink.areashop.managers.IFileManager; @@ -21,7 +22,6 @@ import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; -import org.incendo.cloud.parser.ParserDescriptor; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -70,18 +70,14 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { - ParserDescriptor regionParser = ParserDescriptor.of( - new GeneralRegionParser<>(this.fileManager), - GeneralRegion.class - ); + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("del", "delete") - .optional(KEY_REGION, regionParser) + .optional(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .handler(this::handleCommand); } - public void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + public void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.destroybuy") && !sender.hasPermission("areashop.destroybuy.landlord") && !sender.hasPermission("areashop.destroyrent") diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelFriendCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelFriendCommand.java index 7f1e7456..baea5ecc 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelFriendCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelFriendCommand.java @@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.features.FriendsFeature; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; @@ -81,19 +82,19 @@ public String stringDescription() { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("delfriend", "deletefriend") .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser(), this::suggestFriends) .flag(this.regionFlag) .handler(this::handleCommand); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) { throw new AreaShopCommandException("delfriend-noPermission"); } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); OfflinePlayer friend = context.get(KEY_PLAYER); FriendsFeature friendsFeature = region.getFriendsFeature(); if (sender.hasPermission("areashop.delfriendall")) { @@ -128,16 +129,16 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestFriends( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { - CommandSender sender = context.sender(); + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.delfriend")) { return CompletableFuture.completedFuture(Collections.emptyList()); } GeneralRegion region; try { - region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); } catch (AreaShopCommandException ignored) { return CompletableFuture.completedFuture(Collections.emptyList()); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelSignCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelSignCommand.java index 081db43f..f19dc134 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelSignCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/DelSignCommand.java @@ -5,6 +5,8 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.features.signs.RegionSign; import me.wiefferink.areashop.features.signs.SignManager; import me.wiefferink.areashop.tools.Materials; @@ -44,9 +46,9 @@ public String stringDescription() { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("delsign", "deletesign") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .handler(this::handleCommand); } @@ -58,8 +60,8 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { - Player sender = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.delsign")) { throw new AreaShopCommandException("delsign-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/FindCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/FindCommand.java index 65d0b87d..13050fab 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/FindCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/FindCommand.java @@ -6,6 +6,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionGroupParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -73,9 +75,9 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("find") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION_TYPE, EnumParser.enumParser(GeneralRegion.RegionType.class)) .optional(KEY_PRICE, DoubleParser.doubleParser(0)) .flag(this.regionGroupFlag) @@ -87,8 +89,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("find"); } - private void handleCommand(@Nonnull CommandContext context) { - Player sender = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.find")) { throw new AreaShopCommandException("find-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupAddCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupAddCommand.java index 393133b5..eda6aaba 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupAddCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupAddCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.RegionFactory; @@ -65,7 +66,7 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("groupadd") .required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames) .flag(this.regionFlag) @@ -77,8 +78,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("groupadd"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.groupadd")) { throw new AreaShopCommandException("groupadd-noPermission"); } @@ -102,7 +103,7 @@ private void handleCommand(@Nonnull CommandContext context) { return; } - Collection regions = RegionParseUtil.getOrParseRegionsInSel(context, this.regionFlag); + Collection regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag); Set regionsSuccess = new TreeSet<>(); Set regionsFailed = new TreeSet<>(); for (GeneralRegion region : regions) { @@ -129,7 +130,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestGroupNames( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupDelCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupDelCommand.java index d717b061..0c59d623 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupDelCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupDelCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.RegionFactory; @@ -65,7 +66,7 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("groupdel") .required(KEY_GROUP, StringParser.stringParser(), this::suggestGroupNames) .flag(this.regionFlag) @@ -77,8 +78,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("groupdel"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("groupdel")) { throw new AreaShopCommandException("groupdel-noPermission"); } @@ -101,7 +102,7 @@ private void handleCommand(@Nonnull CommandContext context) { return; } - Collection regions = RegionParseUtil.getOrParseRegionsInSel(context, this.regionFlag); + Collection regions = RegionParseUtil.getOrParseRegionsInSel(context, sender, this.regionFlag); Set regionsSuccess = new TreeSet<>(); Set regionsFailed = new TreeSet<>(); for (GeneralRegion region : regions) { @@ -129,7 +130,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestGroupNames( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupInfoCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupInfoCommand.java index 427680d3..cba656df 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupInfoCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupInfoCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionGroupParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.RegionGroup; import me.wiefferink.areashop.tools.Utils; @@ -47,8 +48,8 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { - ParserDescriptor regionGroupParser = ParserDescriptor.of( + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { + ParserDescriptor, RegionGroup> regionGroupParser = ParserDescriptor.of( new RegionGroupParser<>(this.fileManager, "groupinfo-noGroup"), RegionGroup.class); return builder @@ -63,7 +64,7 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("groupinfo"); } - public void handleCommand(@Nonnull CommandContext context) { + public void handleCommand(@Nonnull CommandContext> context) { if (!context.hasPermission("groupinfo")) { throw new AreaShopCommandException("groupinfo-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupListCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupListCommand.java index a0fa7d87..2f705d1c 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupListCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/GroupListCommand.java @@ -5,6 +5,7 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.tools.Utils; import org.bukkit.command.CommandSender; @@ -41,7 +42,7 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("grouplist", "groups") .handler(this::handleCommand); } @@ -51,12 +52,12 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("grouplist", "groups"); } - private void handleCommand(@Nonnull CommandContext context) { + private void handleCommand(@Nonnull CommandContext> context) { if (!context.hasPermission("areashop.grouplist")) { throw new AreaShopCommandException("grouplist-noPermission"); } List groups = this.fileManager.getGroupNames(); - CommandSender sender = context.sender(); + CommandSender sender = context.sender().sender(); if(groups.isEmpty()) { messageBridge.message(sender, "grouplist-noGroups"); } else { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/HelpCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/HelpCommand.java index f698db34..30bc0bf7 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/HelpCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/HelpCommand.java @@ -5,12 +5,12 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.AreashopCommands; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -36,9 +36,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("help") .handler(this::handleCommand); } @@ -48,8 +47,8 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("help"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.help")) { throw new AreaShopCommandException("help-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ImportCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ImportCommand.java index 0e760a78..dc8c288e 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ImportCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ImportCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AcceptedValuesParser; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.regions.ImportJobFactory; import org.bukkit.command.CommandSender; import org.incendo.cloud.Command; @@ -50,7 +51,7 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { withConfirmation(); var sourceParser = AcceptedValuesParser.ofConstant(List.of("RegionForSale"), "import-wrongSource", true); return builder.literal("import") @@ -69,8 +70,8 @@ public String getHelpKey(CommandSender target) { // - Region flags? // - Settings from the 'permissions' section in RegionForSale/config.yml? - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.import")) { this.messageBridge.message(sender, "import-noPermission"); return; diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoBaseCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoBaseCommand.java index 518254c7..81bc0f9a 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoBaseCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoBaseCommand.java @@ -4,6 +4,7 @@ import jakarta.inject.Singleton; import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import org.bukkit.command.CommandSender; import org.incendo.cloud.Command; import org.incendo.cloud.bean.CommandProperties; @@ -37,7 +38,7 @@ public String getHelpKey(CommandSender target) { } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("info").handler(this::handleCommand); } @@ -46,8 +47,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("info"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.info")) { messageBridge.message(sender, "info-noPermission"); return; diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java index 7b9ef0b1..22add309 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java @@ -5,6 +5,7 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionGroupParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -60,14 +61,11 @@ public String stringDescription() { @Override public String getHelpKey(CommandSender target) { - if(target.hasPermission("areashop.info")) { - return "help-info"; - } return null; } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("info") .required(KEY_TYPE, EnumParser.enumParser(RegionStateFilterType.class)) .flag(FLAG_PAGE) @@ -80,8 +78,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("info"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.info")) { messageBridge.message(sender, "info-noPermission"); return; @@ -90,7 +88,7 @@ private void handleCommand(@Nonnull CommandContext context) { processOtherFilters(context, filterType); } - private void processOtherFilters(@Nonnull CommandContext context, + private void processOtherFilters(@Nonnull CommandContext> context, @Nonnull RegionStateFilterType filterType) { RegionGroup filterGroup = context.flags().get(this.filterGroupFlag); int page = context.flags().getValue(FLAG_PAGE).orElse(1); @@ -127,7 +125,7 @@ private void processOtherFilters(@Nonnull CommandContext context, case RESELLING -> "info reselling"; case NOGROUP -> "info nogroup"; }; - showSortedPagedList(context.sender(), toShow, filterGroup, header, page, baseCommand); + showSortedPagedList(context.sender().sender(), toShow, filterGroup, header, page, baseCommand); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java index e7a02b41..5d96d5ff 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionInfoUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -40,14 +41,11 @@ public String stringDescription() { @Override public String getHelpKey(CommandSender target) { - if (target.hasPermission("areashop.info")) { - return "help-info"; - } return null; } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("info").literal("player") .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .handler(this::handleCommand); @@ -58,8 +56,8 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("info region"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.info")) { messageBridge.message(sender, "info-noPermission"); return; diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java index cee6c05f..f47b69f6 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -46,14 +47,11 @@ public String stringDescription() { @Override public String getHelpKey(CommandSender target) { - if (target.hasPermission("areashop.info")) { - return "help-info"; - } return null; } @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("info").literal("region") .flag(this.regionFlag) .handler(this::handleCommand); @@ -64,14 +62,14 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("info region"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.info")) { messageBridge.message(sender, "info-noPermission"); return; } // Region info - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); if (region instanceof RentRegion rent) { handleRent(sender, rent); } else if (region instanceof BuyRegion buy) { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/LinkSignsCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/LinkSignsCommand.java index 5e68f570..19b992fc 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/LinkSignsCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/LinkSignsCommand.java @@ -7,6 +7,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.SignProfileUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.SignLinkerManager; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,7 +17,6 @@ import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.parser.flag.CommandFlag; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -46,11 +47,10 @@ public String stringDescription() { } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("linksign") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .flag(this.profileFlag) .handler(this::handleCommand); } @@ -68,8 +68,8 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("linksigns")) { throw new AreaShopCommandException("linksigns-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java index 6421df15..ea25cc90 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java @@ -7,6 +7,8 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionInfoUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -16,7 +18,6 @@ import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -41,11 +42,10 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("me") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .optional(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .handler(this::handleCommand); } @@ -63,8 +63,8 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { - Player sender = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.me")) { throw new AreaShopCommandException("me-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/MessageCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/MessageCommand.java index 7a9d91e1..aa20c21b 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/MessageCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/MessageCommand.java @@ -1,10 +1,9 @@ package me.wiefferink.areashop.commands; -import jakarta.inject.Inject; import jakarta.inject.Singleton; -import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.tools.SimpleMessageBridge; import me.wiefferink.interactivemessenger.processing.Message; import org.bukkit.command.CommandSender; @@ -16,7 +15,6 @@ import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.standard.StringParser; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -26,13 +24,6 @@ public class MessageCommand extends AreashopCommandBean { private static final CloudKey KEY_PLAYER = CloudKey.of("player", Player.class); private static final CloudKey KEY_MESSAGE = CloudKey.of("message", String.class); - private final MessageBridge messageBridge; - - @Inject - public MessageCommand(@Nonnull MessageBridge messageBridge) { - this.messageBridge = messageBridge; - } - public String getHelpKey(CommandSender target) { // Internal command, no need to show in the help list return null; @@ -43,9 +34,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("message") .required(KEY_PLAYER, PlayerParser.playerParser()) .required(KEY_MESSAGE, StringParser.greedyStringParser()) @@ -57,8 +47,8 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("message"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if(!sender.hasPermission("areashop.message")) { throw new AreaShopCommandException("message-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickBuyCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickBuyCommand.java index 0da1dd62..205b6117 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickBuyCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickBuyCommand.java @@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.ArgumentParseExceptionHandler; import me.wiefferink.areashop.commands.util.RegionCreationUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.RegionFactory; @@ -61,10 +63,10 @@ public String stringDescription() { @Nonnull @Override - protected Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("quickbuy") .permission("permission") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION, StringParser.stringParser()) .required(KEY_PRICE, DoubleParser.doubleParser(0)) .required(KEY_LANDLORD, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) @@ -73,16 +75,16 @@ protected Command.Builder configureCommand(@Nonnull Com // /as quickbuy - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("areashop.quickbuy")) { player.sendMessage("Insufficient permission"); return; } - this.regionCreationUtil.createRegion(context, KEY_REGION) + this.regionCreationUtil.createRegion(context, player, KEY_REGION) .exceptionally(throwable -> { if (throwable instanceof AreaShopCommandException exception) { - ArgumentParseExceptionHandler.handleException(this.messageBridge, player, exception); + ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception); } else { throw new CommandExecutionException(throwable, context); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickDeleteCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickDeleteCommand.java index 6f584ccc..ca903c4a 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickDeleteCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickDeleteCommand.java @@ -7,6 +7,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.events.ask.DeletingRegionEvent; import me.wiefferink.areashop.interfaces.WorldGuardInterface; import me.wiefferink.areashop.managers.IFileManager; @@ -56,16 +58,16 @@ public String stringDescription() { @Nonnull @Override - protected Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("quickdelete", "quickdel") .permission("areashop.quickdelete") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .handler(this::handleCommand); } - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); GeneralRegion region = context.get(KEY_REGION); boolean giveMoneyBack = context.flags().isPresent(FLAG_RETURN_MONEY); DeletingRegionEvent event = this.fileManager.deleteRegion(region, giveMoneyBack); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickRentCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickRentCommand.java index 37a2d9ff..1ab32652 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickRentCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/QuickRentCommand.java @@ -9,6 +9,8 @@ import me.wiefferink.areashop.commands.util.DurationInputParser; import me.wiefferink.areashop.commands.util.RegionCreationUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.RegionFactory; import me.wiefferink.areashop.regions.RentRegion; @@ -65,10 +67,10 @@ public String stringDescription() { @Nonnull @Override - protected Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("quickrent") .permission("permission") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION, StringParser.stringParser()) .required(KEY_PRICE, DoubleParser.doubleParser(0)) .required(KEY_DURATION, DurationInputParser.durationInputParser()) @@ -78,16 +80,16 @@ protected Command.Builder configureCommand(@Nonnull Com // /as quickrent - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("areashop.quickrent")) { player.sendMessage("Insufficient permission"); return; } - this.regionCreationUtil.createRegion(context, KEY_REGION) + this.regionCreationUtil.createRegion(context, player, KEY_REGION) .exceptionally(throwable -> { if (throwable instanceof AreaShopCommandException exception) { - ArgumentParseExceptionHandler.handleException(this.messageBridge, player, exception); + ArgumentParseExceptionHandler.handleException(this.messageBridge, context.sender(), exception); } else { throw new CommandExecutionException(throwable, context); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ReloadCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ReloadCommand.java index 6c20674d..244d2edf 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ReloadCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ReloadCommand.java @@ -5,6 +5,7 @@ import me.wiefferink.areashop.AreaShop; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; @@ -30,7 +31,7 @@ public String stringDescription() { @Nonnull @Override - protected Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("reload") .handler(this::handleCommand); } @@ -49,10 +50,10 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { + private void handleCommand(@Nonnull CommandContext> context) { if (!context.hasPermission("areashop.reload")) { throw new AreaShopCommandException("reload-noPermission"); } - this.plugin.reload(context.sender()); + this.plugin.reload(context.sender().sender()); } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/RentCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/RentCommand.java index ed34b83e..21910ff7 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/RentCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/RentCommand.java @@ -5,6 +5,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.RentRegion; import org.bukkit.command.CommandSender; @@ -46,20 +48,21 @@ public String getHelpKey(CommandSender target) { @Override - protected @Nonnull Command.Builder configureCommand(@Nonnull Command.Builder builder) { + protected @Nonnull Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder .literal("rent") .flag(this.rentRegionFlag) - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .handler(this::handleCommand); } - private void handleCommand(@Nonnull CommandContext context) { + private void handleCommand(@Nonnull CommandContext context) { if (!context.hasPermission("areashop.rent")) { throw new AreaShopCommandException("rent-noPermission"); } - RentRegion region = RegionParseUtil.getOrParseRentRegion(context, this.rentRegionFlag); - region.rent(context.sender()); + Player sender = context.sender().sender(); + RentRegion region = RegionParseUtil.getOrParseRentRegion(context, sender, this.rentRegionFlag); + region.rent(sender); } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ResellCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ResellCommand.java index 95eebcdb..43ade334 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ResellCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ResellCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.BuyRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -21,7 +22,6 @@ import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.DoubleParser; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -39,11 +39,11 @@ public class ResellCommand extends AreashopCommandBean { public ResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) { this.messageBridge = messageBridge; this.fileManager = fileManager; - ParserDescriptor regionParser = ParserDescriptor.of( + ParserDescriptor, BuyRegion> regionParser = ParserDescriptor.of( new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class ); - this.regionFlag = CommandFlag.builder("region").withComponent(regionParser).build(); + this.regionFlag = CommandFlag.>builder("region").withComponent(regionParser).build(); } @Override @@ -51,9 +51,9 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + @Nonnull + protected Command.Builder> configureCommand(@Nonnull Command.Builder> builder) { return builder.literal("resell") .required(KEY_PRICE, DoubleParser.doubleParser(0)) .flag(this.regionFlag) @@ -75,14 +75,14 @@ public String getHelpKey(CommandSender target) { } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.resell") && !sender.hasPermission("areashop.resellall")) { messageBridge.message(sender, "resell-noPermissionOther"); return; } double price = context.get(KEY_PRICE); - BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.regionFlag); + BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag); if (!buy.isSold()) { messageBridge.message(sender, "resell-notBought", buy); return; @@ -111,7 +111,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestBuyRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SchematicEventCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SchematicEventCommand.java index 9007f928..aac1b772 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SchematicEventCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SchematicEventCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.command.CommandSender; @@ -15,7 +16,6 @@ import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.standard.EnumParser; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -39,9 +39,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("schemevent") .required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .required(KEY_EVENT_TYPE, EnumParser.enumParser(GeneralRegion.RegionEvent.class)) @@ -61,8 +60,8 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.schematicevents")) { throw new AreaShopCommandException("schemevent-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SellCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SellCommand.java index 9930628b..5fe5e16e 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SellCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SellCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.BuyRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -19,7 +20,6 @@ import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -34,11 +34,11 @@ public class SellCommand extends AreashopCommandBean { @Inject public SellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) { - ParserDescriptor regionParser = + ParserDescriptor, BuyRegion> regionParser = ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class); this.messageBridge = messageBridge; this.fileManager = fileManager; - this.buyRegionFlag = CommandFlag.builder("region").withComponent(regionParser).build(); + this.buyRegionFlag = CommandFlag.>builder("region").withComponent(regionParser).build(); } /** @@ -63,9 +63,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("sell") .flag(this.buyRegionFlag) .handler(this::handleCommand); @@ -84,13 +83,13 @@ public String getHelpKey(CommandSender target) { return null; } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.sell") && !sender.hasPermission("areashop.sellown")) { this.messageBridge.message(sender, "sell-noPermission"); return; } - BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.buyRegionFlag); + BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.buyRegionFlag); if (!buy.isSold()) { messageBridge.message(sender, "sell-notBought", buy); return; @@ -99,7 +98,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestBuyRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetDurationCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetDurationCommand.java index 45c300df..fba52cf6 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetDurationCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetDurationCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.RentRegion; import me.wiefferink.areashop.tools.DurationInput; @@ -18,7 +19,6 @@ import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.StringParser; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.concurrent.TimeUnit; @@ -52,9 +52,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("setduration") .required(KEY_DURATION, StringParser.stringParser()) .flag(this.regionFlag) @@ -66,13 +65,13 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("setduration"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) { this.messageBridge.message(sender, "setduration-noPermission"); return; } - RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, this.regionFlag); + RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag); if (!sender.hasPermission("areashop.setduration") && !(sender instanceof Player player && rent.isLandlord(player.getUniqueId())) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetLandlordCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetLandlordCommand.java index c4ae1204..b30c035e 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetLandlordCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetLandlordCommand.java @@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.OfflinePlayer; @@ -17,7 +18,6 @@ import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -52,9 +52,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("setlandlord") .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .flag(this.regionFlag) @@ -66,12 +65,12 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("setlandlord"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.setlandlord")) { throw new AreaShopCommandException("setlandlord-noPermission"); } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); OfflinePlayer player = context.get(KEY_PLAYER); String playerName = player.getName(); region.setLandlord(player.getUniqueId(), playerName); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetOwnerCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetOwnerCommand.java index 83f8a629..ccdef6a9 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetOwnerCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetOwnerCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -18,7 +19,6 @@ import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.Calendar; @@ -54,9 +54,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("setowner") .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .flag(this.regionFlag) @@ -68,13 +67,13 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("setowner"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) { this.messageBridge.message(sender, "setowner-noPermission"); return; } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); if (region instanceof RentRegion && !sender.hasPermission("areashop.setownerrent")) { this.messageBridge.message(sender, "setowner-noPermissionRent", region); return; diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetPriceCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetPriceCommand.java index 7f5753cc..98f4567c 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetPriceCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetPriceCommand.java @@ -5,6 +5,7 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -18,7 +19,6 @@ import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.StringParser; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -49,9 +49,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("setprice") .required(KEY_PRICE, StringParser.stringParser()) .flag(this.regionFlag) @@ -63,13 +62,13 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("setprice"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) { this.messageBridge.message(sender, "setprice-noPermission"); return; } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); if (!sender.hasPermission("areashop.setprice") && !(sender instanceof Player player && region.isLandlord(player.getUniqueId()))) { this.messageBridge.message(sender, "setprice-noLandlord", region); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetRestoreCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetRestoreCommand.java index 7812f749..4ea02842 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetRestoreCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetRestoreCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.command.CommandSender; @@ -18,7 +19,6 @@ import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.standard.StringParser; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.Collections; @@ -56,9 +56,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("setrestore") .required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .required(KEY_RESTORE, StringParser.stringParser(), this::suggestRestoreType) @@ -71,8 +70,8 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("setrestore"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.setrestore")) { throw new AreaShopCommandException("setrestore-noPermission"); } @@ -101,7 +100,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestRestoreType( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); @@ -113,7 +112,7 @@ private CompletableFuture> suggestRestoreType( } private CompletableFuture> suggestSchematicProfiles( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { ConfigurationSection schemProfiles = fileManager.getConfig().getConfigurationSection("schematicProfiles"); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTeleportCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTeleportCommand.java index e9482ba0..297ff883 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTeleportCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTeleportCommand.java @@ -7,6 +7,8 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -19,7 +21,6 @@ import org.incendo.cloud.bean.CommandProperties; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.parser.flag.CommandFlag; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -65,11 +66,10 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("settp") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .flag(this.regionFlag) .handler(this::handleCommand); } @@ -79,13 +79,13 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("settp"); } - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("areashop.setteleport") && !player.hasPermission("areashop.setteleportall")) { this.messageBridge.message(player, "setteleport-noPermission"); return; } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, player, this.regionFlag); boolean owner; if (region instanceof RentRegion rentRegion) { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java index 3f1f7985..1f4e228b 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/SetTransferCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.command.CommandSender; @@ -16,7 +17,6 @@ import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.BooleanParser; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -49,9 +49,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("settransfer") .required(KEY_ENABLED, BooleanParser.booleanParser(true)) .flag(this.regionFlag) @@ -63,12 +62,12 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("settransfer"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.settransfer")) { throw new AreaShopCommandException("settransfer-noPermission"); } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); boolean enabled = context.get(KEY_ENABLED); region.setTransferEnabled(enabled); messageBridge.message(sender, "settransfer-success", enabled, region); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/StackCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/StackCommand.java index 657d3e77..0e76ca36 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/StackCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/StackCommand.java @@ -7,6 +7,8 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.events.ask.AddingRegionEvent; import me.wiefferink.areashop.interfaces.WorldEditInterface; import me.wiefferink.areashop.interfaces.WorldEditSelection; @@ -108,11 +110,10 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("stack") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_AMOUNT, IntegerParser.integerParser(0)) .required(KEY_GAP, IntegerParser.integerParser(0)) .required(KEY_NAME, StringParser.stringParser()) @@ -127,8 +128,8 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("stack"); } - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("areashop.stack")) { throw new AreaShopCommandException("stack-noPermission"); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/StopResellCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/StopResellCommand.java index 49155139..5e5efd82 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/StopResellCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/StopResellCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.BuyRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; @@ -19,7 +20,6 @@ import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -35,11 +35,11 @@ public class StopResellCommand extends AreashopCommandBean { @Inject public StopResellCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) { - ParserDescriptor regionParser = + ParserDescriptor, BuyRegion> regionParser = ParserDescriptor.of(new BuyRegionParser<>(fileManager, this::suggestBuyRegions), BuyRegion.class); this.messageBridge = messageBridge; this.fileManager = fileManager; - this.regionFlag = CommandFlag.builder("region") + this.regionFlag = CommandFlag.>builder("region") .withComponent(regionParser) .build(); } @@ -57,9 +57,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("stopresell") .flag(this.regionFlag) .handler(this::handleCommand); @@ -70,14 +69,14 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("stopresell"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.stopresell") && !sender.hasPermission("areashop.stopresellall")) { this.messageBridge.message(sender, "stopresell-noPermissionOther"); return; } - BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, this.regionFlag); + BuyRegion buy = RegionParseUtil.getOrParseBuyRegion(context, sender, this.regionFlag); if (!buy.isInResellingMode()) { this.messageBridge.message(sender, "stopresell-notResell", buy); return; @@ -100,7 +99,7 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestBuyRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TeleportCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TeleportCommand.java index bc8db459..56952e3e 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TeleportCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TeleportCommand.java @@ -5,6 +5,8 @@ import me.wiefferink.areashop.MessageBridge; import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.command.CommandSender; @@ -15,7 +17,6 @@ import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.flag.CommandFlag; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -65,11 +66,10 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("tp", "teleport") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) .handler(this::handleCommand); } @@ -79,8 +79,8 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("teleport", "tp"); } - private void handleCommand(@Nonnull CommandContext context) { - Player player = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player player = context.sender().sender(); if (!player.hasPermission("areashop.teleport") && !player.hasPermission("areashop.teleportall") && !player.hasPermission( "areashop.teleportavailable") && !player.hasPermission("areashop.teleportavailablesign") && !player.hasPermission( "areashop.teleportsign") && !player.hasPermission("areashop.teleportsignall") && !player.hasPermission( diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ToggleHomeCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ToggleHomeCommand.java index ef8a8b9d..80996e99 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/ToggleHomeCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/ToggleHomeCommand.java @@ -7,6 +7,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.GeneralRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.features.homeaccess.HomeAccessFeature; import me.wiefferink.areashop.features.homeaccess.HomeAccessType; import me.wiefferink.areashop.managers.IFileManager; @@ -24,7 +25,6 @@ import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.EnumParser; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -43,9 +43,9 @@ public final class ToggleHomeCommand extends AreashopCommandBean { public ToggleHomeCommand(@Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager) { this.messageBridge = messageBridge; this.fileManager = fileManager; - this.regionFlag = CommandFlag.builder("region") + this.regionFlag = CommandFlag.>builder("region") .withComponent( - new CommandComponent.Builder() + CommandComponent., GeneralRegion>builder() .name("region") .description(Description.EMPTY) .valueType(GeneralRegion.class) @@ -69,9 +69,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("togglehome") .required(KEY_ACCESS_TYPE, EnumParser.enumParser(HomeAccessType.class)) .flag(this.regionFlag) @@ -83,13 +82,13 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("togglehome"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.togglehome")) { throw new AreaShopCommandException("togglehome-noPermission"); } final HomeAccessType accessType = context.get(KEY_ACCESS_TYPE); - final GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + final GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); if (!(sender instanceof Player) && !sender.hasPermission("sethome.control.other")) { return; } @@ -101,11 +100,11 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); - CommandSender sender = context.sender(); + CommandSender sender = context.sender().sender(); Stream regions; if (sender.hasPermission("sethome.control.other")) { regions = this.fileManager.getRegionsRef().stream(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java index 9418c60e..88996058 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/TransferCommand.java @@ -8,6 +8,8 @@ import me.wiefferink.areashop.commands.util.GeneralRegionParser; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.ValidatedOfflinePlayerParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import org.bukkit.OfflinePlayer; @@ -22,7 +24,6 @@ import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -43,11 +44,11 @@ public TransferCommand( @Nonnull MessageBridge messageBridge, @Nonnull IFileManager fileManager ) { - ParserDescriptor regionParser = + ParserDescriptor regionParser = ParserDescriptor.of(new GeneralRegionParser<>(fileManager, this::suggestRegions), GeneralRegion.class); this.messageBridge = messageBridge; this.fileManager = fileManager; - this.regionFlag = CommandFlag.builder("region") + this.regionFlag = CommandFlag.builder("region") .withComponent(regionParser) .build(); } @@ -65,11 +66,10 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("transfer") - .senderType(Player.class) + .senderType(PlayerCommandSource.class) .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) .flag(this.regionFlag) .handler(this::handleCommand); @@ -80,12 +80,12 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("transfer"); } - private void handleCommand(@Nonnull CommandContext context) { - Player sender = context.sender(); + private void handleCommand(@Nonnull CommandContext context) { + Player sender = context.sender().sender(); if (!sender.hasPermission("areashop.transfer")) { throw new AreaShopCommandException("transfer-noPermission"); } - GeneralRegion region = RegionParseUtil.getOrParseRegion(context, this.regionFlag); + GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag); if (!region.isTransferEnabled()) { throw new AreaShopCommandException("transfer-disabled"); } @@ -124,11 +124,11 @@ private void handleCommand(@Nonnull CommandContext context) { } private CompletableFuture> suggestRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext context, @Nonnull CommandInput input ) { String text = input.peekString(); - UUID uuid = context.sender().getUniqueId(); + UUID uuid = context.sender().sender().getUniqueId(); List suggestions = this.fileManager.getRegions() .stream() .filter(region -> region.isOwner(uuid) || region.isLandlord(uuid)) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/UnrentCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/UnrentCommand.java index 5470a1b8..6b0c86d9 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/UnrentCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/UnrentCommand.java @@ -6,6 +6,7 @@ import me.wiefferink.areashop.commands.util.AreashopCommandBean; import me.wiefferink.areashop.commands.util.RegionParseUtil; import me.wiefferink.areashop.commands.util.RentRegionParser; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.RentRegion; @@ -19,7 +20,6 @@ import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import java.util.List; @@ -32,10 +32,10 @@ public class UnrentCommand extends AreashopCommandBean { @Inject public UnrentCommand(@Nonnull IFileManager fileManager) { - ParserDescriptor regionParser = + ParserDescriptor, RentRegion> regionParser = ParserDescriptor.of(new RentRegionParser<>(fileManager, this::suggestRegions), RentRegion.class); this.fileManager = fileManager; - this.regionFlag = CommandFlag.builder("region") + this.regionFlag = CommandFlag.>builder("region") .withComponent(regionParser) .build(); } @@ -70,9 +70,8 @@ public String stringDescription() { return null; } - @NotNull @Override - protected Command.Builder configureCommand(@NotNull Command.Builder builder) { + protected Command.Builder> configureCommand(Command.Builder> builder) { return builder.literal("unrent") .flag(this.regionFlag) .handler(this::handleCommand); @@ -83,12 +82,12 @@ protected Command.Builder configureCommand(@NotNull Com return CommandProperties.of("unrent"); } - private void handleCommand(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); + private void handleCommand(@Nonnull CommandContext> context) { + CommandSender sender = context.sender().sender(); if (!sender.hasPermission("areashop.unrent") && !sender.hasPermission("areashop.unrentown")) { throw new AreaShopCommandException("unrent-noPermission"); } - RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, this.regionFlag); + RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag); if (!rent.isRented()) { throw new AreaShopCommandException("unrent-notRented", rent); } @@ -97,7 +96,7 @@ private void handleCommand(@Nonnull CommandContext context) { @Nonnull private CompletableFuture> suggestRegions( - @Nonnull CommandContext context, + @Nonnull CommandContext> context, @Nonnull CommandInput input ) { String text = input.peekString(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommandBean.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommandBean.java index 59abdb60..8dfb7439 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommandBean.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommandBean.java @@ -1,6 +1,6 @@ package me.wiefferink.areashop.commands.util; -import org.bukkit.command.CommandSender; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import org.incendo.cloud.Command; import org.incendo.cloud.bean.CommandBean; import org.incendo.cloud.key.CloudKey; @@ -12,7 +12,7 @@ * An extension of {@link CommandBean} which does extra pre-processing of the commands. * Adapted from KitchenSink */ -public abstract class AreashopCommandBean extends CommandBean implements HelpProvider { +public abstract class AreashopCommandBean extends CommandBean> implements HelpProvider { private boolean requireConfirmation; @@ -21,8 +21,8 @@ protected void withConfirmation() { } @Override - protected final @Nonnull Command.Builder configure( - final @Nonnull Command.Builder builder + protected final @Nonnull Command.Builder> configure( + final @Nonnull Command.Builder> builder ) { return this.configureCommand(builder) .meta(CloudKey.of("bukkit_description", String.class), this.stringDescription()) @@ -44,7 +44,7 @@ protected void withConfirmation() { * @param builder builder to configure * @return the updated builder */ - protected abstract @Nonnull Command.Builder configureCommand( - @Nonnull Command.Builder builder + protected abstract @Nonnull Command.Builder> configureCommand( + @Nonnull Command.Builder> builder ); } \ No newline at end of file diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommands.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommands.java index 90c2be90..97c17f5c 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommands.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/AreashopCommands.java @@ -46,10 +46,10 @@ import me.wiefferink.areashop.commands.ToggleHomeCommand; import me.wiefferink.areashop.commands.TransferCommand; import me.wiefferink.areashop.commands.UnrentCommand; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.CommandSourceMapper; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; -import org.incendo.cloud.SenderMapper; -import org.incendo.cloud.bukkit.CloudBukkitCapabilities; import org.incendo.cloud.exception.ArgumentParseException; import org.incendo.cloud.exception.CommandExecutionException; import org.incendo.cloud.exception.InvalidCommandSenderException; @@ -115,7 +115,7 @@ public class AreashopCommands { private final MessageBridge messageBridge; private final Injector injector; - private final PaperCommandManager commandManager; + private final PaperCommandManager> commandManager; private final List commands = new ArrayList<>(); private HelpRenderer helpRenderer; @@ -123,11 +123,9 @@ public class AreashopCommands { @Inject AreashopCommands(@Nonnull Injector injector, @Nonnull Plugin plugin, @Nonnull MessageBridge messageBridge) { this.injector = injector; - this.commandManager = new PaperCommandManager<>( - plugin, - ExecutionCoordinator.simpleCoordinator(), - SenderMapper.identity() - ); + this.commandManager = PaperCommandManager.builder(new CommandSourceMapper()) + .executionCoordinator(ExecutionCoordinator.simpleCoordinator()) + .buildOnEnable(plugin); this.messageBridge = messageBridge; } @@ -142,15 +140,12 @@ public void registerCommands() { this.commandManager.command(configuredBuilder); } // Show help by default - this.commandManager.command(builder.handler(context -> showHelp(context.sender()))); + this.commandManager.command(builder.handler(context -> showHelp(context.sender().sender()))); this.helpRenderer = new HelpRenderer(this.messageBridge, this.commands); } private void initCommandManager() { - if (this.commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { - this.commandManager.registerBrigadier(); - } - ExceptionController exceptionController = this.commandManager.exceptionController(); + ExceptionController> exceptionController = this.commandManager.exceptionController(); // We need to unwrap ArgumentParseException because they wrap the custom exception messages exceptionController.registerHandler(ArgumentParseException.class, ExceptionHandler.unwrappingHandler(AreaShopCommandException.class)); @@ -160,7 +155,7 @@ private void initCommandManager() { new InvalidCommandSenderHandler(this.messageBridge)); exceptionController.registerHandler(AreaShopCommandException.class, new ArgumentParseExceptionHandler<>(this.messageBridge)); - var confirmationConfiguration = ConfirmationConfiguration.builder() + var confirmationConfiguration = ConfirmationConfiguration.>builder() .cache(GuavaCache.of(CacheBuilder.newBuilder().build())) .noPendingCommandNotifier(x -> { }) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ArgumentParseExceptionHandler.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ArgumentParseExceptionHandler.java index 746b116c..cc3740ce 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ArgumentParseExceptionHandler.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ArgumentParseExceptionHandler.java @@ -1,13 +1,13 @@ package me.wiefferink.areashop.commands.util; import me.wiefferink.areashop.MessageBridge; -import org.bukkit.command.CommandSender; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; import org.incendo.cloud.exception.handling.ExceptionContext; import org.incendo.cloud.exception.handling.ExceptionHandler; import javax.annotation.Nonnull; -public class ArgumentParseExceptionHandler implements ExceptionHandler { +public class ArgumentParseExceptionHandler> implements ExceptionHandler { private final MessageBridge messageBridge; @@ -17,7 +17,7 @@ public ArgumentParseExceptionHandler(@Nonnull MessageBridge messageBridge) { public static void handleException( @Nonnull MessageBridge messageBridge, - @Nonnull CommandSender sender, + @Nonnull CommandSource sender, @Nonnull AreaShopCommandException exception ) { String key = exception.messageKey(); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/InvalidCommandSenderHandler.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/InvalidCommandSenderHandler.java index 97c7a950..0bdf27e7 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/InvalidCommandSenderHandler.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/InvalidCommandSenderHandler.java @@ -1,8 +1,8 @@ package me.wiefferink.areashop.commands.util; import me.wiefferink.areashop.MessageBridge; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import me.wiefferink.areashop.commands.util.commandsource.CommandSource; +import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.exception.InvalidCommandSenderException; import org.incendo.cloud.exception.handling.ExceptionContext; @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; -public class InvalidCommandSenderHandler implements ExceptionHandler { +public class InvalidCommandSenderHandler implements ExceptionHandler, InvalidCommandSenderException> { private final MessageBridge messageBridge; @@ -19,9 +19,9 @@ public InvalidCommandSenderHandler(@Nonnull MessageBridge messageBridge) { } @Override - public void handle(@NonNull ExceptionContext context) throws Throwable { + public void handle(@NonNull ExceptionContext, InvalidCommandSenderException> context) throws Throwable { InvalidCommandSenderException exception = context.exception(); - if (exception.requiredSender().equals(Player.class)) { + if (exception.requiredSenderTypes().contains(PlayerCommandSource.class)) { this.messageBridge.message(exception.commandSender(), "cmd-onlyByPlayer"); return; } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionCreationUtil.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionCreationUtil.java index 8f54f367..350ef6bf 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionCreationUtil.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionCreationUtil.java @@ -38,16 +38,16 @@ public RegionCreationUtil( } public CompletableFuture createRegion( - @Nonnull CommandContext context, + @Nonnull CommandContext context, + @Nonnull Player sender, @Nonnull CloudKey regionKey ) { - Player player = context.sender(); - World world = player.getWorld(); + World world = sender.getWorld(); String regionName = context.get(regionKey); if (this.fileManager.getRegion(regionName) != null) { return CompletableFuture.failedFuture(new AreaShopCommandException("add-failed", regionName)); } - this.server.dispatchCommand(player, String.format("rg define %s", regionName)); + this.server.dispatchCommand(sender, String.format("rg define %s", regionName)); CompletableFuture future = new CompletableFuture<>(); this.server.getScheduler().runTaskLater(this.plugin, () -> { ProtectedRegion region = this.worldGuardInterface.getRegionManager(world).getRegion(regionName); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionParseUtil.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionParseUtil.java index 584cb952..363abde9 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionParseUtil.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/RegionParseUtil.java @@ -33,10 +33,10 @@ public static CommandFlag createDefault(@Nonnull IFileManager fil @Nonnull public static Collection getOrParseRegionsInSel( - @Nonnull CommandContext context, + @Nonnull CommandContext context, + @Nonnull CommandSender sender, @Nonnull CommandFlag regionFlag ) { - CommandSender sender = context.sender(); if (!(sender instanceof Player player)) { throw new AreaShopCommandException("cmd-weOnlyByPlayer"); } @@ -54,15 +54,15 @@ public static Collection getOrParseRegionsInSel( } @Nonnull - public static GeneralRegion getOrParseRegion( - @Nonnull CommandContext context, + public static GeneralRegion getOrParseRegion( + @Nonnull CommandContext context, + @Nonnull CommandSender sender, @Nonnull CommandFlag flag ) throws AreaShopCommandException { GeneralRegion region = context.flags().get(flag); if (region != null) { return region; } - C sender = context.sender(); if (!(sender instanceof Entity entity)) { throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer"); } @@ -74,21 +74,21 @@ public static GeneralRegion getOrParseRegion( } else if (regions.size() > 1) { errorMessageKey = "cmd-moreRegionsAtLocation"; } else { - return regions.get(0); + return regions.getFirst(); } throw new AreaShopCommandException(errorMessageKey); } @Nonnull - public static GeneralRegion getOrParseRegion( - @Nonnull CommandContext context, + public static GeneralRegion getOrParseRegion( + @Nonnull CommandContext context, + @Nonnull CommandSender sender, @Nonnull CloudKey key ) throws AreaShopCommandException { GeneralRegion region = context.getOrDefault(key, null); if (region != null) { return region; } - C sender = context.sender(); if (!(sender instanceof Entity entity)) { throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer"); } @@ -100,7 +100,7 @@ public static GeneralRegion getOrParseRegion( } else if (regions.size() > 1) { errorMessageKey = "cmd-moreRegionsAtLocation"; } else { - return regions.get(0); + return regions.getFirst(); } throw new AreaShopCommandException(errorMessageKey); } @@ -121,12 +121,14 @@ public static CommandFlag createDefaultRent(@Nonnull IFileManager fi } @Nonnull - public static BuyRegion getOrParseBuyRegion(@Nonnull CommandContext context, CommandFlag flag) { + public static BuyRegion getOrParseBuyRegion( + @Nonnull CommandContext context, + @Nonnull CommandSender sender, + @Nonnull CommandFlag flag) { BuyRegion buyRegion = context.flags().get(flag); if (buyRegion != null) { return buyRegion; } - CommandSender sender = context.sender(); if (!(sender instanceof Player player)) { throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer"); } @@ -136,16 +138,18 @@ public static BuyRegion getOrParseBuyRegion(@Nonnull CommandContext context, CommandFlag flag) { + public static RentRegion getOrParseRentRegion( + @Nonnull CommandContext context, + @Nonnull CommandSender sender, + @Nonnull CommandFlag flag) { RentRegion rentRegion = context.flags().get(flag); if (rentRegion != null) { return rentRegion; } - CommandSender sender = context.sender(); if (!(sender instanceof Player player)) { throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer"); } @@ -155,7 +159,7 @@ public static RentRegion getOrParseRentRegion(@Nonnull CommandContext createDefault(@Nonnull Plugin plugin) { } @Nullable - public static String getOrParseProfile(@Nonnull CommandContext context, + public static String getOrParseProfile(@Nonnull CommandContext context, @Nonnull Plugin plugin) { return getOrParseProfile(context, DEFAULT_FLAG, plugin); } @Nullable public static String getOrParseProfile( - @Nonnull CommandContext context, + @Nonnull CommandContext context, @Nonnull CommandFlag flag, @Nonnull Plugin plugin ) throws AreaShopCommandException { diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ValidatedOfflinePlayerParser.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ValidatedOfflinePlayerParser.java index 66b37842..4e0b59b9 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ValidatedOfflinePlayerParser.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/ValidatedOfflinePlayerParser.java @@ -13,6 +13,8 @@ import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.suggestion.BlockingSuggestionProvider; +import java.util.Collections; + public class ValidatedOfflinePlayerParser implements ArgumentParser, BlockingSuggestionProvider.Strings { public static ParserDescriptor validatedOfflinePlayerParser() { @@ -50,6 +52,9 @@ public static ParserDescriptor validatedOfflinePlayerParse final @NonNull CommandContext commandContext, final @NonNull CommandInput input ) { + if (!commandContext.contains(BukkitCommandContextKeys.BUKKIT_COMMAND_SENDER)) { + return Collections.emptyList(); + } final CommandSender sender = commandContext.get(BukkitCommandContextKeys.BUKKIT_COMMAND_SENDER); return Bukkit.getOnlinePlayers().stream() .filter(onlinePlayer -> !(sender instanceof Player player && !((Player) sender).canSee(player))) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldFlagUtil.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldFlagUtil.java index 95383535..1311f4b8 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldFlagUtil.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldFlagUtil.java @@ -19,20 +19,21 @@ private WorldFlagUtil() { } @Nonnull - public static World parseOrDetectWorld(@Nonnull CommandContext context) { - return parseOrDetectWorld(context, DEFAULT_WORLD_FLAG); + public static World parseOrDetectWorld(@Nonnull CommandContext context, @Nonnull Entity sender) { + return parseOrDetectWorld(context, sender, DEFAULT_WORLD_FLAG); } @Nonnull - public static World parseOrDetectWorld( - @Nonnull CommandContext context, + public static World parseOrDetectWorld( + @Nonnull CommandContext context, + @Nonnull Entity sender, @Nonnull CommandFlag flag ) { World world = context.flags().get(flag); if (world != null) { return world; } - return context.sender().getWorld(); + return sender.getWorld(); } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldGuardRegionParser.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldGuardRegionParser.java index 9484f2f1..c4a84276 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldGuardRegionParser.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/WorldGuardRegionParser.java @@ -2,6 +2,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import me.wiefferink.areashop.commands.util.commandsource.EntityCommandSource; import me.wiefferink.areashop.interfaces.WorldGuardInterface; import org.bukkit.World; import org.bukkit.entity.Entity; @@ -17,7 +18,7 @@ import javax.annotation.Nonnull; import java.util.Collections; -public class WorldGuardRegionParser implements ArgumentParser { +public class WorldGuardRegionParser implements ArgumentParser { private final WorldGuardInterface worldGuardInterface; private final CommandFlag worldFlag; @@ -29,7 +30,7 @@ public WorldGuardRegionParser( this.worldGuardInterface = worldGuardInterface; } - public static ParserDescriptor worldGuardRegionParser( + public static ParserDescriptor worldGuardRegionParser( @Nonnull CommandFlag worldFlag, @Nonnull WorldGuardInterface worldGuardInterface ) { @@ -39,7 +40,8 @@ public static ParserDescriptor worldGuard @Override public @Nonnull ArgumentParseResult parse(@Nonnull CommandContext commandContext, @Nonnull CommandInput commandInput) { - World world = WorldFlagUtil.parseOrDetectWorld(commandContext, worldFlag); + Entity sender = commandContext.sender().sender(); + World world = WorldFlagUtil.parseOrDetectWorld(commandContext, sender, worldFlag); String regionName = commandInput.peekString(); RegionManager regionManager = this.worldGuardInterface.getRegionManager(world); if (regionManager == null) { @@ -57,7 +59,7 @@ public static ParserDescriptor worldGuard @Override public @Nonnull SuggestionProvider suggestionProvider() { return SuggestionProvider.blockingStrings((commandContext, input) -> { - C sender = commandContext.sender(); + Entity sender = commandContext.sender().sender(); if (!(sender instanceof Player player)) { return Collections.emptyList(); } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSource.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSource.java new file mode 100644 index 00000000..2f5c8e30 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSource.java @@ -0,0 +1,16 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.command.CommandSender; + +import javax.annotation.Nonnull; + +public interface CommandSource { + + @Nonnull + CommandSourceStack sourceStack(); + + @Nonnull + C sender(); + +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceMapper.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceMapper.java new file mode 100644 index 00000000..e12eb3c4 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceMapper.java @@ -0,0 +1,27 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.SenderMapper; + +public class CommandSourceMapper implements SenderMapper> { + + @Override + public @NonNull CommandSource map(@NonNull CommandSourceStack base) { + CommandSender sender = base.getSender(); + if (sender instanceof Player) { + return new PlayerCommandSource(base); + } else if (sender instanceof Entity) { + return new EntityCommandSource(base); + } + return new GenericCommandSource(base); + } + + @Override + public @NonNull CommandSourceStack reverse(@NonNull CommandSource mapped) { + return mapped.sourceStack(); + } +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceWrapper.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceWrapper.java new file mode 100644 index 00000000..d036ce18 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/CommandSourceWrapper.java @@ -0,0 +1,15 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.command.CommandSender; + +import javax.annotation.Nonnull; + +public record CommandSourceWrapper(@Nonnull CommandSourceStack commandSourceStack) { + + @Nonnull + public CommandSender sender() { + return commandSourceStack().getSender(); + } + +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/EntityCommandSource.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/EntityCommandSource.java new file mode 100644 index 00000000..efcf16ee --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/EntityCommandSource.java @@ -0,0 +1,23 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +public sealed class EntityCommandSource extends GenericCommandSource permits PlayerCommandSource { + + public EntityCommandSource(@Nonnull CommandSourceStack sourceStack) { + super(sourceStack); + if (!(sourceStack.getSender() instanceof Entity)) { + throw new IllegalArgumentException("Source stack sender is not an entity!"); + } + } + + @NotNull + @Override + public Entity sender() { + return (Entity) super.sender(); + } +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/GenericCommandSource.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/GenericCommandSource.java new file mode 100644 index 00000000..a56aa539 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/GenericCommandSource.java @@ -0,0 +1,31 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +public class GenericCommandSource implements CommandSource { + + private final CommandSourceStack sourceStack; + + private final CommandSender sender; + + public GenericCommandSource(@Nonnull CommandSourceStack sourceStack) { + this.sourceStack = sourceStack; + this.sender = sourceStack.getSender(); + } + + @NotNull + @Override + public final CommandSourceStack sourceStack() { + return this.sourceStack; + } + + @NotNull + @Override + public CommandSender sender() { + return this.sender; + } +} diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/PlayerCommandSource.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/PlayerCommandSource.java new file mode 100644 index 00000000..89fe2cd2 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/util/commandsource/PlayerCommandSource.java @@ -0,0 +1,23 @@ +package me.wiefferink.areashop.commands.util.commandsource; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +public final class PlayerCommandSource extends EntityCommandSource { + + public PlayerCommandSource(@Nonnull CommandSourceStack sourceStack) { + super(sourceStack); + if (!(sourceStack.getSender() instanceof Player)) { + throw new IllegalArgumentException("Source stack sender is not a player!"); + } + } + + @Override + public @NotNull Player sender() { + return (Player) super.sender(); + } +}