Skip to content

Commit

Permalink
feat: Add buyer variable to offline transaction record (Close #10), U…
Browse files Browse the repository at this point in the history
…pdate patches
  • Loading branch information
blank038 committed Jul 24, 2024
1 parent f5e8c95 commit eb2bd0c
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 40 deletions.
12 changes: 12 additions & 0 deletions PATCHES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ServerMarket Patches

> [!CAUTION]
> 可能存在数据安全隐患,需要您手动备份数据后再执行
当您在使用过程中遇到一些 BUG,需要进行修复时确定 ServerMarket 已经有修复的版本再执行下面的步骤,
将插件更新至最新版,通过执行命令 `/market patch <补丁编号>` 来修复,补丁编号支持命令补全。

| 补丁编号 | 补丁功能 |
|:-------:|:------------------------------------------------------------------------:|
| 251-U-1 | 修复离线记录金额超过数值范围,例:[#2](https://github.com/blank038/ServerMarket/issues/2) |
| 270-F-1 | 修复 MySQL 离线记录表(`servermarket_offline_transactions`) `buyer` 字段不存在 |
14 changes: 14 additions & 0 deletions PATCHES_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ServerMarket Patches

> [!CAUTION]
> There may be potential data security risks. Please manually back up your data before proceeding.
When you encounter bugs during use that need to be fixed, make sure that ServerMarket already has a version with the fix
before following the steps below. Update the plugin to the latest version and use the
command `/market patch <patch number>` to apply the fix.
> The patch number supports command completion.
| Patch Number | Patch Function |
|:------------:|:---------------------------------------------------------------------------------------------------------------------------------------:|
| 251-U-1 | Fixed an issue where the offline recording amount exceeded the numerical range. [#2](https://github.com/blank038/ServerMarket/issues/2) |
| 270-F-1 | Fixed the non-existent `buyer` field in the MySQL offline record table.(`servermarket_offline_transactions`) |
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@

## 🔨 补丁

> [!CAUTION]
> 可能存在数据安全隐患,需要您手动备份数据后再执行
当您在使用过程中遇到一些 BUG,需要进行修复时确定 ServerMarket 已经有修复的版本再执行下面的步骤,
将插件更新至最新版,通过执行命令 `/market patch <补丁编号>` 来修复,补丁编号支持命令补全。

| 补丁编号 | 补丁功能 |
|:-------:|:------------------------------------------------------------------------:|
| 251-U-1 | 修复离线记录金额超过数值范围,例:[#2](https://github.com/blank038/ServerMarket/issues/2) |
[补丁列表](PATCHES.md)

## 🌱 贡献者 & Contributors

Expand Down
10 changes: 1 addition & 9 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@

## 🔨 Patch

> [!CAUTION]
> There may be potential data security risks. Please manually back up your data before proceeding.
When you encounter bugs during use that need to be fixed, make sure that ServerMarket already has a version with the fix before following the steps below. Update the plugin to the latest version and use the command `/market patch <patch number>` to apply the fix.
> The patch number supports command completion.
| Patch Number | Patch Function |
|:-------:|:------------------------------------------------------------------------:|
| 251-U-1 | Fixed an issue where the offline recording amount exceeded the numerical range. [#2](https://github.com/blank038/ServerMarket/issues/2) |
[ServerMarket Patches](PATCHES_EN.md)

## 🌱 Contributors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ public static void openMarket(Player player, String key, int page, FilterHandler
}
}

public static void addOfflineTransaction(String uuid, PayType payType, String ectType, double moeny, String sourceMarket) {
public static void addOfflineTransaction(String uuid, String buyer, PayType payType, String ectType, double moeny, String sourceMarket) {
ConfigurationSection section = new YamlConfiguration();
section.set("amount", moeny);
section.set("pay-type", payType.name());
section.set("owner-uuid", uuid);
section.set("eco-type", ectType);
section.set("source-market", sourceMarket);
section.set("buyer", buyer);
// 存入数据
OfflineTransactionData resultData = new OfflineTransactionData(section);
ServerMarket.getStorageHandler().addOfflineTransaction(resultData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void initialize() {
"CREATE TABLE IF NOT EXISTS `servermarket_players`( `player_uuid` VARCHAR(36) NOT NULL, `data` TEXT, `locked` TINYINT, PRIMARY KEY (`player_uuid`)) ENGINE = InnoDB DEFAULT CHARSET = utf8;",
"CREATE TABLE IF NOT EXISTS `servermarket_sales` ( `sale_uuid` VARCHAR(36) NOT NULL, `market` VARCHAR(20) NOT NULL, `owner_name` VARCHAR(20) NOT NULL, `owner_uuid` VARCHAR(36) NOT NULL, `pay_type` VARCHAR(20) NOT NULL, `eco_type` VARCHAR(50), `price` int, `data` TEXT, `post_time` TIMESTAMP NOT NULL, PRIMARY KEY (`sale_uuid`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;",
"CREATE TABLE IF NOT EXISTS `servermarket_logs` ( `id` INT AUTO_INCREMENT, `trigger_time` TIMESTAMP, `trigger_uuid` VARCHAR(36) NOT NULL, `market` VARCHAR(50), `log_type` VARCHAR(10) NOT NULL, `data` TEXT, PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;",
"CREATE TABLE IF NOT EXISTS `servermarket_offline_transactions` ( `id` INT AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `market` VARCHAR(50) NOT NULL, `amount` INT, `pay_type` VARCHAR(20) NOT NULL, `eco_type` VARCHAR(50), PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;"
"CREATE TABLE IF NOT EXISTS `servermarket_offline_transactions` ( `id` INT AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `buyer` VARCHAR(20) NOT NULL, `market` VARCHAR(50) NOT NULL, `amount` INT, `pay_type` VARCHAR(20) NOT NULL, `eco_type` VARCHAR(50), PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;"
};
storageHandler = new MySqlStorageHandler(
ServerMarket.getInstance(),
Expand Down Expand Up @@ -485,15 +485,20 @@ public void addOfflineTransaction(OfflineTransactionData data) {
storageHandler.connect((preparedStatement) -> {
try {
preparedStatement.setString(1, data.getOwnerUniqueId().toString());
preparedStatement.setString(2, data.getSourceMarket());
preparedStatement.setInt(3, (int) (data.getAmount() * 100));
preparedStatement.setString(4, data.getPayType().name());
preparedStatement.setString(5, data.getEconomyType());
preparedStatement.setString(2, data.getBuyer());
preparedStatement.setString(3, data.getSourceMarket());
preparedStatement.setInt(4, (int) (data.getAmount() * 100));
preparedStatement.setString(5, data.getPayType().name());
preparedStatement.setString(6, data.getEconomyType());
preparedStatement.executeUpdate();
} catch (SQLException e) {
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Failed to add offline transaction.");
StringBuilder builder = new StringBuilder();
if (e.getSQLState().startsWith("42")) {
builder.append("(Maybe you need to use the '/market patch 270-F-1' command, see https://github.com/blank038/ServerMarket/PATCHES.md)");
}
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Failed to add offline transaction." + builder);
}
}, "INSERT INTO " + offlineTransactionsTable + " (owner_uuid,market,amount,pay_type,eco_type) VALUES (?,?,?,?,?);");
}, "INSERT INTO " + offlineTransactionsTable + " (owner_uuid,buyer,market,amount,pay_type,eco_type) VALUES (?,?,?,?,?,?);");
}

@Override
Expand Down Expand Up @@ -522,17 +527,22 @@ public Map<String, OfflineTransactionData> getOfflineTransactionByPlayer(UUID ow
while (resultSet.next()) {
OfflineTransactionData data = new OfflineTransactionData(
resultSet.getString(2),
resultSet.getString(3),
ownerUniqueId,
PayType.valueOf(resultSet.getString(3)),
resultSet.getString(4),
resultSet.getInt(5) * 0.01
PayType.valueOf(resultSet.getString(4)),
resultSet.getString(5),
resultSet.getInt(6) * 0.01
);
map.put(String.valueOf(resultSet.getInt(1)), data);
}
} catch (SQLException e) {
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Failed to get offline transactions.");
StringBuilder builder = new StringBuilder();
if (e.getSQLState().startsWith("42")) {
builder.append("(Maybe you need to use the '/market patch 270-F-1' command, see https://github.com/blank038/ServerMarket/PATCHES.md)");
}
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Failed to get offline transactions." + builder);
}
}, "SELECT id,market,pay_type,eco_type,amount FROM " + offlineTransactionsTable + " WHERE owner_uuid = ?;");
}, "SELECT id,market,buyer,pay_type,eco_type,amount FROM " + offlineTransactionsTable + " WHERE owner_uuid = ?;");
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ public class OfflineTransactionData {
private final double amount;
private final PayType payType;
private final UUID ownerUniqueId;
private final String economyType, sourceMarket;
private final String economyType, sourceMarket, buyer;

public OfflineTransactionData(ConfigurationSection section) {
this.amount = section.getDouble("amount");
this.payType = PayType.valueOf(section.getString("pay-type"));
this.ownerUniqueId = UUID.fromString(section.getString("owner-uuid"));
this.economyType = section.getString("eco-type", null);
this.sourceMarket = section.getString("source-market");
this.buyer = section.getString("buyer");
}

public OfflineTransactionData(String sourceMarket, UUID ownerUniqueId, PayType payType, String economyType, double amount) {
public OfflineTransactionData(String sourceMarket, String buyer, UUID ownerUniqueId, PayType payType, String economyType, double amount) {
this.sourceMarket = sourceMarket;
this.ownerUniqueId = ownerUniqueId;
this.buyer = buyer;
this.payType = payType;
this.economyType = economyType;
this.amount = amount;
Expand All @@ -41,6 +43,7 @@ public ConfigurationSection toSection() {
section.set("owner-uuid", this.ownerUniqueId.toString());
section.set("eco-type", this.economyType);
section.set("source-market", this.sourceMarket);
section.set("buyer", this.buyer);
return section;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public enum ActionType {
DecimalFormat df = new DecimalFormat("#0.00");
BaseEconomy.getEconomyBridge(marketData.getPaymentType()).give(seller, marketData.getEconomyType(), last);
seller.sendMessage(I18n.getStrAndHeader("sale-sell")
.replace("%market%", marketData == null ? "" : marketData.getDisplayName())
.replace("%economy%", marketData.getEconomyName())
.replace("%money%", df.format(saleItem.getPrice()))
.replace("%last%", df.format(last)));
.replace("%last%", df.format(last))
.replaceAll("%buyer%", buyer.getName()));
// send taxes
ServerMarketApi.sendTaxes(marketData.getPaymentType(), marketData.getEconomyName(), tax);
} else {
ServerMarketApi.addOfflineTransaction(saleItem.getOwnerUUID(), marketData.getPaymentType(),
ServerMarketApi.addOfflineTransaction(saleItem.getOwnerUUID(), buyer.getName(), marketData.getPaymentType(),
marketData.getEconomyType(), saleItem.getPrice(), marketData.getMarketKey());
}
// give sale item to buyer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.blank038.servermarket.dto.impl.MysqlStorageHandlerImpl;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import lombok.Getter;

import java.sql.SQLException;
import java.util.HashMap;
Expand All @@ -21,7 +20,7 @@ public class PatchHandler {
static {
// Patch id example: "version-level-number"
// Patch level: F=FATAL, U=URGENT, S=SLIGHT, O=OPTIONAL
PATCH_MAP.put("251-U-1", () -> {
registerPatch("251-U-1", () -> {
AtomicBoolean atomicBoolean = new AtomicBoolean(true);
if (ServerMarket.getStorageHandler() instanceof MysqlStorageHandlerImpl) {
MysqlStorageHandlerImpl.getStorageHandler().connect((statement) -> {
Expand All @@ -35,6 +34,20 @@ public class PatchHandler {
}
return atomicBoolean.get();
});
registerPatch("270-F-1", () -> {
AtomicBoolean atomicBoolean = new AtomicBoolean(true);
if (ServerMarket.getStorageHandler() instanceof MysqlStorageHandlerImpl) {
MysqlStorageHandlerImpl.getStorageHandler().connect((statement) -> {
try {
statement.executeUpdate();
} catch (SQLException e) {
atomicBoolean.set(false);
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "Failed add column buyer to servermarket_offline_transactions.");
}
}, "ALTER TABLE `servermarket_offline_transactions` ADD COLUMN `buyer` VARCHAR(20) NOT NULL AFTER `owner_uuid`;");
}
return atomicBoolean.get();
});
}

public static boolean executePatch(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ private void checkResult(Player player) {
DecimalFormat df = new DecimalFormat("#0.00");
BaseEconomy.getEconomyBridge(v.getPayType()).give(player, v.getEconomyType(), last);
player.sendMessage(I18n.getStrAndHeader("sale-sell")
.replace("%economy%", marketData == null ? "" : marketData.getDisplayName())
.replace("%money%", df.format(price)).replace("%last%", df.format(last)));
.replace("%market%", marketData == null ? "" : marketData.getDisplayName())
.replace("%economy%", marketData == null ? "" : marketData.getEconomyName())
.replace("%money%", df.format(price))
.replace("%last%", df.format(last))
.replace("%buyer%", v.getBuyer()));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/resources/language/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inventory-full: "背包已满, 无法取出物品."
unsale: "成功下架物品, 请前往暂存箱取出."
is-owner: "你不能购买自己的物品."
buy-item: "成功购买该物品, 请前往暂存箱取出."
sale-sell: "从市场中出售物品获得 %money%%economy%(税后: %last%%economy%)"
sale-sell: "从市场中出售物品获得 %money%%economy%(购买者: %buyer% 税后: %last%%economy%)"
market-error: "市场异常, 无法查看."
no-permission: "你没有权限这么做."
lack-money: "你没有足够的%economy%来购买这个商品."
Expand Down

0 comments on commit eb2bd0c

Please sign in to comment.