Skip to content

Commit cccc145

Browse files
authored
chore(deps): upgrade to Minestom 1.21.2+ (#4)
2 parents d767445 + 1683783 commit cccc145

File tree

51 files changed

+542
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+542
-775
lines changed

api/src/main/java/net/luckperms/api/LuckPermsProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ private static final class NotLoadedException extends IllegalStateException {
7979
" a) the LuckPerms plugin is not installed or it failed to enable\n" +
8080
" b) the plugin in the stacktrace does not declare a dependency on LuckPerms\n" +
8181
" c) the plugin in the stacktrace is retrieving the API before the plugin 'enable' phase\n" +
82-
" (call the #get method in onEnable, not the constructor!)\n";
82+
" (call the #get method in onEnable, not the constructor!)\n" +
83+
" d) the plugin in the stacktrace is incorrectly 'shading' the LuckPerms API into its jar\n";
8384

8485
NotLoadedException() {
8586
super(MESSAGE);

bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,13 @@
2525

2626
package me.lucko.luckperms.bungee.context;
2727

28-
import com.github.benmanes.caffeine.cache.LoadingCache;
2928
import me.lucko.luckperms.bungee.LPBungeePlugin;
30-
import me.lucko.luckperms.common.context.manager.ContextManager;
31-
import me.lucko.luckperms.common.context.manager.InlineQueryOptionsSupplier;
32-
import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier;
33-
import me.lucko.luckperms.common.util.CaffeineFactory;
34-
import net.luckperms.api.context.ImmutableContextSet;
35-
import net.luckperms.api.query.QueryOptions;
29+
import me.lucko.luckperms.common.context.manager.InlineContextManager;
3630
import net.md_5.bungee.api.connection.ProxiedPlayer;
3731

3832
import java.util.UUID;
39-
import java.util.concurrent.TimeUnit;
40-
41-
public class BungeeContextManager extends ContextManager<ProxiedPlayer, ProxiedPlayer> {
42-
43-
private final LoadingCache<ProxiedPlayer, QueryOptions> contextsCache = CaffeineFactory.newBuilder()
44-
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
45-
.build(this::calculate);
4633

34+
public class BungeeContextManager extends InlineContextManager<ProxiedPlayer, ProxiedPlayer> {
4735
public BungeeContextManager(LPBungeePlugin plugin) {
4836
super(plugin, ProxiedPlayer.class, ProxiedPlayer.class);
4937
}
@@ -52,35 +40,4 @@ public BungeeContextManager(LPBungeePlugin plugin) {
5240
public UUID getUniqueId(ProxiedPlayer player) {
5341
return player.getUniqueId();
5442
}
55-
56-
@Override
57-
public QueryOptionsSupplier getCacheFor(ProxiedPlayer subject) {
58-
if (subject == null) {
59-
throw new NullPointerException("subject");
60-
}
61-
62-
return new InlineQueryOptionsSupplier<>(subject, this.contextsCache);
63-
}
64-
65-
// override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier
66-
@Override
67-
public ImmutableContextSet getContext(ProxiedPlayer subject) {
68-
return getQueryOptions(subject).context();
69-
}
70-
71-
@Override
72-
public QueryOptions getQueryOptions(ProxiedPlayer subject) {
73-
return this.contextsCache.get(subject);
74-
}
75-
76-
@Override
77-
protected void invalidateCache(ProxiedPlayer subject) {
78-
this.contextsCache.invalidate(subject);
79-
}
80-
81-
@Override
82-
public QueryOptions formQueryOptions(ProxiedPlayer subject, ImmutableContextSet contextSet) {
83-
return formQueryOptions(contextSet);
84-
}
85-
8643
}

common/src/main/java/me/lucko/luckperms/common/context/manager/ContextManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
/**
4949
* Base implementation of {@link ContextManager} which caches content lookups.
5050
*
51-
* @param <S> the calculator type
51+
* @param <S> the subject type
52+
* @param <P> the player type
5253
*/
5354
public abstract class ContextManager<S, P extends S> {
5455

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
package me.lucko.luckperms.common.context.manager;
27+
28+
import com.github.benmanes.caffeine.cache.LoadingCache;
29+
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
30+
import me.lucko.luckperms.common.util.CaffeineFactory;
31+
import net.luckperms.api.context.ImmutableContextSet;
32+
import net.luckperms.api.query.QueryOptions;
33+
34+
import java.util.concurrent.TimeUnit;
35+
36+
public abstract class InlineContextManager<S, P extends S> extends ContextManager<S, P> {
37+
38+
private final LoadingCache<S, QueryOptions> contextsCache = CaffeineFactory.newBuilder()
39+
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
40+
.build(this::calculate);
41+
42+
protected InlineContextManager(LuckPermsPlugin plugin, Class<S> subjectClass, Class<P> playerClass) {
43+
super(plugin, subjectClass, playerClass);
44+
}
45+
46+
@Override
47+
public final QueryOptionsSupplier getCacheFor(S subject) {
48+
if (subject == null) {
49+
throw new NullPointerException("subject");
50+
}
51+
52+
return new InlineQueryOptionsSupplier<>(subject, this.contextsCache);
53+
}
54+
55+
// override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier
56+
@Override
57+
public final ImmutableContextSet getContext(S subject) {
58+
return getQueryOptions(subject).context();
59+
}
60+
61+
@Override
62+
public final QueryOptions getQueryOptions(S subject) {
63+
return this.contextsCache.get(subject);
64+
}
65+
66+
@Override
67+
protected final void invalidateCache(S subject) {
68+
this.contextsCache.invalidate(subject);
69+
}
70+
71+
@Override
72+
public QueryOptions formQueryOptions(S subject, ImmutableContextSet contextSet) {
73+
return formQueryOptions(contextSet);
74+
}
75+
76+
private static final class InlineQueryOptionsSupplier<T> implements QueryOptionsSupplier {
77+
private final T key;
78+
private final LoadingCache<T, QueryOptions> cache;
79+
80+
InlineQueryOptionsSupplier(T key, LoadingCache<T, QueryOptions> cache) {
81+
this.key = key;
82+
this.cache = cache;
83+
}
84+
85+
@Override
86+
public QueryOptions getQueryOptions() {
87+
return this.cache.get(this.key);
88+
}
89+
}
90+
}

common/src/main/java/me/lucko/luckperms/common/messaging/sql/SqlMessenger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ protected Connection getConnection() throws SQLException {
8686

8787
@Override
8888
protected String getTableName() {
89-
return this.sqlStorage.getStatementProcessor().apply("{prefix}messenger");
89+
return this.sqlStorage.getStatementProcessor().process("{prefix}messenger");
9090
}
9191
}

common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/SchemaReader.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,24 @@
3232
import java.nio.charset.StandardCharsets;
3333
import java.util.LinkedList;
3434
import java.util.List;
35+
import java.util.Locale;
36+
import java.util.regex.Matcher;
37+
import java.util.regex.Pattern;
38+
import java.util.stream.Collectors;
3539

3640
public final class SchemaReader {
3741
private SchemaReader() {}
3842

43+
private static final Pattern CREATE_TABLE_PATTERN = Pattern.compile("^CREATE TABLE [`\"']([^`\"']+)[`\"'].*");
44+
private static final Pattern CREATE_INDEX_PATTERN = Pattern.compile("^CREATE INDEX.* ON [`\"']([^`\"']+)[`\"'].*");
45+
46+
/**
47+
* Parses a schema file to a list of SQL statements
48+
*
49+
* @param is the input stream to read from
50+
* @return a list of statements
51+
* @throws IOException if an error occurs whilst reading the file
52+
*/
3953
public static List<String> getStatements(InputStream is) throws IOException {
4054
List<String> queries = new LinkedList<>();
4155

@@ -53,7 +67,7 @@ public static List<String> getStatements(InputStream is) throws IOException {
5367
if (line.endsWith(";")) {
5468
sb.deleteCharAt(sb.length() - 1);
5569

56-
String result = sb.toString().trim();
70+
String result = sb.toString().trim().replaceAll(" +", " ");
5771
if (!result.isEmpty()) {
5872
queries.add(result);
5973
}
@@ -66,4 +80,29 @@ public static List<String> getStatements(InputStream is) throws IOException {
6680

6781
return queries;
6882
}
83+
84+
public static String tableFromStatement(String statement) {
85+
Matcher table = CREATE_TABLE_PATTERN.matcher(statement);
86+
if (table.matches()) {
87+
return table.group(1).toLowerCase(Locale.ROOT);
88+
}
89+
Matcher index = CREATE_INDEX_PATTERN.matcher(statement);
90+
if (index.matches()) {
91+
return index.group(1).toLowerCase(Locale.ROOT);
92+
}
93+
throw new IllegalArgumentException("Unknown statement type: " + statement);
94+
}
95+
96+
/**
97+
* Filters which statements should be executed based on the current list of tables in the database
98+
*
99+
* @param statements the statements to filter
100+
* @param currentTables the current tables in the database
101+
* @return the filtered list of statements
102+
*/
103+
public static List<String> filterStatements(List<String> statements, List<String> currentTables) {
104+
return statements.stream()
105+
.filter(statement -> !currentTables.contains(tableFromStatement(statement)))
106+
.collect(Collectors.toList());
107+
}
69108
}

0 commit comments

Comments
 (0)