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

Mirror implementation of new database system from main Skript plugin #96

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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 .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Build Skript-1.8
run: ./gradlew clean build
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Skript
path: build/libs/Skript.jar
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/

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

*.iml
Expand Down
21 changes: 16 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ["-source", "1.8", "-target", "1.8"]
options.compilerArgs += ["-source", "17", "-target", "17"]
}

allprojects {
Expand All @@ -28,13 +28,16 @@ allprojects {

dependencies {
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.0'
shadow group: 'com.h2database', name: 'h2', version: '2.1.214'
shadow group: 'com.zaxxer', name: 'HikariCP', version: '5.0.1'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.19.2-R0.1-SNAPSHOT'
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.600'
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', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
}

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

Expand Down Expand Up @@ -79,6 +82,8 @@ tasks.withType(ShadowJar) {
dependencies {
include(dependency('org.bstats:bstats-bukkit'))
include(dependency('org.bstats:bstats-base'))
include(dependency('com.h2database:h2'))
include(dependency('com.zaxxer:HikariCP'))
}
relocate 'org.bstats', 'ch.njol.skript.bstats'
manifest {
Expand Down Expand Up @@ -186,6 +191,15 @@ createTestTask('skriptTestFull', 'src/test/skript/environments/', false)
createTestTask('skriptTestDev', 'src/test/skript/environments/main/' + (project.property('testEnv') == null
? 'paper-1.17.json' : project.property('testEnv') + '.json'), true)

// 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 @@ -198,7 +212,6 @@ task githubResources(type: ProcessResources) {
channel = 'beta'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'github-matocolotoe-1.8', // Skript-1.8 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 @@ -234,7 +247,6 @@ task spigotResources(type: ProcessResources) {
channel = 'beta'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'spigot-matocolotoe-1.8', // Skript-1.8 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 @@ -266,7 +278,6 @@ task nightlyResources(type: ProcessResources) {
version = project.property('version') + '-nightly-' + hash
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'nightly-matocolotoe-1.8', // Skript-1.8 build, automatically done by CI
'release-channel' : 'alpha', // No update checking, but these are VERY unstable
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No autoupdates for now
Expand All @@ -289,4 +300,4 @@ task nightlyRelease(type: ShadowJar) {
)
}
from 'skript-worldguard6/build/classes/java/main'
}
}
8 changes: 8 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ version=2.6.5-for-1.8
jarName=Skript.jar
testEnv=java17/paper-1.19
testEnvJavaVersion=17

# java21
#h2.version=2.3.232
#hikaricp.version=5.1.0

# java17
h2.version=2.1.214
hikaricp.version=5.0.1
18 changes: 17 additions & 1 deletion src/main/java/ch/njol/skript/SkriptAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import ch.njol.skript.localization.Language;
import ch.njol.skript.util.Utils;
import ch.njol.skript.util.Version;
import ch.njol.skript.variables.Variables;
import ch.njol.skript.variables.VariableStorage;
import ch.njol.util.coll.iterator.EnumerationIterable;
import org.bukkit.plugin.java.JavaPlugin;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -128,7 +130,21 @@ 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;
}

