diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 46d8155..b4c98a7 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.legendaryrealms.shop LegendaryDailyShop-Reset - 2.0.3-SNAPSHOT + 2.0.5-SNAPSHOT @@ -41,6 +41,10 @@ jitpack.io https://jitpack.io + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + rosewood-repo https://repo.rosewooddev.io/repository/public/ @@ -48,8 +52,14 @@ - com.destroystokyo.paper - paper-api + me.clip + placeholderapi + 2.10.6 + provided + + + org.spigotmc + spigot-api 1.16.5-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 85e28e2..1863eae 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.legendaryrealms.shop LegendaryDailyShop-Reset - 2.0.3-SNAPSHOT + 2.0.5-SNAPSHOT 8 @@ -26,6 +26,10 @@ jitpack.io https://jitpack.io + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + rosewood-repo https://repo.rosewooddev.io/repository/public/ @@ -33,8 +37,14 @@ - com.destroystokyo.paper - paper-api + me.clip + placeholderapi + 2.10.6 + provided + + + org.spigotmc + spigot-api 1.16.5-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/legendaryrealms/shop/API/ShopBuyEvent.java b/src/main/java/com/legendaryrealms/shop/API/ShopBuyEvent.java index 07ab6d9..82622f4 100644 --- a/src/main/java/com/legendaryrealms/shop/API/ShopBuyEvent.java +++ b/src/main/java/com/legendaryrealms/shop/API/ShopBuyEvent.java @@ -3,7 +3,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; + public class ShopBuyEvent extends Event { private Player player; @@ -35,8 +35,7 @@ public int getAmount() { return amount; } - @NotNull - public HandlerList getHandlers() { + public HandlerList getHandlers() { return HANDLERS; } diff --git a/src/main/java/com/legendaryrealms/shop/API/ShopSellEvent.java b/src/main/java/com/legendaryrealms/shop/API/ShopSellEvent.java index f58fd30..658b834 100644 --- a/src/main/java/com/legendaryrealms/shop/API/ShopSellEvent.java +++ b/src/main/java/com/legendaryrealms/shop/API/ShopSellEvent.java @@ -3,7 +3,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; + public class ShopSellEvent extends Event { private Player player; @@ -35,7 +35,7 @@ public int getAmount() { return amount; } - @NotNull + public HandlerList getHandlers() { return HANDLERS; } diff --git a/src/main/java/com/legendaryrealms/shop/Data/Database/YamlStore.java b/src/main/java/com/legendaryrealms/shop/Data/Database/YamlStore.java index 07ed4b0..f838ccf 100644 --- a/src/main/java/com/legendaryrealms/shop/Data/Database/YamlStore.java +++ b/src/main/java/com/legendaryrealms/shop/Data/Database/YamlStore.java @@ -23,12 +23,18 @@ public void saveData(PlayerData data) { { String shop=shopMap.getKey(); ShopData shopData=shopMap.getValue(); + + yml.set("data."+shop+".items",null); yml.set("data."+shop+".items",toStringList(shopData.getItems())); + yml.set("data."+shop+".roll",shopData.getRoll()); + + yml.set("data."+shop+".buy",null); for (Map.Entry uuid:shopData.getBuy().entrySet()){ yml.set("data."+shop+".buy."+uuid.getKey(),uuid.getValue()); } + yml.set("data."+shop+".price",null); for (Map.Entry uuid:shopData.getPrice().entrySet()){ yml.set("data."+shop+".price."+uuid.getKey(),uuid.getValue()); } diff --git a/src/main/java/com/legendaryrealms/shop/Data/Player/PlayerData.java b/src/main/java/com/legendaryrealms/shop/Data/Player/PlayerData.java index 87c02a9..8507401 100644 --- a/src/main/java/com/legendaryrealms/shop/Data/Player/PlayerData.java +++ b/src/main/java/com/legendaryrealms/shop/Data/Player/PlayerData.java @@ -8,8 +8,6 @@ import java.util.*; public class PlayerData { - - private static HashMap cache=new HashMap<>(); private Map data; private String p; private int date; @@ -20,7 +18,6 @@ public PlayerData(Map data, String p, int date, boolean tip) { this.p = p; this.date = date; this.tip = tip; - cache.put(p,this); } public Map getData() { @@ -61,39 +58,11 @@ public void setTip(boolean tip) { this.tip = tip; } - public static PlayerData getPlayerData(Player p) - { - if (cache.containsKey(p.getName())) - { - return cache.get(p.getName()); - } - PlayerData playerData=LegendaryDailyShop.getInstance().getDataProvider().loadData(p.getName()); - cache.put(p.getName(),playerData); - return playerData; - } - - public static void updata(PlayerData data) - { - cache.put(data.p,data); - } - public void setShop(String shopId,ShopData shopData) { data.put(shopId,shopData); } - public static void saveAllToLocal() - { - if (cache.isEmpty()) - { - return; - } - for (String player:cache.keySet()) - { - PlayerData data=LegendaryDailyShop.getInstance().getDataProvider().loadData(player); - LegendaryDailyShop.getInstance().getDataProvider().saveData(data); - } - } } diff --git a/src/main/java/com/legendaryrealms/shop/Events/JoinEvent.java b/src/main/java/com/legendaryrealms/shop/Events/JoinEvent.java index 42e79e3..22cff44 100644 --- a/src/main/java/com/legendaryrealms/shop/Events/JoinEvent.java +++ b/src/main/java/com/legendaryrealms/shop/Events/JoinEvent.java @@ -19,7 +19,7 @@ public void onJoin(PlayerJoinEvent e) Player p=e.getPlayer(); if (LegendaryDailyShop.getInstance().getDataProvider().isExist(p.getName())) { - PlayerData.getPlayerData(p); + LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); new RandomUtils().refreshCheckDate(p); return; } diff --git a/src/main/java/com/legendaryrealms/shop/Events/QuitEvent.java b/src/main/java/com/legendaryrealms/shop/Events/QuitEvent.java index ebb8b5d..2c7bd8b 100644 --- a/src/main/java/com/legendaryrealms/shop/Events/QuitEvent.java +++ b/src/main/java/com/legendaryrealms/shop/Events/QuitEvent.java @@ -12,7 +12,6 @@ public class QuitEvent implements Listener { public void onQuit(PlayerQuitEvent e) { Player p=e.getPlayer(); - PlayerData data=PlayerData.getPlayerData(p); - LegendaryDailyShop.getInstance().getDataProvider().saveData(data); + LegendaryDailyShop.getInstance().getPlayerDataManager().saveAndRemve(p.getName()); } } diff --git a/src/main/java/com/legendaryrealms/shop/LegendaryDailyShop.java b/src/main/java/com/legendaryrealms/shop/LegendaryDailyShop.java index 89f49f7..ab4a8a2 100644 --- a/src/main/java/com/legendaryrealms/shop/LegendaryDailyShop.java +++ b/src/main/java/com/legendaryrealms/shop/LegendaryDailyShop.java @@ -10,6 +10,7 @@ import com.legendaryrealms.shop.Manager.*; import com.legendaryrealms.shop.PluginCommand.PluginCommand; import com.legendaryrealms.shop.Utils.MsgUtils; +import com.legendaryrealms.shop.Utils.ShopPAPI; import net.milkbowl.vault.economy.Economy; import org.black_ixx.playerpoints.PlayerPoints; import org.bukkit.Bukkit; @@ -24,6 +25,7 @@ public class LegendaryDailyShop extends JavaPlugin { private ShopRarityManager shopRarityManager; private ShopManager shopManager; private MenusManager menusManager; + private PlayerDataManager playerDataManager; private Economy eco; private PlayerPoints pp; private static LegendaryDailyShop legendaryDailyShop; @@ -50,35 +52,21 @@ public void onEnable() { this.getPluginLoader().disablePlugin(this); } setDepend(); - - - if (configManager.Mysql) - { - dataProvider = new MysqlStore(); - Bukkit.getConsoleSender().sendMessage("[LegendaryDailyShop] 正在连接 Mysql 数据库."); - MysqlManager.setConnectPool(); - } - else { - dataProvider = new YamlStore(); - Bukkit.getConsoleSender().sendMessage("[LegendaryDailyShop] 正在使用 Yaml 存储方式."); - } - - - - + setStoreMethod(); + playerDataManager=new PlayerDataManager(); new ListenManager(); - Bukkit.getPluginCommand("LegendaryDailyShop").setExecutor(new PluginCommand()); Bukkit.getPluginCommand("LegendaryDailyShop").setTabCompleter(new PluginCommand()); PluginCommand.registerCommands(); - new BukkitRunnable() { @Override public void run() { - PlayerData.saveAllToLocal(); + playerDataManager.saveAll(); } }.runTaskTimerAsynchronously(this,20*configManager.auto_save,20*configManager.auto_save); + + } public void setDepend() @@ -89,9 +77,22 @@ public void setDepend() } + public void setStoreMethod(){ + if (configManager.Mysql) + { + dataProvider = new MysqlStore(); + Bukkit.getConsoleSender().sendMessage("[LegendaryDailyShop] 正在连接 Mysql 数据库."); + MysqlManager.setConnectPool(); + } + else { + dataProvider = new YamlStore(); + Bukkit.getConsoleSender().sendMessage("[LegendaryDailyShop] 正在使用 Yaml 存储方式."); + } + } + @Override public void onDisable() { - PlayerData.saveAllToLocal(); + playerDataManager.saveAll(); } public void reload() @@ -107,6 +108,10 @@ public void reload() menusManager=new MenusManager(); menusManager.reload(); + + if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){ + new ShopPAPI().register(); + } } public DataProvider getDataProvider() {return dataProvider;} @@ -116,6 +121,7 @@ public void reload() public MenusManager getMenusManager(){return menusManager;} public Economy getEco(){return eco;} public PlayerPoints getPlayerPointsAPI(){return pp;} + public PlayerDataManager getPlayerDataManager(){return playerDataManager;} public static LegendaryDailyShop getInstance() {return legendaryDailyShop;} public boolean BukkitVersionHigh() @@ -126,9 +132,4 @@ public boolean BukkitVersionHigh() return version >=13; } - public double getJavaVersion() - { - double version=Double.parseDouble(System.getProperty("java.specification.version")); - return version; - } } diff --git a/src/main/java/com/legendaryrealms/shop/Manager/ConfigManager.java b/src/main/java/com/legendaryrealms/shop/Manager/ConfigManager.java index c5ca057..b7e596e 100644 --- a/src/main/java/com/legendaryrealms/shop/Manager/ConfigManager.java +++ b/src/main/java/com/legendaryrealms/shop/Manager/ConfigManager.java @@ -41,7 +41,10 @@ public class ConfigManager { public int auto_save; public String noplayer; public String notonline; - + public int click_left_amount; + public int click_shift_left_amount; + public int click_right_amount; + public int click_shift_right_amount; public ConfigManager() { File file=new File("./plugins/LegendaryDailyShop","config.yml"); @@ -87,6 +90,10 @@ public void reload() noplayer = MsgUtils.msg(yml.getString("message.noplayer","&c该玩家不存在!")); notonline = MsgUtils.msg(yml.getString("message.notonline","&c该玩家不在你当前的区服或者不在线!")); + click_left_amount = yml.getInt("click_amount.left",1); + click_shift_left_amount = yml.getInt("click_amount.shift_left",32); + click_right_amount = yml.getInt("click_amount.right",16); + click_shift_right_amount = yml.getInt("click_amount.shift_right",-1); } diff --git a/src/main/java/com/legendaryrealms/shop/Manager/PlayerDataManager.java b/src/main/java/com/legendaryrealms/shop/Manager/PlayerDataManager.java new file mode 100644 index 0000000..136be5a --- /dev/null +++ b/src/main/java/com/legendaryrealms/shop/Manager/PlayerDataManager.java @@ -0,0 +1,40 @@ +package com.legendaryrealms.shop.Manager; + +import com.legendaryrealms.shop.Data.Player.PlayerData; +import com.legendaryrealms.shop.LegendaryDailyShop; + +import java.util.HashMap; +import java.util.Map; + +public class PlayerDataManager { + + private HashMap cache; + public PlayerDataManager(){ + cache=new HashMap<>(); + } + public PlayerData getData(String player){ + if (cache.containsKey(player)) { + return cache.get(player); + } + PlayerData data= LegendaryDailyShop.getInstance().getDataProvider().loadData(player); + cache.put(player,data); + return data; + } + + public void saveAndRemve(String player){ + if (cache.containsKey(player)){ + PlayerData data=cache.remove(player); + LegendaryDailyShop.getInstance().getDataProvider().saveData(data); + } + } + public void saveAll() + { + int a=0; + for (Map.Entry entry:cache.entrySet()){ + PlayerData data=entry.getValue(); + LegendaryDailyShop.getInstance().getDataProvider().saveData(data); + a++; + } + System.out.println("成功保存 "+a+" 个玩家数据"); + } +} diff --git a/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/DeleteMenu.java b/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/DeleteMenu.java index 7078559..1d79803 100644 --- a/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/DeleteMenu.java +++ b/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/DeleteMenu.java @@ -12,7 +12,7 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; + import java.awt.*; import java.util.ArrayList; @@ -114,7 +114,7 @@ public String getRarity() { } @Override - public @NotNull Inventory getInventory() { + public Inventory getInventory() { return inv; } public void dealEvent(InventoryClickEvent e) diff --git a/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/ShopMenu.java b/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/ShopMenu.java index af60373..ef2a689 100644 --- a/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/ShopMenu.java +++ b/src/main/java/com/legendaryrealms/shop/Menu/MenuUI/ShopMenu.java @@ -9,6 +9,7 @@ import com.legendaryrealms.shop.Shop.ProductType; import com.legendaryrealms.shop.Shop.Shop; import com.legendaryrealms.shop.Shop.ShopCurrency; +import com.legendaryrealms.shop.Shop.ShopRarity; import com.legendaryrealms.shop.Utils.ItemUtils; import com.legendaryrealms.shop.Utils.RandomUtils; import org.bukkit.Bukkit; @@ -18,7 +19,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; import java.text.DecimalFormat; import java.util.ArrayList; @@ -48,7 +48,7 @@ public ShopMenu(Player p, String shopId) { public void loadMenu() { - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); ShopData shopData=data.getShopData(shopId); for (String key:read.getKeys()) { @@ -75,19 +75,29 @@ public void loadMenu() for (UUID uuid : shopData.getItems()) { if (shop.getItems().get(uuid) == null) { - inv.setItem(read.getLayout().get(a),read.getUnknown()); - fuction.put(read.getLayout().get(a),"null"); - a++; - continue; + if (a < read.getLayout().size()) { + inv.setItem(read.getLayout().get(a), read.getUnknown()); + fuction.put(read.getLayout().get(a), "null"); + a++; + continue; + } } ItemStack i = shop.getItems().get(uuid).clone(); ItemMeta id=i.getItemMeta(); List oldlore=id.hasLore() ? id.getLore() : new ArrayList<>(); List format=new ArrayList<>(read.getLore_format()); ArrayList lore=new ArrayList(); + + String rarity=shop.getRarity().get(uuid); + String rarityDisplay="Unknown"; + if (rarity != null) { + ShopRarity shopRarity = LegendaryDailyShop.getInstance().getShopRarityManager().getRarity(rarity); + rarityDisplay=shopRarity.getDisplay(); + } + for (String l:format) { - l=l.replace("%price%",""+shopData.getPrice().get(uuid)); + l=l.replace("%price%",""+shopData.getPrice().get(uuid)).replace("%rarity%",rarityDisplay); switch (l) { case "%lore%": lore.addAll(oldlore); @@ -127,11 +137,12 @@ public void loadMenu() } } else { - for (int a=0;a 0) { int limit = shop.getLimitAmount(uuid); int buy=shopData.getBuyAmount(uuid); @@ -218,7 +233,7 @@ public void OnClick(InventoryClickEvent e) if (shop.getLimitAmount(uuid) > 0) { shopData.addBuyAmount(uuid, amount); data.setShop(shopId,shopData); - PlayerData.updata(data); + //LegendaryDailyShop.getInstance().getDataProvider().saveData(data); } Bukkit.getPluginManager().callEvent(new ShopBuyEvent(p,shopId,shop.getRarity().get(uuid),amount)); @@ -248,9 +263,10 @@ public void OnClick(InventoryClickEvent e) if (shop.getLimitAmount(uuid) > 0) { shopData.addBuyAmount(uuid, amount); data.setShop(shopId,shopData); - PlayerData.updata(data); + //LegendaryDailyShop.getInstance().getDataProvider().saveData(data); } + Bukkit.getPluginManager().callEvent(new ShopSellEvent(p,shopId,shop.getRarity().get(uuid),amount)); menu = new ShopMenu(p, shopId); menu.loadMenu(); @@ -294,7 +310,7 @@ public String getShopId() { } @Override - public @NotNull Inventory getInventory() { + public Inventory getInventory() { return inv; } } diff --git a/src/main/java/com/legendaryrealms/shop/PluginCommand/PluginCommand.java b/src/main/java/com/legendaryrealms/shop/PluginCommand/PluginCommand.java index 709ced7..165fa29 100644 --- a/src/main/java/com/legendaryrealms/shop/PluginCommand/PluginCommand.java +++ b/src/main/java/com/legendaryrealms/shop/PluginCommand/PluginCommand.java @@ -10,8 +10,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -32,7 +30,7 @@ public static void registerCommands() } @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { + public boolean onCommand( CommandSender sender, Command command, String s, String[] args) { if (args.length==0) { @@ -61,7 +59,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } @Override - public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { + public List onTabComplete( CommandSender commandSender, Command command, String s, String[] args) { List list=new ArrayList<>(); if (args.length==1) diff --git a/src/main/java/com/legendaryrealms/shop/PluginCommand/SubCommands/PointsCommand.java b/src/main/java/com/legendaryrealms/shop/PluginCommand/SubCommands/PointsCommand.java index 4482f73..c6f8a30 100644 --- a/src/main/java/com/legendaryrealms/shop/PluginCommand/SubCommands/PointsCommand.java +++ b/src/main/java/com/legendaryrealms/shop/PluginCommand/SubCommands/PointsCommand.java @@ -44,11 +44,11 @@ public void reslove(CommandSender sender, String[] args) { } int a=Integer.parseInt(args[3]); Player p=Bukkit.getPlayer(player); - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); ShopData shopData=data.getShopData(shop)!=null ? data.getShopData(shop) : new ShopData(shop,new ArrayList<>(),new HashMap<>(),new HashMap<>(),0); shopData.setRoll(shopData.getRoll()+a); data.setShop(shop,shopData); - PlayerData.updata(data); + String display=LegendaryDailyShop.getInstance().getShopManager().getShop(shop).getDisplay(); p.sendMessage(LegendaryDailyShop.getInstance().getConfigManager().plugin+LegendaryDailyShop.getInstance().getConfigManager().points_recive.replace("%amount%",""+a).replace("%shop%",display)); sender.sendMessage(LegendaryDailyShop.getInstance().getConfigManager().plugin+LegendaryDailyShop.getInstance().getConfigManager().points_give.replace("%player%",player).replace("%amount%",""+a).replace("%shop%",display)); diff --git a/src/main/java/com/legendaryrealms/shop/Shop/Shop.java b/src/main/java/com/legendaryrealms/shop/Shop/Shop.java index 6b166dd..5d87884 100644 --- a/src/main/java/com/legendaryrealms/shop/Shop/Shop.java +++ b/src/main/java/com/legendaryrealms/shop/Shop/Shop.java @@ -137,7 +137,7 @@ public int getLimitAmount(UUID uuid) public boolean canBuy(UUID uuid,Player p,int amount) { - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); ShopData shopData=data.getShopData(id); if (shopData == null) { @@ -175,7 +175,7 @@ public boolean canBuy(UUID uuid,Player p,int amount) public void dealPrice(UUID uuid,Player p,int amount) { - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); ShopData shopData=data.getShopData(id); if (shopData == null) { diff --git a/src/main/java/com/legendaryrealms/shop/Utils/RandomUtils.java b/src/main/java/com/legendaryrealms/shop/Utils/RandomUtils.java index 07ee0ce..27d4515 100644 --- a/src/main/java/com/legendaryrealms/shop/Utils/RandomUtils.java +++ b/src/main/java/com/legendaryrealms/shop/Utils/RandomUtils.java @@ -14,7 +14,7 @@ public class RandomUtils { public void refreshCheckDate(Player p) { - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); Calendar calendar=Calendar.getInstance(); if (data.getDate() != calendar.get(Calendar.DATE)) { data.setDate(calendar.get(Calendar.DATE)); @@ -38,13 +38,13 @@ public void randomAll(Player p) } public void random(Player p,String shopId) { - PlayerData data=PlayerData.getPlayerData(p); + PlayerData data=LegendaryDailyShop.getInstance().getPlayerDataManager().getData(p.getName()); ShopData shopData=data.getShopData(shopId) != null ? data.getShopData(shopId) : new ShopData(shopId,new ArrayList<>(),new HashMap<>(),new HashMap<>(),0); List uuids=RandomUUIDs(shopId); shopData.setItems(uuids); shopData.setPrice(RandomPrice(shopId,uuids)); + shopData.setBuy(new HashMap<>()); data.setShop(shopId,shopData); - LegendaryDailyShop.getInstance().getDataProvider().saveData(data); } private Map RandomPrice(String shopId,List uuids) @@ -52,11 +52,12 @@ private Map RandomPrice(String shopId,List uuids) Shop shop=LegendaryDailyShop.getInstance().getShopManager().getShop(shopId); Map map=new HashMap<>(); uuids.forEach(uuid -> { + double min=(shop.getMin_price().get(uuid) !=null ? shop.getMin_price().get(uuid) : 0.0 ) * 100; double max=(shop.getMax_price().get(uuid) !=null ? shop.getMax_price().get(uuid) : 50.0 ) * 100; if (max == min) { - map.put(uuid,min); + map.put(uuid,min/100); } else { double next=(new Random()).nextInt((int) (max-min)) + min; diff --git a/src/main/java/com/legendaryrealms/shop/Utils/ShopPAPI.java b/src/main/java/com/legendaryrealms/shop/Utils/ShopPAPI.java new file mode 100644 index 0000000..fe80735 --- /dev/null +++ b/src/main/java/com/legendaryrealms/shop/Utils/ShopPAPI.java @@ -0,0 +1,53 @@ +package com.legendaryrealms.shop.Utils; + +import com.legendaryrealms.shop.Data.Player.PlayerData; +import com.legendaryrealms.shop.Data.Player.ShopData; +import com.legendaryrealms.shop.LegendaryDailyShop; +import com.legendaryrealms.shop.Shop.Shop; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class ShopPAPI extends PlaceholderExpansion { + public String getIdentifier() { + return "LegendaryDailyShop"; + } + + public String getAuthor() { + return "Gyzer"; + } + + public String getVersion() { + return "2.0.5"; + } + + @Override + public String onRequest(OfflinePlayer player, String params) { + if (params.contains("amount_")) { + String[] args = params.split("_"); + if (args.length == 3) { + String shopId = args[1]; + String rarity = args[2]; + PlayerData data = LegendaryDailyShop.getInstance().getPlayerDataManager().getData(player.getName()); + ShopData shopData = data.getShopData(shopId); + if (shopData != null) { + int a = 0; + Shop shop = LegendaryDailyShop.getInstance().getShopManager().getShop(shopId); + Map rarities = shop.getRarity(); + for (UUID uuid : shopData.getItems()) { + String itemRarity = rarities.containsKey(uuid) ? rarities.get(uuid) : "无"; + if (itemRarity.equals(rarity)) { + a++; + } + } + return a + ""; + } + } + } + return "0"; + } +} diff --git a/src/main/resources/Menus/ShopMenu.yml b/src/main/resources/Menus/ShopMenu.yml index 8cc2343..d6d0394 100644 --- a/src/main/resources/Menus/ShopMenu.yml +++ b/src/main/resources/Menus/ShopMenu.yml @@ -16,6 +16,7 @@ empty: - '&f你的运气似乎不是很好...' #商品的lore模板 %lore%为商品的原lore & The lore template% lore% of the product is the original lore of the product items_lore: + - '&7商品品质: &e%rarity%' - '%lore%' - '' - '%placeholder_sellOrBuy%' diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b2e5eba..99c3d55 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -35,6 +35,12 @@ settings: #直到不超过下面设定值的轮数中的某轮第五个商品被随机到商品后结束 #或者到了设定值的轮数仍未有商品则该商品为空 times: 20 +#设置不同点击出售/收购的数量 -1为所有 +click_amount: + left: 1 + shift_left: 16 + right: 32 + shift_right: -1 message: plugin: '&7[&3&lLegendary&b&lDailyShop&7] ' command_player: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fe73887..e93d45b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,8 @@ name: LegendaryDailyShop main: com.legendaryrealms.shop.LegendaryDailyShop -version: 2.0.2 +version: 2.0.5 +softdepend: + - PlaceholderAPI depend: - Vault - PlayerPoints