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.0'
|
||||
version '2.1.1'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
@@ -43,7 +43,7 @@ public abstract class CurrencyAPI {
|
||||
}
|
||||
data.setPlayerCurrency(currencyID, amount);
|
||||
dataManager.savePlayerData(data);
|
||||
dataManager.insertLog(new CurrencyLog(uuid, currencyID, "set", amount, amount));
|
||||
dataManager.insertLog(new CurrencyLog(uuid, data.getPlayerName(), currencyID, "set", amount, amount));
|
||||
}
|
||||
|
||||
public static void addPlayerCurrency(UUID uuid, String currencyID, double amount) {
|
||||
@@ -58,7 +58,7 @@ public abstract class CurrencyAPI {
|
||||
double balance = data.getPlayerCurrency(currencyID) + amount;
|
||||
data.setPlayerCurrency(currencyID, balance);
|
||||
dataManager.savePlayerData(data);
|
||||
dataManager.insertLog(new CurrencyLog(uuid, currencyID, "add", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(uuid, data.getPlayerName(), currencyID, "add", amount, balance));
|
||||
}
|
||||
|
||||
public static void takePlayerCurrency(UUID uuid, String currencyID, double amount) {
|
||||
@@ -73,7 +73,7 @@ public abstract class CurrencyAPI {
|
||||
double balance = data.getPlayerCurrency(currencyID) - amount;
|
||||
data.setPlayerCurrency(currencyID, balance);
|
||||
dataManager.savePlayerData(data);
|
||||
dataManager.insertLog(new CurrencyLog(uuid, currencyID, "take", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(uuid, data.getPlayerName(), currencyID, "take", amount, balance));
|
||||
}
|
||||
|
||||
public static boolean hasPlayerCurrency(UUID uuid, String currencyID, double amount) {
|
||||
|
@@ -19,7 +19,7 @@ public class CurrencyGiveCommand extends CurrencyAdminSetCommand {
|
||||
protected void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
double balance = data.getPlayerCurrency(type.getId()) + amount;
|
||||
data.setPlayerCurrency(type.getId(), balance);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "add", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "add", amount, balance));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -91,8 +91,8 @@ public class CurrencyPayCommand extends CommandExecutor {
|
||||
toData.setPlayerCurrency(type.getId(), toBalance);
|
||||
dataManager.savePlayerData(fromData);
|
||||
dataManager.savePlayerData(toData);
|
||||
dataManager.insertLog(new CurrencyLog(fromData.getUuid(), type.getId(), "payOut", amount, fromBalance));
|
||||
dataManager.insertLog(new CurrencyLog(toData.getUuid(), type.getId(), "payIn", amount, toBalance));
|
||||
dataManager.insertLog(new CurrencyLog(fromData.getUuid(), fromData.getPlayerName(), type.getId(), "payOut", amount, fromBalance));
|
||||
dataManager.insertLog(new CurrencyLog(toData.getUuid(), toData.getPlayerName(), type.getId(), "payIn", amount, toBalance));
|
||||
sender.sendMessage(
|
||||
Message.paySuccess.toString()
|
||||
.replace("%player%", toData.getPlayerName())
|
||||
|
@@ -18,7 +18,7 @@ public class CurrencySetCommand extends CurrencyAdminSetCommand {
|
||||
@Override
|
||||
protected void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
data.setPlayerCurrency(type.getId(), amount);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "set", amount, amount));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "set", amount, amount));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,6 +19,6 @@ public class CurrencyTakeCommand extends CurrencyAdminSetCommand {
|
||||
protected void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
double balance = data.getPlayerCurrency(type.getId()) - amount;
|
||||
data.setPlayerCurrency(type.getId(), balance);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "take", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "take", amount, balance));
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,6 @@ public class VaultGiveCommand extends VaultAdminSetCommand {
|
||||
public void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
double balance = data.getPlayerCurrency(type.getId()) + amount;
|
||||
data.setPlayerCurrency(type.getId(), balance);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "add", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "add", amount, balance));
|
||||
}
|
||||
}
|
||||
|
@@ -95,8 +95,8 @@ public class VaultPayCommand extends CommandManager {
|
||||
toData.setPlayerCurrency(type.getId(), toBalance);
|
||||
dataManager.savePlayerData(fromData);
|
||||
dataManager.savePlayerData(toData);
|
||||
dataManager.insertLog(new CurrencyLog(fromData.getUuid(), type.getId(), "payOut", amount, fromBalance));
|
||||
dataManager.insertLog(new CurrencyLog(toData.getUuid(), type.getId(), "payIn", amount, toBalance));
|
||||
dataManager.insertLog(new CurrencyLog(fromData.getUuid(), fromData.getPlayerName(), type.getId(), "payOut", amount, fromBalance));
|
||||
dataManager.insertLog(new CurrencyLog(toData.getUuid(), toData.getPlayerName(), type.getId(), "payIn", amount, toBalance));
|
||||
sender.sendMessage(
|
||||
Message.paySuccess.toString()
|
||||
.replace("%player%", toData.getPlayerName())
|
||||
|
@@ -18,6 +18,6 @@ public class VaultSetCommand extends VaultAdminSetCommand {
|
||||
@Override
|
||||
public void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
data.setPlayerCurrency(type.getId(), amount);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "set", amount, amount));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "set", amount, amount));
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,6 @@ public class VaultTakeCommand extends VaultAdminSetCommand {
|
||||
public void doSet(PlayerData data, CurrencyType type, double amount) {
|
||||
double balance = data.getPlayerCurrency(type.getId()) - amount;
|
||||
data.setPlayerCurrency(type.getId(), balance);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type.getId(), "take", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type.getId(), "take", amount, balance));
|
||||
}
|
||||
}
|
||||
|
@@ -57,12 +57,14 @@ public class SQLDataManager implements IDataManager {
|
||||
") CHARACTER SET = utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_logs(" +
|
||||
"uuid VARCHAR(36) NOT NULL," +
|
||||
"player_name VARCHAR(36) NOT NULL," +
|
||||
"type VARCHAR(36) NOT NULL," +
|
||||
"action VARCHAR(36) NOT NULL," +
|
||||
"amount DOUBLE NOT NULL," +
|
||||
"balance DOUBLE NOT NULL," +
|
||||
"time DATETIME NOT NULL DEFAULT NOW()," +
|
||||
"INDEX idx_uuid(uuid)" +
|
||||
"INDEX idx_uuid(uuid)," +
|
||||
"INDEX idx_name(player_name)" +
|
||||
") CHARACTER SET = utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + database + ".hamster_currency_settings(" +
|
||||
"title VARCHAR(64) PRIMARY KEY," +
|
||||
@@ -307,13 +309,14 @@ 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(?, ?, ?, ?, ?, DEFAULT);"
|
||||
"INSERT INTO " + database + ".hamster_currency_logs VALUES(?, ?, ?, ?, ?, ?, DEFAULT);"
|
||||
)) {
|
||||
statement.setString(1, log.getUuid().toString());
|
||||
statement.setString(2, log.getType());
|
||||
statement.setString(3, log.getAction());
|
||||
statement.setDouble(4, log.getAmount());
|
||||
statement.setDouble(5, log.getBalance());
|
||||
statement.setString(2, log.getPlayerName());
|
||||
statement.setString(3, log.getType());
|
||||
statement.setString(4, log.getAction());
|
||||
statement.setDouble(5, log.getAmount());
|
||||
statement.setDouble(6, log.getBalance());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@@ -7,6 +7,8 @@ import java.util.UUID;
|
||||
public class CurrencyLog {
|
||||
@NotNull
|
||||
private final UUID uuid;
|
||||
@NotNull
|
||||
private final String playerName;
|
||||
/**
|
||||
* 货币类型
|
||||
*/
|
||||
@@ -26,26 +28,28 @@ public class CurrencyLog {
|
||||
*/
|
||||
private final double balance;
|
||||
|
||||
public CurrencyLog(@NotNull UUID uuid, @NotNull String type, @NotNull String action, double amount, double balance) {
|
||||
public CurrencyLog(@NotNull UUID uuid, @NotNull String playerName, @NotNull String type, @NotNull String action, double amount, double balance) {
|
||||
this.uuid = uuid;
|
||||
this.playerName = playerName;
|
||||
this.type = type;
|
||||
this.action = action;
|
||||
this.amount = amount;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public UUID getUuid() {
|
||||
public @NotNull UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getType() {
|
||||
public @NotNull String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public @NotNull String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getAction() {
|
||||
public @NotNull String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ public class VaultEconomyHook extends AbstractEconomy {
|
||||
}
|
||||
data.setPlayerCurrency(type, balance);
|
||||
dataManager.savePlayerData(data);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type, "add", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type, "add", amount, balance));
|
||||
return new EconomyResponse(amount, data.getPlayerCurrency(type), EconomyResponse.ResponseType.SUCCESS, "");
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class VaultEconomyHook extends AbstractEconomy {
|
||||
double balance = data.getPlayerCurrency(type) - amount;
|
||||
data.setPlayerCurrency(type, balance);
|
||||
dataManager.savePlayerData(data);
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), type, "take", amount, balance));
|
||||
dataManager.insertLog(new CurrencyLog(data.getUuid(), data.getPlayerName(), type, "take", amount, balance));
|
||||
return new EconomyResponse(amount, data.getPlayerCurrency(type), EconomyResponse.ResponseType.SUCCESS, "扣款成功");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user