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