Skip to content

Commit

Permalink
Revert "Remove argument from me command"
Browse files Browse the repository at this point in the history
This reverts commit b631cfc.
  • Loading branch information
md5sha256 committed Aug 4, 2024
1 parent b631cfc commit e5d190d
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@
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;

@Singleton
public class MeCommand extends AreashopCommandBean {

private static final CloudKey<String> 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
Expand All @@ -43,6 +54,7 @@ public String stringDescription() {
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
return builder.literal("me")
.senderType(PlayerCommandSource.class)
.optional(KEY_PLAYER, OfflinePlayerParser.parser())
.handler(this::handleCommand);
}

Expand All @@ -64,7 +76,19 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> 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);
}

}
Expand Down

0 comments on commit e5d190d

Please sign in to comment.