Search in sources :

Example 1 with VelocityPartiesBootstrap

use of com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap in project Parties by AlessioDP.

the class VelocityCommandTeleport method performTeleport.

public void performTeleport(PartyImpl party, PartyPlayerImpl player, int delay) {
    Player velocityPlayer = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(player.getPlayerUUID()).orElse(null);
    if (velocityPlayer != null) {
        if (ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_ENABLE)
            player.sendMessage(Messages.ADDCMD_TELEPORT_ACCEPT_REQUEST_SENT);
        else
            player.sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTING);
        for (PartyPlayer onlinePlayer : party.getOnlineMembers(true)) {
            if (!onlinePlayer.getPlayerUUID().equals(player.getPlayerUUID())) {
                if (ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_ENABLE) {
                    VelocityPartyTeleportRequest request = new VelocityPartyTeleportRequest((PartiesPlugin) plugin, (PartyPlayerImpl) onlinePlayer, player);
                    ((PartyPlayerImpl) onlinePlayer).getPendingTeleportRequests().add(request);
                    ((PartyPlayerImpl) onlinePlayer).sendMessage(Messages.ADDCMD_TELEPORT_ACCEPT_REQUEST_RECEIVED, player, party);
                    plugin.getScheduler().scheduleAsyncLater(request::timeout, ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_TIME, TimeUnit.SECONDS);
                } else {
                    handleSinglePlayerTeleport((PartiesPlugin) plugin, (PartyPlayerImpl) onlinePlayer, player, delay);
                }
            }
        }
    }
}
Also used : VelocityPartyTeleportRequest(com.alessiodp.parties.velocity.parties.objects.VelocityPartyTeleportRequest) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(com.velocitypowered.api.proxy.Player) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) VelocityPartiesBootstrap(com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap)

Example 2 with VelocityPartiesBootstrap

use of com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap in project Parties by AlessioDP.

the class VelocityCommandSetHome method getLocationAndSave.

@Override
protected void getLocationAndSave(PartyPlayerImpl sender, PartyImpl party, String name) {
    Player player = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(sender.getPlayerUUID()).orElse(null);
    if (player != null) {
        ServerConnection serverConnection = player.getCurrentServer().orElse(null);
        if (serverConnection != null) {
            String serverName = serverConnection.getServerInfo().getName();
            ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(party, sender, name, serverName);
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) VelocityPartiesBootstrap(com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap)

Example 3 with VelocityPartiesBootstrap

use of com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap in project Parties by AlessioDP.

the class VelocityCommandTeleport method teleportSinglePlayer.

public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, RegisteredServer server) {
    Player velocityPlayer = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(player.getPlayerUUID()).orElse(null);
    if (velocityPlayer != null) {
        PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
        IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, server);
        plugin.getEventManager().callEvent(partiesPreTeleportEvent);
        if (!partiesPreTeleportEvent.isCancelled()) {
            velocityPlayer.getCurrentServer().ifPresent(serverConnection1 -> {
                boolean serverChange = false;
                if (!serverConnection1.getServer().equals(server)) {
                    serverChange = true;
                    velocityPlayer.createConnectionRequest(server);
                }
                User velocityUser = plugin.getPlayer(player.getPlayerUUID());
                if (velocityUser != null) {
                    if (serverChange) {
                        plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer), VelocityConfigParties.ADDITIONAL_TELEPORT_EXACT_LOCATION_DELAY, TimeUnit.MILLISECONDS);
                    } else {
                        ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer);
                    }
                    player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
                    IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, server);
                    plugin.getEventManager().callEvent(partiesPostTeleportEvent);
                }
            });
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_TELEPORTEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    }
}
Also used : IPlayerPreTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(com.velocitypowered.api.proxy.Player) User(com.alessiodp.core.common.user.User) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) IPlayerPostTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent) VelocityPartiesBootstrap(com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

VelocityPartiesBootstrap (com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap)3 Player (com.velocitypowered.api.proxy.Player)3 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)2 VelocityPartiesMessageDispatcher (com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher)2 User (com.alessiodp.core.common.user.User)1 IPlayerPostTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent)1 IPlayerPreTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 VelocityPartyTeleportRequest (com.alessiodp.parties.velocity.parties.objects.VelocityPartyTeleportRequest)1 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)1