Skip to content

Commit

Permalink
chore(deps): upgrade to Minestom 1.21.2+ (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
LooFifteen authored Dec 6, 2024
2 parents d767445 + 1683783 commit cccc145
Show file tree
Hide file tree
Showing 51 changed files with 542 additions and 775 deletions.
3 changes: 2 additions & 1 deletion api/src/main/java/net/luckperms/api/LuckPermsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static final class NotLoadedException extends IllegalStateException {
" a) the LuckPerms plugin is not installed or it failed to enable\n" +
" b) the plugin in the stacktrace does not declare a dependency on LuckPerms\n" +
" c) the plugin in the stacktrace is retrieving the API before the plugin 'enable' phase\n" +
" (call the #get method in onEnable, not the constructor!)\n";
" (call the #get method in onEnable, not the constructor!)\n" +
" d) the plugin in the stacktrace is incorrectly 'shading' the LuckPerms API into its jar\n";

NotLoadedException() {
super(MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,13 @@

package me.lucko.luckperms.bungee.context;

import com.github.benmanes.caffeine.cache.LoadingCache;
import me.lucko.luckperms.bungee.LPBungeePlugin;
import me.lucko.luckperms.common.context.manager.ContextManager;
import me.lucko.luckperms.common.context.manager.InlineQueryOptionsSupplier;
import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier;
import me.lucko.luckperms.common.util.CaffeineFactory;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.query.QueryOptions;
import me.lucko.luckperms.common.context.manager.InlineContextManager;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class BungeeContextManager extends ContextManager<ProxiedPlayer, ProxiedPlayer> {

private final LoadingCache<ProxiedPlayer, QueryOptions> contextsCache = CaffeineFactory.newBuilder()
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
.build(this::calculate);

public class BungeeContextManager extends InlineContextManager<ProxiedPlayer, ProxiedPlayer> {
public BungeeContextManager(LPBungeePlugin plugin) {
super(plugin, ProxiedPlayer.class, ProxiedPlayer.class);
}
Expand All @@ -52,35 +40,4 @@ public BungeeContextManager(LPBungeePlugin plugin) {
public UUID getUniqueId(ProxiedPlayer player) {
return player.getUniqueId();
}

@Override
public QueryOptionsSupplier getCacheFor(ProxiedPlayer subject) {
if (subject == null) {
throw new NullPointerException("subject");
}

return new InlineQueryOptionsSupplier<>(subject, this.contextsCache);
}

// override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier
@Override
public ImmutableContextSet getContext(ProxiedPlayer subject) {
return getQueryOptions(subject).context();
}

@Override
public QueryOptions getQueryOptions(ProxiedPlayer subject) {
return this.contextsCache.get(subject);
}

@Override
protected void invalidateCache(ProxiedPlayer subject) {
this.contextsCache.invalidate(subject);
}

@Override
public QueryOptions formQueryOptions(ProxiedPlayer subject, ImmutableContextSet contextSet) {
return formQueryOptions(contextSet);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
/**
* Base implementation of {@link ContextManager} which caches content lookups.
*
* @param <S> the calculator type
* @param <S> the subject type
* @param <P> the player type
*/
public abstract class ContextManager<S, P extends S> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.context.manager;

import com.github.benmanes.caffeine.cache.LoadingCache;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.CaffeineFactory;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.query.QueryOptions;

import java.util.concurrent.TimeUnit;

public abstract class InlineContextManager<S, P extends S> extends ContextManager<S, P> {

private final LoadingCache<S, QueryOptions> contextsCache = CaffeineFactory.newBuilder()
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
.build(this::calculate);

protected InlineContextManager(LuckPermsPlugin plugin, Class<S> subjectClass, Class<P> playerClass) {
super(plugin, subjectClass, playerClass);
}

@Override
public final QueryOptionsSupplier getCacheFor(S subject) {
if (subject == null) {
throw new NullPointerException("subject");
}

return new InlineQueryOptionsSupplier<>(subject, this.contextsCache);
}

// override getContext, getQueryOptions and invalidateCache to skip the QueryOptionsSupplier
@Override
public final ImmutableContextSet getContext(S subject) {
return getQueryOptions(subject).context();
}

@Override
public final QueryOptions getQueryOptions(S subject) {
return this.contextsCache.get(subject);
}

@Override
protected final void invalidateCache(S subject) {
this.contextsCache.invalidate(subject);
}

@Override
public QueryOptions formQueryOptions(S subject, ImmutableContextSet contextSet) {
return formQueryOptions(contextSet);
}

private static final class InlineQueryOptionsSupplier<T> implements QueryOptionsSupplier {
private final T key;
private final LoadingCache<T, QueryOptions> cache;

InlineQueryOptionsSupplier(T key, LoadingCache<T, QueryOptions> cache) {
this.key = key;
this.cache = cache;
}

@Override
public QueryOptions getQueryOptions() {
return this.cache.get(this.key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ protected Connection getConnection() throws SQLException {

@Override
protected String getTableName() {
return this.sqlStorage.getStatementProcessor().apply("{prefix}messenger");
return this.sqlStorage.getStatementProcessor().process("{prefix}messenger");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,24 @@
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public final class SchemaReader {
private SchemaReader() {}

private static final Pattern CREATE_TABLE_PATTERN = Pattern.compile("^CREATE TABLE [`\"']([^`\"']+)[`\"'].*");
private static final Pattern CREATE_INDEX_PATTERN = Pattern.compile("^CREATE INDEX.* ON [`\"']([^`\"']+)[`\"'].*");

/**
* Parses a schema file to a list of SQL statements
*
* @param is the input stream to read from
* @return a list of statements
* @throws IOException if an error occurs whilst reading the file
*/
public static List<String> getStatements(InputStream is) throws IOException {
List<String> queries = new LinkedList<>();

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

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

return queries;
}

public static String tableFromStatement(String statement) {
Matcher table = CREATE_TABLE_PATTERN.matcher(statement);
if (table.matches()) {
return table.group(1).toLowerCase(Locale.ROOT);
}
Matcher index = CREATE_INDEX_PATTERN.matcher(statement);
if (index.matches()) {
return index.group(1).toLowerCase(Locale.ROOT);
}
throw new IllegalArgumentException("Unknown statement type: " + statement);
}

/**
* Filters which statements should be executed based on the current list of tables in the database
*
* @param statements the statements to filter
* @param currentTables the current tables in the database
* @return the filtered list of statements
*/
public static List<String> filterStatements(List<String> statements, List<String> currentTables) {
return statements.stream()
.filter(statement -> !currentTables.contains(tableFromStatement(statement)))
.collect(Collectors.toList());
}
}
Loading

0 comments on commit cccc145

Please sign in to comment.