From 663da9c226621ff42d27f4f4de8b356a9c948da8 Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Wed, 31 Jul 2024 02:06:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/Demon/DemonLevels/Main.java | 1 + .../me/Demon/DemonLevels/data/PlayerData.java | 15 ++-- .../Demon/DemonLevels/listener/JoinEvent.java | 19 ++++- .../Demon/DemonLevels/listener/MobDeath.java | 71 ++++++++++--------- .../DemonLevels/listener/UpgradePrompt.java | 18 ++--- src/main/resources/plugin.yml | 2 +- 6 files changed, 77 insertions(+), 49 deletions(-) diff --git a/src/main/java/me/Demon/DemonLevels/Main.java b/src/main/java/me/Demon/DemonLevels/Main.java index f99fa59..685b445 100644 --- a/src/main/java/me/Demon/DemonLevels/Main.java +++ b/src/main/java/me/Demon/DemonLevels/Main.java @@ -43,6 +43,7 @@ public class Main extends JavaPlugin { DemonAPI.sendConsoleMessage("§f[§6!§f] §b极光像素工作室出品"); } + @Override public void onDisable() { for (String uuid : serverManage.getDataHashMap().keySet()){ diff --git a/src/main/java/me/Demon/DemonLevels/data/PlayerData.java b/src/main/java/me/Demon/DemonLevels/data/PlayerData.java index 52157e4..6d4ed55 100644 --- a/src/main/java/me/Demon/DemonLevels/data/PlayerData.java +++ b/src/main/java/me/Demon/DemonLevels/data/PlayerData.java @@ -27,6 +27,7 @@ public class PlayerData { this.exp = new BigInteger(expString); String totalExpString = fileConfiguration.getString("totalExp"); this.totalExp = new BigInteger(totalExpString); + } public String getUuid() { @@ -86,9 +87,10 @@ public class PlayerData { // 加载文件配置 FileConfiguration yml = YamlConfiguration.loadConfiguration(file); yml.set("uuid",uuid); - Player player = Bukkit.getPlayer(UUID.fromString(uuid)); + UUID uuid1 = UUID.fromString(uuid); + Player player = Bukkit.getPlayer(uuid1); if(player != null) { - System.out.println("[日志 - 等级] 玩家 " + player.getName() + " 已创建档案数据."); + System.out.println("[调试 - UUID检测] uuid: "+uuid+" name: "+player.getName()); yml.set("name",player.getName()); // 判断玩家之前是否存在等级数据 FileConfiguration config = Main.plugin.getConfig(); @@ -96,16 +98,19 @@ public class PlayerData { if(config.getInt(str+"level") >= 1){ int dlevel = config.getInt(str+"level"); int exp = config.getInt(str+"exp"); - int totalExp = config.getInt(str+"totalExp"); + BigInteger totalExp = new BigInteger(config.getString(str+"totalExp")); yml.set("level", dlevel); yml.set("exp", exp); - yml.set("totalExp", totalExp); + yml.set("totalExp", totalExp.toString()); + System.out.println("[日志 - 等级] 玩家 " + player.getName() + " 已创建数据档案.#"+config.getInt(str+"level")+" - "+totalExp.toString()); }else{ yml.set("level", 1); yml.set("exp", 0); yml.set("totalExp", 1); + System.out.println("[日志 - 等级] 玩家 " + player.getName() + " 等级低于1级,已创建默认数据档案.#"+config.getInt(str+"level")+" - "+config.getInt(str+"totalExp")); } - }else { + } else { + System.out.println("[调试 - UUID检测] uuid: "+uuid+" name: 检测失败"); yml.set("level", 1); yml.set("exp", 0); yml.set("totalExp", 1); diff --git a/src/main/java/me/Demon/DemonLevels/listener/JoinEvent.java b/src/main/java/me/Demon/DemonLevels/listener/JoinEvent.java index 5600204..7843314 100644 --- a/src/main/java/me/Demon/DemonLevels/listener/JoinEvent.java +++ b/src/main/java/me/Demon/DemonLevels/listener/JoinEvent.java @@ -1,20 +1,37 @@ package me.Demon.DemonLevels.listener; import me.Demon.DemonLevels.Main; +import me.Demon.DemonLevels.api.DLevelAPI; import me.Demon.DemonLevels.data.PlayerData; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import java.math.BigInteger; public class JoinEvent implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e){ Player p = e.getPlayer(); + String name = p.getName(); String uuid = p.getUniqueId().toString(); - Main.serverManage.getPlayerData(uuid); // 读取玩家的等级数据 + PlayerData playerData = Main.serverManage.getPlayerData(uuid); // 读取玩家的等级数据 + new BukkitRunnable() { + @Override + public void run() { + FileConfiguration yml = Main.plugin.getConfig(); + int totalExp = yml.getInt("levelstats."+name+".totalExp"); + if(totalExp > playerData.getTotalExp().intValue()){ + DLevelAPI.setTotalExp(p,new BigInteger(yml.getString("levelstats."+name+".totalExp"))); + System.out.println("[调试 - 修正] 玩家 "+name+" 经验出现错误,已被纠正."); + } + } + }.runTaskLater(Main.plugin,100L); } @EventHandler diff --git a/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java b/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java index 013795a..e6abf1d 100644 --- a/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java +++ b/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java @@ -94,9 +94,9 @@ public class MobDeath implements Listener { // 获取队伍成员列表 List memberList = teamData.getMemberList(); double teamExp = teamMap.get(teamData); // 获取队伍瓜分经验数量 - if(memberList.size() >= 3) { // 当成员满足3人后 开启队伍经验加成 + if(memberList.size() >= 2) { // 当成员满足3人后 开启队伍经验加成 double teamAddonExp = 1.0; - if(Main.serverManage.isLinkDemonVipSystem()) { + if (Main.serverManage.isLinkDemonVipSystem()) { int vip_level = DvipAPI.getLevel(owner.getName()); if (vip_level >= 8) { teamAddonExp = 1.30; @@ -112,41 +112,46 @@ public class MobDeath implements Listener { magnificationDisplay = magnificationDisplay + (teamAddonExp - 1); } teamExp = teamExp * teamAddonExp; - List playerList = new ArrayList<>(); // 参与经验共享的成员 - for (String memberName : memberList){// 遍历成员列表 - Player teamPlayer = Bukkit.getPlayer(memberName); - if(teamPlayer == null || !teamPlayer.isOnline()){ - continue; - } - // 获取队友所在世界名 - String locationWorld = teamPlayer.getWorld().getName(); - if(supportedDirectness(locationWorld)){ // 判断玩家所处世界是否是新手世界 + } + List playerList = new ArrayList<>(); // 参与经验共享的成员 + for (String memberName : memberList){// 遍历成员列表 + Player teamPlayer = Bukkit.getPlayer(memberName); + if(teamPlayer == null || !teamPlayer.isOnline()){ + continue; + } + // 获取队友所在世界名 + String locationWorld = teamPlayer.getWorld().getName(); + if(supportedDirectness(locationWorld)){ // 判断玩家所处世界是否是新手世界 + playerList.add(memberName); + }else if(p.getWorld().equals(teamPlayer.getWorld())){ + // 若玩家所处世界相同则开启共享 + // 但前提是他们两点距离不超过15格 + double distance = p.getLocation().distance(teamPlayer.getLocation()); + if(distance <= 50){ playerList.add(memberName); - }else if(p.getWorld().equals(teamPlayer.getWorld())){ - // 若玩家所处世界相同则开启共享 - // 但前提是他们两点距离不超过15格 - double distance = p.getLocation().distance(teamPlayer.getLocation()); - if(distance <= 30){ - playerList.add(memberName); - } } } - int magnificationDisplayString = (int) (magnificationDisplay * 100); - for (String memberName : playerList){ - Player player = Bukkit.getPlayer(memberName); - if(player == null){continue;} - int shareExperience = (int) (teamExp / playerList.size()); - // 给予玩家经验值 - DLevelAPI.addExp(p,shareExperience); - experienceGainTips(player,shareExperience,magnificationDisplayString); - if(magnificationDisplayString >= 1){ - player.sendMessage("§f[§e提示§f] §7队伍经验分享你获得了§6" + shareExperience + "§7! [§a+" + magnificationDisplayString + "%§7]"); - } else { - player.sendMessage("§f[§c消息§f] §7队伍经验分享你获得了 §d§l+" + shareExperience); - } - ShareExpEvent share_event = new ShareExpEvent(player, shareExperience, playerList); - Bukkit.getPluginManager().callEvent(share_event); + } + int magnificationDisplayString = (int) (magnificationDisplay * 100); + for (String memberName : memberList){ + Player player = Bukkit.getPlayer(memberName); + if(player == null){continue;} + if(!playerList.contains(memberName)){ + player.sendMessage("§f[§e提示§f] §7由于距离过远,组队经验共享失败."); + continue; } + // 检测玩家在队伍里但是不在共享名单里 + int shareExperience = (int) (teamExp / playerList.size()); + // 给予玩家经验值 + DLevelAPI.addExp(p,shareExperience); + experienceGainTips(player,shareExperience,magnificationDisplayString); + if(magnificationDisplayString >= 1){ + player.sendMessage("§f[§e提示§f] §7队伍经验分享你获得了§6" + shareExperience + "§7! [§a+" + magnificationDisplayString + "%§7]"); + } else { + player.sendMessage("§f[§c消息§f] §7队伍经验分享你获得了 §d§l+" + shareExperience); + } + ShareExpEvent share_event = new ShareExpEvent(player, shareExperience, playerList); + Bukkit.getPluginManager().callEvent(share_event); } } } diff --git a/src/main/java/me/Demon/DemonLevels/listener/UpgradePrompt.java b/src/main/java/me/Demon/DemonLevels/listener/UpgradePrompt.java index 19716aa..988e479 100644 --- a/src/main/java/me/Demon/DemonLevels/listener/UpgradePrompt.java +++ b/src/main/java/me/Demon/DemonLevels/listener/UpgradePrompt.java @@ -11,18 +11,18 @@ public class UpgradePrompt implements Listener { @EventHandler public void onUpLevel(UpLevelEvant e){ - // 获取触发事件的玩家 - Player p = e.getPlayer(); - // 获取玩家名称 - String name = p.getName(); // 获取玩家的新等级 int level = e.getLevel(); - // 从配置中获取当前等级对应的前缀 - String prefix = Main.configYml.getRankTitle(level); - // 广播消息,通知所有玩家该玩家达到新的境界 - Bukkit.broadcastMessage("§f[§c§l公告§f] §a玩家§e" + name + "§a境界成功达到了 §7[" + prefix + "§7]"); // 检查玩家的等级是否是5的倍数 - if (level%5 == 0) { + if (level % 5 == 0) { + // 获取触发事件的玩家 + Player p = e.getPlayer(); + // 获取玩家名称 + String name = p.getName(); + // 从配置中获取当前等级对应的前缀 + String prefix = Main.configYml.getRankTitle(level); + // 广播消息,通知所有玩家该玩家达到新的境界 + Bukkit.broadcastMessage("§f[§c§l公告§f] §a玩家§e" + name + "§a境界成功达到了 §7[" + prefix + "§7]"); // 获取玩家对象 Player player = Bukkit.getPlayer(name); if(player == null){return;} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dcc2aa7..c8b36e3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: DemonLevels main: me.Demon.DemonLevels.Main -version: 2.1.6 +version: 2.1.9 depend: [DemonTeam] commands: dlevel: \ No newline at end of file