Skip to content

Commit

Permalink
fix(:ambulance:): Fixed duplicate item acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Apr 6, 2024
1 parent 321d9be commit c2d7f13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import org.bukkit.Bukkit;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* @author Blank038
*/
public abstract class AbstractStorageHandler implements IStorageHandler {
protected static final HashMap<UUID, PlayerCache> PLAYER_DATA_MAP = new HashMap<>();
protected static final Map<UUID, PlayerCache> PLAYER_DATA_MAP = new HashMap<>();

protected final ServerMarket pluign = ServerMarket.getInstance();

Expand Down Expand Up @@ -55,4 +56,8 @@ public void setLock(UUID uuid, boolean locked) {
public boolean isLocked(UUID uuid) {
return false;
}

public void removePlyerData(UUID uuid) {
PLAYER_DATA_MAP.entrySet().removeIf(entry -> entry.getKey().equals(uuid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,9 @@ public void save(String market, Map<String, SaleCache> map) {
@Override
public void removeTimeOutItem() {
DataContainer.MARKET_DATA.forEach((k, v) -> {
Iterator<Map.Entry<String, SaleCache>> iterator = this.getSaleItemsByMarket(k).entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, SaleCache> entry = iterator.next();
for (Map.Entry<String, SaleCache> entry : this.getSaleItemsByMarket(k).entrySet()) {
int second = (int) ((System.currentTimeMillis() - entry.getValue().getPostTime()) / 1000L);
if (second >= v.getEffectiveTime()) {
iterator.remove();
UUID uuid = UUID.fromString(entry.getValue().getOwnerUUID());
ServerMarket.getStorageHandler().removeSaleItem(k, entry.getKey()).ifPresent((sale) -> {
ServerMarket.getStorageHandler().addItemToStore(uuid, sale.getSaleItem(), "timeout");
Expand Down Expand Up @@ -302,7 +299,7 @@ public void savePlayerData(PlayerCache playerCache, boolean removeCache) {
}, "UPDATE " + playersTable + " SET data = ? WHERE player_uuid = ?;");
}
if (removeCache) {
PLAYER_DATA_MAP.remove(playerCache.getOwnerUniqueId());
this.removePlyerData(playerCache.getOwnerUniqueId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.blank038.servermarket.internal.cache.other.SaleLog;
import com.blank038.servermarket.internal.cache.player.PlayerCache;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -32,10 +31,6 @@ public class YamlStorageHandlerImpl extends AbstractStorageHandler {
private static final Map<String, MarketCache> MARKET_STORAGE_DATA_MAP = new HashMap<>();
private static final Map<String, ConfigurationSection> LOG_SECTION_MAP = new HashMap<>();

/*
* self methods
*/


private void saveResults() {
File resultFile = new File(this.pluign.getDataFolder(), "results.yml");
Expand All @@ -50,8 +45,7 @@ private void saveResults() {
}
}


/*
/**
* AbstractStorageHandler methods
*/
private void saveLogs() {
Expand Down Expand Up @@ -210,13 +204,9 @@ public void removeTimeOutItem() {
if (marketConfigData == null) {
return;
}
// 开始计算
Iterator<Map.Entry<String, SaleCache>> iterator = v.getSales().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, SaleCache> entry = iterator.next();
for (Map.Entry<String, SaleCache> entry : v.getSales().entrySet()) {
int second = (int) ((System.currentTimeMillis() - entry.getValue().getPostTime()) / 1000L);
if (second >= marketConfigData.getEffectiveTime()) {
iterator.remove();
if (second >= marketConfigData.getEffectiveTime() && this.removeSaleItem(k, entry.getValue().getSaleUUID()).isPresent()) {
UUID uuid = UUID.fromString(entry.getValue().getOwnerUUID());
ServerMarket.getStorageHandler().addItemToStore(uuid, entry.getValue().getSaleItem(), "timeout");
}
Expand All @@ -227,9 +217,7 @@ public void removeTimeOutItem() {
@Override
public void saveAll() {
this.saveAllPlayerData();
for (Map.Entry<String, MarketCache> entry : MARKET_STORAGE_DATA_MAP.entrySet()) {
this.save(entry.getKey(), entry.getValue().getSales());
}
MARKET_STORAGE_DATA_MAP.forEach((k, v) -> this.save(k, v.getSales()));
this.saveResults();
}

Expand All @@ -248,7 +236,7 @@ public void savePlayerData(PlayerCache playerCache, boolean removeCache) {
ServerMarket.getInstance().getLogger().log(Level.WARNING, e, () -> "cannot save player data: " + playerCache.getOwnerUniqueId().toString());
}
if (removeCache) {
PLAYER_DATA_MAP.remove(playerCache.getOwnerUniqueId());
this.removePlyerData(playerCache.getOwnerUniqueId());
}
}

Expand Down

0 comments on commit c2d7f13

Please sign in to comment.