All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sanctum.myessentials.commands.TPRejectCommand Maven / Gradle / Ivy

The newest version!
package com.github.sanctum.myessentials.commands;

import com.github.sanctum.myessentials.model.CommandBuilder;
import com.github.sanctum.myessentials.model.InternalCommandData;
import com.github.sanctum.myessentials.util.ConfiguredMessage;
import com.github.sanctum.myessentials.util.teleportation.TeleportRequest;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public final class TPRejectCommand extends CommandBuilder {
    public TPRejectCommand() {
        super(InternalCommandData.TP_REJECT_COMMAND);
    }

    @Override
    public List tabComplete(@NotNull Player player, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
        return Collections.emptyList();
    }

    @Override
    public boolean playerView(@NotNull Player player, @NotNull String commandLabel, @NotNull String[] args) {
        if (!testPermission(player)) return false;
        final Optional any = api.getTeleportRunner().getActiveRequests().stream()
                .filter(r -> r.getPlayerRequested().map(value -> value.getUniqueId().equals(player.getUniqueId())).orElse(false))
                .findAny();
        if (any.isPresent()) {
            api.getTeleportRunner().rejectTeleport(any.get());
            sendMessage(player, "Teleport request rejected.");
        } else {
            sendMessage(player, "There are no teleport requests to reject at this time.");
        }
        return true;
    }

    @Override
    public boolean consoleView(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
        sendMessage(sender, ConfiguredMessage.MUST_BE_PLAYER);
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy