Search in sources :

Example 1 with BungeePartiesPartyFollowEvent

use of com.alessiodp.parties.api.events.bungee.unique.BungeePartiesPartyFollowEvent in project Parties by AlessioDP.

the class BungeeFollowListener method onConnected.

@EventHandler
public void onConnected(ServerSwitchEvent event) {
    if (!BungeeConfigMain.ADDITIONAL_FOLLOW_ENABLE)
        return;
    // Not connected to the network yet
    if (event.getPlayer().getServer() == null)
        return;
    plugin.getScheduler().scheduleAsyncLater(() -> {
        if (allowedServer(event.getPlayer().getServer().getInfo().getName())) {
            PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
            PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
            if (party != null && party.isFollowEnabled() && (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID()))) {
                String playerServer = event.getPlayer().getServer().getInfo().getName();
                ServerInfo serverInfo = ((BungeePartiesBootstrap) plugin.getBootstrap()).getProxy().getServerInfo(playerServer);
                // Calling API event
                BungeePartiesPartyFollowEvent partyFollowEvent = ((BungeeEventManager) plugin.getEventManager()).preparePartyFollowEvent(party, playerServer);
                plugin.getEventManager().callEvent(partyFollowEvent);
                if (!partyFollowEvent.isCancelled()) {
                    // Let other players follow him
                    sendMembers(party, player, serverInfo);
                }
            }
        }
    }, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
}
Also used : BungeeEventManager(com.alessiodp.parties.bungeecord.events.BungeeEventManager) BungeePartiesPartyFollowEvent(com.alessiodp.parties.api.events.bungee.unique.BungeePartiesPartyFollowEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ServerInfo(net.md_5.bungee.api.config.ServerInfo) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

BungeePartiesPartyFollowEvent (com.alessiodp.parties.api.events.bungee.unique.BungeePartiesPartyFollowEvent)1 BungeeEventManager (com.alessiodp.parties.bungeecord.events.BungeeEventManager)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 EventHandler (net.md_5.bungee.event.EventHandler)1