3
3
import com .destroystokyo .paper .event .profile .PreLookupProfileEvent ;
4
4
import com .destroystokyo .paper .profile .ProfileProperty ;
5
5
import com .google .common .base .Charsets ;
6
+ import io .papermc .paper .event .connection .PlayerConnectionValidateLoginEvent ;
7
+ import io .papermc .paper .event .player .PlayerServerFullCheckEvent ;
6
8
import net .kyori .adventure .text .Component ;
7
9
import net .kyori .adventure .text .serializer .legacy .LegacyComponentSerializer ;
8
10
import net .kyori .adventure .title .Title ;
9
- import org .bukkit .Bukkit ;
10
11
import org .bukkit .Location ;
11
- import org .bukkit .Server ;
12
12
import org .bukkit .World ;
13
13
import org .bukkit .configuration .file .FileConfiguration ;
14
14
import org .bukkit .entity .Player ;
15
15
import org .bukkit .event .EventHandler ;
16
16
import org .bukkit .event .Listener ;
17
17
import org .bukkit .event .player .*;
18
- import org .bukkit .event .player .PlayerLoginEvent .Result ;
19
18
import org .bukkit .plugin .java .JavaPlugin ;
20
19
import org .spigotmc .event .player .PlayerSpawnLocationEvent ;
21
20
import pw .kaboom .extras .Main ;
25
24
26
25
import java .time .Duration ;
27
26
import java .util .HashSet ;
27
+ import java .util .Set ;
28
28
import java .util .UUID ;
29
29
import java .util .concurrent .ThreadLocalRandom ;
30
30
@@ -57,6 +57,7 @@ public final class PlayerConnection implements Listener {
57
57
"allowJoinOnFullServer" );
58
58
private static final boolean OP_ON_JOIN = CONFIG .getBoolean ("opOnJoin" );
59
59
private static final boolean RANDOMIZE_SPAWN = CONFIG .getBoolean ("randomizeSpawn" );
60
+ private final Set <UUID > disallowedLogins = new HashSet <>(5 );
60
61
61
62
@ EventHandler
62
63
void onAsyncPlayerPreLogin (final AsyncPlayerPreLoginEvent event ) {
@@ -85,13 +86,21 @@ void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
85
86
void onPlayerJoin (final PlayerJoinEvent event ) {
86
87
final Player player = event .getPlayer ();
87
88
89
+ if (OP_ON_JOIN && !player .isOp ()) {
90
+ player .setOp (true );
91
+ }
92
+
88
93
player .showTitle (Title .title (
89
94
TITLE ,
90
95
SUBTITLE ,
91
96
Title .Times .times (FADE_IN , STAY , FADE_OUT )
92
97
));
93
98
94
99
ServerTabComplete .getLoginNameList ().put (player .getUniqueId (), player .getName ());
100
+
101
+ if (!player .getPlayerProfile ().hasTextures ()) {
102
+ SkinManager .applySkin (player , player .getName (), false );
103
+ }
95
104
}
96
105
97
106
@ EventHandler
@@ -102,34 +111,32 @@ void onPlayerKick(final PlayerKickEvent event) {
102
111
}
103
112
104
113
@ 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 ());
115
119
}
120
+ }
116
121
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 ) {
118
138
event .allow ();
119
139
}
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
- }
133
140
}
134
141
135
142
@ EventHandler
0 commit comments