mirror of
https://github.com/MiniDay/HamsterCurrency-Parent.git
synced 2025-08-22 12:15:31 +08:00
fix: 修复事件错误
This commit is contained in:
@@ -17,7 +17,7 @@ public abstract class FileManager {
|
||||
plugin.reloadConfig();
|
||||
pluginConfig = plugin.getConfig();
|
||||
useBC = pluginConfig.getBoolean("useBC", false);
|
||||
mainServer = pluginConfig.getBoolean("datasource.template");
|
||||
mainServer = pluginConfig.getBoolean("datasource.template", true);
|
||||
setPluginConfig(pluginConfig);
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,6 @@ public class SQLDataManager implements IDataManager {
|
||||
private final HamsterCurrency plugin;
|
||||
private final JsonParser parser;
|
||||
|
||||
private final String database;
|
||||
private final DataSource datasource;
|
||||
|
||||
private final Map<UUID, PlayerData> playerData;
|
||||
@@ -38,16 +37,15 @@ public class SQLDataManager implements IDataManager {
|
||||
currencyTypes = new HashSet<>();
|
||||
|
||||
ConfigurationSection datasourceConfig = FileManager.getPluginConfig().getConfigurationSection("datasource");
|
||||
database = datasourceConfig.getString("database");
|
||||
datasource = HamsterAPI.getHikariDataSource(datasourceConfig);
|
||||
|
||||
Connection connection = datasource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_player_data(" +
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_player_data(" +
|
||||
"uuid VARCHAR(36) PRIMARY KEY," +
|
||||
"data TEXT" +
|
||||
") CHARACTER SET = utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_logs(" +
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_logs(" +
|
||||
"uuid VARCHAR(36) NOT NULL," +
|
||||
"player_name VARCHAR(36) NOT NULL," +
|
||||
"type VARCHAR(36) NOT NULL," +
|
||||
@@ -58,7 +56,7 @@ public class SQLDataManager implements IDataManager {
|
||||
"INDEX idx_uuid(uuid)," +
|
||||
"INDEX idx_name(player_name)" +
|
||||
") CHARACTER SET = utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_settings(" +
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS hamster_currency_settings(" +
|
||||
"title VARCHAR(64) PRIMARY KEY," +
|
||||
"data TEXT" +
|
||||
") CHARACTER SET = utf8mb4;");
|
||||
@@ -78,7 +76,7 @@ public class SQLDataManager implements IDataManager {
|
||||
Statement statement = connection.createStatement();
|
||||
String data = Base64.getEncoder().encodeToString(config.saveToString().getBytes(StandardCharsets.UTF_8));
|
||||
statement.executeUpdate(String.format(
|
||||
"REPLACE INTO " + database + ".hamster_currency_settings VALUES('%s', '%s');",
|
||||
"REPLACE INTO hamster_currency_settings VALUES('%s', '%s');",
|
||||
"pluginConfig",
|
||||
data
|
||||
));
|
||||
@@ -98,7 +96,7 @@ public class SQLDataManager implements IDataManager {
|
||||
getLogUtils().info("从数据库中下载配置文件...");
|
||||
Connection connection = datasource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_settings;");
|
||||
ResultSet set = statement.executeQuery("SELECT * FROM hamster_currency_settings;");
|
||||
while (set.next()) {
|
||||
String title = set.getString("title");
|
||||
String data = new String(Base64.getDecoder().decode(set.getString("data")), StandardCharsets.UTF_8);
|
||||
@@ -190,7 +188,7 @@ public class SQLDataManager implements IDataManager {
|
||||
try {
|
||||
Connection connection = datasource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet set = statement.executeQuery("SELECT * FROM " + database + ".hamster_currency_player_data;");
|
||||
ResultSet set = statement.executeQuery("SELECT * FROM hamster_currency_player_data;");
|
||||
while (set.next()) {
|
||||
String uuid = set.getString("uuid");
|
||||
String string = set.getString("data");
|
||||
@@ -237,7 +235,7 @@ public class SQLDataManager implements IDataManager {
|
||||
Connection connection = datasource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet set = statement.executeQuery(String.format(
|
||||
"SELECT * FROM " + database + ".hamster_currency_player_data WHERE uuid='%s';",
|
||||
"SELECT * FROM hamster_currency_player_data WHERE uuid='%s';",
|
||||
uuid
|
||||
));
|
||||
PlayerData data;
|
||||
@@ -272,7 +270,7 @@ public class SQLDataManager implements IDataManager {
|
||||
Connection connection = datasource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
statement.executeUpdate(String.format(
|
||||
"REPLACE INTO " + database + ".hamster_currency_player_data VALUES('%s', '%s');",
|
||||
"REPLACE INTO hamster_currency_player_data VALUES('%s', '%s');",
|
||||
data.getUuid().toString(),
|
||||
data.saveToJson().toString()
|
||||
));
|
||||
@@ -295,7 +293,7 @@ public class SQLDataManager implements IDataManager {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = datasource.getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(
|
||||
"INSERT INTO " + database + ".hamster_currency_logs VALUES(?, ?, ?, ?, ?, ?, NOW());"
|
||||
"INSERT INTO hamster_currency_logs VALUES(?, ?, ?, ?, ?, ?, NOW());"
|
||||
)) {
|
||||
statement.setString(1, log.getUuid().toString());
|
||||
statement.setString(2, log.getPlayerName());
|
||||
|
@@ -23,6 +23,10 @@ public class VaultEconomyGiveEvent extends Event {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public @NotNull UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
@@ -23,6 +23,10 @@ public class VaultEconomySeeEvent extends Event {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public @NotNull UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
@@ -23,6 +23,10 @@ public class VaultEconomyTakeEvent extends Event {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public @NotNull UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class VaultEconomyHook extends AbstractEconomy {
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
return data.getPlayerCurrency(FileManager.getVaultCurrencyType()) >= amount;
|
||||
return getBalance(data) >= amount;
|
||||
}
|
||||
|
||||
private double getBalance(PlayerData data) {
|
||||
|
@@ -5,19 +5,10 @@ useBC: true
|
||||
|
||||
# 若开启跨服模式,则需要配置datasource
|
||||
datasource:
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
url: "jdbc:mysql://sql.hamster3.cn:3306?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false"
|
||||
user: Test
|
||||
password: Test123..
|
||||
database: Test1
|
||||
# 是否将这个服务器的配置文件设为模板
|
||||
# 若设为true,config将会在服务器启动时自动上传至数据库
|
||||
# 其他template为false的服务器将会在启动和重载时自动从数据库上下载config
|
||||
# 可以节省一些config配置时的麻烦事情
|
||||
# 但是请先保证template为true的服务器完全启动了再启动子服
|
||||
# 如果觉得这样反而更麻烦,也可以直接把所有服务器的template设为true
|
||||
# 这样每个服务器都会使用自己本地的config文件了
|
||||
template: true
|
||||
driver: "com.mysql.jdbc.Driver"
|
||||
url: "jdbc:mysql://localhost:3306/mc1.12.2-germ?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
user: root
|
||||
password: Root123...
|
||||
|
||||
currencyTypes:
|
||||
# 货币ID
|
||||
|
Reference in New Issue
Block a user