-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set server max players to number of total members (#25)
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/pro/cloudnode/smp/smpcore/listener/PlayerSlotsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pro.cloudnode.smp.smpcore.listener; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerLoginEvent; | ||
import org.bukkit.event.server.ServerListPingEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import pro.cloudnode.smp.smpcore.Member; | ||
|
||
import java.util.Optional; | ||
|
||
public final class PlayerSlotsListener implements Listener { | ||
/** | ||
* Change the max players number in server list ping | ||
*/ | ||
@EventHandler | ||
public void onServerListPing(final @NotNull ServerListPingEvent event) { | ||
event.setMaxPlayers(Member.count()); | ||
} | ||
|
||
/** | ||
* If the player is a member, but the server thinks it's full, allow them to join | ||
*/ | ||
@EventHandler | ||
public void onPlayerLogin(final @NotNull PlayerLoginEvent event) { | ||
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) { | ||
final @NotNull Optional<@NotNull Member> member = Member.get(event.getPlayer()); | ||
if (member.isPresent()) event.allow(); | ||
} | ||
} | ||
} |