Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 20dc34714e | |||
| 267bd3644c | |||
| d6515d9cbb | |||
| 5e6eff241e | |||
| 204198f143 | |||
| 9fdc4f4991 | |||
| b88d7f3e08 | |||
| ebbb92f66d | |||
| 6b9d4fa968 | |||
| 041bff1908 | |||
| caa52be19e | |||
| 2c38a76c0a | |||
| fede46e91e | |||
| 95ff56969e | |||
| 0a7d61e45e |
@@ -33,6 +33,14 @@ jobs:
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'oracle'
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
- name: make gradle wrapper executable
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
run: |
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package fr.altarik.toolbox.core.config;
|
||||
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Code "inspired" from <a href="https://github.com/CaffeineMC/sodium-fabric/blob/dev/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java">
|
||||
* https://github.com/CaffeineMC/sodium-fabric/blob/dev/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java
|
||||
* </a>
|
||||
*/
|
||||
public class ConfigI {
|
||||
|
||||
protected static final Gson GSON = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().excludeFieldsWithModifiers(Modifier.PROTECTED, Modifier.PRIVATE).create();
|
||||
|
||||
protected Path configPath;
|
||||
|
||||
protected static Path getConfigPath(Path configPath, String name) {
|
||||
return configPath.resolve(name);
|
||||
}
|
||||
|
||||
public static <T extends ConfigI> T load(Path configPath, String name, Class<T> clazz) throws IOException, JsonSyntaxException, JsonIOException {
|
||||
Path path = getConfigPath(configPath, name);
|
||||
|
||||
T file;
|
||||
|
||||
if(Files.exists(path)) {
|
||||
FileReader reader = new FileReader(path.toFile());
|
||||
file = GSON.fromJson(reader, clazz);
|
||||
} else {
|
||||
try {
|
||||
file = clazz.getConstructor().newInstance();
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
file.configPath = path;
|
||||
|
||||
file.writeChanges();
|
||||
return file;
|
||||
}
|
||||
|
||||
public void writeChanges() throws IOException {
|
||||
Path dir = this.configPath.getParent();
|
||||
if(!Files.exists(dir)) {
|
||||
Files.createDirectories(dir);
|
||||
} else if (!Files.isDirectory(dir)) {
|
||||
throw new IOException("Not a directory: " + dir);
|
||||
}
|
||||
// Use a temporary location next to the config's final destination to replace it atomically
|
||||
// Path tempPath = this.configPath.resolveSibling(this.configPath.getFileName() + ".tmp");
|
||||
Files.writeString(this.configPath, GSON.toJson(this));
|
||||
// Files.copy(tempPath, this.configPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
// Files.delete(tempPath);
|
||||
// commented because throws an error on windows each time if the file already exist
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package fr.altarik.toolbox.core.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
||||
public interface PlayerLifecycleCallback {
|
||||
|
||||
Event<PlayerJoin> PLAYER_JOIN = EventFactory.createArrayBacked(PlayerJoin.class, listeners -> player -> {
|
||||
for(PlayerJoin listener : listeners) {
|
||||
ActionResult result = listener.onPlayerJoin(player);
|
||||
if (result != ActionResult.PASS)
|
||||
return result;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
Event<PlayerLeave> PLAYER_LEAVE = EventFactory.createArrayBacked(PlayerLeave.class, listeners -> player -> {
|
||||
for(PlayerLeave listener : listeners) {
|
||||
ActionResult result = listener.onPlayerLeave(player);
|
||||
if (result != ActionResult.PASS)
|
||||
return result;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
interface PlayerJoin {
|
||||
ActionResult onPlayerJoin(ServerPlayerEntity player);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface PlayerLeave {
|
||||
ActionResult onPlayerLeave(ServerPlayerEntity player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.altarik.toolbox.core.mixin;
|
||||
|
||||
import fr.altarik.toolbox.core.event.PlayerLifecycleCallback;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(PlayerManager.class)
|
||||
public class PlayerJoinEvent {
|
||||
|
||||
@Inject(method = "onPlayerConnect", at = @At(value = "RETURN"))
|
||||
private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
||||
PlayerLifecycleCallback.PLAYER_JOIN.invoker().onPlayerJoin(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package fr.altarik.toolbox.core.mixin;
|
||||
|
||||
import fr.altarik.toolbox.core.event.PlayerLifecycleCallback;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class PlayerLeaveEvent {
|
||||
|
||||
@Shadow
|
||||
public ServerPlayerEntity player;
|
||||
|
||||
@Inject(at = @At(value = "HEAD"), method = "onDisconnected")
|
||||
private void onPlayerQuit(Text reason, CallbackInfo ci) {
|
||||
PlayerLifecycleCallback.PLAYER_LEAVE.invoker().onPlayerLeave(player);
|
||||
}
|
||||
}
|
||||
14
Core/src/main/resources/Core.mixins.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "fr.altarik.toolbox.core.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"PlayerJoinEvent",
|
||||
"PlayerLeaveEvent"
|
||||
],
|
||||
"verbose": false,
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 323 KiB |
@@ -8,7 +8,7 @@
|
||||
"Altarik"
|
||||
],
|
||||
"contributors": [
|
||||
"Legot Quentin<legotquentin@gmail.com>"
|
||||
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://altarik.fr"
|
||||
@@ -19,11 +19,21 @@
|
||||
"entrypoints": {
|
||||
"main": []
|
||||
},
|
||||
"mixins": [],
|
||||
"mixins": [
|
||||
"Core.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": "^${loaderVersion}",
|
||||
"fabric-api": "*",
|
||||
"minecraft": "${minecraftVersion}",
|
||||
"java": ">=17"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"badges": [ "library" ],
|
||||
"parent": {
|
||||
"parent": "toolbox"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BuilderImpl implements IBuilder<BuilderResult> {
|
||||
|
||||
|
||||
@Override
|
||||
public BuilderResult build() throws Exception {
|
||||
public BuilderResult build() {
|
||||
return new BuilderResult(collection.get(), numberOfSentences.get());
|
||||
}
|
||||
}
|
||||
|
||||
40
Core/src/test/java/ConfigITest.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import fr.altarik.toolbox.core.config.ConfigI;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigITest {
|
||||
|
||||
public static class ConfigClazz extends ConfigI {
|
||||
|
||||
public int par1 = 5;
|
||||
public String par2 = "bad";
|
||||
public double para3 = 3.14;
|
||||
|
||||
public static ConfigClazz load() throws IOException {
|
||||
return load(Path.of("."), "test.json", ConfigClazz.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfig() throws IOException {
|
||||
ConfigClazz config = ConfigClazz.load();
|
||||
Assertions.assertEquals(5, config.par1);
|
||||
Assertions.assertEquals("bad", config.par2);
|
||||
Assertions.assertEquals(3.14, config.para3);
|
||||
config.par1 = 6;
|
||||
config.par2 = "good";
|
||||
config.para3 = 4.2;
|
||||
Assertions.assertEquals(6, config.par1);
|
||||
config.writeChanges();
|
||||
config = ConfigClazz.load();
|
||||
Assertions.assertEquals(6, config.par1);
|
||||
Assertions.assertEquals("good", config.par2);
|
||||
Assertions.assertEquals(4.2, config.para3);
|
||||
|
||||
Path.of(".").resolve("test.json").toFile().delete();
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,6 @@ public abstract class AbstractSqlConnection implements SqlConnection {
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
try {
|
||||
close();
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if(!connection.isClosed()) {
|
||||
|
||||
@@ -23,10 +23,4 @@ public interface SqlConnection extends AutoCloseable {
|
||||
*/
|
||||
void checkConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* @deprecated replaced with {@link AutoCloseable#close()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
void closeConnection();
|
||||
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 323 KiB |
@@ -8,7 +8,7 @@
|
||||
"Altarik"
|
||||
],
|
||||
"contributors": [
|
||||
"Legot Quentin<legotquentin@gmail.com>"
|
||||
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://altarik.fr"
|
||||
@@ -26,5 +26,13 @@
|
||||
"minecraft": "${minecraftVersion}",
|
||||
"java": ">=17",
|
||||
"toolbox-core": "${version}"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"badges": [ "library" ],
|
||||
"parent": {
|
||||
"parent": "toolbox"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 323 KiB |
@@ -8,7 +8,7 @@
|
||||
"Altarik"
|
||||
],
|
||||
"contributors": [
|
||||
"Legot Quentin<legotquentin@gmail.com>"
|
||||
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://altarik.fr"
|
||||
@@ -29,5 +29,13 @@
|
||||
"fabric-api": "*",
|
||||
"minecraft": "${minecraftVersion}",
|
||||
"java": ">=17"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"badges": [ "library" ],
|
||||
"parent": {
|
||||
"parent": "toolbox"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 323 KiB |
@@ -8,7 +8,7 @@
|
||||
"Altarik"
|
||||
],
|
||||
"contributors": [
|
||||
"Legot Quentin<legotquentin@gmail.com>"
|
||||
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://altarik.fr"
|
||||
|
||||
@@ -2,7 +2,7 @@ import fr.altarik.CreateTag
|
||||
import fr.altarik.ReportDiscord
|
||||
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.4-SNAPSHOT' apply false
|
||||
id 'fabric-loom' version '1.6-SNAPSHOT' apply false
|
||||
}
|
||||
|
||||
Properties local = new Properties()
|
||||
|
||||
@@ -1 +1 @@
|
||||
okhttp_version=4.10.0
|
||||
okhttp_version=4.12.0
|
||||
@@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G
|
||||
fabric.loom.multiProjectOptimisation=true
|
||||
|
||||
junit_version=5.9.0
|
||||
minecraft_version=1.20.2
|
||||
yarn_mappings=1.20.2+build.4
|
||||
loader_version=0.15.3
|
||||
fabric_version=0.91.3+1.20.2
|
||||
minecraft_version=1.20.4
|
||||
yarn_mappings=1.20.4+build.3
|
||||
loader_version=0.15.6
|
||||
fabric_version=0.97.1+1.20.4
|
||||
|
||||
maven_group=fr.altarik.toolbox
|
||||
maven_version=4.4.0
|
||||
maven_version=5.1.0
|
||||
|
||||
git_owner=quentinlegot
|
||||
git_repo=Toolbox
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 323 KiB |
@@ -8,7 +8,7 @@
|
||||
"Altarik"
|
||||
],
|
||||
"contributors": [
|
||||
"Legot Quentin<legotquentin@gmail.com>"
|
||||
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://altarik.fr"
|
||||
@@ -25,6 +25,11 @@
|
||||
"toolbox-database": "${version}",
|
||||
"toolbox-pagination": "${version}",
|
||||
"toolbox-task": "${version}"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"badges": [ "library" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||