Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for player's groups off the main thread. #6192

Merged
merged 4 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
implementation group: 'com.sk89q.worldguard', name: 'worldguard-legacy', version: '7.0.0-SNAPSHOT'
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.1', {
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.3', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@Name("Group")
@Description({
Expand All @@ -53,7 +54,7 @@
public class ExprGroup extends SimpleExpression<String> {

static {
PropertyExpression.register(ExprGroup.class, String.class, "group[(1¦s)]", "offlineplayers");
PropertyExpression.register(ExprGroup.class, String.class, "group[plural:s]", "offlineplayers");
}

private boolean primary;
Expand All @@ -68,21 +69,25 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
return false;
}
players = (Expression<OfflinePlayer>) exprs[0];
primary = parseResult.mark == 0;
primary = !parseResult.hasTag("plural");
return true;
}

@SuppressWarnings("null")
@Override
protected String[] get(Event e) {
List<String> groups = new ArrayList<>();
for (OfflinePlayer player : players.getArray(e)) {
if (primary)
groups.add(VaultHook.permission.getPrimaryGroup(null, player));
else
Collections.addAll(groups, VaultHook.permission.getPlayerGroups(null, player));
}
return groups.toArray(new String[0]);
protected String[] get(Event event) {
OfflinePlayer[] players = this.players.getArray(event);
return CompletableFuture.supplyAsync(() -> { // #5692: LuckPerms errors for vault requests on main thread
List<String> groups = new ArrayList<>();
for (OfflinePlayer player : players) {
if (primary) {
groups.add(VaultHook.permission.getPrimaryGroup(null, player));
} else {
Collections.addAll(groups, VaultHook.permission.getPlayerGroups(null, player));
}
}
return groups.toArray(new String[0]);
}).join();
}

@Override
Expand Down Expand Up @@ -140,8 +145,8 @@ public Class<? extends String> getReturnType() {

@SuppressWarnings("null")
@Override
public String toString(Event e, boolean debug) {
return "group" + (primary ? "" : "s") + " of " + players.toString(e, debug);
public String toString(Event event, boolean debug) {
return "group" + (primary ? "" : "s") + " of " + players.toString(event, debug);
}

}
Loading