Skip to content

Commit

Permalink
fix: Fix potential issues with the SaleCache
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Mar 24, 2024
1 parent 1d5156f commit 1005e71
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public ItemStack removeStoreItem(String uuid) {
return storeItems.remove(uuid);
}

public Map<String, ItemStack> getStoreItems() {
return new HashMap<>(storeItems);
}

/**
* 增加暂存物品至暂存箱
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ default-market: "example"
command-help: true
# 冷却设定, 单位: 秒
cooldown:
action: 3
action: 3
# 税收流向账户
tax-account: "Blank038"
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ commands:
aliases:
- market
- sale
description: Command for ServerMarket.
description: Command for ServerMarket.
folia-supported: true

0 comments on commit 1005e71

Please sign in to comment.