Search in sources :

Example 1 with VelocityPartiesMessageDispatcher

use of com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher in project Parties by AlessioDP.

the class VelocityCommandHome method teleportToPartyHome.

public static void teleportToPartyHome(PartiesPlugin plugin, User player, PartyPlayerImpl partyPlayer, PartyHomeImpl home) {
    PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
    if (home.getServer() != null && !home.getServer().isEmpty()) {
        boolean serverChange = false;
        RegisteredServer server = ((ADPVelocityBootstrap) plugin.getBootstrap()).getServer().getServer(home.getServer()).orElse(null);
        IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
        plugin.getEventManager().callEvent(partiesPreHomeEvent);
        if (!partiesPreHomeEvent.isCancelled()) {
            if (VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((VelocityUser) player).getServerName().equalsIgnoreCase(home.getServer())) {
                if (server == null) {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
                    return;
                }
                ((VelocityUser) player).connectTo(server);
                serverChange = true;
            }
            String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
            if (serverChange) {
                plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message), VelocityConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
            } else {
                ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message);
            }
            IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(partyPlayer, party, home);
            plugin.getEventManager().callEvent(partiesPostHomeEvent);
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_HOME_NO_SERVER, party.getId()));
    }
}
Also used : ADPVelocityBootstrap(com.alessiodp.core.velocity.bootstrap.ADPVelocityBootstrap) IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) VelocityUser(com.alessiodp.core.velocity.user.VelocityUser) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with VelocityPartiesMessageDispatcher

use of com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher 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 VelocityPartiesMessageDispatcher

use of com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher 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

VelocityPartiesMessageDispatcher (com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)2 VelocityPartiesBootstrap (com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap)2 Player (com.velocitypowered.api.proxy.Player)2 User (com.alessiodp.core.common.user.User)1 ADPVelocityBootstrap (com.alessiodp.core.velocity.bootstrap.ADPVelocityBootstrap)1 VelocityUser (com.alessiodp.core.velocity.user.VelocityUser)1 IPlayerPostHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent)1 IPlayerPostTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent)1 IPlayerPreHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent)1 IPlayerPreTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent)1 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)1 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1