测试版
This commit is contained in:
parent
8dd09ff170
commit
ec716658d5
|
@ -15,13 +15,68 @@ public class PlayerData {
|
|||
private Player player;
|
||||
private UUID uuid;
|
||||
private int level;
|
||||
private int exp;
|
||||
private BigInteger exp;
|
||||
private BigInteger totalExp;
|
||||
private File file;
|
||||
private FileConfiguration fileConfiguration;
|
||||
|
||||
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(){
|
||||
|
@ -39,19 +94,16 @@ public class PlayerData {
|
|||
yml.set("name",player.getName());
|
||||
yml.set("uuid",player.getUniqueId().toString());
|
||||
yml.set("level",1);
|
||||
yml.set("exp",0);
|
||||
yml.set("totalExp",1);
|
||||
this.file = file;
|
||||
this.fileConfiguration = yml;
|
||||
saveFile();
|
||||
System.out.println("[日志 - 等级] 玩家 "+player.getName()+" 已创建档案数据.");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveFile(){
|
||||
try {
|
||||
this.fileConfiguration.save(this.file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}else{
|
||||
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
this.file = file;
|
||||
this.fileConfiguration = yml;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package me.Demon.DemonLevels.manage;
|
||||
|
||||
import me.Demon.DemonLevels.data.PlayerData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ServerManage {
|
||||
|
||||
private HashMap<Player,PlayerData> dataHashMap = new HashMap<>();
|
||||
private double expMultiplicity; // 当前经验倍率
|
||||
|
||||
private boolean LinkDemonVipSystem = false;
|
||||
private boolean LinkDemonVipSystem = false; // 是否已关联 贵族系统
|
||||
|
||||
public ServerManage(FileConfiguration yml){
|
||||
expMultiplicity = yml.getDouble("DoubleExp",1.0);
|
||||
|
@ -23,4 +27,15 @@ public class ServerManage {
|
|||
public boolean isLinkDemonVipSystem() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user