Search in sources :

Example 1 with ServerConnectedEvent

use of net.md_5.bungee.api.event.ServerConnectedEvent in project SubServers-2 by ME1312.

the class ExProxy method connected.

@SuppressWarnings("deprecation")
@EventHandler(priority = Byte.MAX_VALUE)
public void connected(ServerConnectedEvent e) {
    if (e.getPlayer().isConnected()) {
        synchronized (rPlayers) {
            ObjectMap<String> raw = CachedPlayer.translate(e.getPlayer());
            raw.set("server", e.getServer().getInfo().getName());
            CachedPlayer player = new CachedPlayer(raw);
            rPlayerLinkP.put(player.getUniqueId(), player.getProxyName().toLowerCase());
            rPlayers.put(player.getUniqueId(), player);
            if (e.getServer().getInfo() instanceof ServerImpl)
                rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) e.getServer().getInfo());
            if (api.getSubDataNetwork()[0] != null) {
                ((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(true, player));
            }
        }
        if (fallback.containsKey(e.getPlayer().getUniqueId())) {
            fallback.get(e.getPlayer().getUniqueId()).done(() -> {
                if (e.getPlayer().getServer() != null && !((UserConnection) e.getPlayer()).isDimensionChange() && e.getPlayer().getServer().getInfo().getName().equals(e.getServer().getInfo().getName())) {
                    fallback.remove(e.getPlayer().getUniqueId());
                    e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback.Result").replace("$str$", (e.getServer().getInfo() instanceof ServerImpl) ? ((ServerImpl) e.getServer().getInfo()).getDisplayName() : e.getServer().getInfo().getName()));
                }
            }, getConfig().getServerConnectTimeout() + 500);
        }
    }
}
Also used : CachedPlayer(net.ME1312.SubServers.Sync.Server.CachedPlayer) SubDataClient(net.ME1312.SubData.Client.SubDataClient) ServerImpl(net.ME1312.SubServers.Sync.Server.ServerImpl) SubServerImpl(net.ME1312.SubServers.Sync.Server.SubServerImpl) PacketExSyncPlayer(net.ME1312.SubServers.Sync.Network.Packet.PacketExSyncPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with ServerConnectedEvent

use of net.md_5.bungee.api.event.ServerConnectedEvent in project HCore by deHasher.

the class Extra method onServerConnectEvent.

@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnectEvent(ServerConnectedEvent e) {
    HCore.getBungee().getScheduler().runAsync(HCore.getPlugin(), () -> {
        if (!HCore.settings.getBoolean("check-MoonVKAuth"))
            return;
        if (HCore.auth.contains(e.getPlayer().getName()))
            return;
        ServerInfo info = e.getServer().getInfo();
        if (info == null)
            return;
        String name = info.getName().toLowerCase();
        if (name.contains("hub") || name.contains("lobby")) {
            Informer.sendTitle(e.getPlayer(), HCore.lang.getString("info.auth"));
        }
    });
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with ServerConnectedEvent

use of net.md_5.bungee.api.event.ServerConnectedEvent in project XConomy by YiC200333.

the class BCPlayerEvent method join.

@SuppressWarnings(value = { "UnstableApiUsage", "unused" })
@EventHandler
public void join(ServerConnectedEvent event) {
    String playername = event.getPlayer().getName();
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("Join");
    output.writeUTF(playername);
    for (ServerInfo s : ProxyServer.getInstance().getServers().values()) {
        if (s.getPlayers().size() > 0) {
            ProxyServer.getInstance().getScheduler().runAsync(XConomyBungee.getInstance(), () -> SendMessTaskB(s, output));
        }
    }
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) EventHandler(net.md_5.bungee.event.EventHandler)

Example 4 with ServerConnectedEvent

use of net.md_5.bungee.api.event.ServerConnectedEvent in project ViaVersion by ViaVersion.

the class BungeeServerHandler method checkServerChange.

public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
    if (user == null)
        return;
    // Handle server/version change
    if (user.has(BungeeStorage.class)) {
        BungeeStorage storage = user.get(BungeeStorage.class);
        ProxiedPlayer player = storage.getPlayer();
        if (e.getServer() != null) {
            if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) {
                // Clear auto-team
                EntityTracker1_9 oldEntityTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (oldEntityTracker != null) {
                    if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) {
                        oldEntityTracker.sendTeamPacket(false, true);
                    }
                }
                String serverName = e.getServer().getInfo().getName();
                storage.setCurrentServer(serverName);
                int protocolId = ProtocolDetectorService.getProtocolId(serverName);
                if (protocolId <= ProtocolVersion.v1_8.getVersion()) {
                    // 1.8 doesn't have BossBar packet
                    if (storage.getBossbar() != null) {
                        // This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
                        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
                            for (UUID uuid : storage.getBossbar()) {
                                PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, null, user);
                                wrapper.write(Type.UUID, uuid);
                                // remove
                                wrapper.write(Type.VAR_INT, 1);
                                wrapper.send(Protocol1_9To1_8.class);
                            }
                        }
                        storage.getBossbar().clear();
                    }
                }
                ProtocolInfo info = user.getProtocolInfo();
                int previousServerProtocol = info.getServerProtocolVersion();
                // Refresh the pipes
                List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
                ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
                user.clearStoredObjects();
                pipeline.cleanPipes();
                if (protocolPath == null) {
                    // TODO Check Bungee Supported Protocols? *shrugs*
                    protocolId = info.getProtocolVersion();
                } else {
                    List<Protocol> protocols = new ArrayList<>(protocolPath.size());
                    for (ProtocolPathEntry entry : protocolPath) {
                        protocols.add(entry.protocol());
                    }
                    pipeline.add(protocols);
                }
                info.setServerProtocolVersion(protocolId);
                // Add version-specific base Protocol
                pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId));
                // Workaround 1.13 server change
                int id1_13 = ProtocolVersion.v1_13.getVersion();
                boolean toNewId = previousServerProtocol < id1_13 && protocolId >= id1_13;
                boolean toOldId = previousServerProtocol >= id1_13 && protocolId < id1_13;
                if (previousServerProtocol != -1 && (toNewId || toOldId)) {
                    Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(e.getPlayer().getPendingConnection());
                    if (!registeredChannels.isEmpty()) {
                        Collection<String> newChannels = new HashSet<>();
                        for (Iterator<String> iterator = registeredChannels.iterator(); iterator.hasNext(); ) {
                            String channel = iterator.next();
                            String oldChannel = channel;
                            if (toNewId) {
                                channel = InventoryPackets.getNewPluginChannelId(channel);
                            } else {
                                channel = InventoryPackets.getOldPluginChannelId(channel);
                            }
                            if (channel == null) {
                                iterator.remove();
                                continue;
                            }
                            if (!oldChannel.equals(channel)) {
                                iterator.remove();
                                newChannels.add(channel);
                            }
                        }
                        registeredChannels.addAll(newChannels);
                    }
                    PluginMessage brandMessage = (PluginMessage) getBrandMessage.invoke(e.getPlayer().getPendingConnection());
                    if (brandMessage != null) {
                        String channel = brandMessage.getTag();
                        if (toNewId) {
                            channel = InventoryPackets.getNewPluginChannelId(channel);
                        } else {
                            channel = InventoryPackets.getOldPluginChannelId(channel);
                        }
                        if (channel != null) {
                            brandMessage.setTag(channel);
                        }
                    }
                }
                user.put(storage);
                user.setActive(protocolPath != null);
                // Init all protocols TODO check if this can get moved up to the previous for loop, and doesn't require the pipeline to already exist.
                for (Protocol protocol : pipeline.pipes()) {
                    protocol.init(user);
                }
                EntityTracker1_9 newTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (newTracker != null) {
                    if (Via.getConfig().isAutoTeam()) {
                        String currentTeam = null;
                        for (Team team : player.getScoreboard().getTeams()) {
                            if (team.getPlayers().contains(info.getUsername())) {
                                currentTeam = team.getName();
                            }
                        }
                        // Reinitialize auto-team
                        newTracker.setAutoTeam(true);
                        if (currentTeam == null) {
                            // Send auto-team as it was cleared above
                            newTracker.sendTeamPacket(true, true);
                            newTracker.setCurrentTeam("viaversion");
                        } else {
                            // Auto-team will be sent when bungee send remove packet
                            newTracker.setAutoTeam(Via.getConfig().isAutoTeam());
                            newTracker.setCurrentTeam(currentTeam);
                        }
                    }
                }
                Object wrapper = channelWrapper.get(player);
                setVersion.invoke(wrapper, protocolId);
                Object entityMap = getEntityMap.invoke(null, protocolId);
                entityRewrite.set(player, entityMap);
            }
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) BungeeStorage(com.viaversion.viaversion.bungee.storage.BungeeStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ProtocolPipeline(com.viaversion.viaversion.api.protocol.ProtocolPipeline) PluginMessage(net.md_5.bungee.protocol.packet.PluginMessage) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) Team(net.md_5.bungee.api.score.Team) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) Protocol(com.viaversion.viaversion.api.protocol.Protocol)

