测试版
This commit is contained in:
parent
ddbd2b4d4c
commit
c10baf11b6
|
@ -8,13 +8,18 @@ import me.Demon.DemonLevels.event.UpLevelEvant;
|
||||||
import me.Demon.DemonLevels.listener.MobDeath;
|
import me.Demon.DemonLevels.listener.MobDeath;
|
||||||
import me.Demon.DemonLevels.util.ScriptEngineAPI;
|
import me.Demon.DemonLevels.util.ScriptEngineAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.serverct.ersha.jd.AttributeAPI;
|
import org.serverct.ersha.jd.AttributeAPI;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class DLevelAPI {
|
public abstract class DLevelAPI {
|
||||||
|
|
||||||
|
@ -260,6 +265,56 @@ public abstract class DLevelAPI {
|
||||||
setTotalExp(p,totalExp);
|
setTotalExp(p,totalExp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setOffPlayerLevel(String uuid,int level){
|
||||||
|
if(level <= 0){return;}
|
||||||
|
// 初始化经验值
|
||||||
|
BigInteger defaultExp = BigInteger.ZERO;
|
||||||
|
// 循环计算到当前等级所需的经验
|
||||||
|
for (int i = 1; i < level; i++) {
|
||||||
|
// 获取当前等级所需经验
|
||||||
|
BigInteger currentLevelNeedExp = DLevelAPI.getLevelNeedExp(i);
|
||||||
|
defaultExp = defaultExp.add(currentLevelNeedExp);
|
||||||
|
}
|
||||||
|
// 计算并设置玩家的经验值
|
||||||
|
// 由于经验值是从上一级到当前级别的剩余经验
|
||||||
|
BigInteger totalExp = defaultExp;
|
||||||
|
// 设置玩家的总经验
|
||||||
|
setOffPlayerTotalExp(uuid,totalExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setOffPlayerTotalExp(String uuid, BigInteger exp){
|
||||||
|
File file = new File(Main.plugin.getDataFolder()+"/PlayerData",uuid+".yml");
|
||||||
|
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||||
|
BigInteger totalExp = new BigInteger(String.valueOf(exp));
|
||||||
|
yml.set("totalExp",totalExp.toString());
|
||||||
|
int level = 1;
|
||||||
|
// 获取当前等级1所需的经验
|
||||||
|
BigInteger needExp = DLevelAPI.getLevelNeedExp(level);
|
||||||
|
// 循环检查总经验是否足够升级
|
||||||
|
while (totalExp.compareTo(needExp) >= 0) {
|
||||||
|
// 从总经验中减去当前等级所需的经验
|
||||||
|
totalExp = totalExp.subtract(needExp);
|
||||||
|
// 升级玩家等级
|
||||||
|
level++;
|
||||||
|
// 获取下一个等级所需的经验
|
||||||
|
needExp = DLevelAPI.getLevelNeedExp(level);
|
||||||
|
// 如果等级小于0,退出循环(虽然在实际中等级通常不会小于0)
|
||||||
|
if (level < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新玩家的数据
|
||||||
|
yml.set("level",level);
|
||||||
|
yml.set("exp",totalExp.toString());
|
||||||
|
try {
|
||||||
|
yml.save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("[调试 - 等级保存] level = "+level+" exp = "+exp+" totalExp = "+new BigInteger(String.valueOf(exp)));
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateThePlayerExperienceBar(Player p,PlayerData playerData){
|
public static void updateThePlayerExperienceBar(Player p,PlayerData playerData){
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -98,20 +98,34 @@ public class MainCmd implements CommandExecutor , TabCompleter {
|
||||||
}
|
}
|
||||||
Player player = Bukkit.getPlayer(name);
|
Player player = Bukkit.getPlayer(name);
|
||||||
int value = GameUtil.convertInt(args[2]);
|
int value = GameUtil.convertInt(args[2]);
|
||||||
|
if(args[0].equalsIgnoreCase("give")){
|
||||||
if(player == null) {
|
if(player == null) {
|
||||||
DemonAPI.sendMessage(sender,"目标玩家不在线.");
|
DemonAPI.sendMessage(sender,"目标玩家不在线.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args[0].equalsIgnoreCase("give")){
|
|
||||||
DLevelAPI.addExp(player,value);
|
DLevelAPI.addExp(player,value);
|
||||||
DemonAPI.sendMessage(sender,"给予 §6"+name+" §a经验: §d+"+value);
|
DemonAPI.sendMessage(sender,"给予 §6"+name+" §a经验: §d+"+value);
|
||||||
}else if(args[0].equalsIgnoreCase("take")){
|
}else if(args[0].equalsIgnoreCase("take")){
|
||||||
|
if(player == null) {
|
||||||
|
DemonAPI.sendMessage(sender,"目标玩家不在线.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
DLevelAPI.takeExp(player,value);
|
DLevelAPI.takeExp(player,value);
|
||||||
DemonAPI.sendMessage(sender,"扣除 §6"+name+" §a经验: §d-"+value);
|
DemonAPI.sendMessage(sender,"扣除 §6"+name+" §a经验: §d-"+value);
|
||||||
}else if(args[0].equalsIgnoreCase("setlevel")){
|
}else if(args[0].equalsIgnoreCase("setlevel")){
|
||||||
DLevelAPI.setPlayerLevel(player,value);
|
if(player == null) {
|
||||||
|
DLevelAPI.setOffPlayerLevel(uuid,value);
|
||||||
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a等级: §dLv."+value);
|
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a等级: §dLv."+value);
|
||||||
|
}else {
|
||||||
|
DLevelAPI.setPlayerLevel(player, value);
|
||||||
|
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a等级: §dLv."+value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}else if(args[0].equalsIgnoreCase("settotal")){
|
}else if(args[0].equalsIgnoreCase("settotal")){
|
||||||
|
if(player == null) {
|
||||||
|
DemonAPI.sendMessage(sender,"目标玩家不在线.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
BigInteger bigInteger = new BigInteger(args[2]);
|
BigInteger bigInteger = new BigInteger(args[2]);
|
||||||
DLevelAPI.setTotalExp(player,bigInteger);
|
DLevelAPI.setTotalExp(player,bigInteger);
|
||||||
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a总经验: §d"+bigInteger.toString());
|
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a总经验: §d"+bigInteger.toString());
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class JoinEvent implements Listener {
|
||||||
FileConfiguration yml = Main.plugin.getConfig();
|
FileConfiguration yml = Main.plugin.getConfig();
|
||||||
int totalExp = yml.getInt("levelstats."+name+".totalExp");
|
int totalExp = yml.getInt("levelstats."+name+".totalExp");
|
||||||
BigInteger bigInteger = BigInteger.valueOf(totalExp);
|
BigInteger bigInteger = BigInteger.valueOf(totalExp);
|
||||||
if(bigInteger.compareTo(playerData.getTotalExp()) > 0){
|
if (bigInteger.compareTo(playerData.getTotalExp()) > 0) {
|
||||||
System.out.println("[调试 - 修正] 玩家 "+name+" 经验出现错误,已被纠正. YmlExp = "+bigInteger.toString()+" playerdata = "+playerData.getTotalExp().toString());
|
System.out.println("[调试 - 修正] 玩家 "+name+" 经验出现错误,已被纠正. YmlExp = "+bigInteger.toString()+" playerdata = "+playerData.getTotalExp().toString());
|
||||||
DLevelAPI.setTotalExp(p,bigInteger);
|
DLevelAPI.setTotalExp(p,bigInteger);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class MobDeath implements Listener {
|
||||||
// 检测玩家在队伍里但是不在共享名单里
|
// 检测玩家在队伍里但是不在共享名单里
|
||||||
int shareExperience = (int) (teamExp / playerList.size());
|
int shareExperience = (int) (teamExp / playerList.size());
|
||||||
// 给予玩家经验值
|
// 给予玩家经验值
|
||||||
DLevelAPI.addExp(p,shareExperience);
|
DLevelAPI.addExp(player,shareExperience);
|
||||||
experienceGainTips(player,shareExperience,magnificationDisplayString);
|
experienceGainTips(player,shareExperience,magnificationDisplayString);
|
||||||
if(magnificationDisplayString >= 1){
|
if(magnificationDisplayString >= 1){
|
||||||
player.sendMessage("§f[§e提示§f] §7队伍经验分享你获得了§6" + shareExperience + "§7! [§a+" + magnificationDisplayString + "%§7]");
|
player.sendMessage("§f[§e提示§f] §7队伍经验分享你获得了§6" + shareExperience + "§7! [§a+" + magnificationDisplayString + "%§7]");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: DemonLevels
|
name: DemonLevels
|
||||||
main: me.Demon.DemonLevels.Main
|
main: me.Demon.DemonLevels.Main
|
||||||
version: 2.2.0
|
version: 2.2.2
|
||||||
depend: [DemonTeam]
|
depend: [DemonTeam]
|
||||||
commands:
|
commands:
|
||||||
dlevel:
|
dlevel:
|
Loading…
Reference in New Issue
Block a user