Search in sources :

Example 1 with TeleportTask

use of com.alessiodp.parties.tasks.TeleportTask in project Parties by AlessioDP.

the class CommandTeleport method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    long unixNow = -1;
    if (ConfigParties.TELEPORT_COOLDOWN > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
        Long unixTimestamp = plugin.getPlayerManager().getTeleportCooldown().get(pp.getPlayerUUID());
        unixNow = System.currentTimeMillis() / 1000L;
        if (unixTimestamp != null) {
            pp.sendMessage(Messages.ADDCMD_TELEPORT_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.TELEPORT_COOLDOWN - (unixNow - unixTimestamp))));
            return;
        }
    }
    if (VaultHandler.payCommand(VaultHandler.VaultCommand.TELEPORT, pp, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    /*
		 * Command starts
		 */
    if (unixNow != -1) {
        plugin.getPlayerManager().getTeleportCooldown().put(pp.getPlayerUUID(), unixNow);
        new TeleportTask(pp.getPlayerUUID(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.TELEPORT_COOLDOWN * 20);
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_TELEPORT_START.replace("{value}", Integer.toString(ConfigParties.TELEPORT_COOLDOWN * 20)).replace("{player}", pp.getName()), true);
    }
    pp.sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTING);
    for (Player pl : party.getOnlinePlayers()) {
        if (!pl.getUniqueId().equals(pp.getPlayerUUID())) {
            // Make it sync
            plugin.getPartiesScheduler().runSync(() -> {
                pl.teleport(commandData.getPlayer().getLocation());
                plugin.getPlayerManager().getPlayer(pl.getUniqueId()).sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTED, pp);
            });
        }
    }
    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_TELEPORT.replace("{player}", pp.getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) TeleportTask(com.alessiodp.parties.tasks.TeleportTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 TeleportTask (com.alessiodp.parties.tasks.TeleportTask)1 Player (org.bukkit.entity.Player)1