Search in sources :

Example 1 with VelocityUser

use of com.alessiodp.core.velocity.user.VelocityUser 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 VelocityUser

use of com.alessiodp.core.velocity.user.VelocityUser in project Parties by AlessioDP.

the class VelocityFollowListener method sendMembers.

private void sendMembers(PartyImpl party, PartyPlayerImpl player, RegisteredServer server) {
    for (PartyPlayer member : party.getOnlineMembers(true)) {
        VelocityUser memberUser = (VelocityUser) plugin.getPlayer(member.getPlayerUUID());
        if (memberUser != null && !memberUser.getUUID().equals(player.getPlayerUUID()) && !memberUser.getServerName().equals(server.getServerInfo().getName())) {
            memberUser.sendMessage(plugin.getMessageUtils().convertPlaceholders(VelocityMessages.OTHER_FOLLOW_SERVER.replace("%server%", server.getServerInfo().getName()), player, party), true);
            memberUser.connectTo(server);
            if (VelocityConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_ENABLE) {
                // Schedule it later
                plugin.getScheduler().scheduleAsyncLater(() -> {
                    for (String command : VelocityConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_COMMANDS) {
                        memberUser.chat(plugin.getMessageUtils().convertPlaceholders(command, (PartyPlayerImpl) member, party));
                    }
                }, VelocityConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_DELAY, TimeUnit.MILLISECONDS);
            }
        }
    }
}
Also used : PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) VelocityUser(com.alessiodp.core.velocity.user.VelocityUser)

Aggregations

VelocityUser (com.alessiodp.core.velocity.user.VelocityUser)2 ADPVelocityBootstrap (com.alessiodp.core.velocity.bootstrap.ADPVelocityBootstrap)1 IPlayerPostHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent)1 IPlayerPreHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent)1 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 VelocityPartiesMessageDispatcher (com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1