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

Get SQL databases working again #7653

Open
wants to merge 40 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b22d87f
Progress so far
TheLimeGlass Apr 26, 2023
1cac4d8
Merge branch 'master' of https://github.com/SkriptLang/Skript into en…
TheLimeGlass Apr 26, 2023
b35fa99
Finalize SQL database system
TheLimeGlass Apr 26, 2023
5babe26
Remove comments
TheLimeGlass Apr 26, 2023
19e3848
Remove SQLibrary
TheLimeGlass Apr 26, 2023
038cfdd
Complete SQL rework
TheLimeGlass Apr 26, 2023
b733bc9
Formatting
TheLimeGlass Apr 26, 2023
31ce091
Tackle some todo list nodes
TheLimeGlass Apr 27, 2023
f55d702
Class check
TheLimeGlass Apr 27, 2023
3f7b78a
Update to dev/feature
TheLimeGlass Nov 13, 2023
47f0adf
Apply changes
TheLimeGlass Nov 13, 2023
0117ad9
changes
TheLimeGlass Nov 14, 2023
c01537f
Add SkriptAddon reference to the storage
TheLimeGlass Dec 17, 2023
f18dac0
Add SQLite tests
TheLimeGlass Dec 17, 2023
d441bda
Fix MySQL
TheLimeGlass Dec 17, 2023
8f60b01
licence
TheLimeGlass Dec 17, 2023
18670ac
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Dec 17, 2023
b1e35a2
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Dec 17, 2023
e758d56
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Feb 20, 2024
b791ffe
Complete MySQL
TheLimeGlass Feb 20, 2024
4afaacb
Merge branch 'dev/feature' into enhancement/sql
Moderocky Mar 26, 2024
c3d07b1
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass May 13, 2024
46ee7fa
Fix java21 folder reference'
TheLimeGlass May 13, 2024
7dad632
Better get method design. Monitor changes fixes. SQL tweaks
TheLimeGlass May 13, 2024
2c71679
Undo rowid SQLite test
TheLimeGlass May 13, 2024
fadcc0d
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Jul 2, 2024
e3fd27f
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Aug 17, 2024
427f0ee
Conflicts
TheLimeGlass Sep 20, 2024
d6c2608
Conflicts
TheLimeGlass Sep 20, 2024
cb9842f
Code cleaning and security
TheLimeGlass Sep 20, 2024
8be6d63
Code cleaning and security
TheLimeGlass Sep 20, 2024
980ddfd
Update Hikari and H2
TheLimeGlass Sep 20, 2024
37314d3
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Oct 12, 2024
217ecfd
git conflicts
TheLimeGlass Nov 16, 2024
ecb416f
Aliases
TheLimeGlass Nov 16, 2024
3a2f722
More git conflicts
TheLimeGlass Nov 16, 2024
349b1c2
Git conflicts for 2.10.1
TheLimeGlass Feb 27, 2025
8877860
Apply suggestions from code review
TheLimeGlass Mar 12, 2025
8b94207
Update src/main/java/ch/njol/skript/variables/JdbcStorage.java
TheLimeGlass Mar 12, 2025
a8cf8cd
Merge branch 'dev/feature' into enhancement/sql
TheLimeGlass Mar 12, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ fabric.properties

.idea/

### VS Code ###
.vscode/

Comment on lines +167 to +169
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be in this pr

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

# Exception for the icon
Expand Down
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ dependencies {
exclude group: 'org.bukkit', module: 'bukkit'
}

// Libraries that are installed at runtime. See plugin.yml 'libraries' section.
implementation group: 'com.h2database', name: 'h2', version: project.property('h2.version')
implementation group: 'com.zaxxer', name: 'HikariCP', version: project.property('hikaricp.version')

implementation fileTree(dir: 'lib', include: '*.jar')

testShadow group: 'junit', name: 'junit', version: '4.13.2'
Expand Down Expand Up @@ -289,6 +293,15 @@ tasks.register('JUnit') {
dependsOn JUnitJava17, JUnitJava21
}

// Generic replace tokens, e.g: '@version@'
tasks.withType(Copy).configureEach {
filter(ReplaceTokens, tokens: [
'today' : '' + LocalTime.now(),
'h2.version' : project.property('h2.version'),
'hikaricp.version' : project.property('hikaricp.version')
])
}

