Search in sources :

Example 1 with BungeeUser

use of com.alessiodp.core.bungeecord.user.BungeeUser 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 2 with BungeeUser

use of com.alessiodp.core.bungeecord.user.BungeeUser in project Parties by AlessioDP.

the class BungeeChatListener method onPlayerChat.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(ChatEvent event) {
    if (!event.isCancelled() && event.getSender() instanceof ProxiedPlayer && !event.getMessage().startsWith("/")) {
        boolean isCancelled = super.onPlayerChat(new BungeeUser(plugin, (ProxiedPlayer) event.getSender()), event.getMessage());
        event.setCancelled(isCancelled);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with BungeeUser

use of com.alessiodp.core.bungeecord.user.BungeeUser in project Parties by AlessioDP.

the class BungeeFollowListener method sendMembers.

private void sendMembers(PartyImpl party, PartyPlayerImpl player, ServerInfo serverInfo) {
    for (PartyPlayer member : party.getOnlineMembers(true)) {
        BungeeUser memberUser = (BungeeUser) plugin.getPlayer(member.getPlayerUUID());
        if (memberUser != null && !memberUser.getUUID().equals(player.getPlayerUUID()) && !memberUser.getServerName().equals(serverInfo.getName())) {
            memberUser.sendMessage(plugin.getMessageUtils().convertPlaceholders(BungeeMessages.OTHER_FOLLOW_SERVER.replace("%server%", serverInfo.getName()), player, party), true);
            memberUser.connectTo(serverInfo);
            if (BungeeConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_ENABLE) {
                // Schedule it later
                plugin.getScheduler().scheduleAsyncLater(() -> {
                    for (String command : BungeeConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_COMMANDS) {
                        memberUser.chat(plugin.getMessageUtils().convertPlaceholders(command, (PartyPlayerImpl) member, party));
                    }
                }, BungeeConfigMain.ADDITIONAL_FOLLOW_PERFORMCMD_DELAY, TimeUnit.MILLISECONDS);
            }
        }
    }
}
Also used : PartyPlayer(com.alessiodp.parties.api.interfaces.PartyPlayer) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser)

Example 4 with BungeeUser

use of com.alessiodp.core.bungeecord.user.BungeeUser 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);
    }
}
Also used : BungeePartiesMessageDispatcher(com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser) User(com.alessiodp.core.common.user.User) BungeeUser(com.alessiodp.core.bungeecord.user.BungeeUser)

Aggregations

BungeeUser (com.alessiodp.core.bungeecord.user.BungeeUser)4 BungeePartiesMessageDispatcher (com.alessiodp.parties.bungeecord.messaging.BungeePartiesMessageDispatcher)2 User (com.alessiodp.core.common.user.User)1 IPlayerPostHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostHomeEvent)1 IPlayerPreHomeEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreHomeEvent)1 PartyPlayer (com.alessiodp.parties.api.interfaces.PartyPlayer)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 EventHandler (net.md_5.bungee.event.EventHandler)1