Skip to content

Commit

Permalink
v2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyzerc committed Oct 3, 2023
1 parent 3532857 commit e7f9cd4
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 112 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.legendaryrealms.shop</groupId>
<artifactId>LegendaryDailyShop-Reset</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.5-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -41,15 +41,25 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand Down
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.legendaryrealms.shop</groupId>
<artifactId>LegendaryDailyShop-Reset</artifactId>
<version>2.0.3-SNAPSHOT</version>
<version>2.0.5-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand All @@ -26,15 +26,25 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/legendaryrealms/shop/API/ShopBuyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,8 +35,7 @@ public int getAmount() {
return amount;
}

@NotNull
public HandlerList getHandlers() {
public HandlerList getHandlers() {
return HANDLERS;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/legendaryrealms/shop/API/ShopSellEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +35,7 @@ public int getAmount() {
return amount;
}

@NotNull

public HandlerList getHandlers() {
return HANDLERS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, Integer> uuid:shopData.getBuy().entrySet()){
yml.set("data."+shop+".buy."+uuid.getKey(),uuid.getValue());

}
yml.set("data."+shop+".price",null);
for (Map.Entry<UUID, Double> uuid:shopData.getPrice().entrySet()){
yml.set("data."+shop+".price."+uuid.getKey(),uuid.getValue());
}
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/com/legendaryrealms/shop/Data/Player/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.*;

public class PlayerData {

private static HashMap<String,PlayerData> cache=new HashMap<>();
private Map<String, ShopData> data;
private String p;
private int date;
Expand All @@ -20,7 +18,6 @@ public PlayerData(Map<String, ShopData> data, String p, int date, boolean tip) {
this.p = p;
this.date = date;
this.tip = tip;
cache.put(p,this);
}

public Map<String, ShopData> getData() {
Expand Down Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/legendaryrealms/shop/Events/QuitEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
51 changes: 26 additions & 25 deletions src/main/java/com/legendaryrealms/shop/LegendaryDailyShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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;}
Expand All @@ -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()
Expand All @@ -126,9 +132,4 @@ public boolean BukkitVersionHigh()
return version >=13;
}

public double getJavaVersion()
{
double version=Double.parseDouble(System.getProperty("java.specification.version"));
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, PlayerData> 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<String,PlayerData> entry:cache.entrySet()){
PlayerData data=entry.getValue();
LegendaryDailyShop.getInstance().getDataProvider().saveData(data);
a++;
}
System.out.println("成功保存 "+a+" 个玩家数据");
}
}
Loading

0 comments on commit e7f9cd4

Please sign in to comment.