Skip to content

Commit

Permalink
split into SpigotDataStorageBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jun 5, 2024
1 parent 76c3be2 commit 2263dd7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
1 change: 1 addition & 0 deletions spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<packaging>pom</packaging>
<modules>
<module>spigot-config</module>
<module>spigot-agent-storage-simple</module>
<module>spigot-number</module>
<module>spigot-block</module>
<module>spigot-block-impl</module>
Expand Down
36 changes: 36 additions & 0 deletions spigot/spigot-agent-storage-simple/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.hsgamer</groupId>
<artifactId>topper-spigot</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>topper-spigot-agent-storage-simple</artifactId>

<dependencies>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>topper-spigot-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>topper-agent-storage-simple</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.hsgamer.topper.spigot.agent.storage.simple;

import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
import me.hsgamer.hscore.config.proxy.ConfigGenerator;
import me.hsgamer.topper.agent.storage.simple.builder.DataStorageBuilder;
import me.hsgamer.topper.agent.storage.simple.config.DatabaseConfig;
import me.hsgamer.topper.agent.storage.simple.converter.FlatEntryConverter;
import me.hsgamer.topper.agent.storage.simple.converter.SqlEntryConverter;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;

public class SpigotDataStorageBuilder<K, V> extends DataStorageBuilder<K, V> {
public SpigotDataStorageBuilder(JavaPlugin plugin, File holderBaseFolder, FlatEntryConverter<K, V> flatEntryConverter, SqlEntryConverter<K, V> sqlEntryConverter) {
super(
runnable -> {
Task task = GlobalScheduler.get(plugin).runLater(runnable, 40L);
return task::cancel;
},
runnable -> GlobalScheduler.get(plugin).run(runnable),
BukkitConfig::new,
() -> ConfigGenerator.newInstance(DatabaseConfig.class, new BukkitConfig(plugin, "database.yml")),
holderBaseFolder,
flatEntryConverter,
sqlEntryConverter
);
}
}
7 changes: 1 addition & 6 deletions spigot/spigot-number/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
<dependencies>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>topper-spigot-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>topper-agent-storage-simple</artifactId>
<artifactId>topper-spigot-agent-storage-simple</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package me.hsgamer.topper.spigot.number;

import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
import me.hsgamer.hscore.config.proxy.ConfigGenerator;
import me.hsgamer.hscore.database.client.sql.StatementBuilder;
import me.hsgamer.topper.agent.storage.simple.builder.DataStorageBuilder;
import me.hsgamer.topper.agent.storage.simple.config.DatabaseConfig;
import me.hsgamer.topper.agent.storage.simple.converter.FlatEntryConverter;
import me.hsgamer.topper.agent.storage.simple.converter.SqlEntryConverter;
import me.hsgamer.topper.spigot.agent.storage.simple.SpigotDataStorageBuilder;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand All @@ -19,20 +14,9 @@
import java.util.Map;
import java.util.UUID;

public class NumberStorageBuilder extends DataStorageBuilder<UUID, Double> {
public NumberStorageBuilder(JavaPlugin plugin, File baseFolder) {
super(
runnable -> {
Task task = GlobalScheduler.get(plugin).runLater(runnable, 40L);
return task::cancel;
},
runnable -> GlobalScheduler.get(plugin).run(runnable),
BukkitConfig::new,
() -> ConfigGenerator.newInstance(DatabaseConfig.class, new BukkitConfig(plugin, "database.yml")),
baseFolder,
new FlatNumberEntryConverter(),
new SqlNumberEntryConverter()
);
public class NumberStorageBuilder extends SpigotDataStorageBuilder<UUID, Double> {
public NumberStorageBuilder(JavaPlugin plugin, File holderBaseFolder) {
super(plugin, holderBaseFolder, new FlatNumberEntryConverter(), new SqlNumberEntryConverter());
}

private static class FlatNumberEntryConverter implements FlatEntryConverter<UUID, Double> {
Expand Down

0 comments on commit 2263dd7

Please sign in to comment.