Skip to content

Commit

Permalink
refactor: Complete restructuring of the entire project
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Dec 6, 2023
1 parent 9318c20 commit 339b8df
Show file tree
Hide file tree
Showing 42 changed files with 231 additions and 219 deletions.
33 changes: 21 additions & 12 deletions src/main/java/com/blank038/servermarket/api/ServerMarketApi.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package com.blank038.servermarket.api;

import com.blank038.servermarket.ServerMarket;
import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.data.cache.market.MarketData;
import com.blank038.servermarket.data.cache.other.OfflineTransactionData;
import com.blank038.servermarket.enums.PayType;
import com.blank038.servermarket.filter.FilterBuilder;
import com.blank038.servermarket.gui.impl.MarketGui;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import com.blank038.servermarket.internal.data.DataContainer;
import com.blank038.servermarket.api.entity.MarketData;
import com.blank038.servermarket.internal.cache.other.OfflineTransactionData;
import com.blank038.servermarket.internal.enums.PayType;
import com.blank038.servermarket.api.handler.filter.FilterHandler;
import com.blank038.servermarket.internal.gui.impl.MarketGui;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author Blank038
* @date 2021/03/05
*/
public class ServerMarketApi {
private final ServerMarket plugin = ServerMarket.getInstance();

public MarketData fuzzySearchMarketData(String key) {
public static List<String> getMarketList() {
return new ArrayList<>(DataContainer.MARKET_DATA.keySet());
}

public static MarketData getMarketData(String marketKey) {
return DataContainer.MARKET_DATA.getOrDefault(marketKey, null);
}

public static MarketData fuzzySearchMarketData(String key) {
for (Map.Entry<String, MarketData> entry : DataContainer.MARKET_DATA.entrySet()) {
if (entry.getKey().equals(key) || entry.getValue().getDisplayName().contains(key)) {
return entry.getValue();
Expand All @@ -35,9 +44,9 @@ public MarketData fuzzySearchMarketData(String key) {
* @param player 目标玩家
* @param key 目标市场编号
*/
public void openMarket(Player player, String key, int page, FilterBuilder filter) {
public static void openMarket(Player player, String key, int page, FilterHandler filter) {
MarketData marketData = DataContainer.MARKET_DATA.containsKey(key) ? DataContainer.MARKET_DATA.get(key)
: DataContainer.MARKET_DATA.get(plugin.getConfig().getString("default-market"));
: DataContainer.MARKET_DATA.get(ServerMarket.getInstance().getConfig().getString("default-market"));
if (marketData == null) {
return;
}
Expand All @@ -46,7 +55,7 @@ public void openMarket(Player player, String key, int page, FilterBuilder filter
}
}

public void addOfflineTransaction(String uuid, PayType payType, String ectType, double moeny, String sourceMarket) {
public static void addOfflineTransaction(String uuid, PayType payType, String ectType, double moeny, String sourceMarket) {
ConfigurationSection section = new YamlConfiguration();
section.set("amount", moeny);
section.set("pay-type", payType.name());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.blank038.servermarket.data.cache.market;
package com.blank038.servermarket.api.entity;

import com.blank038.servermarket.ServerMarket;
import com.blank038.servermarket.api.ServerMarketApi;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import com.blank038.servermarket.api.event.MarketLoadEvent;
import com.blank038.servermarket.api.event.PlayerSaleEvent;
import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.economy.BaseEconomy;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.enums.MarketStatus;
import com.blank038.servermarket.enums.PayType;
import com.blank038.servermarket.filter.FilterBuilder;
import com.blank038.servermarket.filter.impl.KeyFilterImpl;
import com.blank038.servermarket.filter.interfaces.IFilter;
import com.blank038.servermarket.gui.impl.MarketGui;
import com.blank038.servermarket.i18n.I18n;
import com.blank038.servermarket.util.TextUtil;
import com.blank038.servermarket.internal.data.DataContainer;
import com.blank038.servermarket.internal.economy.BaseEconomy;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import com.blank038.servermarket.internal.enums.MarketStatus;
import com.blank038.servermarket.internal.enums.PayType;
import com.blank038.servermarket.api.handler.filter.FilterHandler;
import com.blank038.servermarket.api.handler.filter.impl.KeyFilterImpl;
import com.blank038.servermarket.api.handler.filter.interfaces.IFilter;
import com.blank038.servermarket.internal.gui.impl.MarketGui;
import com.blank038.servermarket.internal.i18n.I18n;
import com.blank038.servermarket.internal.util.TextUtil;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -151,7 +152,7 @@ public void setDateFormat(String format) {
this.dateFormat = format;
}

public void tryBuySale(Player buyer, String uuid, boolean shift, int page, FilterBuilder filter) {
public void tryBuySale(Player buyer, String uuid, boolean shift, int page, FilterHandler filter) {
// 判断商品是否存在
if (!ServerMarket.getStorageHandler().hasSale(this.sourceId, uuid)) {
buyer.sendMessage(I18n.getStrAndHeader("error-sale"));
Expand Down Expand Up @@ -197,7 +198,7 @@ public void tryBuySale(Player buyer, String uuid, boolean shift, int page, Filte
.replace("%money%", df.format(saleItem.getPrice()))
.replace("%last%", df.format(last)));
} else {
ServerMarket.getApi().addOfflineTransaction(saleItem.getOwnerUUID(), this.paytype, this.ecoType, saleItem.getPrice(), this.marketKey);
ServerMarketApi.addOfflineTransaction(saleItem.getOwnerUUID(), this.paytype, this.ecoType, saleItem.getPrice(), this.marketKey);
}
// 给予购买者物品
ServerMarket.getStorageHandler().addItemToStore(buyer.getUniqueId(), saleItem, "buy");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blank038.servermarket.api.event;

import com.blank038.servermarket.data.handler.IStorageHandler;
import com.blank038.servermarket.dto.IStorageHandler;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.event.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blank038.servermarket.api.event;

import com.blank038.servermarket.data.cache.market.MarketData;
import com.blank038.servermarket.api.entity.MarketData;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blank038.servermarket.api.event;

import com.blank038.servermarket.data.cache.market.MarketData;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.api.entity.MarketData;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.blank038.servermarket.filter;
package com.blank038.servermarket.api.handler.filter;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.filter.impl.TypeFilterImpl;
import com.blank038.servermarket.filter.interfaces.IFilter;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import com.blank038.servermarket.api.handler.filter.impl.TypeFilterImpl;
import com.blank038.servermarket.api.handler.filter.interfaces.IFilter;
import lombok.Getter;
import org.bukkit.inventory.ItemStack;

Expand All @@ -13,16 +13,16 @@
* @author Blank038
*/
@Getter
public class FilterBuilder {
public class FilterHandler {
private final List<IFilter> saleFilters = new ArrayList<>();
private TypeFilterImpl typeFilter;

public FilterBuilder addKeyFilter(IFilter saleFilter) {
public FilterHandler addKeyFilter(IFilter saleFilter) {
this.saleFilters.add(saleFilter);
return this;
}

public FilterBuilder setTypeFilter(TypeFilterImpl typeFilter) {
public FilterHandler setTypeFilter(TypeFilterImpl typeFilter) {
this.typeFilter = typeFilter;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blank038.servermarket.filter.impl;
package com.blank038.servermarket.api.handler.filter.impl;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.filter.interfaces.IFilter;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import com.blank038.servermarket.api.handler.filter.interfaces.IFilter;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blank038.servermarket.filter.impl;
package com.blank038.servermarket.api.handler.filter.impl;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.filter.interfaces.IFilter;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import com.blank038.servermarket.api.handler.filter.interfaces.IFilter;
import lombok.Getter;
import org.bukkit.inventory.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blank038.servermarket.filter.interfaces;
package com.blank038.servermarket.api.handler.filter.interfaces;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import org.bukkit.inventory.ItemStack;

public interface IFilter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.blank038.servermarket.data.handler;
package com.blank038.servermarket.dto;

import com.blank038.servermarket.ServerMarket;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import com.blank038.servermarket.api.event.InitializeStorageHandlerEvent;
import com.blank038.servermarket.data.cache.player.PlayerCache;
import com.blank038.servermarket.data.handler.impl.MysqlStorageHandlerImpl;
import com.blank038.servermarket.data.handler.impl.YamlStorageHandlerImpl;
import com.blank038.servermarket.internal.cache.player.PlayerCache;
import com.blank038.servermarket.dto.impl.MysqlStorageHandlerImpl;
import com.blank038.servermarket.dto.impl.YamlStorageHandlerImpl;
import org.bukkit.Bukkit;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.blank038.servermarket.data.handler;
package com.blank038.servermarket.dto;

import com.blank038.servermarket.data.cache.other.OfflineTransactionData;
import com.blank038.servermarket.data.cache.other.SaleLog;
import com.blank038.servermarket.data.cache.player.PlayerCache;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.internal.cache.other.OfflineTransactionData;
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.inventory.ItemStack;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.blank038.servermarket.data.handler.impl;
package com.blank038.servermarket.dto.impl;

import com.aystudio.core.bukkit.thread.BlankThread;
import com.aystudio.core.bukkit.thread.ThreadProcessor;
import com.aystudio.core.bukkit.util.mysql.MySqlStorageHandler;
import com.blank038.servermarket.ServerMarket;
import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.data.cache.other.OfflineTransactionData;
import com.blank038.servermarket.data.cache.other.SaleLog;
import com.blank038.servermarket.data.cache.player.PlayerCache;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.data.handler.AbstractStorageHandler;
import com.blank038.servermarket.enums.PayType;
import com.blank038.servermarket.i18n.I18n;
import com.blank038.servermarket.dto.AbstractStorageHandler;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import com.blank038.servermarket.internal.data.DataContainer;
import com.blank038.servermarket.internal.cache.other.OfflineTransactionData;
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 com.blank038.servermarket.internal.enums.PayType;
import com.blank038.servermarket.internal.i18n.I18n;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.blank038.servermarket.data.handler.impl;

import com.blank038.servermarket.ServerMarket;
import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.data.cache.market.MarketData;
import com.blank038.servermarket.data.cache.market.MarketStorageData;
import com.blank038.servermarket.data.cache.other.OfflineTransactionData;
import com.blank038.servermarket.data.cache.other.SaleLog;
import com.blank038.servermarket.data.cache.player.PlayerCache;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.data.handler.AbstractStorageHandler;
package com.blank038.servermarket.dto.impl;

import com.blank038.servermarket.dto.AbstractStorageHandler;
import com.blank038.servermarket.internal.plugin.ServerMarket;
import com.blank038.servermarket.internal.data.DataContainer;
import com.blank038.servermarket.api.entity.MarketData;
import com.blank038.servermarket.internal.cache.market.MarketCache;
import com.blank038.servermarket.internal.cache.other.OfflineTransactionData;
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;
Expand All @@ -28,7 +28,7 @@
*/
public class YamlStorageHandlerImpl extends AbstractStorageHandler {
private static final Map<String, OfflineTransactionData> RESULT_DATA = new HashMap<>();
private static final Map<String, MarketStorageData> MARKET_STORAGE_DATA_MAP = new HashMap<>();
private static final Map<String, MarketCache> MARKET_STORAGE_DATA_MAP = new HashMap<>();
private static final Map<String, ConfigurationSection> LOG_SECTION_MAP = new HashMap<>();

/*
Expand Down Expand Up @@ -110,14 +110,14 @@ public void load(String market) {
if (MARKET_STORAGE_DATA_MAP.containsKey(market)) {
this.save(market, MARKET_STORAGE_DATA_MAP.get(market).getSales());
}
MarketStorageData marketStorageData = new MarketStorageData(market);
MarketCache marketCache = new MarketCache(market);
File file = new File(ServerMarket.getInstance().getDataFolder() + "/saleData/", market + ".yml");
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
for (String key : data.getKeys(false)) {
SaleCache saleItem = new SaleCache(market, data.getConfigurationSection(key));
marketStorageData.addSale(saleItem.getSaleUUID(), saleItem);
marketCache.addSale(saleItem.getSaleUUID(), saleItem);
}
MARKET_STORAGE_DATA_MAP.put(market, marketStorageData);
MARKET_STORAGE_DATA_MAP.put(market, marketCache);
}

@Override
Expand Down Expand Up @@ -147,8 +147,8 @@ public Optional<SaleCache> getSaleItem(String market, String saleId) {
@Override
public Map<String, SaleCache> getSaleItemsByMarket(String market) {
if (!MARKET_STORAGE_DATA_MAP.containsKey(market)) {
MarketStorageData marketStorageData = new MarketStorageData(market);
MARKET_STORAGE_DATA_MAP.put(market, marketStorageData);
MarketCache marketCache = new MarketCache(market);
MARKET_STORAGE_DATA_MAP.put(market, marketCache);
}
return MARKET_STORAGE_DATA_MAP.get(market).getSales();
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public void removeTimeOutItem() {
@Override
public void saveAll() {
this.saveAllPlayerData();
for (Map.Entry<String, MarketStorageData> entry : MARKET_STORAGE_DATA_MAP.entrySet()) {
for (Map.Entry<String, MarketCache> entry : MARKET_STORAGE_DATA_MAP.entrySet()) {
this.save(entry.getKey(), entry.getValue().getSales());
}
this.saveResults();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blank038.servermarket.data.cache.market;
package com.blank038.servermarket.internal.cache.market;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.internal.cache.sale.SaleCache;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -13,11 +13,11 @@
*
* @author Blank038
*/
public class MarketStorageData {
public class MarketCache {
private final String market;
private final Map<String, SaleCache> saleMap = new HashMap<>();

public MarketStorageData(String market) {
public MarketCache(String market) {
this.market = market;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blank038.servermarket.data.cache.other;
package com.blank038.servermarket.internal.cache.other;

import com.blank038.servermarket.enums.PayType;
import com.blank038.servermarket.internal.enums.PayType;
import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blank038.servermarket.data.cache.other;
package com.blank038.servermarket.internal.cache.other;

import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.enums.LogType;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import com.blank038.servermarket.internal.enums.LogType;
import lombok.Builder;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blank038.servermarket.data.cache.player;
package com.blank038.servermarket.internal.cache.player;

import com.blank038.servermarket.api.event.PlayerStoreItemAddEvent;
import com.blank038.servermarket.data.cache.sale.SaleCache;
import com.blank038.servermarket.internal.cache.sale.SaleCache;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
Expand Down
Loading

0 comments on commit 339b8df

Please sign in to comment.