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