From c49b7457de78a33e858627eb9c7f71281535c7d6 Mon Sep 17 00:00:00 2001 From: CodeTheDev Date: Fri, 3 Feb 2023 14:55:41 -0500 Subject: [PATCH] feat: implement proper player limit - disconnect if player count is over or equal to set limit. --- README.md | 2 +- src/main/java/dev/codeerror/overflow/OverflowLimbo.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ef172b..8ccb9b1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ To find the compiled server jar, navigate to the `build/libs` directory inside t | *server-port* | `25565` | Integer | The port of the server. | | *compression-threshold* | `-1` | Integer | Network Compression (-1 is 0, which means no compression). | | *view-distance* | `3` | Integer | Player view distance (May cause visual issues if set below 3). | -| *max-players* | `-1` | Integer | Maximum player limit (-1 is unlimited, player limit is only visual). | +| *max-players* | `-1` | Integer | Maximum player limit (-1 is unlimited). | | *motd* | `An OverflowLimbo Server` | String | Server list MOTD (Uses MiniMessage text formatting). | | *tablist-enabled* | `false` | Boolean | Toggle tablist visibility. | | *proxy-type* | `none` | String | Specifies the type of proxy being used (velocity, bungeecord, none). | diff --git a/src/main/java/dev/codeerror/overflow/OverflowLimbo.java b/src/main/java/dev/codeerror/overflow/OverflowLimbo.java index 17a1282..dc4dcf1 100644 --- a/src/main/java/dev/codeerror/overflow/OverflowLimbo.java +++ b/src/main/java/dev/codeerror/overflow/OverflowLimbo.java @@ -100,7 +100,11 @@ public static void main(String[] args) { }); events.addListener(AsyncPlayerPreLoginEvent.class, event -> { Player player = event.getPlayer(); - logger.info(player.getUsername() + " [" + player.getPlayerConnection().getRemoteAddress() + "] connected."); + if (world.getPlayers().size() >= config.getPlayerLimit() && config.getPlayerLimit() > -1) { + event.getPlayer().getPlayerConnection().disconnect(); + } else { + logger.info(player.getUsername() + " [" + player.getPlayerConnection().getRemoteAddress() + "] connected."); + } }); events.addListener(PlayerLoginEvent.class, event -> { Player player = event.getPlayer();