Search in sources :

Example 11 with Server

use of net.md_5.bungee.api.connection.Server in project ChangeSkin by games647.

the class ChangeSkinBungee method onEnable.

@Override
public void onEnable() {
    logger = CommonUtil.createLoggerFromJDK(getLogger());
    core = new ChangeSkinCore(this);
    try {
        core.load(true);
    } catch (Exception ioExc) {
        logger.error("Error initializing plugin. Disabling...", ioExc);
        return;
    }
    PluginManager pluginManager = getProxy().getPluginManager();
    pluginManager.registerListener(this, new ConnectListener(this));
    pluginManager.registerListener(this, new ServerSwitchListener(this));
    // this is required to listen to messages from the server
    getProxy().registerChannel(getName());
    pluginManager.registerListener(this, new MessageListener(this));
    // register commands
    pluginManager.registerCommand(this, new SetCommand(this));
    pluginManager.registerCommand(this, new InvalidateCommand(this));
    pluginManager.registerCommand(this, new UploadCommand(this));
    pluginManager.registerCommand(this, new SelectCommand(this));
    pluginManager.registerCommand(this, new InfoCommand(this));
}
Also used : PluginManager(net.md_5.bungee.api.plugin.PluginManager) ChangeSkinCore(com.github.games647.changeskin.core.ChangeSkinCore) ServerSwitchListener(com.github.games647.changeskin.bungee.listener.ServerSwitchListener) UploadCommand(com.github.games647.changeskin.bungee.command.UploadCommand) InfoCommand(com.github.games647.changeskin.bungee.command.InfoCommand) MessageListener(com.github.games647.changeskin.bungee.listener.MessageListener) SelectCommand(com.github.games647.changeskin.bungee.command.SelectCommand) ConnectListener(com.github.games647.changeskin.bungee.listener.ConnectListener) InvalidateCommand(com.github.games647.changeskin.bungee.command.InvalidateCommand) SetCommand(com.github.games647.changeskin.bungee.command.SetCommand)

Example 12 with Server

use of net.md_5.bungee.api.connection.Server 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 13 with Server

use of net.md_5.bungee.api.connection.Server in project UltimateChat by FabioZumbi12.

the class UCProxy method sendMessage.

public void sendMessage(Connection server, String ch, String json, String id) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(stream);
    try {
        out.writeUTF(id);
        out.writeUTF(ch);
        out.writeUTF(json);
    } catch (IOException e) {
        e.printStackTrace();
    }
    for (ServerInfo si : getProxy().getServers().values()) {
        si.sendData("uChat", stream.toByteArray());
    }
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo)

Example 14 with Server

use of net.md_5.bungee.api.connection.Server in project LuckPerms by lucko.

the class BungeeMessenger method onPluginMessage.

@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
    if (!e.getTag().equals(CHANNEL)) {
        return;
    }
    e.setCancelled(true);
    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }
    byte[] data = e.getData();
    ByteArrayDataInput in = ByteStreams.newDataInput(data);
    String msg = in.readUTF();
    if (this.consumer.consumeIncomingMessageAsString(msg)) {
        // Forward to other servers
        this.plugin.getBootstrap().getScheduler().doAsync(() -> {
            for (ServerInfo server : this.plugin.getBootstrap().getProxy().getServers().values()) {
                server.sendData(CHANNEL, data, true);
            }
        });
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) EventHandler(net.md_5.bungee.event.EventHandler)

Example 15 with Server

use of net.md_5.bungee.api.connection.Server in project LuckPerms by lucko.

the class BungeeMessenger method sendOutgoingMessage.

@Override
public void sendOutgoingMessage(@Nonnull OutgoingMessage outgoingMessage) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(outgoingMessage.asEncodedString());
    byte[] data = out.toByteArray();
    for (ServerInfo server : this.plugin.getBootstrap().getProxy().getServers().values()) {
        server.sendData(CHANNEL, data, true);
    }
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)6 Document (de.dytanic.cloudnet.lib.utility.document.Document)5 ServerInfo (net.md_5.bungee.api.config.ServerInfo)5 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 File (java.io.File)4 Configuration (net.md_5.bungee.config.Configuration)4 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)4 Path (java.nio.file.Path)3 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)3 UserPreference (com.github.games647.changeskin.core.model.UserPreference)2 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)2 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)2 Template (de.dytanic.cloudnet.lib.server.template.Template)2 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)2 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)2 Properties (java.util.Properties)2