@Nullable
private String languageFileDirectory = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {

if (isEvent) {
FurnaceBurnEvent event = (FurnaceBurnEvent) e;
event.setBurnTime(value.apply(Timespan.fromTicks_i(event.getBurnTime())).getTicks());
//event.setBurnTime(value.apply(Timespan.fromTicks_i(event.getBurnTime())).getTicks()); // original
//event.setBurnTime((int) value.apply(Timespan.fromTicks_i(event.getBurnTime())).getTicks()); // modified with explicit cast
long ticks = value.apply(Timespan.fromTicks_i(event.getBurnTime())).getTicks(); // modified with overflow handling and safe casting
if (ticks > Integer.MAX_VALUE) {
event.setBurnTime(Integer.MAX_VALUE);
} else {
event.setBurnTime((int) ticks);
}
return;
}

Expand Down
25 changes: 20 additions & 5 deletions src/main/java/ch/njol/skript/lang/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ public Object getRaw(Event e) {
String n = name.toString(e);
if (n.endsWith(Variable.SEPARATOR + "*") != list) // prevents e.g. {%expr%} where "%expr%" ends with "::*" from returning a Map
return null;
Object val = !list ? convertIfOldPlayer(n, e, Variables.getVariable(n, e, local)) : Variables.getVariable(n, e, local);
//Object val = !list ? convertIfOldPlayer(n, e, Variables.getVariable(n, e, local)) : Variables.getVariable(n, e, local); // original
Object val = !list ? convertIfOldPlayer(n, local, e, Variables.getVariable(n, e, local)) : Variables.getVariable(n, e, local); // modified
if (val == null)
return Variables.getVariable((local ? LOCAL_VARIABLE_TOKEN : "") + name.getDefaultVariableName(), e, false);
return val;
Expand All @@ -322,7 +323,8 @@ private Object get(Event e) {
else
o = v.getValue();
if (o != null)
l.add(convertIfOldPlayer(name + v.getKey(), e, o));
//l.add(convertIfOldPlayer(name + v.getKey(), e, o)); // original
l.add(convertIfOldPlayer(name + v.getKey(), local, e, o)); // modified
}
}
return l.toArray();
Expand All @@ -335,7 +337,7 @@ private Object get(Event e) {
* because the player object inside the variable will be a (kinda) dead variable
* as a new player object has been created by the server.
*/
@Nullable Object convertIfOldPlayer(String key, Event event, @Nullable Object t){
/*@Nullable Object convertIfOldPlayer(String key, Event event, @Nullable Object t){
if(SkriptConfig.enablePlayerVariableFix.value() && t != null && t instanceof Player){
Player p = (Player) t;
if(!p.isValid() && p.isOnline()){
Expand All @@ -345,6 +347,17 @@ private Object get(Event e) {
}
}
return t;
}*/
public static <T> @Nullable T convertIfOldPlayer(String key, boolean local, Event event, @Nullable T object) {
if (SkriptConfig.enablePlayerVariableFix.value() && object instanceof Player oldPlayer) {
if (!oldPlayer.isValid() && oldPlayer.isOnline()) {
Player newPlayer = Bukkit.getPlayer(oldPlayer.getUniqueId());
Variables.setVariable(key, newPlayer, event, local);
//noinspection unchecked
return (T) newPlayer;
}
}
return object;
}

public Iterator<Pair<String, Object>> variablesIterator(Event e) {
Expand All @@ -371,7 +384,8 @@ public boolean hasNext() {
while (keys.hasNext()) {
key = keys.next();
if (key != null) {
next = convertIfOldPlayer(name + key, e, Variables.getVariable(name + key, e, local));
//next = convertIfOldPlayer(name + key, e, Variables.getVariable(name + key, e, local)); // original
next = convertIfOldPlayer(name + key, local, e, Variables.getVariable(name + key, e, local)); // modified
if (next != null && !(next instanceof TreeMap))
return true;
}
Expand Down Expand Up @@ -426,7 +440,8 @@ public boolean hasNext() {
key = keys.next();
if (key != null) {
next = Converters.convert(Variables.getVariable(name + key, e, local), types);
next = (T) convertIfOldPlayer(name + key, e, next);
//next = (T) convertIfOldPlayer(name + key, e, next); // original
next = (T) convertIfOldPlayer(name + key, local, e, next); // modified
if (next != null && !(next instanceof TreeMap))
return true;
}
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 @@ -56,7 +56,7 @@
import ch.njol.skript.log.ParseLogHandler;
import ch.njol.skript.log.SkriptLogger;
import ch.njol.skript.util.StringMode;
import ch.njol.skript.variables.DatabaseStorage;
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 @@ -91,8 +91,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() > DatabaseStorage.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 " + DatabaseStorage.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
Loading