测试版

This commit is contained in:
yaohunya 2024-08-04 01:49:55 +08:00
parent ddbd2b4d4c
commit c10baf11b6
5 changed files with 78 additions and 9 deletions

View File

@ -8,13 +8,18 @@ import me.Demon.DemonLevels.event.UpLevelEvant;
import me.Demon.DemonLevels.listener.MobDeath;
import me.Demon.DemonLevels.util.ScriptEngineAPI;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.serverct.ersha.jd.AttributeAPI;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public abstract class DLevelAPI {
@ -260,6 +265,56 @@ public abstract class DLevelAPI {
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){
new BukkitRunnable() {
public void run() {

View File

@ -98,20 +98,34 @@ public class MainCmd implements CommandExecutor , TabCompleter {
}
Player player = Bukkit.getPlayer(name);
int value = GameUtil.convertInt(args[2]);
if(args[0].equalsIgnoreCase("give")){
if(player == null) {
DemonAPI.sendMessage(sender,"目标玩家不在线.");
return true;
}
if(args[0].equalsIgnoreCase("give")){
DLevelAPI.addExp(player,value);
DemonAPI.sendMessage(sender,"给予 §6"+name+" §a经验: §d+"+value);
}else if(args[0].equalsIgnoreCase("take")){
if(player == null) {
DemonAPI.sendMessage(sender,"目标玩家不在线.");
return true;
}
DLevelAPI.takeExp(player,value);
DemonAPI.sendMessage(sender,"扣除 §6"+name+" §a经验: §d-"+value);
}else if(args[0].equalsIgnoreCase("setlevel")){
if(player == null) {
DLevelAPI.setOffPlayerLevel(uuid,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")){
if(player == null) {
DemonAPI.sendMessage(sender,"目标玩家不在线.");
return true;
}
BigInteger bigInteger = new BigInteger(args[2]);
DLevelAPI.setTotalExp(player,bigInteger);
DemonAPI.sendMessage(sender,"设置 §6"+name+" §a总经验: §d"+bigInteger.toString());

View File

@ -143,7 +143,7 @@ public class MobDeath implements Listener {
// 检测玩家在队伍里但是不在共享名单里
int shareExperience = (int) (teamExp / playerList.size());
// 给予玩家经验值
DLevelAPI.addExp(p,shareExperience);
DLevelAPI.addExp(player,shareExperience);
experienceGainTips(player,shareExperience,magnificationDisplayString);
if(magnificationDisplayString >= 1){
player.sendMessage("§f[§e提示§f] §7队伍经验分享你获得了§6" + shareExperience + "§7! [§a+" + magnificationDisplayString + "%§7]");

View File

@ -1,6 +1,6 @@
name: DemonLevels
main: me.Demon.DemonLevels.Main
version: 2.2.0
version: 2.2.2
depend: [DemonTeam]
commands:
dlevel: