Search in sources :

Example 1 with ServerConnectEvent

use of net.md_5.bungee.api.event.ServerConnectEvent in project Parties by AlessioDP.

the class BungeeListener method onConnect.

@EventHandler
public void onConnect(ServerConnectEvent event) {
    /*
		 * Connect chain starts here,
		 * this method will sent a PartiesPacket to the player server
		 */
    if (event.isCancelled())
        return;
    ProxiedPlayer proxyPlayer = event.getPlayer();
    // Return if its not a player
    if (proxyPlayer.getServer() == null)
        return;
    // Return if the player is already in the server
    if (proxyPlayer.getServer().getInfo().equals(event.getTarget()))
        return;
    // Return if the server is not into the follow list
    if (!listContains(ConfigMain.follow_listserver, proxyPlayer.getServer().getInfo().getName()))
        return;
    /*
		 * 
		 */
    try {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(stream);
        // Initialize packet
        Packet packet = new Packet(plugin.getDescription().getVersion(), event.getTarget().getName(), ConfigMain.follow_neededrank, ConfigMain.follow_minimumrank);
        // Write to the DataOutputStream the data
        packet.write(out);
        if (proxyPlayer.getServer() != null) {
            PartiesBungee.debugLog("Parties packet sent to " + proxyPlayer.getServer().getInfo().getName());
            proxyPlayer.getServer().sendData(partiesChannel, stream.toByteArray());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Packet(com.alessiodp.parties.bungeecord.utils.Packet) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with ServerConnectEvent

use of net.md_5.bungee.api.event.ServerConnectEvent in project ChangeSkin by games647.

the class ServerSwitchListener method onServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnect(ServerConnectEvent connectEvent) {
    ServerInfo targetServer = connectEvent.getTarget();
    Server fromServer = connectEvent.getPlayer().getServer();
    if (fromServer != null && Objects.equals(targetServer, fromServer.getInfo())) {
        // check if we are switching to the same server
        return;
    }
    if (!isBlacklistEnabled()) {
        return;
    }
    ProxiedPlayer player = connectEvent.getPlayer();
    UserPreference session = plugin.getLoginSession(player.getPendingConnection());
    List<String> blacklist = core.getConfig().getStringList("server-blacklist");
    if (blacklist.contains(targetServer.getName())) {
        // clear the skin
        plugin.getApi().applySkin(player, null);
    } else if (session == null) {
        // lazy load
        ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> onLazyLoad(player));
    } else {
        // player switched to an enabled server
        Optional<SkinModel> optSkin = session.getTargetSkin();
        optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ProxyServer(net.md_5.bungee.api.ProxyServer) Objects(java.util.Objects) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) List(java.util.List) EventPriority(net.md_5.bungee.event.EventPriority) ChangeSkinBungee(com.github.games647.changeskin.bungee.ChangeSkinBungee) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) EventHandler(net.md_5.bungee.event.EventHandler) ServerConnectEvent(net.md_5.bungee.api.event.ServerConnectEvent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProxyServer(net.md_5.bungee.api.ProxyServer) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) ServerInfo(net.md_5.bungee.api.config.ServerInfo) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with ServerConnectEvent

use of net.md_5.bungee.api.event.ServerConnectEvent in project CloudNet by Dytanic.

the class ProxiedListener method handleServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleServerConnect(ServerConnectEvent event) {
    if (event.getPlayer().getServer() == null) {
        String fallback = CloudProxy.getInstance().fallback(event.getPlayer());
        ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(event.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(event.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
        ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
        fallback = proxiedPlayerFallbackEvent.getFallback();
        if (fallback != null) {
            event.setTarget(ProxyServer.getInstance().getServerInfo(fallback));
            CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
            NetworkUtils.sleepUninterruptedly(6);
        } else
            event.setCancelled(true);
    } else {
        CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
        NetworkUtils.sleepUninterruptedly(6);
    }
}
Also used : ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent) Document(de.dytanic.cloudnet.lib.utility.document.Document) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)3 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 Packet (com.alessiodp.parties.bungeecord.utils.Packet)1 ChangeSkinBungee (com.github.games647.changeskin.bungee.ChangeSkinBungee)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)1 ProxiedPlayerFallbackEvent (de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)1 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ProxyServer (net.md_5.bungee.api.ProxyServer)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 Server (net.md_5.bungee.api.connection.Server)1 ServerConnectEvent (net.md_5.bungee.api.event.ServerConnectEvent)1 EventPriority (net.md_5.bungee.event.EventPriority)1