From d66b79ba6789db06e90d87a1ab08ec9914e72e4d Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:03:05 +1000 Subject: [PATCH] Refactor the info command into 3 distinct subcommands --- .../areashop/commands/InfoCommand.java | 278 +----------------- .../areashop/commands/InfoPlayerCommand.java | 97 ++++++ .../areashop/commands/InfoRegionCommand.java | 275 +++++++++++++++++ .../commands/util/AreashopCommands.java | 4 + 4 files changed, 379 insertions(+), 275 deletions(-) create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java create mode 100644 AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java 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 203df427..691f70f1 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoCommand.java @@ -1,46 +1,30 @@ package me.wiefferink.areashop.commands; -import io.github.bakedlibs.dough.blocks.BlockPosition; import jakarta.inject.Inject; import jakarta.inject.Singleton; import me.wiefferink.areashop.MessageBridge; -import me.wiefferink.areashop.adapters.platform.OfflinePlayerHelper; -import me.wiefferink.areashop.commands.util.AreaShopCommandException; import me.wiefferink.areashop.commands.util.AreashopCommandBean; -import me.wiefferink.areashop.commands.util.ParserWrapper; import me.wiefferink.areashop.commands.util.RegionGroupParser; -import me.wiefferink.areashop.commands.util.RegionInfoUtil; import me.wiefferink.areashop.managers.IFileManager; import me.wiefferink.areashop.regions.BuyRegion; import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.RegionGroup; import me.wiefferink.areashop.regions.RentRegion; -import me.wiefferink.areashop.tools.BukkitSchedulerExecutor; import me.wiefferink.areashop.tools.SimpleMessageBridge; -import me.wiefferink.areashop.tools.Utils; import me.wiefferink.interactivemessenger.processing.Message; -import org.bukkit.Server; import org.bukkit.command.CommandSender; -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.context.CommandInput; import org.incendo.cloud.key.CloudKey; import org.incendo.cloud.parser.ParserDescriptor; import org.incendo.cloud.parser.flag.CommandFlag; import org.incendo.cloud.parser.standard.EnumParser; import org.incendo.cloud.parser.standard.IntegerParser; -import org.incendo.cloud.parser.standard.StringParser; -import org.incendo.cloud.suggestion.Suggestion; import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; @Singleton @@ -53,33 +37,20 @@ public class InfoCommand extends AreashopCommandBean { private final MessageBridge messageBridge; private final IFileManager fileManager; - private final Server server; - private final OfflinePlayerHelper offlinePlayerHelper; - private final BukkitSchedulerExecutor executor; private final CommandFlag filterGroupFlag; - private final CommandFlag filterArgFlag; @Inject public InfoCommand( @Nonnull MessageBridge messageBridge, - @Nonnull IFileManager fileManager, - @Nonnull Server server, - @Nonnull OfflinePlayerHelper offlinePlayerHelper, - @Nonnull BukkitSchedulerExecutor executor + @Nonnull IFileManager fileManager ) { this.messageBridge = messageBridge; this.fileManager = fileManager; - this.server = server; this.filterGroupFlag = CommandFlag.builder("group") .withComponent(ParserDescriptor.of(new RegionGroupParser<>(fileManager, "info-noFiltergroup"), RegionGroup.class)) .build(); - this.filterArgFlag = CommandFlag.builder("filterArg") - .withComponent(ParserWrapper.wrap(StringParser.stringParser(), this::suggestFilterArg)) - .build(); - this.offlinePlayerHelper = offlinePlayerHelper; - this.executor = executor; } @Override @@ -101,7 +72,6 @@ public String getHelpKey(CommandSender target) { .required(KEY_TYPE, EnumParser.enumParser(RegionStateFilterType.class)) .flag(FLAG_PAGE) .flag(this.filterGroupFlag) - .flag(filterArgFlag) .handler(this::handleCommand); } @@ -110,23 +80,6 @@ public String getHelpKey(CommandSender target) { return CommandProperties.of("info"); } - private CompletableFuture> suggestFilterArg( - @Nonnull CommandContext context, - @Nonnull CommandInput commandInput) { - Optional filterType = context.optional(KEY_TYPE); - if (filterType.isEmpty()) { - return CompletableFuture.completedFuture(Collections.emptyList()); - } - String text = commandInput.peekString(); - Stream stream = switch (filterType.get()) { - case PLAYER -> this.server.getOnlinePlayers().stream().map(Player::getName); - case REGION -> this.fileManager.getRegionNames().stream(); - default -> Stream.empty(); - }; - List suggestions = stream.filter(value -> value.startsWith(text)).map(Suggestion::suggestion).toList(); - return CompletableFuture.completedFuture(suggestions); - } - private void handleCommand(@Nonnull CommandContext context) { CommandSender sender = context.sender(); if (!sender.hasPermission("areashop.info")) { @@ -134,13 +87,7 @@ private void handleCommand(@Nonnull CommandContext context) { return; } RegionStateFilterType filterType = context.get(KEY_TYPE); - if (filterType == RegionStateFilterType.REGION) { - processWithRegionFilter(context); - } else if (filterType == RegionStateFilterType.PLAYER) { - processWithPlayerFilter(context); - } else { - processOtherFilters(context, filterType); - } + processOtherFilters(context, filterType); } private void processOtherFilters(@Nonnull CommandContext context, @@ -161,7 +108,6 @@ private void processOtherFilters(@Nonnull CommandContext context, } yield regions.stream(); } - default -> Stream.empty(); }; String header = switch (filterType) { case ALL -> "info-allHeader"; @@ -171,7 +117,6 @@ private void processOtherFilters(@Nonnull CommandContext context, case FORSALE -> "info-forsaleHeader"; case RESELLING -> "info-resellingHeader"; case NOGROUP -> "info-nogroupHeader"; - default -> ""; }; String baseCommand = switch (filterType) { case ALL -> "info all"; @@ -181,225 +126,10 @@ private void processOtherFilters(@Nonnull CommandContext context, case FORSALE -> "info forsale"; case RESELLING -> "info reselling"; case NOGROUP -> "info nogroup"; - default -> ""; }; showSortedPagedList(context.sender(), toShow, filterGroup, header, page, baseCommand); } - private void processWithPlayerFilter(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); - Optional optionalArg = context.flags().getValue(filterArgFlag); - if (optionalArg.isEmpty()) { - throw new AreaShopCommandException("info-playerHelp"); - } - String playerName = optionalArg.get(); - this.offlinePlayerHelper.lookupOfflinePlayerAsync(playerName).thenAcceptAsync(offlinePlayer -> { - if (!offlinePlayer.hasPlayedBefore()) { - // Don't throw an exception here, just send the error message directly - this.messageBridge.message(sender, "me-noPlayer", playerName); - return; - } - RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer); - }, executor); - - } - - private void processWithRegionFilter(@Nonnull CommandContext context) { - CommandSender sender = context.sender(); - // Region info - Optional optionalArg = context.flags().getValue(filterArgFlag); - GeneralRegion region; - if (optionalArg.isPresent()) { - region = this.fileManager.getRegion(optionalArg.get()); - if (region == null) { - throw new AreaShopCommandException("info-regionNotExisting", optionalArg); - } - } else if (sender instanceof Player player) { - // get the region by location - List regions = Utils.getImportantRegions(player.getLocation()); - if (regions.isEmpty()) { - throw new AreaShopCommandException("cmd-noRegionsAtLocation"); - } else if (regions.size() > 1) { - throw new AreaShopCommandException("cmd-moreRegionsAtLocation"); - } else { - region = regions.get(0); - } - } else { - throw new AreaShopCommandException("cmd-automaticRegionOnlyByPlayer"); - } - if (region instanceof RentRegion rent) { - handleRent(sender, rent); - } else if (region instanceof BuyRegion buy) { - handleBuy(sender, buy); - } - } - - private void handleBuy(@Nonnull CommandSender sender, @Nonnull BuyRegion buy) { - messageBridge.message(sender, "info-regionHeaderBuy", buy); - if (buy.isSold()) { - if (buy.isInResellingMode()) { - messageBridge.messageNoPrefix(sender, "info-regionReselling", buy); - messageBridge.messageNoPrefix(sender, "info-regionReselPrice", buy); - } else { - messageBridge.messageNoPrefix(sender, "info-regionBought", buy); - } - // Money back - if (!buy.getBooleanSetting("buy.sellDisabled")) { - if (SellCommand.canUse(sender, buy)) { - messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuyClick", buy); - } else { - messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuy", buy); - } - } - // Friends - if (!buy.getFriendsFeature().getFriendNames().isEmpty()) { - String messagePart = "info-friend"; - if (DelFriendCommand.canUse(sender, buy)) { - messagePart = "info-friendRemove"; - } - messageBridge.messageNoPrefix(sender, - "info-regionFriends", - buy, - Utils.combinedMessage(buy.getFriendsFeature().getFriendNames(), messagePart)); - } - } else { - messageBridge.messageNoPrefix(sender, "info-regionCanBeBought", buy); - } - if (buy.getLandlord() != null) { - messageBridge.messageNoPrefix(sender, "info-regionLandlord", buy); - } - if (buy.getInactiveTimeUntilSell() != -1) { - messageBridge.messageNoPrefix(sender, "info-regionInactiveSell", buy); - } - // Restoring - if (buy.isRestoreEnabled()) { - messageBridge.messageNoPrefix(sender, "info-regionRestoringBuy", buy); - } - // Restrictions - if (!buy.isSold()) { - if (buy.restrictedToRegion()) { - messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionBuy", buy); - } else if (buy.restrictedToWorld()) { - messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldBuy", buy); - } - } - messageBridge.messageNoPrefix(sender, "info-regionFooterBuy", buy); - } - - private void handleRent(@Nonnull CommandSender sender, @Nonnull RentRegion rent) { - messageBridge.message(sender, "info-regionHeaderRent", rent); - if (rent.isRented()) { - messageBridge.messageNoPrefix(sender, "info-regionRented", rent); - messageBridge.messageNoPrefix(sender, "info-regionExtending", rent); - // Money back - if (UnrentCommand.canUse(sender, rent)) { - messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRentClick", rent); - } else { - messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRent", rent); - } - // Friends - if (!rent.getFriendsFeature().getFriendNames().isEmpty()) { - String messagePart = "info-friend"; - if (DelFriendCommand.canUse(sender, rent)) { - messagePart = "info-friendRemove"; - } - messageBridge.messageNoPrefix(sender, - "info-regionFriends", - rent, - Utils.combinedMessage(rent.getFriendsFeature().getFriendNames(), messagePart)); - } - } else { - messageBridge.messageNoPrefix(sender, "info-regionCanBeRented", rent); - } - if (rent.getLandlordName() != null) { - messageBridge.messageNoPrefix(sender, "info-regionLandlord", rent); - } - // Maximum extends - if (rent.getMaxExtends() != -1) { - if (rent.getMaxExtends() == 0) { - messageBridge.messageNoPrefix(sender, "info-regionNoExtending", rent); - } else if (rent.isRented()) { - messageBridge.messageNoPrefix(sender, "info-regionExtendsLeft", rent); - } else { - messageBridge.messageNoPrefix(sender, "info-regionMaxExtends", rent); - } - } - // If maxExtends is zero it does not make sense to show this message - if (rent.getMaxRentTime() != -1 && rent.getMaxExtends() != 0) { - messageBridge.messageNoPrefix(sender, "info-regionMaxRentTime", rent); - } - if (rent.getInactiveTimeUntilUnrent() != -1) { - messageBridge.messageNoPrefix(sender, "info-regionInactiveUnrent", rent); - } - displayMiscInfo(sender, rent); - // Restoring - if (rent.isRestoreEnabled()) { - messageBridge.messageNoPrefix(sender, "info-regionRestoringRent", rent); - } - // Restrictions - if (!rent.isRented()) { - if (rent.restrictedToRegion()) { - messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent); - } else if (rent.restrictedToWorld()) { - messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent); - } - } - messageBridge.messageNoPrefix(sender, "info-regionFooterRent", rent); - } - - private void displayMiscInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { - displayTeleportInfo(sender, region); - displaySignInfo(sender, region); - displayGroupInfo(sender, region); - } - - private void displayGroupInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {// Groups - if (sender.hasPermission("areashop.groupinfo") && !region.getGroupNames().isEmpty()) { - messageBridge.messageNoPrefix(sender, - "info-regionGroups", - Utils.createCommaSeparatedList(region.getGroupNames())); - } - } - - private void displaySignInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { - // Signs - List signLocations = new ArrayList<>(); - for (BlockPosition location : region.getSignsFeature().signManager().allSignLocations()) { - signLocations.add(Message.fromKey("info-regionSignLocation") - .replacements(location.getWorld().getName(), - location.getX(), - location.getY(), - location.getZ()) - .getPlain()); - } - if (!signLocations.isEmpty()) { - messageBridge.messageNoPrefix(sender, - "info-regionSigns", - Utils.createCommaSeparatedList(signLocations)); - } - } - - private void displayTeleportInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { - // Teleport - Message tp = Message.fromKey("info-prefix"); - boolean foundSomething = false; - if (TeleportCommand.canUse(sender, region)) { - foundSomething = true; - tp.append(Message.fromKey("info-regionTeleport").replacements(region)); - } - if (SetTeleportCommand.canUse(sender, region)) { - if (foundSomething) { - tp.append(", "); - } - foundSomething = true; - tp.append(Message.fromKey("info-setRegionTeleport").replacements(region)); - } - if (foundSomething) { - tp.append("."); - SimpleMessageBridge.send(tp, sender); - } - } - /** * Display a page of a list of regions. @@ -535,9 +265,7 @@ private enum RegionStateFilterType { SOLD, FORSALE, RESELLING, - NOGROUP, - PLAYER, - REGION + NOGROUP } } diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java new file mode 100644 index 00000000..e7a02b41 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoPlayerCommand.java @@ -0,0 +1,97 @@ +package me.wiefferink.areashop.commands; + +import jakarta.inject.Inject; +import jakarta.inject.Singleton; +import me.wiefferink.areashop.MessageBridge; +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.managers.IFileManager; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.incendo.cloud.Command; +import org.incendo.cloud.bean.CommandProperties; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.key.CloudKey; + +import javax.annotation.Nonnull; + +@Singleton +public class InfoPlayerCommand extends AreashopCommandBean { + + private static final CloudKey KEY_PLAYER = CloudKey.of("player", OfflinePlayer.class); + + private final MessageBridge messageBridge; + private final IFileManager fileManager; + + @Inject + public InfoPlayerCommand( + @Nonnull MessageBridge messageBridge, + @Nonnull IFileManager fileManager + ) { + this.messageBridge = messageBridge; + this.fileManager = fileManager; + } + + @Override + public String stringDescription() { + return null; + } + + @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) { + return builder.literal("info").literal("player") + .required(KEY_PLAYER, ValidatedOfflinePlayerParser.validatedOfflinePlayerParser()) + .handler(this::handleCommand); + } + + @Override + protected @Nonnull CommandProperties properties() { + return CommandProperties.of("info region"); + } + + private void handleCommand(@Nonnull CommandContext context) { + CommandSender sender = context.sender(); + if (!sender.hasPermission("areashop.info")) { + messageBridge.message(sender, "info-noPermission"); + return; + } + OfflinePlayer offlinePlayer = context.get(KEY_PLAYER); + RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer); + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java new file mode 100644 index 00000000..26c28c55 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/InfoRegionCommand.java @@ -0,0 +1,275 @@ +package me.wiefferink.areashop.commands; + +import io.github.bakedlibs.dough.blocks.BlockPosition; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; +import me.wiefferink.areashop.MessageBridge; +import me.wiefferink.areashop.commands.util.AreashopCommandBean; +import me.wiefferink.areashop.commands.util.GeneralRegionParser; +import me.wiefferink.areashop.managers.IFileManager; +import me.wiefferink.areashop.regions.BuyRegion; +import me.wiefferink.areashop.regions.GeneralRegion; +import me.wiefferink.areashop.regions.RentRegion; +import me.wiefferink.areashop.tools.SimpleMessageBridge; +import me.wiefferink.areashop.tools.Utils; +import me.wiefferink.interactivemessenger.processing.Message; +import org.bukkit.command.CommandSender; +import org.incendo.cloud.Command; +import org.incendo.cloud.bean.CommandProperties; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.key.CloudKey; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; + +@Singleton +public class InfoRegionCommand extends AreashopCommandBean { + + private static final CloudKey KEY_REGION = CloudKey.of("region", GeneralRegion.class); + + private final MessageBridge messageBridge; + private final IFileManager fileManager; + + @Inject + public InfoRegionCommand( + @Nonnull MessageBridge messageBridge, + @Nonnull IFileManager fileManager + ) { + this.messageBridge = messageBridge; + this.fileManager = fileManager; + } + + @Override + public String stringDescription() { + return null; + } + + @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) { + return builder.literal("info").literal("region") + .required(KEY_REGION, GeneralRegionParser.generalRegionParser(this.fileManager)) + .handler(this::handleCommand); + } + + @Override + protected @Nonnull CommandProperties properties() { + return CommandProperties.of("info region"); + } + + private void handleCommand(@Nonnull CommandContext context) { + CommandSender sender = context.sender(); + if (!sender.hasPermission("areashop.info")) { + messageBridge.message(sender, "info-noPermission"); + return; + } + // Region info + GeneralRegion region = context.get(KEY_REGION); + if (region instanceof RentRegion rent) { + handleRent(sender, rent); + } else if (region instanceof BuyRegion buy) { + handleBuy(sender, buy); + } + } + + private void handleBuy(@Nonnull CommandSender sender, @Nonnull BuyRegion buy) { + messageBridge.message(sender, "info-regionHeaderBuy", buy); + if (buy.isSold()) { + if (buy.isInResellingMode()) { + messageBridge.messageNoPrefix(sender, "info-regionReselling", buy); + messageBridge.messageNoPrefix(sender, "info-regionReselPrice", buy); + } else { + messageBridge.messageNoPrefix(sender, "info-regionBought", buy); + } + // Money back + if (!buy.getBooleanSetting("buy.sellDisabled")) { + if (SellCommand.canUse(sender, buy)) { + messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuyClick", buy); + } else { + messageBridge.messageNoPrefix(sender, "info-regionMoneyBackBuy", buy); + } + } + // Friends + if (!buy.getFriendsFeature().getFriendNames().isEmpty()) { + String messagePart = "info-friend"; + if (DelFriendCommand.canUse(sender, buy)) { + messagePart = "info-friendRemove"; + } + messageBridge.messageNoPrefix(sender, + "info-regionFriends", + buy, + Utils.combinedMessage(buy.getFriendsFeature().getFriendNames(), messagePart)); + } + } else { + messageBridge.messageNoPrefix(sender, "info-regionCanBeBought", buy); + } + if (buy.getLandlord() != null) { + messageBridge.messageNoPrefix(sender, "info-regionLandlord", buy); + } + if (buy.getInactiveTimeUntilSell() != -1) { + messageBridge.messageNoPrefix(sender, "info-regionInactiveSell", buy); + } + // Restoring + if (buy.isRestoreEnabled()) { + messageBridge.messageNoPrefix(sender, "info-regionRestoringBuy", buy); + } + // Restrictions + if (!buy.isSold()) { + if (buy.restrictedToRegion()) { + messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionBuy", buy); + } else if (buy.restrictedToWorld()) { + messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldBuy", buy); + } + } + messageBridge.messageNoPrefix(sender, "info-regionFooterBuy", buy); + } + + private void handleRent(@Nonnull CommandSender sender, @Nonnull RentRegion rent) { + messageBridge.message(sender, "info-regionHeaderRent", rent); + if (rent.isRented()) { + messageBridge.messageNoPrefix(sender, "info-regionRented", rent); + messageBridge.messageNoPrefix(sender, "info-regionExtending", rent); + // Money back + if (UnrentCommand.canUse(sender, rent)) { + messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRentClick", rent); + } else { + messageBridge.messageNoPrefix(sender, "info-regionMoneyBackRent", rent); + } + // Friends + if (!rent.getFriendsFeature().getFriendNames().isEmpty()) { + String messagePart = "info-friend"; + if (DelFriendCommand.canUse(sender, rent)) { + messagePart = "info-friendRemove"; + } + messageBridge.messageNoPrefix(sender, + "info-regionFriends", + rent, + Utils.combinedMessage(rent.getFriendsFeature().getFriendNames(), messagePart)); + } + } else { + messageBridge.messageNoPrefix(sender, "info-regionCanBeRented", rent); + } + if (rent.getLandlordName() != null) { + messageBridge.messageNoPrefix(sender, "info-regionLandlord", rent); + } + // Maximum extends + if (rent.getMaxExtends() != -1) { + if (rent.getMaxExtends() == 0) { + messageBridge.messageNoPrefix(sender, "info-regionNoExtending", rent); + } else if (rent.isRented()) { + messageBridge.messageNoPrefix(sender, "info-regionExtendsLeft", rent); + } else { + messageBridge.messageNoPrefix(sender, "info-regionMaxExtends", rent); + } + } + // If maxExtends is zero it does not make sense to show this message + if (rent.getMaxRentTime() != -1 && rent.getMaxExtends() != 0) { + messageBridge.messageNoPrefix(sender, "info-regionMaxRentTime", rent); + } + if (rent.getInactiveTimeUntilUnrent() != -1) { + messageBridge.messageNoPrefix(sender, "info-regionInactiveUnrent", rent); + } + displayMiscInfo(sender, rent); + // Restoring + if (rent.isRestoreEnabled()) { + messageBridge.messageNoPrefix(sender, "info-regionRestoringRent", rent); + } + // Restrictions + if (!rent.isRented()) { + if (rent.restrictedToRegion()) { + messageBridge.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent); + } else if (rent.restrictedToWorld()) { + messageBridge.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent); + } + } + messageBridge.messageNoPrefix(sender, "info-regionFooterRent", rent); + } + + private void displayMiscInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { + displayTeleportInfo(sender, region); + displaySignInfo(sender, region); + displayGroupInfo(sender, region); + } + + private void displayGroupInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) {// Groups + if (sender.hasPermission("areashop.groupinfo") && !region.getGroupNames().isEmpty()) { + messageBridge.messageNoPrefix(sender, + "info-regionGroups", + Utils.createCommaSeparatedList(region.getGroupNames())); + } + } + + private void displaySignInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { + // Signs + List signLocations = new ArrayList<>(); + for (BlockPosition location : region.getSignsFeature().signManager().allSignLocations()) { + signLocations.add(Message.fromKey("info-regionSignLocation") + .replacements(location.getWorld().getName(), + location.getX(), + location.getY(), + location.getZ()) + .getPlain()); + } + if (!signLocations.isEmpty()) { + messageBridge.messageNoPrefix(sender, + "info-regionSigns", + Utils.createCommaSeparatedList(signLocations)); + } + } + + private void displayTeleportInfo(@Nonnull CommandSender sender, @Nonnull GeneralRegion region) { + // Teleport + Message tp = Message.fromKey("info-prefix"); + boolean foundSomething = false; + if (TeleportCommand.canUse(sender, region)) { + foundSomething = true; + tp.append(Message.fromKey("info-regionTeleport").replacements(region)); + } + if (SetTeleportCommand.canUse(sender, region)) { + if (foundSomething) { + tp.append(", "); + } + foundSomething = true; + tp.append(Message.fromKey("info-setRegionTeleport").replacements(region)); + } + if (foundSomething) { + tp.append("."); + SimpleMessageBridge.send(tp, sender); + } + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + 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 05dbd98e..90c2be90 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 @@ -20,6 +20,8 @@ import me.wiefferink.areashop.commands.HelpCommand; import me.wiefferink.areashop.commands.InfoBaseCommand; import me.wiefferink.areashop.commands.InfoCommand; +import me.wiefferink.areashop.commands.InfoPlayerCommand; +import me.wiefferink.areashop.commands.InfoRegionCommand; import me.wiefferink.areashop.commands.LinkSignsCommand; import me.wiefferink.areashop.commands.MeCommand; import me.wiefferink.areashop.commands.MessageCommand; @@ -82,6 +84,8 @@ public class AreashopCommands { HelpCommand.class, InfoCommand.class, InfoBaseCommand.class, + InfoPlayerCommand.class, + InfoRegionCommand.class, LinkSignsCommand.class, MeCommand.class, MessageCommand.class,