Search in sources :

Example 1 with BungeePartiesMessageDispatcher

use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher in project Parties by AlessioDP.

the class BungeeCommandHome 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;
        ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(home.getServer());
        IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(partyPlayer, party, home);
        plugin.getEventManager().callEvent(partiesPreHomeEvent);
        if (!partiesPreHomeEvent.isCancelled()) {
            if (((BungeeUser) player).getServer() == null)
                // Cannot get player server
                return;
            if (BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER && !((BungeeUser) player).getServer().getName().equalsIgnoreCase(home.getServer())) {
                if (serverInfo == null) {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_CMD_HOME_NO_SERVER, home));
                    return;
                }
                ((BungeeUser) player).connectTo(serverInfo);
                serverChange = true;
            }
            String message = plugin.getMessageUtils().convertPlaceholders(Messages.ADDCMD_HOME_TELEPORTED, partyPlayer, party);
            if (serverChange) {
                plugin.getScheduler().scheduleAsyncLater(() -> ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo), BungeeConfigParties.ADDITIONAL_HOME_CROSS_SERVER_DELAY, TimeUnit.MILLISECONDS);
            } else {
                ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendHomeTeleport(player, home, message, serverInfo);
            }
            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 : BungeePartiesMessageDispatcher(com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher) IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) ServerInfo(net.md_5.bungee.api.config.ServerInfo) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with BungeePartiesMessageDispatcher

use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher in project Parties by AlessioDP.

the class BungeeCommandSetHome method getLocationAndSave.

@Override
protected void getLocationAndSave(PartyPlayerImpl sender, PartyImpl party, String name) {
    User user = plugin.getPlayer(sender.getPlayerUUID());
    if (user != null && ((BungeeUser) user).getServer() != null) {
        String serverName = ((BungeeUser) user).getServer().getName();
        ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(user, party, name, serverName);
    }
}
Also used : BungeePartiesMessageDispatcher(com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser) User(com.alessiodp.core.common.user.User) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser)

Example 3 with BungeePartiesMessageDispatcher

use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher in project Parties by AlessioDP.

the class BungeeCommandTeleport method teleportSinglePlayer.

public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, ServerInfo serverInfo) {
    ProxiedPlayer bungeePlayer = ((BungeePartiesBootstrap) plugin.getBootstrap()).getProxy().getPlayer(player.getPlayerUUID());
    if (bungeePlayer != null) {
        boolean serverChange = false;
        PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
        IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, serverInfo);
        plugin.getEventManager().callEvent(partiesPreTeleportEvent);
        if (!partiesPreTeleportEvent.isCancelled()) {
            if (!bungeePlayer.getServer().getInfo().equals(serverInfo)) {
                serverChange = true;
                bungeePlayer.connect(serverInfo);
            }
            User bungeeUser = plugin.getPlayer(player.getPlayerUUID());
            if (bungeeUser != null) {
                if (serverChange) {
                    plugin.getScheduler().scheduleAsyncLater(() -> ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(bungeeUser, targetPlayer, serverInfo), BungeeConfigParties.ADDITIONAL_TELEPORT_EXACT_LOCATION_DELAY, TimeUnit.MILLISECONDS);
                } else {
                    ((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(bungeeUser, targetPlayer, serverInfo);
                }
                player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
                IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, serverInfo);
                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 : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) IPlayerPreTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent) BungeePartiesMessageDispatcher(com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher) User(com.alessiodp.core.common.user.User) IPlayerPostTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

BungeePartiesMessageDispatcher (com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher)3 BungeeUser (com.alessiodp.core.bungeecord.user.BungeeUser)2 User (com.alessiodp.core.common.user.User)2 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)2 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 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1