// Build flavor configurations
task githubResources(type: ProcessResources) {
from 'src/main/resources', {
Expand All @@ -299,7 +312,6 @@ task githubResources(type: ProcessResources) {
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-github', // SkriptLang build, distributed on Github
'release-channel' : channel, // Release channel, see above
'release-updater' : 'ch.njol.skript.update.GithubChecker', // Github API client
Expand Down Expand Up @@ -332,7 +344,6 @@ task spigotResources(type: ProcessResources) {
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-spigot', // SkriptLang build, distributed on Spigot resources
'release-channel' : channel, // Release channel, see above
'release-updater' : 'ch.njol.skript.update.GithubChecker', // Github API client
Expand Down Expand Up @@ -363,7 +374,6 @@ task nightlyResources(type: ProcessResources) {
version = project.property('version') + '-nightly-' + hash
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-nightly', // SkriptLang build, automatically done by CI
'release-channel' : 'prerelease', // No update checking, but these are VERY unstable
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No auto updates for now
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ version=2.10.2
jarName=Skript.jar
testEnv=java21/paper-1.21.4
testEnvJavaVersion=21

hikaricp.version=5.1.0
h2.version=2.3.232
Binary file removed lib/SQLibrary-7.1.jar
Binary file not shown.
19 changes: 17 additions & 2 deletions src/main/java/ch/njol/skript/SkriptAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.util.Utils;
import ch.njol.skript.util.Version;
import ch.njol.skript.variables.VariableStorage;
import ch.njol.skript.variables.Variables;

import org.jetbrains.annotations.ApiStatus;
import org.skriptlang.skript.localization.Localizer;
import org.skriptlang.skript.registration.SyntaxRegistry;
Expand Down Expand Up @@ -76,6 +77,20 @@ public SkriptAddon loadClasses(String basePackage, String... subPackages) throws
return this;
}

/**
* Register a VariableStorage class for Skript to create if the user config value matches.
*
* @param <T> A class to extend VariableStorage.
* @param storage The class of the VariableStorage implementation.
* @param names The names used in the config of Skript to select this VariableStorage.
* @return This SkriptAddon for method chaining.
* @throws SkriptAPIException if the operation was not successful because the storage class is already registered.
*/
public <T extends VariableStorage> SkriptAddon registerStorage(Class<T> storage, String... names) throws SkriptAPIException {
Variables.registerStorage(this, storage, names);
return this;
}

/**
* Makes Skript load language files from the specified directory, e.g. "lang" or "skript lang" if you have a lang folder yourself. Localised files will be read from the
* plugin's jar and the plugin's data folder, but the default English file is only taken from the jar and <b>must</b> exist!
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/ch/njol/skript/lang/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.function.Function;

Expand All @@ -16,7 +14,7 @@
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.classes.Changer.ChangerUtils;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.variables.VariablesStorage;
import ch.njol.skript.variables.VariableStorage;
import org.skriptlang.skript.lang.arithmetic.Arithmetics;
import org.skriptlang.skript.lang.arithmetic.OperationInfo;
import org.skriptlang.skript.lang.arithmetic.Operator;
Expand All @@ -41,21 +39,12 @@
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.arithmetic.Arithmetics;
import org.skriptlang.skript.lang.arithmetic.OperationInfo;
import org.skriptlang.skript.lang.arithmetic.Operator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.comparator.Relation;
import org.skriptlang.skript.lang.converter.Converters;
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.script.ScriptWarning;

import java.lang.reflect.Array;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.function.Predicate;

public class Variable<T> implements Expression<T>, KeyReceiverExpression<T>, KeyProviderExpression<T> {

private final static String SINGLE_SEPARATOR_CHAR = ":";
Expand Down Expand Up @@ -120,8 +109,8 @@ public static boolean isValidVariableName(String name, boolean allowListVariable
A lot of people already use '-' so we want to skip this warning iff they're using it here
*/
if (first == '-') {
for (VariablesStorage store : Variables.getStores()) {
@Nullable Pattern pattern = store.getNamePattern();
for (VariableStorage storage : Variables.getLoadedStorages()) {
@Nullable Pattern pattern = storage.getNamePattern();
if (pattern != null && pattern.pattern().equals("(?!-).*"))
continue check_reserved_tokens;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ch/njol/skript/registrations/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import ch.njol.skript.log.ParseLogHandler;
import ch.njol.skript.log.SkriptLogger;
import ch.njol.skript.util.StringMode;
import ch.njol.skript.variables.SQLStorage;
import ch.njol.skript.variables.JdbcStorage;
import ch.njol.skript.variables.SerializedVariable;
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
Expand Down Expand Up @@ -79,8 +79,8 @@ public static <T> void registerClass(final ClassInfo<T> info) {
throw new IllegalArgumentException("Can't register " + info.getC().getName() + " with the code name " + info.getCodeName() + " because that name is already used by " + classInfosByCodeName.get(info.getCodeName()));
if (exactClassInfos.containsKey(info.getC()))
throw new IllegalArgumentException("Can't register the class info " + info.getCodeName() + " because the class " + info.getC().getName() + " is already registered");
if (info.getCodeName().length() > SQLStorage.MAX_CLASS_CODENAME_LENGTH)
throw new IllegalArgumentException("The codename '" + info.getCodeName() + "' is too long to be saved in a database, the maximum length allowed is " + SQLStorage.MAX_CLASS_CODENAME_LENGTH);
if (info.getCodeName().length() > JdbcStorage.MAX_CLASS_CODENAME_LENGTH)
throw new IllegalArgumentException("The codename '" + info.getCodeName() + "' is too long to be saved in a database, the maximum length allowed is " + JdbcStorage.MAX_CLASS_CODENAME_LENGTH);
exactClassInfos.put(info.getC(), info);
classInfosByCodeName.put(info.getCodeName(), info);
tempClassInfos.add(info);
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/ch/njol/skript/variables/FlatFileStorage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.njol.skript.variables;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.lang.Variable;
import ch.njol.skript.log.SkriptLogger;
Expand Down Expand Up @@ -40,7 +41,7 @@
* accessed. (rem: print a warning when Skript starts)
* rem: store null variables (in memory) to prevent looking up the same variables over and over again
*/
public class FlatFileStorage extends VariablesStorage {
public class FlatFileStorage extends VariableStorage {

/**
* The {@link Charset} used in the CSV storage file.
Expand Down Expand Up @@ -108,21 +109,22 @@ public class FlatFileStorage extends VariablesStorage {
/**
* Create a new CSV storage of the given name.
*
* @param source the source of this storage.
* @param type the databse type i.e. CSV.
*/
FlatFileStorage(String type) {
super(type);
FlatFileStorage(SkriptAddon source, String type) {
super(source, type);
}

/**
* Loads the variables in the CSV file.
* <p>
* Doesn't lock the connection, as required by
* {@link Variables#variableLoaded(String, Object, VariablesStorage)}.
* {@link Variables#variableLoaded(String, Object, VariableStorage)}.
*/
@SuppressWarnings("deprecation")
@Override
protected boolean load_i(SectionNode sectionNode) {
@SuppressWarnings("deprecation")
protected final boolean load(SectionNode sectionNode) {
SkriptLogger.setNode(null);

if (file == null) {
Expand Down Expand Up @@ -464,16 +466,16 @@ private void save(PrintWriter pw, String parent, TreeMap<String, Object> map) {
if (childNode == null)
continue; // Leaf node

if (childNode instanceof TreeMap) {
if (childNode instanceof TreeMap multiVariable) {
// TreeMap found, recurse
save(pw, parent + childKey + Variable.SEPARATOR, (TreeMap<String, Object>) childNode);
save(pw, parent + childKey + Variable.SEPARATOR, multiVariable);
} else {
// Remove variable separator if needed
String name = childKey == null ? parent.substring(0, parent.length() - Variable.SEPARATOR.length()) : parent + childKey;

try {
// Loop over storages to make sure this variable is ours to store
for (VariablesStorage storage : Variables.STORAGES) {
for (VariableStorage storage : Variables.STORAGES) {
if (storage.accept(name)) {
if (storage == this) {
// Serialize the value
Expand Down
Loading