Search in sources :

Example 1 with IPlayerPostTeleportEvent

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

the class VelocityCommandTeleport method teleportSinglePlayer.

public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, RegisteredServer server) {
    Player velocityPlayer = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(player.getPlayerUUID()).orElse(null);
    if (velocityPlayer != null) {
        PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
        IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, server);
        plugin.getEventManager().callEvent(partiesPreTeleportEvent);
        if (!partiesPreTeleportEvent.isCancelled()) {
            velocityPlayer.getCurrentServer().ifPresent(serverConnection1 -> {
                boolean serverChange = false;
                if (!serverConnection1.getServer().equals(server)) {
                    serverChange = true;
                    velocityPlayer.createConnectionRequest(server);
                }
                User velocityUser = plugin.getPlayer(player.getPlayerUUID());
                if (velocityUser != null) {
                    if (serverChange) {
                        plugin.getScheduler().scheduleAsyncLater(() -> ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer), VelocityConfigParties.ADDITIONAL_TELEPORT_EXACT_LOCATION_DELAY, TimeUnit.MILLISECONDS);
                    } else {
                        ((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendTeleport(velocityUser, targetPlayer);
                    }
                    player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
                    IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, server);
                    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 : IPlayerPreTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(com.velocitypowered.api.proxy.Player) User(com.alessiodp.core.common.user.User) VelocityPartiesMessageDispatcher(com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher) IPlayerPostTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent) VelocityPartiesBootstrap(com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with IPlayerPostTeleportEvent

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

Example 3 with IPlayerPostTeleportEvent

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

the class BukkitCommandTeleport method teleportSinglePlayer.

public static void teleportSinglePlayer(PartiesPlugin plugin, PartyPlayerImpl player, PartyPlayerImpl targetPlayer, Location location) {
    BukkitUser bukkitUser = (BukkitUser) plugin.getPlayer(player.getPlayerUUID());
    Player bukkitTargetPlayer = Bukkit.getPlayer(targetPlayer.getPlayerUUID());
    if (bukkitUser != null && bukkitTargetPlayer != null) {
        PartyImpl party = plugin.getPartyManager().getParty(player.getPartyId());
        IPlayerPreTeleportEvent partiesPreTeleportEvent = plugin.getEventManager().preparePlayerPreTeleportEvent(player, party, location);
        plugin.getEventManager().callEvent(partiesPreTeleportEvent);
        if (!partiesPreTeleportEvent.isCancelled()) {
            plugin.getScheduler().getSyncExecutor().execute(() -> {
                EssentialsHandler.updateLastTeleportLocation(bukkitUser.getUUID());
                bukkitUser.teleportAsync(location).thenAccept(result -> {
                    if (result) {
                        player.sendMessage(Messages.ADDCMD_TELEPORT_PLAYER_TELEPORTED, targetPlayer);
                        IPlayerPostTeleportEvent partiesPostTeleportEvent = plugin.getEventManager().preparePlayerPostTeleportEvent(player, party, location);
                        plugin.getEventManager().callEvent(partiesPostTeleportEvent);
                    } else {
                        plugin.getLoggerManager().logError(PartiesConstants.DEBUG_TELEPORT_ASYNC);
                    }
                });
            });
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_TELEPORTEVENT_DENY, player.getName(), party.getName() != null ? party.getName() : "_"), true);
    }
}
Also used : IPlayerPreTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent) PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) Player(org.bukkit.entity.Player) IPlayerPostTeleportEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent) BukkitUser(com.alessiodp.core.bukkit.user.BukkitUser) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

IPlayerPostTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostTeleportEvent)3 IPlayerPreTeleportEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 User (com.alessiodp.core.common.user.User)2 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)2 BukkitUser (com.alessiodp.core.bukkit.user.BukkitUser)1 BungeePartiesMessageDispatcher (com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher)1 VelocityPartiesBootstrap (com.alessiodp.parties.velocity.bootstrap.VelocityPartiesBootstrap)1 VelocityPartiesMessageDispatcher (com.alessiodp.parties.velocity.messaging.VelocityPartiesMessageDispatcher)1 Player (com.velocitypowered.api.proxy.Player)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 Player (org.bukkit.entity.Player)1