use of net.md_5.bungee.event.EventHandler 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.event.EventHandler in project ChangeSkin by games647.
the class ConnectListener method onPostLogin.
@EventHandler(priority = EventPriority.HIGH)
public void onPostLogin(LoginEvent loginEvent) {
if (loginEvent.isCancelled() || isBlacklistEnabled()) {
return;
}
PendingConnection connection = loginEvent.getConnection();
String playerName = connection.getName().toLowerCase();
loginEvent.registerIntent(plugin);
Runnable task = () -> loadProfile(loginEvent, connection, playerName);
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
}
use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.
the class ConnectListener method onPlayerLogin.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(PostLoginEvent postLoginEvent) {
ProxiedPlayer player = postLoginEvent.getPlayer();
UserPreference preferences = plugin.getLoginSession(player.getPendingConnection());
if (preferences == null || isBlacklistEnabled()) {
return;
}
if (!preferences.getTargetSkin().isPresent()) {
getRandomSkin().ifPresent(preferences::setTargetSkin);
}
preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.
the class ConnectListener method onDisconnect.
@EventHandler
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
PendingConnection pendingConnection = disconnectEvent.getPlayer().getPendingConnection();
UserPreference preference = plugin.endSession(pendingConnection);
if (preference != null) {
save(preference);
}
}
use of net.md_5.bungee.event.EventHandler in project ViaCheckConnection by x9nico.
the class Bungee method join.
@SuppressWarnings({ "unchecked" })
@EventHandler
public void join(ServerConnectedEvent e) throws IOException {
ProxiedPlayer p = e.getPlayer();
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
if (Bungee.isProtocolSupport()) {
if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_7_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_6.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_7_6").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
}
} else {
if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
}
}
}
Aggregations