测试版

This commit is contained in:
yaohunya 2024-07-31 02:06:06 +08:00
parent 1c6c59b9a0
commit 663da9c226
6 changed files with 77 additions and 49 deletions

View File

@ -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()){

View File

@ -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);

View File

@ -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

View File

@ -94,9 +94,9 @@ public class MobDeath implements Listener {
// 获取队伍成员列表
List<String> 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<String> 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<String> 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);
}
}
}

View File

@ -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;}

View File

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