From 1005e717aa8849f86b7e6f67a7e7021e4de602d4 Mon Sep 17 00:00:00 2001
From: Blank038 <admin@mc9y.com>
Date: Mon, 11 Mar 2024 14:06:21 +0800
Subject: [PATCH] fix: Fix potential issues with the SaleCache

---
 build.gradle                                                 | 5 +----
 .../com/blank038/servermarket/api/entity/MarketData.java     | 2 +-
 .../servermarket/internal/cache/market/MarketCache.java      | 2 +-
 .../servermarket/internal/cache/player/PlayerCache.java      | 4 ++++
 .../blank038/servermarket/internal/cache/sale/SaleCache.java | 4 ++++
 .../blank038/servermarket/internal/gui/impl/MarketGui.java   | 2 +-
 src/main/resources/config.yml                                | 4 +++-
 src/main/resources/plugin.yml                                | 3 ++-
 8 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/build.gradle b/build.gradle
index 3d833a2..7472abe 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,10 +14,7 @@ repositories {
     }
 }
 
-sourceCompatibility = targetCompatibility = '1.8'
-compileJava {
-    sourceCompatibility = targetCompatibility = '1.8'
-}
+java.toolchain.languageVersion = JavaLanguageVersion.of(8)
 
 dependencies {
     implementation fileTree(dir: "libs", includes: ["*.jar"])
diff --git a/src/main/java/com/blank038/servermarket/api/entity/MarketData.java b/src/main/java/com/blank038/servermarket/api/entity/MarketData.java
index bc4b3ae..661bebc 100644
--- a/src/main/java/com/blank038/servermarket/api/entity/MarketData.java
+++ b/src/main/java/com/blank038/servermarket/api/entity/MarketData.java
@@ -158,7 +158,7 @@ public void tryBuySale(Player buyer, String uuid, boolean shift, int page, Filte
                 if (shift) {
                     ServerMarket.getStorageHandler().removeSaleItem(this.sourceId, uuid)
                             .ifPresent((sale) -> {
-                                buyer.getInventory().addItem(sale.getSaleItem().clone());
+                                buyer.getInventory().addItem(sale.getSaleItem());
                                 buyer.sendMessage(I18n.getStrAndHeader("unsale"));
                                 new MarketGui(this.marketKey, page, filter).openGui(buyer);
                             });
diff --git a/src/main/java/com/blank038/servermarket/internal/cache/market/MarketCache.java b/src/main/java/com/blank038/servermarket/internal/cache/market/MarketCache.java
index 3502993..b85f25e 100644
--- a/src/main/java/com/blank038/servermarket/internal/cache/market/MarketCache.java
+++ b/src/main/java/com/blank038/servermarket/internal/cache/market/MarketCache.java
@@ -49,7 +49,7 @@ public Optional<SaleCache> removeSale(String saleId) {
     }
 
     public Map<String, SaleCache> getSales() {
-        return this.saleMap;
+        return new HashMap<>(this.saleMap);
     }
 
     public Map<String, SaleCache> getSaleByPlayer(UUID uuid) {
diff --git a/src/main/java/com/blank038/servermarket/internal/cache/player/PlayerCache.java b/src/main/java/com/blank038/servermarket/internal/cache/player/PlayerCache.java
index 9bdcdef..6873374 100644
--- a/src/main/java/com/blank038/servermarket/internal/cache/player/PlayerCache.java
+++ b/src/main/java/com/blank038/servermarket/internal/cache/player/PlayerCache.java
@@ -58,6 +58,10 @@ public ItemStack removeStoreItem(String uuid) {
         return storeItems.remove(uuid);
     }
 
+    public Map<String, ItemStack> getStoreItems() {
+        return new HashMap<>(storeItems);
+    }
+
     /**
      * 增加暂存物品至暂存箱
      *
diff --git a/src/main/java/com/blank038/servermarket/internal/cache/sale/SaleCache.java b/src/main/java/com/blank038/servermarket/internal/cache/sale/SaleCache.java
index 9ab3ef1..a7e2755 100644
--- a/src/main/java/com/blank038/servermarket/internal/cache/sale/SaleCache.java
+++ b/src/main/java/com/blank038/servermarket/internal/cache/sale/SaleCache.java
@@ -75,6 +75,10 @@ public void setSaleTypes(List<String> types) {
         this.saleTypes.addAll(types);
     }
 
+    public ItemStack getSaleItem() {
+        return saleItem.clone();
+    }
+
     public ConfigurationSection toSection() {
         ConfigurationSection section = new YamlConfiguration();
         section.set("owner-uuid", ownerUUID);
diff --git a/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java b/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java
index 698ddac..7f84474 100644
--- a/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java
+++ b/src/main/java/com/blank038/servermarket/internal/gui/impl/MarketGui.java
@@ -246,7 +246,7 @@ private void nextSort(Player clicker) {
      * @return 展示物品
      */
     private ItemStack getShowItem(MarketData marketData, SaleCache saleItem, FileConfiguration data) {
-        ItemStack itemStack = saleItem.getSaleItem().clone();
+        ItemStack itemStack = saleItem.getSaleItem();
         ItemMeta itemMeta = itemStack.getItemMeta();
         String displayName = itemMeta.hasDisplayName() ? itemMeta.getDisplayName() : itemStack.getType().name();
         if (data.contains("sale-name")) {
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index ca0ae50..cb30737 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -19,4 +19,6 @@ default-market: "example"
 command-help: true
 # 冷却设定, 单位: 秒
 cooldown:
-  action: 3
\ No newline at end of file
+  action: 3
+# 税收流向账户
+tax-account: "Blank038"
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index bef4ef5..bc71e2f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -16,4 +16,5 @@ commands:
     aliases:
       - market
       - sale
-    description: Command for ServerMarket.
\ No newline at end of file
+    description: Command for ServerMarket.
+folia-supported: true
\ No newline at end of file