use of com.velocitypowered.api.event.player.KickedFromServerEvent in project SubServers-2 by ME1312.
the class ExProxy method validate.
@Subscribe(order = PostOrder.LAST)
public void validate(ServerPreConnectEvent e) {
if (e.getPlayer().isActive()) {
ServerData server = getData(e.getOriginalServer().getServerInfo());
if (server == null || !server.canAccess(e.getPlayer())) {
if (!e.getPlayer().getCurrentServer().isPresent() || fallback.containsKey(e.getPlayer().getUniqueId())) {
if (!fallback.containsKey(e.getPlayer().getUniqueId()) || fallback.get(e.getPlayer().getUniqueId()).names.contains(e.getOriginalServer().getServerInfo().getName())) {
Component text = ChatColor.convertColor(api.getLang("SubServers", "Bungee.Restricted"));
KickedFromServerEvent kick = new KickedFromServerEvent(e.getPlayer(), e.getOriginalServer(), text, true, KickedFromServerEvent.DisconnectPlayer.create(text));
fallback(kick);
if (e.getPlayer().getCurrentServer().isPresent())
e.setResult(ServerPreConnectEvent.ServerResult.denied());
if (kick.getResult() instanceof KickedFromServerEvent.DisconnectPlayer)
e.getPlayer().disconnect(text);
else if (kick.getResult() instanceof KickedFromServerEvent.RedirectPlayer)
e.getPlayer().createConnectionRequest(((KickedFromServerEvent.RedirectPlayer) kick.getResult()).getServer()).fireAndForget();
}
} else {
e.getPlayer().sendMessage(ChatColor.convertColor(api.getLang("SubServers", "Bungee.Restricted")));
e.setResult(ServerPreConnectEvent.ServerResult.denied());
}
} else if (e.getPlayer().getCurrentServer().isPresent() && !fallback.containsKey(e.getPlayer().getUniqueId()) && server instanceof SubServerData && !((SubServerData) server).isRunning()) {
e.getPlayer().sendMessage(ChatColor.convertColor(api.getLang("SubServers", "Bungee.Server.Offline")));
e.setResult(ServerPreConnectEvent.ServerResult.denied());
}
if (fallback.containsKey(e.getPlayer().getUniqueId())) {
FallbackState state = fallback.get(e.getPlayer().getUniqueId());
if (state.names.contains(e.getOriginalServer().getServerInfo().getName())) {
state.remove(e.getOriginalServer().getServerInfo().getName());
} else if (e.getPlayer().getCurrentServer().isPresent()) {
fallback.remove(e.getPlayer().getUniqueId());
}
}
} else {
e.setResult(ServerPreConnectEvent.ServerResult.denied());
}
}
use of com.velocitypowered.api.event.player.KickedFromServerEvent in project ProxyQueues by JLyne.
the class ProxyQueueEventHandler method onKick.
@Subscribe(order = PostOrder.LAST)
public void onKick(KickedFromServerEvent event) {
if (!event.getServer().equals(queue.getServer()) || event.kickedDuringServerConnect()) {
return;
}
proxyQueues.getLogger().debug("Player " + event.getPlayer().getUsername() + " kicked from " + event.getServer().getServerInfo().getName() + ". Reason: " + event.getServerKickReason());
Component reason = event.getServerKickReason().orElse(Component.empty());
String reasonPlain = PlainTextComponentSerializer.plainText().serialize(reason);
List<String> fatalErrors = proxyQueues.getSettingsHandler().getSettingsManager().getProperty(ConfigOptions.FATAL_ERRORS);
Optional<RegisteredServer> waitingServer = proxyQueues.getWaitingServer();
boolean fatal = fatalErrors.stream().anyMatch(reasonPlain::contains);
if (!fatal) {
proxyQueues.getLogger().debug("Reason not fatal, re-queueing " + event.getPlayer().getUsername());
boolean staff = event.getPlayer().hasPermission(settingsManager.getProperty(ConfigOptions.STAFF_PERMISSION));
queue.addPlayer(event.getPlayer(), staff ? QueueType.STAFF : QueueType.PRIORITY);
if (event.getResult() instanceof KickedFromServerEvent.DisconnectPlayer && waitingServer.isPresent()) {
event.setResult(KickedFromServerEvent.RedirectPlayer.create(waitingServer.get()));
}
} else {
proxyQueues.getLogger().debug("Reason fatal");
}
}
Aggregations