mirror of
https://github.com/MiniDay/HamsterCurrency-Parent.git
synced 2025-08-23 04:35:30 +08:00
feat: 修复启动报错
This commit is contained in:
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'cn.hamster3'
|
group 'cn.hamster3'
|
||||||
version '2.1.1'
|
version '2.1.2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
@@ -18,7 +18,7 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
||||||
compileOnly group: 'org.jetbrains', name: 'annotations', version: '22.0.0'
|
compileOnly group: 'org.jetbrains', name: 'annotations', version: '22.0.0'
|
||||||
compileOnly "cn.hamster3:HamsterService-Bukkit:2.8.3-SNAPSHOT"
|
compileOnly "cn.hamster3:HamsterService-Bukkit:2.8.3-SNAPSHOT"
|
||||||
compileOnly "cn.hamster3:HamsterAPI:2.4.7-SNAPSHOT"
|
compileOnly "cn.hamster3:HamsterAPI:2.4.8-SNAPSHOT"
|
||||||
compileOnly 'net.milkbowl.vault:VaultAPI:1.7'
|
compileOnly 'net.milkbowl.vault:VaultAPI:1.7'
|
||||||
compileOnly "me.clip:placeholderapi:2.10.9"
|
compileOnly "me.clip:placeholderapi:2.10.9"
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@ processResources {
|
|||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
withJavadocJar()
|
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,19 +47,6 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
options.compilerArgs << "-Xlint:unchecked"
|
options.compilerArgs << "-Xlint:unchecked"
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
|
||||||
options.quiet()
|
|
||||||
options.encoding = 'UTF-8'
|
|
||||||
options.addStringOption('Xdoclint:none', '-quiet')
|
|
||||||
options.links = [
|
|
||||||
"https://javadoc.io/doc/org.jetbrains/annotations/21.0.1",
|
|
||||||
'https://javadoc.io/doc/com.google.code.gson/gson/2.8.0',
|
|
||||||
'https://ci.dmulloy2.net/job/ProtocolLib/javadoc',
|
|
||||||
'http://milkbowl.github.io/VaultAPI',
|
|
||||||
'https://bukkit.windit.net/javadoc'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create("mavenJava", MavenPublication.class) {
|
create("mavenJava", MavenPublication.class) {
|
||||||
@@ -73,10 +59,7 @@ publishing {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
def releasesRepoUrl = 'https://maven.airgame.net/maven-releases/'
|
url = 'https://maven.airgame.net/maven-airgame/'
|
||||||
def snapshotsRepoUrl = 'https://maven.airgame.net/maven-snapshots/'
|
|
||||||
|
|
||||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username maven_username
|
username maven_username
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
package cn.hamster3.currency.core;
|
package cn.hamster3.currency.core;
|
||||||
|
|
||||||
|
import cn.hamster3.api.HamsterAPI;
|
||||||
import cn.hamster3.currency.HamsterCurrency;
|
import cn.hamster3.currency.HamsterCurrency;
|
||||||
import cn.hamster3.currency.data.CurrencyLog;
|
import cn.hamster3.currency.data.CurrencyLog;
|
||||||
import cn.hamster3.currency.data.CurrencyType;
|
import cn.hamster3.currency.data.CurrencyType;
|
||||||
import cn.hamster3.currency.data.PlayerData;
|
import cn.hamster3.currency.data.PlayerData;
|
||||||
import cn.hamster3.service.bukkit.api.ServiceMessageAPI;
|
import cn.hamster3.service.bukkit.api.ServiceMessageAPI;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -25,7 +25,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
private final JsonParser parser;
|
private final JsonParser parser;
|
||||||
|
|
||||||
private final String database;
|
private final String database;
|
||||||
private final HikariDataSource dataSource;
|
private final DataSource datasource;
|
||||||
|
|
||||||
private final HashSet<PlayerData> playerData;
|
private final HashSet<PlayerData> playerData;
|
||||||
private final HashSet<CurrencyType> currencyTypes;
|
private final HashSet<CurrencyType> currencyTypes;
|
||||||
@@ -38,18 +38,9 @@ public class SQLDataManager implements IDataManager {
|
|||||||
|
|
||||||
ConfigurationSection datasourceConfig = FileManager.getPluginConfig().getConfigurationSection("datasource");
|
ConfigurationSection datasourceConfig = FileManager.getPluginConfig().getConfigurationSection("datasource");
|
||||||
database = datasourceConfig.getString("database");
|
database = datasourceConfig.getString("database");
|
||||||
HikariConfig hikariConfig = new HikariConfig();
|
datasource = HamsterAPI.getHikariDataSource(datasourceConfig);
|
||||||
|
|
||||||
hikariConfig.setDriverClassName(datasourceConfig.getString("driver"));
|
Connection connection = datasource.getConnection();
|
||||||
hikariConfig.setJdbcUrl(datasourceConfig.getString("url"));
|
|
||||||
hikariConfig.setUsername(datasourceConfig.getString("user"));
|
|
||||||
hikariConfig.setPassword(datasourceConfig.getString("password"));
|
|
||||||
|
|
||||||
hikariConfig.setMaximumPoolSize(10);
|
|
||||||
hikariConfig.setMinimumIdle(1);
|
|
||||||
|
|
||||||
dataSource = new HikariDataSource(hikariConfig);
|
|
||||||
Connection connection = dataSource.getConnection();
|
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_player_data(" +
|
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_player_data(" +
|
||||||
"uuid VARCHAR(36) PRIMARY KEY," +
|
"uuid VARCHAR(36) PRIMARY KEY," +
|
||||||
@@ -82,7 +73,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
getLogUtils().info("配置文件重载完成!");
|
getLogUtils().info("配置文件重载完成!");
|
||||||
try {
|
try {
|
||||||
getLogUtils().info("将配置文件上传至数据库...");
|
getLogUtils().info("将配置文件上传至数据库...");
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
String data = Base64.getEncoder().encodeToString(config.saveToString().getBytes(StandardCharsets.UTF_8));
|
String data = Base64.getEncoder().encodeToString(config.saveToString().getBytes(StandardCharsets.UTF_8));
|
||||||
statement.executeUpdate(String.format(
|
statement.executeUpdate(String.format(
|
||||||
@@ -104,7 +95,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
public void loadConfigFromSQL() {
|
public void loadConfigFromSQL() {
|
||||||
try {
|
try {
|
||||||
getLogUtils().info("从数据库中下载配置文件...");
|
getLogUtils().info("从数据库中下载配置文件...");
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_settings;");
|
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_settings;");
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
@@ -156,7 +147,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
getLogUtils().info("玩家经济列名: %s", moneyCol);
|
getLogUtils().info("玩家经济列名: %s", moneyCol);
|
||||||
getLogUtils().info("导入至经济类型: %s", currencyType);
|
getLogUtils().info("导入至经济类型: %s", currencyType);
|
||||||
try {
|
try {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet set = statement.executeQuery(String.format("SELECT * FROM %s.%s;", database, table));
|
ResultSet set = statement.executeQuery(String.format("SELECT * FROM %s.%s;", database, table));
|
||||||
synchronized (playerData) {
|
synchronized (playerData) {
|
||||||
@@ -198,7 +189,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogUtils().info("从数据库中读取玩家数据...");
|
getLogUtils().info("从数据库中读取玩家数据...");
|
||||||
try {
|
try {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_player_data;");
|
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_player_data;");
|
||||||
synchronized (playerData) {
|
synchronized (playerData) {
|
||||||
@@ -246,7 +237,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
@Override
|
@Override
|
||||||
public void loadPlayerData(UUID uuid) {
|
public void loadPlayerData(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet set = statement.executeQuery(String.format(
|
ResultSet set = statement.executeQuery(String.format(
|
||||||
"SELECT * FROM " + database + ".hamster_currency_player_data WHERE uuid='%s';",
|
"SELECT * FROM " + database + ".hamster_currency_player_data WHERE uuid='%s';",
|
||||||
@@ -283,7 +274,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
public void savePlayerData(PlayerData data) {
|
public void savePlayerData(PlayerData data) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = datasource.getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
statement.executeUpdate(String.format(
|
statement.executeUpdate(String.format(
|
||||||
"REPLACE INTO " + database + ".hamster_currency_player_data VALUES('%s', '%s');",
|
"REPLACE INTO " + database + ".hamster_currency_player_data VALUES('%s', '%s');",
|
||||||
@@ -307,7 +298,7 @@ public class SQLDataManager implements IDataManager {
|
|||||||
@Override
|
@Override
|
||||||
public void insertLog(CurrencyLog log) {
|
public void insertLog(CurrencyLog log) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = datasource.getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement(
|
try (PreparedStatement statement = connection.prepareStatement(
|
||||||
"INSERT INTO " + database + ".hamster_currency_logs VALUES(?, ?, ?, ?, ?, ?, DEFAULT);"
|
"INSERT INTO " + database + ".hamster_currency_logs VALUES(?, ?, ?, ?, ?, ?, DEFAULT);"
|
||||||
)) {
|
)) {
|
||||||
|
Reference in New Issue
Block a user