Skip to content

Commit ca2c6a2

Browse files
committed
standalone template for storage supplier
1 parent 25c91ea commit ca2c6a2

File tree

7 files changed

+188
-134
lines changed

7 files changed

+188
-134
lines changed

plugin/pom.xml

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -109,43 +109,13 @@
109109
</dependency>
110110
<dependency>
111111
<groupId>me.hsgamer</groupId>
112-
<artifactId>topper-template-storage-supplier</artifactId>
113-
<version>${topper.version}</version>
114-
</dependency>
115-
<dependency>
116-
<groupId>me.hsgamer</groupId>
117-
<artifactId>topper-storage-flat-properties</artifactId>
118-
<version>${topper.version}</version>
119-
</dependency>
120-
<dependency>
121-
<groupId>me.hsgamer</groupId>
122-
<artifactId>topper-storage-flat-configfile</artifactId>
123-
<version>${topper.version}</version>
124-
</dependency>
125-
<dependency>
126-
<groupId>me.hsgamer</groupId>
127-
<artifactId>topper-storage-sql-mysql</artifactId>
128-
<version>${topper.version}</version>
129-
</dependency>
130-
<dependency>
131-
<groupId>me.hsgamer</groupId>
132-
<artifactId>topper-storage-sql-sqlite</artifactId>
133-
<version>${topper.version}</version>
134-
</dependency>
135-
<dependency>
136-
<groupId>me.hsgamer</groupId>
137-
<artifactId>topper-storage-flat-converter</artifactId>
138-
<version>${topper.version}</version>
139-
</dependency>
140-
<dependency>
141-
<groupId>me.hsgamer</groupId>
142-
<artifactId>topper-storage-sql-converter</artifactId>
112+
<artifactId>topper-storage-sql-config</artifactId>
143113
<version>${topper.version}</version>
144114
</dependency>
145115
<dependency>
146116
<groupId>me.hsgamer</groupId>
147-
<artifactId>topper-storage-sql-config</artifactId>
148-
<version>${topper.version}</version>
117+
<artifactId>topper-spigot-template-storage-supplier</artifactId>
118+
<version>${project.version}</version>
149119
</dependency>
150120
<dependency>
151121
<groupId>me.hsgamer</groupId>
@@ -216,17 +186,6 @@
216186
<artifactId>hscore-bukkit-config</artifactId>
217187
<version>${core.version}</version>
218188
</dependency>
219-
<dependency>
220-
<groupId>me.hsgamer</groupId>
221-
<artifactId>hscore-config-gson</artifactId>
222-
<version>${core.version}</version>
223-
<exclusions>
224-
<exclusion>
225-
<groupId>com.google.code.gson</groupId>
226-
<artifactId>gson</artifactId>
227-
</exclusion>
228-
</exclusions>
229-
</dependency>
230189
<dependency>
231190
<groupId>me.hsgamer</groupId>
232191
<artifactId>hscore-database-client-java</artifactId>

plugin/src/main/java/me/hsgamer/topper/spigot/plugin/TopperPlugin.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
77
import me.hsgamer.hscore.checker.spigotmc.SpigotVersionChecker;
88
import me.hsgamer.hscore.config.proxy.ConfigGenerator;
9+
import me.hsgamer.hscore.database.Setting;
10+
import me.hsgamer.hscore.database.client.sql.SqlClient;
11+
import me.hsgamer.hscore.database.client.sql.java.JavaSqlClient;
912
import me.hsgamer.topper.spigot.plugin.command.GetTopListCommand;
1013
import me.hsgamer.topper.spigot.plugin.command.ReloadCommand;
1114
import me.hsgamer.topper.spigot.plugin.config.MainConfig;
1215
import me.hsgamer.topper.spigot.plugin.config.MessageConfig;
1316
import me.hsgamer.topper.spigot.plugin.hook.HookSystem;
1417
import me.hsgamer.topper.spigot.plugin.listener.JoinListener;
1518
import me.hsgamer.topper.spigot.plugin.manager.ValueProviderManager;
16-
import me.hsgamer.topper.spigot.plugin.template.SpigotStorageSupplierTemplate;
1719
import me.hsgamer.topper.spigot.plugin.template.SpigotTopTemplate;
20+
import me.hsgamer.topper.spigot.template.storagesupplier.SpigotStorageSupplierTemplate;
1821
import org.bstats.bukkit.Metrics;
1922
import org.bukkit.Bukkit;
2023

