测试版

This commit is contained in:
yaohunya 2024-07-21 02:16:29 +08:00
parent 8dd09ff170
commit ec716658d5
2 changed files with 78 additions and 11 deletions

View File

@ -15,13 +15,68 @@ public class PlayerData {
private Player player; private Player player;
private UUID uuid; private UUID uuid;
private int level; private int level;
private int exp; private BigInteger exp;
private BigInteger totalExp; private BigInteger totalExp;
private File file; private File file;
private FileConfiguration fileConfiguration; private FileConfiguration fileConfiguration;
public PlayerData(Player player){ public PlayerData(Player player){
this.player = player;
this.uuid = player.getUniqueId();
createPlayerData(); // 若没有这个玩家的数据则会创建一个默认文件
this.level = fileConfiguration.getInt("level");
String expString = fileConfiguration.getString("exp");
this.exp = new BigInteger(expString);
String totalExpString = fileConfiguration.getString("totalExp");
this.totalExp = new BigInteger(totalExpString);
}
public Player getPlayer() {
return player;
}
public UUID getUuid() {
return uuid;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public BigInteger getExp() {
return exp;
}
public void setExp(BigInteger exp) {
this.exp = exp;
}
public BigInteger getTotalExp() {
return totalExp;
}
public void setTotalExp(BigInteger totalExp) {
this.totalExp = totalExp;
}
public void savePlayerData(){
FileConfiguration yml = this.fileConfiguration;
yml.set("level",this.level);
yml.set("exp",this.exp.toString());
yml.set("totalExp",this.totalExp.toString());
saveFile();
}
public void saveFile(){
try {
this.fileConfiguration.save(this.file);
} catch (IOException e) {
e.printStackTrace();
}
} }
public void createPlayerData(){ public void createPlayerData(){
@ -39,19 +94,16 @@ public class PlayerData {
yml.set("name",player.getName()); yml.set("name",player.getName());
yml.set("uuid",player.getUniqueId().toString()); yml.set("uuid",player.getUniqueId().toString());
yml.set("level",1); yml.set("level",1);
yml.set("exp",0);
yml.set("totalExp",1); yml.set("totalExp",1);
this.file = file; this.file = file;
this.fileConfiguration = yml; this.fileConfiguration = yml;
saveFile(); saveFile();
System.out.println("[日志 - 等级] 玩家 "+player.getName()+" 已创建档案数据."); System.out.println("[日志 - 等级] 玩家 "+player.getName()+" 已创建档案数据.");
} }else{
} FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
this.file = file;
public void saveFile(){ this.fileConfiguration = yml;
try {
this.fileConfiguration.save(this.file);
} catch (IOException e) {
e.printStackTrace();
} }
} }
} }

View File

@ -1,13 +1,17 @@
package me.Demon.DemonLevels.manage; package me.Demon.DemonLevels.manage;
import me.Demon.DemonLevels.data.PlayerData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class ServerManage { public class ServerManage {
private HashMap<Player,PlayerData> dataHashMap = new HashMap<>();
private double expMultiplicity; // 当前经验倍率 private double expMultiplicity; // 当前经验倍率
private boolean LinkDemonVipSystem = false; // 是否已关联 贵族系统
private boolean LinkDemonVipSystem = false;
public ServerManage(FileConfiguration yml){ public ServerManage(FileConfiguration yml){
expMultiplicity = yml.getDouble("DoubleExp",1.0); expMultiplicity = yml.getDouble("DoubleExp",1.0);
@ -23,4 +27,15 @@ public class ServerManage {
public boolean isLinkDemonVipSystem() { public boolean isLinkDemonVipSystem() {
return LinkDemonVipSystem; return LinkDemonVipSystem;
} }
public PlayerData getPlayerData(Player player){
if(dataHashMap.get(player) == null){
dataHashMap.put(player,new PlayerData(player));
}
return dataHashMap.get(player);
}
public HashMap<Player, PlayerData> getDataHashMap() {
return dataHashMap;
}
} }