Search in sources :

Example 1 with Request

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

the class Transportalizer method getFailureMessage.

@Nullable
private String getFailureMessage(Player player, Entity entity, boolean push, Location from, Location to, ConfigurationSection storage, int cost) {
    if (push && entity instanceof Player) {
        // Sender must have button access to send players
        if (!ProtectionUtil.canUseButtonsAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    if (!push && entity instanceof Player) {
        RegisteredServiceProvider<EasterlynCore> registration = getMachines().getServer().getServicesManager().getRegistration(EasterlynCore.class);
        if (registration == null) {
            return "Easterlyn core plugin not loaded! Cannot pull players.";
        }
        if (player.getUniqueId().equals(entity.getUniqueId())) {
            return null;
        }
        User target = registration.getProvider().getUserManager().getUser(entity.getUniqueId());
        User issuer = registration.getProvider().getUserManager().getUser(player.getUniqueId());
        if (target.setPendingRequest(new Request() {

            @Override
            public void accept() {
                if (getFuel(storage) < cost) {
                    target.sendMessage("Transportalizer is too low on fuel! Ask " + issuer.getDisplayName() + " to add more!");
                }
                Player localTarget = target.getPlayer();
                if (localTarget == null) {
                    return;
                }
                teleport(entity, from, to);
                setFuel(storage, getFuel(storage) - cost);
            }

            @Override
            public void decline() {
                target.sendMessage("Request declined!");
            }
        })) {
            target.sendMessage(issuer.getUniqueId(), issuer.getDisplayName() + " is requesting to transportalize you!\n" + "Use /accept or /decline to manage the request.");
            // Blank message won't actually send, but will preclude immediate transportalization.
            return "";
        }
        return null;
    }
    // Ender dragon or ender dragon parts
    if (entity instanceof ComplexLivingEntity || entity instanceof ComplexEntityPart) {
        return ChatColor.RED + "Great effort, but you can't transportalize a dragon.";
    }
    if (entity instanceof ArmorStand) {
        // Armor stand manipulation requires the ability to build
        if (!ProtectionUtil.canBuildAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    if (entity instanceof Monster || entity instanceof Explosive || entity instanceof ExplosiveMinecart) {
        // Hostiles, TNT, wither projectiles, fireballs, etc. require build permissions
        if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canBuildAt(player, to)) {
            return ChatColor.RED + "You do not have access to the location specified!";
        }
        return null;
    }
    // Generic push/pull requires chest access in send location and full access in arrival location
    if (!ProtectionUtil.canOpenChestsAt(player, from) || !ProtectionUtil.canMobsSpawn(to) && !ProtectionUtil.canBuildAt(player, to)) {
        return ChatColor.RED + "You do not have access to the location specified!";
    }
    return null;
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Player(org.bukkit.entity.Player) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) User(com.easterlyn.user.User) Explosive(org.bukkit.entity.Explosive) ArmorStand(org.bukkit.entity.ArmorStand) EasterlynCore(com.easterlyn.EasterlynCore) Monster(org.bukkit.entity.Monster) Request(com.easterlyn.util.Request) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Request

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

the class ManageRequestCommand method accept.

@CommandAlias("accept|yes|y|tpyes|tpaccept")
@Description("{@@sink.module.request.accept.description}")
@CommandCompletion("")
@Syntax("")
@CommandPermission("easterlyn.command.request")
public void accept(@Flags(CoreContexts.SELF) User user) {
    Request request = user.pollPendingRequest();
    if (request == null) {
        core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.request.error.no_pending");
        return;
    }
    request.accept();
}
Also used : Request(com.easterlyn.util.Request) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 3 with Request

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

the class ManageRequestCommand method decline.

@CommandAlias("decline|no|n|tpno|tpdeny")
@Description("{@@sink.module.request.decline.description}")
@CommandCompletion("")
@Syntax("")
@CommandPermission("easterlyn.command.request")
public void decline(@Flags(CoreContexts.SELF) User user) {
    Request request = user.pollPendingRequest();
    if (request == null) {
        core.getLocaleManager().sendMessage(user.getPlayer(), "sink.module.request.error.no_pending");
        return;
    }
    request.decline();
}
Also used : Request(com.easterlyn.util.Request) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 4 with Request

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

the class User method pollPendingRequest.

/**
 * Gets and clears the pending request, if any.
 *
 * @return the Request or null if not present
 */
@Nullable
public Request pollPendingRequest() {
    Object stored = tempStore.remove("core.request");
    if (!(stored instanceof Request)) {
        return null;
    }
    Request request = (Request) stored;
    return request.getExpiry() > System.currentTimeMillis() ? request : null;
}
Also used : Request(com.easterlyn.util.Request) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Request

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

the class TeleportRequestCommand method tpRequest.

private void tpRequest(User issuer, User requested, boolean to) {
    long nextTPA = issuer.getStorage().getLong(TPREQUEST_COOLDOWN);
    if (nextTPA > System.currentTimeMillis()) {
        SimpleDateFormat format = new SimpleDateFormat("m:ss");
        core.getLocaleManager().sendMessage(issuer.getPlayer(), "sink.module.tprequest.error.cooldown", "{value}", format.format(new Date(nextTPA - System.currentTimeMillis())));
        return;
    }
    issuer.getStorage().set(TPREQUEST_COOLDOWN, System.currentTimeMillis() + sink.getConfig().getLong(CONFIG_IGNORE));
    Player issuingPlayer = issuer.getPlayer();
    Player requestedPlayer = requested.getPlayer();
    if (issuingPlayer == null || requestedPlayer == null) {
        core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.error.offline");
        return;
    }
    if (requested.setPendingRequest(new Request() {

        @Override
        public void accept() {
            Player localIssuer = issuer.getPlayer();
            Player localRequested = requested.getPlayer();
            if (localIssuer == null || localRequested == null) {
                core.getLocaleManager().sendMessage(localRequested, "sink.module.tprequest.error.offline");
                return;
            }
            Player destination = to ? localRequested : localIssuer;
            Player teleportee = to ? localIssuer : localRequested;
            if (teleportee.teleport(destination.getLocation().add(0, 0.1, 0), PlayerTeleportEvent.TeleportCause.PLUGIN)) {
                core.getLocaleManager().sendMessage(localRequested, "sink.module.tprequest.common.accept");
                core.getLocaleManager().sendMessage(localIssuer, "sink.module.tprequest.common.accepted", "{value}", localRequested.getName());
            }
        }

        @Override
        public void decline() {
            core.getLocaleManager().sendMessage(requestedPlayer, "sink.module.tprequest.common.decline");
            core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.common.declined", "{value}", requestedPlayer.getName());
            issuer.getStorage().set(TPREQUEST_COOLDOWN, issuer.getStorage().getLong(TPREQUEST_COOLDOWN) - sink.getConfig().getLong(CONFIG_IGNORE) + sink.getConfig().getLong(CONFIG_ACCEPT));
        }
    })) {
        core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.common.issued");
        String requestMessage = core.getLocaleManager().getValue(to ? "sink.module.tprequest.to.request" : "sink.module.tprequest.pull.request", core.getLocaleManager().getLocale(requestedPlayer), "{value}", issuingPlayer.getName());
        requested.sendMessage(issuer.getUniqueId(), requestMessage);
    } else {
        core.getLocaleManager().sendMessage(issuingPlayer, "sink.module.tprequest.error.popular", "{value}", requestedPlayer.getName());
    }
}
Also used : Player(org.bukkit.entity.Player) Request(com.easterlyn.util.Request) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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