use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher 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()));
}
}
use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher in project Parties by AlessioDP.
the class BungeeCommandSetHome method getLocationAndSave.
@Override
protected void getLocationAndSave(PartyPlayerImpl sender, PartyImpl party, String name) {
User user = plugin.getPlayer(sender.getPlayerUUID());
if (user != null && ((BungeeUser) user).getServer() != null) {
String serverName = ((BungeeUser) user).getServer().getName();
((BungeePartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(user, party, name, serverName);
}
}
use of com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher 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);
}
}
Aggregations