Skip to content

Commit 37e1054

Browse files
authored
Switch to configuration based events on Paper (#6248)
Moves away from PlayerLoginEvent on Paper and makes use of the new configuration state to load user/locale data during configuration phase. Not only does this ensure all I/O is done async before the player even joins but also finally allows us to actually set the join message in the PlayerJoinEvent. This also fixes #5796 and closes #5848
1 parent 0aa25c8 commit 37e1054

File tree

12 files changed

+352
-1481
lines changed

12 files changed

+352
-1481
lines changed

Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java

Lines changed: 274 additions & 196 deletions
Large diffs are not rendered by default.

Essentials/src/main/java/com/earth2me/essentials/User.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,10 @@ public void sendTl(String tlKey, Object... args) {
10981098
public String playerTl(String tlKey, Object... args) {
10991099
if (ess.getSettings().isPerPlayerLocale()) {
11001100
final PlayerLocaleProvider provider = ess.provider(PlayerLocaleProvider.class);
1101-
return tlLocale(getPlayerLocale(provider.getLocale(base)), tlKey, args);
1101+
final Locale locale = base != null ? getPlayerLocale(provider.getLocale(base)) : playerLocale;
1102+
if (locale != null) {
1103+
return tlLocale(locale, tlKey, args);
1104+
}
11021105
}
11031106
return tlLiteral(tlKey, args);
11041107
}

Essentials/src/main/java/com/earth2me/essentials/perm/IPermissionsHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.entity.Player;
88

99
import java.util.List;
10+
import java.util.UUID;
1011
import java.util.function.Function;
1112
import java.util.function.Supplier;
1213

@@ -30,6 +31,8 @@ public interface IPermissionsHandler {
3031
// Does not check for * permissions
3132
boolean isPermissionSet(Player base, String node);
3233

34+
boolean isOfflinePermissionSet(UUID uuid, String node);
35+
3336
TriState isPermissionSetExact(Player base, String node);
3437

3538
String getPrefix(Player base);

Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.List;
2020
import java.util.Optional;
21+
import java.util.UUID;
2122
import java.util.function.Function;
2223
import java.util.function.Supplier;
2324
import java.util.logging.Level;
@@ -106,6 +107,11 @@ public boolean isPermissionSet(final Player base, final String node) {
106107
return handler.isPermissionSet(base, node);
107108
}
108109

110+
@Override
111+
public boolean isOfflinePermissionSet(UUID uuid, String node) {
112+
return handler.isOfflinePermissionSet(uuid, node);
113+
}
114+
109115
@Override
110116
public TriState isPermissionSetExact(Player base, String node) {
111117
return handler.isPermissionSetExact(base, node);

Essentials/src/main/java/com/earth2me/essentials/perm/impl/LuckPermsHandler.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.luckperms.api.context.ContextSet;
99
import net.luckperms.api.context.ImmutableContextSet;
1010
import net.luckperms.api.model.group.Group;
11+
import net.luckperms.api.query.QueryOptions;
1112
import org.bukkit.Bukkit;
1213
import org.bukkit.entity.Player;
1314
import org.bukkit.plugin.RegisteredServiceProvider;
@@ -16,6 +17,7 @@
1617
import java.util.HashSet;
1718
import java.util.List;
1819
import java.util.Set;
20+
import java.util.UUID;
1921
import java.util.function.Function;
2022
import java.util.function.Supplier;
2123

@@ -58,6 +60,17 @@ public List<String> getGroups() {
5860
return groups;
5961
}
6062

63+
@Override
64+
public boolean isOfflinePermissionSet(UUID uuid, String node) {
65+
final net.luckperms.api.model.user.User user = this.luckPerms.getUserManager().loadUser(uuid).join();
66+
if (user == null) {
67+
return false;
68+
}
69+
70+
final QueryOptions options = luckPerms.getContextManager().getStaticQueryOptions();
71+
return user.getCachedData().getPermissionData(options).checkPermission(node).asBoolean();
72+
}
73+
6174
@Override
6275
public boolean tryProvider(Essentials ess) {
6376
final RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);

Essentials/src/main/java/com/earth2me/essentials/perm/impl/SuperpermsHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.util.Arrays;
1515
import java.util.List;
16+
import java.util.UUID;
1617
import java.util.function.Function;
1718
import java.util.function.Supplier;
1819

@@ -121,6 +122,11 @@ public boolean isPermissionSet(final Player base, final String node) {
121122
return base.isPermissionSet(node);
122123
}
123124

125+
@Override
126+
public boolean isOfflinePermissionSet(UUID uuid, String node) {
127+
return false;
128+
}
129+
124130
@Override
125131
public TriState isPermissionSetExact(Player base, String node) {
126132
for (final PermissionAttachmentInfo perm : base.getEffectivePermissions()) {

Essentials/src/main/java/com/earth2me/essentials/userstorage/IUserMap.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public interface IUserMap {
2020
*/
2121
long getCachedCount();
2222

23+
/**
24+
* Checks if a user is cached.
25+
* @param uuid the UUID of the user to check.
26+
* @return true if the user is cached, false otherwise.
27+
*/
28+
boolean isCached(final UUID uuid);
29+
2330
/**
2431
* Gets the amount of users stored by Essentials.
2532
* @return the amount of users stored by Essentials.

Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public long getCachedCount() {
6464
return userCache.size();
6565
}
6666

67+
@Override
68+
public boolean isCached(final UUID uuid) {
69+
if (uuid == null) {
70+
return false;
71+
}
72+
try {
73+
return userCache.getIfPresent(uuid) != null;
74+
} catch (Exception e) {
75+
if (ess.getSettings().isDebug()) {
76+
ess.getLogger().log(Level.WARNING, "Exception while checking if user is cached for " + uuid, e);
77+
}
78+
return false;
79+
}
80+
}
81+
6782
@Override
6883
public int getUserCount() {
6984
return uuidCache.getCacheSize();

providers/1_12Provider/src/main/java/com/earth2me/essentials/FakeAccessor.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)