Search in sources :

Example 1 with IPlayerPostHomeEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent in project Parties by AlessioDP.

the class BukkitCommandHome method teleportToPartyHome.

public static void teleportToPartyHome(PartiesPlugin plugin, PartyPlayerImpl player, BukkitUser bukkitUser, PartyHome home, Location location, String message) {
    PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
    IPlayerPreHomeEvent partiesPreHomeEvent = plugin.getEventManager().preparePlayerPreHomeEvent(player, party, home);
    plugin.getEventManager().callEvent(partiesPreHomeEvent);
    if (!partiesPreHomeEvent.isCancelled()) {
        plugin.getScheduler().getSyncExecutor().execute(() -> {
            EssentialsHandler.updateLastTeleportLocation(player.getPlayerUUID());
            bukkitUser.teleportAsync(location).thenAccept(result -> {
                if (result) {
                    player.sendMessage(message);
                    IPlayerPostHomeEvent partiesPostHomeEvent = plugin.getEventManager().preparePlayerPostHomeEvent(player, party, home);
                    plugin.getEventManager().callEvent(partiesPostHomeEvent);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_TELEPORT_DONE, player.getPlayerUUID()), true);
                } else {
                    plugin.getLoggerManager().logError(String.format(PartiesConstants.DEBUG_TELEPORT_ASYNC, player.getPlayerUUID()));
                }
            });
        });
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_HOMEEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
}
Also used : IPlayerPostHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent) IPlayerPreHomeEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with IPlayerPostHomeEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent 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 3 with IPlayerPostHomeEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent 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)

Aggregations

IPlayerPostHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent)3 IPlayerPreHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 BungeeUser (com.alessiodp.core.bungeecord.user.BungeeUser)1 ADPVelocityBootstrap (com.alessiodp.core.velocity.bootstrap.ADPVelocityBootstrap)1 VelocityUser (com.alessiodp.core.velocity.user.VelocityUser)1 BungeePartiesMessageDispatcher (com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher)1 VelocityPartiesMessageDispatcher (com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1