@@ -33,7 +36,12 @@ protected List<Object> getComponents() {
3336

3437
new HookSystem(this),
3538

36-
new SpigotStorageSupplierTemplate(),
39+
new SpigotStorageSupplierTemplate() {
40+
@Override
41+
public SqlClient<?> getSqlClient(Setting setting) {
42+
return new JavaSqlClient(setting);
43+
}
44+
},
3745
new SpigotTopTemplate(this),
3846

3947
new Permissions(this),

plugin/src/main/java/me/hsgamer/topper/spigot/plugin/template/SpigotStorageSupplierTemplate.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<module>plugin</module>
1414
<module>value</module>
1515
<module>query-forward</module>
16+
<module>template</module>
1617
</modules>
1718

1819
<name>Topper Spigot</name>

template/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>me.hsgamer</groupId>
8+
<artifactId>topper-spigot</artifactId>
9+
<version>4.5.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>topper-spigot-template</artifactId>
13+
<packaging>pom</packaging>
14+
<name>Topper Spigot Template</name>
15+
<modules>
16+
<module>storage-supplier</module>
17+
</modules>
18+
</project>

template/storage-supplier/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>me.hsgamer</groupId>
8+
<artifactId>topper-spigot-template</artifactId>
9+
<version>4.5.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>topper-spigot-template-storage-supplier</artifactId>
13+
<name>Topper Spigot Template - Storage Supplier</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>me.hsgamer</groupId>
18+
<artifactId>topper-template-storage-supplier</artifactId>
19+
<version>${topper.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>me.hsgamer</groupId>
23+
<artifactId>topper-storage-flat-properties</artifactId>
24+
<version>${topper.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>me.hsgamer</groupId>
28+
<artifactId>topper-storage-flat-configfile</artifactId>
29+
<version>${topper.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>me.hsgamer</groupId>
33+
<artifactId>topper-storage-sql-mysql</artifactId>
34+
<version>${topper.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>me.hsgamer</groupId>
38+
<artifactId>topper-storage-sql-sqlite</artifactId>
39+
<version>${topper.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>me.hsgamer</groupId>
43+
<artifactId>topper-storage-flat-converter</artifactId>
44+
<version>${topper.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>me.hsgamer</groupId>
48+
<artifactId>topper-storage-sql-converter</artifactId>
49+
<version>${topper.version}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>me.hsgamer</groupId>
54+
<artifactId>hscore-bukkit-config</artifactId>
55+
<version>${core.version}</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>me.hsgamer</groupId>
59+
<artifactId>hscore-config-gson</artifactId>
60+
<version>${core.version}</version>
61+
<exclusions>
62+
<exclusion>
63+
<groupId>com.google.code.gson</groupId>
64+
<artifactId>gson</artifactId>
65+
</exclusion>
66+
</exclusions>
67+
</dependency>
68+
</dependencies>
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package me.hsgamer.topper.spigot.template.storagesupplier;
2+
3+
import me.hsgamer.hscore.bukkit.config.BukkitConfig;
4+
import me.hsgamer.hscore.config.Config;
5+
import me.hsgamer.hscore.config.gson.GsonConfig;
6+
import me.hsgamer.hscore.database.Setting;
7+
import me.hsgamer.hscore.database.client.sql.SqlClient;
8+
import me.hsgamer.topper.storage.core.DataStorage;
9+
import me.hsgamer.topper.storage.flat.configfile.ConfigFileDataStorage;
10+
import me.hsgamer.topper.storage.flat.core.FlatValueConverter;
11+
import me.hsgamer.topper.storage.flat.properties.PropertiesDataStorage;
12+
import me.hsgamer.topper.storage.sql.mysql.MySqlDataStorageSupplier;
13+
import me.hsgamer.topper.storage.sql.sqlite.NewSqliteDataStorageSupplier;
14+
import me.hsgamer.topper.storage.sql.sqlite.SqliteDataStorageSupplier;
15+
import me.hsgamer.topper.template.storagesupplier.StorageSupplierTemplate;
16+
import me.hsgamer.topper.template.storagesupplier.storage.DataStorageSupplier;
17+
import me.hsgamer.topper.template.storagesupplier.storage.FlatDataStorageSupplier;
18+
import me.hsgamer.topper.template.storagesupplier.storage.SqlDataStorageSupplier;
19+
20+
import java.io.File;
21+
import java.util.Locale;
22+
23+
public abstract class SpigotStorageSupplierTemplate implements StorageSupplierTemplate {
24+
public abstract SqlClient<?> getSqlClient(Setting setting);
25+
26+
@Override
27+
public DataStorageSupplier getDataStorageSupplier(Settings settings) {
28+
switch (settings.storageType().toLowerCase(Locale.ROOT)) {
29+
case "yaml": {
30+
return new FlatDataStorageSupplier() {
31+
@Override
32+
public <K, V> DataStorage<K, V> getStorage(String name, FlatValueConverter<K> keyConverter, FlatValueConverter<V> valueConverter) {
33+
return new ConfigFileDataStorage<K, V>(settings.baseFolder(), name, keyConverter, valueConverter) {
34+
@Override
35+
protected Config getConfig(File file) {
36+
return new BukkitConfig(file);
37+
}
38+
39+
@Override
40+
protected String getConfigName(String name) {
41+
return name + ".yml";
42+
}
43+
};
44+
}
45+
};
46+
}
47+
case "json": {
48+
return new FlatDataStorageSupplier() {
49+
@Override
50+
public <K, V> DataStorage<K, V> getStorage(String name, FlatValueConverter<K> keyConverter, FlatValueConverter<V> valueConverter) {
51+
return new ConfigFileDataStorage<K, V>(settings.baseFolder(), name, keyConverter, valueConverter) {
52+
@Override
53+
protected Config getConfig(File file) {
54+
return new GsonConfig(file);
55+
}
56+
57+
@Override
58+
protected String getConfigName(String name) {
59+
return name + ".json";
60+
}
61+
};
62+
}
63+
};
64+
}
65+
case "sqlite": {
66+
SqliteDataStorageSupplier supplier = new SqliteDataStorageSupplier(settings.baseFolder(), settings.databaseSetting(), this::getSqlClient);
67+
return SqlDataStorageSupplier.of(supplier);
68+
}
69+
case "new-sqlite": {
70+
SqliteDataStorageSupplier supplier = new NewSqliteDataStorageSupplier(settings.baseFolder(), settings.databaseSetting(), this::getSqlClient);
71+
return SqlDataStorageSupplier.of(supplier);
72+
}
73+
case "mysql": {
74+
MySqlDataStorageSupplier supplier = new MySqlDataStorageSupplier(settings.databaseSetting(), this::getSqlClient);
75+
return SqlDataStorageSupplier.of(supplier);
76+
}
77+
default: {
78+
return new FlatDataStorageSupplier() {
79+
@Override
80+
public <K, V> DataStorage<K, V> getStorage(String name, FlatValueConverter<K> keyConverter, FlatValueConverter<V> valueConverter) {
81+
return new PropertiesDataStorage<>(settings.baseFolder(), name, keyConverter, valueConverter);
82+
}
83+
};
84+
}
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)