Search in sources :

Example 6 with Request

use of com.easterlyn.util.Request in project Easterlyn by Easterlyn.

the class SpectateCommand method spectateTPA.

@CommandAlias("spectate|spec|spectpa")
@Subcommand("request")
@Description("{@@spectate.request.description}")
@CommandCompletion("@player")
@Syntax("/spectpa <player>")
@CommandPermission("easterlyn.command.spectpa")
public void spectateTPA(@Flags(CoreContexts.SELF) User user, @Flags(CoreContexts.ONLINE) User target) {
    Player player = user.getPlayer();
    Player targetPlayer = target.getPlayer();
    if (player == null || targetPlayer == null) {
        core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.tprequest.error.offline");
        return;
    }
    if (player.getGameMode() != GameMode.SPECTATOR) {
        core.getLocaleManager().sendMessage(player, "spectate.not_spectator");
        return;
    }
    if (target.setPendingRequest(new Request() {

        @Override
        public void accept() {
            Player issuer = user.getPlayer();
            Player recipient = target.getPlayer();
            if (issuer == null || recipient == null) {
                core.getLocaleManager().sendMessage(recipient, "sink.module.tprequest.error.offline");
                return;
            }
            if (issuer.getGameMode() != GameMode.SPECTATOR) {
                core.getLocaleManager().sendMessage(user.getPlayer(), "spectate.request.not_spectator", "{value}", issuer.getName());
                return;
            }
            user.getStorage().set(EasterlynSpectators.USER_SPECTPA, true);
            if (issuer.teleport(recipient.getLocation().add(0, 0.1, 0), PlayerTeleportEvent.TeleportCause.SPECTATE)) {
                core.getLocaleManager().sendMessage(recipient, "sink.module.tprequest.common.accept");
                core.getLocaleManager().sendMessage(issuer, "sink.module.tprequest.common.accepted", "{target}", recipient.getName());
            }
            user.getStorage().set(EasterlynSpectators.USER_SPECTPA, null);
        }

        @Override
        public void decline() {
            core.getLocaleManager().sendMessage(targetPlayer, "sink.module.tprequest.common.decline");
            core.getLocaleManager().sendMessage(player, "sink.module.tprequest.common.declined", "{target}", targetPlayer.getName());
        // TODO same anti-spam ignore?
        }
    })) {
        String message = core.getLocaleManager().getValue("spectate.request.request", core.getLocaleManager().getLocale(targetPlayer), "{value}", player.getName());
        if (message != null) {
            target.sendMessage(player.getUniqueId(), message);
        }
    } else {
        core.getLocaleManager().sendMessage(player, "sink.module.tprequest.error.popular", "{value}", targetPlayer.getName());
    }
}
Also used : Player(org.bukkit.entity.Player) Request(com.easterlyn.util.Request) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Aggregations

Request (com.easterlyn.util.Request)6 CommandAlias (co.aikar.commands.annotation.CommandAlias)3 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)3 CommandPermission (co.aikar.commands.annotation.CommandPermission)3 Description (co.aikar.commands.annotation.Description)3 Syntax (co.aikar.commands.annotation.Syntax)3 Player (org.bukkit.entity.Player)3 Nullable (org.jetbrains.annotations.Nullable)2 Subcommand (co.aikar.commands.annotation.Subcommand)1 EasterlynCore (com.easterlyn.EasterlynCore)1 User (com.easterlyn.user.User)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ArmorStand (org.bukkit.entity.ArmorStand)1 ComplexEntityPart (org.bukkit.entity.ComplexEntityPart)1 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)1 Explosive (org.bukkit.entity.Explosive)1 Monster (org.bukkit.entity.Monster)1 ExplosiveMinecart (org.bukkit.entity.minecart.ExplosiveMinecart)1