1010import com .velocitypowered .api .proxy .server .RegisteredServer ;
1111import net .kyori .adventure .text .Component ;
1212import net .kyori .adventure .text .logger .slf4j .ComponentLogger ;
13+ import net .kyori .adventure .text .serializer .plain .PlainTextComponentSerializer ;
1314import net .kyori .adventure .title .Title ;
1415
1516import java .time .Duration ;
@@ -73,6 +74,13 @@ public int getSize() {
7374 return playerQueue .size ();
7475 }
7576
77+ /**
78+ * Converts Component to a plain string
79+ */
80+ private String toPlainText (Component component ) {
81+ return PlainTextComponentSerializer .plainText ().serialize (component );
82+ }
83+
7684 /**
7785 * This event is fired before the player connects to a server.
7886 * Velocity will wait on this event to finish firing before initiating the connection.
@@ -95,7 +103,7 @@ public void onServerPreConnect(ServerPreConnectEvent event) {
95103 if (currentPlayers < Config .maxPlayers ) {
96104 // Allow direct connection to target server
97105 event .setResult (ServerPreConnectEvent .ServerResult .allowed (serverTarget ));
98- log .info (mm ("<white>" + event .getPlayer ().getUsername () + "<dark_aqua> was directly connected to server <aqua>" + Config .target + "<dark_aqua>. Main count is " + (getSize () + 1 ) + " of " + Config .maxPlayers + "." ));
106+ log .info (mm ("<white>" + event .getPlayer ().getUsername () + "<dark_aqua> was directly connected to server <aqua>" + Config .target + "<dark_aqua>. Main count is " + (serverTarget . getPlayersConnected (). size () + 1 ) + " of " + Config .maxPlayers + "." ));
99107 } else {
100108 // Notify player that server is full
101109 event .getPlayer ().sendMessage (mm (Config .messageFull ));
@@ -167,16 +175,26 @@ public void onPlayerDisconnect(DisconnectEvent event) {
167175 }
168176 }
169177
170-
171178 /**
172179 * Kick a player if kicking is allowed in the config
173180 *
174181 * @param player Player to kick
175182 * @param reason kicking reason from the target server
176183 */
177184 private void KickOrRequeue (Player player , Component reason ) {
178- // is kicking enabled?
179- if (!Config .kick ) {
185+ String textReason = toPlainText (reason );
186+
187+ // Cancel the event, if one of the following:
188+ // - kicking is not enabled
189+ // - target is restarting (and restart kicks are disabled)
190+ // - target is busy with connecting players (and busy kicks are disabled)
191+ if (!Config .kickPassthrough
192+ || (!Config .kickOnRestart && textReason .contains ("Server is restarting" )) // Restart
193+ || (!Config .kickOnRestart && textReason .contains ("Kicked without a reason." )) // Server went down
194+ || (!Config .kickOnRestart && textReason .contains ("Server closed" )) // Server stopped
195+ || (!Config .kickOnBusy && textReason .contains ("Too many people logging in, retry soon." )) // NCP
196+ || (!Config .kickOnBusy && textReason .contains ("Too fast re-login, try with a little delay." )) // NCP
197+ ) {
180198 // save the disconnection time
181199 kickedPlayers .put (player , Instant .now ().getEpochSecond ());
182200
0 commit comments