Search in sources :

Example 1 with VelocityPartiesPartyFollowEvent

use of com.alessiodp.parties.api.events.velocity.unique.VelocityPartiesPartyFollowEvent in project Parties by AlessioDP.

the class VelocityFollowListener method onConnected.

@Subscribe
public void onConnected(ServerConnectedEvent event) {
    if (!VelocityConfigMain.ADDITIONAL_FOLLOW_ENABLE)
        return;
    // Not connected to the network yet
    if (!event.getPlayer().getCurrentServer().isPresent())
        return;
    plugin.getScheduler().scheduleAsyncLater(() -> {
        if (allowedServer(event.getPlayer().getCurrentServer().get().getServerInfo().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()))) {
                RegisteredServer server = event.getPlayer().getCurrentServer().get().getServer();
                // Calling API event
                VelocityPartiesPartyFollowEvent partyFollowEvent = ((VelocityEventManager) plugin.getEventManager()).preparePartyFollowEvent(party, server);
                plugin.getEventManager().callEvent(partyFollowEvent);
                if (!partyFollowEvent.isCancelled()) {
                    // Let other players follow him
                    sendMembers(party, player, server);
                }
            }
        }
    }, ConfigMain.ADDITIONAL_FOLLOW_DELAY, TimeUnit.MILLISECONDS);
}
Also used : VelocityPartiesPartyFollowEvent(com.alessiodp.parties.api.events.velocity.unique.VelocityPartiesPartyFollowEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) VelocityEventManager(com.alessiodp.parties.velocity.events.VelocityEventManager) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

VelocityPartiesPartyFollowEvent (com.alessiodp.parties.api.events.velocity.unique.VelocityPartiesPartyFollowEvent)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 VelocityEventManager (com.alessiodp.parties.velocity.events.VelocityEventManager)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1