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));
}
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));
}
}
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());
}
}
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);
}
});
}
}
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);
}
}
Aggregations