From e5d190d81eeaa994e16f4040e7fa07919cd953ff Mon Sep 17 00:00:00 2001 From: Andrew Wong <42793301+md5sha256@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:50:39 +1000 Subject: [PATCH] Revert "Remove argument from me command" This reverts commit b631cfc89daf4e3e5077a39e831a1a716d4a5d8a. --- .../areashop/commands/MeCommand.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 a7705d55..37f77d4d 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/MeCommand.java @@ -3,18 +3,22 @@ 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.OfflinePlayerParser; import me.wiefferink.areashop.commands.util.RegionInfoUtil; 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.tools.BukkitSchedulerExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; 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.incendo.cloud.key.CloudKey; import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; @@ -22,16 +26,23 @@ @Singleton public class MeCommand extends AreashopCommandBean { + private static final CloudKey KEY_PLAYER = CloudKey.of("player", String.class); private final IFileManager fileManager; private final MessageBridge messageBridge; + private final OfflinePlayerHelper offlinePlayerHelper; + private final BukkitSchedulerExecutor executor; @Inject public MeCommand( @Nonnull MessageBridge messageBridge, - @Nonnull IFileManager fileManager + @Nonnull IFileManager fileManager, + @Nonnull OfflinePlayerHelper offlinePlayerHelper, + @Nonnull BukkitSchedulerExecutor executor ) { this.messageBridge = messageBridge; this.fileManager = fileManager; + this.offlinePlayerHelper = offlinePlayerHelper; + this.executor = executor; } @Override @@ -43,6 +54,7 @@ public String stringDescription() { protected Command.Builder> configureCommand(Command.@NotNull Builder> builder) { return builder.literal("me") .senderType(PlayerCommandSource.class) + .optional(KEY_PLAYER, OfflinePlayerParser.parser()) .handler(this::handleCommand); } @@ -64,7 +76,19 @@ private void handleCommand(@Nonnull CommandContext context) if (!sender.hasPermission("areashop.me")) { throw new AreaShopCommandException("me-noPermission"); } - RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, sender); + this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER)) + .whenCompleteAsync((offlinePlayer, exception) -> { + if (exception != null) { + sender.sendMessage("failed to lookup offline player!"); + exception.printStackTrace(); + return; + } + if (!offlinePlayer.hasPlayedBefore()) { + this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName()); + return; + } + RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer); + }, this.executor); } }