33import com .destroystokyo .paper .event .profile .PreLookupProfileEvent ;
44import com .destroystokyo .paper .profile .ProfileProperty ;
55import com .google .common .base .Charsets ;
6+ import io .papermc .paper .event .connection .PlayerConnectionValidateLoginEvent ;
7+ import io .papermc .paper .event .player .PlayerServerFullCheckEvent ;
68import net .kyori .adventure .text .Component ;
79import net .kyori .adventure .text .serializer .legacy .LegacyComponentSerializer ;
810import net .kyori .adventure .title .Title ;
9- import org .bukkit .Bukkit ;
1011import org .bukkit .Location ;
11- import org .bukkit .Server ;
1212import org .bukkit .World ;
1313import org .bukkit .configuration .file .FileConfiguration ;
1414import org .bukkit .entity .Player ;
1515import org .bukkit .event .EventHandler ;
1616import org .bukkit .event .Listener ;
1717import org .bukkit .event .player .*;
18- import org .bukkit .event .player .PlayerLoginEvent .Result ;
1918import org .bukkit .plugin .java .JavaPlugin ;
2019import org .spigotmc .event .player .PlayerSpawnLocationEvent ;
2120import pw .kaboom .extras .Main ;
2524
2625import java .time .Duration ;
2726import java .util .HashSet ;
27+ import java .util .Set ;
2828import java .util .UUID ;
2929import java .util .concurrent .ThreadLocalRandom ;
3030
@@ -57,6 +57,7 @@ public final class PlayerConnection implements Listener {
5757 "allowJoinOnFullServer" );
5858 private static final boolean OP_ON_JOIN = CONFIG .getBoolean ("opOnJoin" );
5959 private static final boolean RANDOMIZE_SPAWN = CONFIG .getBoolean ("randomizeSpawn" );
60+ private final Set <UUID > disallowedLogins = new HashSet <>(5 );
6061
6162 @ EventHandler
6263 void onAsyncPlayerPreLogin (final AsyncPlayerPreLoginEvent event ) {
@@ -85,13 +86,21 @@ void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
8586 void onPlayerJoin (final PlayerJoinEvent event ) {
8687 final Player player = event .getPlayer ();
8788
89+ if (OP_ON_JOIN && !player .isOp ()) {
90+ player .setOp (true );
91+ }
92+
8893 player .showTitle (Title .title (
8994 TITLE ,
9095 SUBTITLE ,
9196 Title .Times .times (FADE_IN , STAY , FADE_OUT )
9297 ));
9398
9499 ServerTabComplete .getLoginNameList ().put (player .getUniqueId (), player .getName ());
100+
101+ if (!player .getPlayerProfile ().hasTextures ()) {
102+ SkinManager .applySkin (player , player .getName (), false );
103+ }
95104 }
96105
97106 @ EventHandler
@@ -102,34 +111,32 @@ void onPlayerKick(final PlayerKickEvent event) {
102111 }
103112
104113 @ EventHandler
105- void onPlayerLogin (final PlayerLoginEvent event ) {
106- // #312 - If allow join on full server is off,
107- // but join restrictions are disabled,
108- // player can still join on full server
109-
110- // Full server kicks should be handled differently from other join restrictions
111- // since we have a separate configuration value for it
112-
113- if (!ENABLE_JOIN_RESTRICTIONS && !Result .KICK_FULL .equals (event .getResult ())) {
114- event .allow ();
114+ void onPlayerServerFullCheck (final PlayerServerFullCheckEvent event ) {
115+ if (ALLOW_JOIN_ON_FULL_SERVER ) {
116+ event .allow (true );
117+ } else if (!event .isAllowed ()) {
118+ this .disallowedLogins .add (event .getPlayerProfile ().getId ());
115119 }
120+ }
116121
117- if (Result .KICK_FULL .equals (event .getResult ()) && ALLOW_JOIN_ON_FULL_SERVER ) {
122+ // Note that this event gets fired even if FullCheckEvent returns disallowed, meaning we need
123+ // to keep track of the player's allowed state across events. Yuck.
124+ @ SuppressWarnings ("UnstableApiUsage" )
125+ @ EventHandler
126+ void onPlayerConnectionValidate (final PlayerConnectionValidateLoginEvent event ) {
127+ // #312 - If allow join on full server is off, but join restrictions are disabled, player
128+ // can still join on full server
129+
130+ // Full server kicks should be handled differently from other join restrictions since we
131+ // have a separate configuration value for it
132+ final UUID uuid = Utility .getConnectionUuid (event .getConnection ());
133+ final boolean disallowed = this .disallowedLogins .remove (uuid );
134+
135+ // If uuid is null, disallowedLogins will never contain it. So we always let connections
136+ // without a UUID through if join restrictions are disabled.
137+ if (!ENABLE_JOIN_RESTRICTIONS && !disallowed ) {
118138 event .allow ();
119139 }
120-
121- final Player player = event .getPlayer ();
122-
123- if (OP_ON_JOIN && !player .isOp ()) {
124- player .setOp (true );
125- }
126-
127- final Server server = Bukkit .getServer ();
128-
129-
130- if (!server .getOnlineMode ()) {
131- SkinManager .applySkin (player , player .getName (), false );
132- }
133140 }
134141
135142 @ EventHandler
0 commit comments