Example 5 with ServerConnectedEvent

use of net.md_5.bungee.api.event.ServerConnectedEvent in project CatSeedLogin by CatSeed.

the class Listeners method onServerConnected.

/**
 * 玩家切换到登录服务之后,如果bc端是已登录的状态,就使用bc端的登录状态去更新子服的登录状态,
 * 避免使玩家每次切换到登录服时需要重新进行登录
 */
@EventHandler
public void onServerConnected(ServerConnectedEvent event) {
    if (event.getServer().getInfo().getName().equals(Config.LoginServerName)) {
        ProxiedPlayer player = event.getPlayer();
        String playerName = player.getName();
        boolean loggedIn;
        synchronized (loggedInPlayerList) {
            loggedIn = loggedInPlayerList.contains(playerName);
        }
        if (loggedIn) {
            Communication.sendKeepLoggedInRequest(playerName);
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)13 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)6 ServerInfo (net.md_5.bungee.api.config.ServerInfo)3 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)2 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)2 EntityTracker1_9 (com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9)2 UUID (java.util.UUID)2 Team (net.md_5.bungee.api.score.Team)2 PluginMessage (net.md_5.bungee.protocol.packet.PluginMessage)2 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)1 FloodgateAuthTask (com.github.games647.fastlogin.bungee.task.FloodgateAuthTask)1 ForceLoginTask (com.github.games647.fastlogin.bungee.task.ForceLoginTask)1 FloodgateService (com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService)1 InteractiveChat (com.loohp.interactivechat.InteractiveChat)1 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)1 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)1 Protocol (com.viaversion.viaversion.api.protocol.Protocol)1 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)1