use of com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent 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);
}
}
use of com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent 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);
}
}
use of com.alessiodp.parties.api.events.common.player.IPlayerPreTeleportEvent 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);
}
}
Aggregations