diff --git a/pom.xml b/pom.xml
index d36bfd6..aebeacf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,21 @@
PlaceholderAPI
2.9.2
+
+ io.lumine.xikage.mythicmobs
+ MythicMobs
+ 1.12.2
+
+
+ org.serverct.ersha
+ AttributePlus
+ 2.3.7
+
+
+ me.Demon.DemonTeam
+ DemonTeam
+ 1.2.0
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/DemonLevels/Main.java b/src/main/java/me/Demon/DemonLevels/Main.java
index 9b3bf37..c90fdb1 100644
--- a/src/main/java/me/Demon/DemonLevels/Main.java
+++ b/src/main/java/me/Demon/DemonLevels/Main.java
@@ -1,6 +1,9 @@
package me.Demon.DemonLevels;
+import me.Demon.DemonLevels.listener.MobDeath;
+import me.Demon.DemonLevels.listener.QuitEvent;
import me.Demon.DemonLevels.manage.MobsManage;
+import me.Demon.DemonLevels.manage.ServerManage;
import me.Demon.DemonLevels.util.ConfigYml;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -15,11 +18,19 @@ public class Main extends JavaPlugin {
public static String TypeEvent = "DragonCore";
- public static MobsManage mobsManage;
+ public static ServerManage serverManage;
public static ConfigYml configYml;
@Override
public void onEnable() {
+ plugin = this;
+ loadConfigData();
+ serverManage = new ServerManage(getConfig());
+ getServer().getPluginManager().registerEvents(new MobDeath(),this);
+ getServer().getPluginManager().registerEvents(new QuitEvent(),this);
+ }
+
+ public void loadConfigData(){
File file = new File(getDataFolder(),"Data.yml");
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
configYml = new ConfigYml(yml);
diff --git a/src/main/java/me/Demon/DemonLevels/api/DLevelAPI.java b/src/main/java/me/Demon/DemonLevels/api/DLevelAPI.java
new file mode 100644
index 0000000..0cb9442
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/api/DLevelAPI.java
@@ -0,0 +1,4 @@
+package me.Demon.DemonLevels.api;
+
+public abstract class DLevelAPI {
+}
diff --git a/src/main/java/me/Demon/DemonLevels/event/ShareExpEvent.java b/src/main/java/me/Demon/DemonLevels/event/ShareExpEvent.java
new file mode 100644
index 0000000..703e569
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/event/ShareExpEvent.java
@@ -0,0 +1,47 @@
+package me.Demon.DemonLevels.event;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+
+import java.util.List;
+
+public class ShareExpEvent extends Event {
+
+
+ private static HandlerList handlers = new HandlerList();
+ // 获取玩家
+ private Player player;
+ // 获取本次瓜分到的经验
+ private int ShareExp;
+ // 获取瓜分经验的名单列表
+ private List ShareList;
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+ public ShareExpEvent(Player player, int ShareExp, List ShareList) {
+ this.player = player;
+ this.ShareExp = ShareExp;
+ this.ShareList = ShareList;
+ }
+
+
+ public Player getPlayer() {
+ return player;
+ }
+
+ public int getShareExp() {
+ return ShareExp;
+ }
+
+ public List getShareList() {
+ return ShareList;
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java b/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java
new file mode 100644
index 0000000..4a124ee
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/listener/MobDeath.java
@@ -0,0 +1,159 @@
+package me.Demon.DemonLevels.listener;
+
+import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
+import me.Demon.DemonLevels.Main;
+import me.Demon.DemonLevels.event.ShareExpEvent;
+import me.Demon.DemonLevels.manage.MobsManage;
+import me.Demon.DemonTeam.DTeamAPI;
+import me.Demon.DemonTeam.TeamData;
+import me.Demon.DemonVipSystem.DvipAPI;
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.Bukkit;
+import org.bukkit.Sound;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.serverct.ersha.jd.AttributeAPI;
+import org.serverct.ersha.jd.Ha;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MobDeath implements Listener {
+
+ @EventHandler
+ public void onkillDropExp(MythicMobDeathEvent e) {
+ LivingEntity killer = e.getKiller(); // 获取击杀mm怪的生物
+ if (!(killer instanceof Player)) {return;}// 判断生物是否是玩家
+ String mmKey = e.getMob().getType().getInternalName(); // 获取MM怪物的id
+ if (Main.configYml.getMobsManage(mmKey) == null){return;}
+ MobsManage mobsManage = Main.configYml.getMobsManage(mmKey);
+ // 获取服务器当前经验倍率
+ double serverDouble = Main.serverManage.getExpMultiplicity();
+ // 获取玩家经验加成属性
+ double att_expAddition = 1;
+ Player p = ((Player) killer).getPlayer();
+ String playerName = p.getName(); // 获取玩家名字
+ if(AttributeAPI.getAttrData(p) != null) {
+ if (AttributeAPI.getAttrData(p).getAttributeValue().get("经验加成") != null) {
+ att_expAddition = 1 + (AttributeAPI.getAttrData(p).getAttributeValue().get("经验加成") / 100);
+ }
+ }
+ // 获取死亡后的经验 x 全服经验倍率 x 玩家经验加成
+ // 假设 死亡经验 = 10 server = 2.0 att = 1.5
+ // 则结果将会是 10 * 2.0 * 1.5 = 30
+ int exp = (int) (mobsManage.getExp() * serverDouble * att_expAddition);
+ // 假设serverDouble = 2.0 att_expAddition = 1.50;
+ // 则结果将会是 2.0 + 1.5 = 3.5 但实际上是 1.0 + 0.5 = 1.5
+ double magnificationDisplay = (serverDouble + att_expAddition) - 2; // 获取玩家当前倍率
+ // 判断玩家是否在队伍之中
+ boolean isTeamExit = false;
+ Map teamMap = new HashMap<>();
+ if(DTeamAPI.isPlayerExistTeam(playerName)){
+ TeamData teamData = DTeamAPI.getPlayerTeam(playerName); // 获取队伍数据
+ // 判断队伍是否开启经验共享 并成员大于2人
+ if(teamData.getMemberList().size() >= 2 && teamData.isExpButt()){
+ teamMap.put(teamData, (double) exp);
+ isTeamExit = true;
+ }
+ }
+ if(!isTeamExit){
+ int magnificationDisplayString = (int) (magnificationDisplay * 100);
+ // 给予玩家经验值
+ experienceGainTips(p,exp,magnificationDisplayString);
+ if(magnificationDisplayString >= 1) {
+ p.sendMessage("§f[§e提示§f] §7你的经验增加了§6" + exp + "§7! [§a+" + magnificationDisplayString + "%§7]");
+ }else{
+ p.sendMessage("§f[§e提示§f] §7你的经验增加了§6" + exp + "§7!");
+ }
+ } else {
+ for (TeamData teamData : teamMap.keySet()){
+ Player owner = teamData.getOwner_Player();
+ if (owner == null) {
+ return;
+ }
+ // 获取队伍成员列表
+ List memberList = teamData.getMemberList();
+ double teamExp = teamMap.get(teamData); // 获取队伍瓜分经验数量
+ if(memberList.size() >= 3) { // 当成员满足3人后 开启队伍经验加成
+ double teamAddonExp = 1.0;
+ if(Main.serverManage.isLinkDemonVipSystem()) {
+ int vip_level = DvipAPI.getLevel(owner.getName());
+ if (vip_level >= 8) {
+ teamAddonExp = 1.30;
+ } else if (vip_level >= 7) {
+ teamAddonExp = 1.20;
+ } else if (vip_level >= 6) {
+ teamAddonExp = 1.15;
+ } else if (vip_level >= 5) {
+ teamAddonExp = 1.10;
+ } else if (vip_level >= 4) {
+ teamAddonExp = 1.05;
+ }
+ 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)){ // 判断玩家所处世界是否是新手世界
+ 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());
+ // 给予玩家经验值
+ 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);
+ }
+ }
+ }
+ }
+ }
+
+ public static void experienceGainTips(Player p,int exp,int magnificationDisplayString){
+ String playName = "§8§l[ §b"+p.getName()+" §8§l]";
+ String nowexp = "§8§l[ §e§lLv."+111+" §c§l"+111+"§f§l/§a§l"+111+" §8§l]";
+ String addExp = "§8§l[ §d§l+" + exp + " §8§l]";
+ if(magnificationDisplayString >= 1){
+ addExp = "§8§l[ §d§l++" + exp + "++ §8§l]";
+ }
+ String message = playName+" "+nowexp+" "+addExp;
+ p.spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(message));
+ p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
+ }
+
+ public static boolean supportedDirectness(String worldName){
+ if(worldName.equalsIgnoreCase("lrzs")){
+ return true;
+ }else if(worldName.equalsIgnoreCase("xdsl")){
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonLevels/listener/QuitEvent.java b/src/main/java/me/Demon/DemonLevels/listener/QuitEvent.java
new file mode 100644
index 0000000..c6efab1
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/listener/QuitEvent.java
@@ -0,0 +1,16 @@
+package me.Demon.DemonLevels.listener;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+public class QuitEvent implements Listener {
+
+ @EventHandler
+ public void onQuit(PlayerQuitEvent e){
+ // 当玩家离开服务器时保存等级数据
+ Player p = e.getPlayer();
+
+ }
+}
diff --git a/src/main/java/me/Demon/DemonLevels/manage/LevelManage.java b/src/main/java/me/Demon/DemonLevels/manage/LevelManage.java
deleted file mode 100644
index 1cb34e3..0000000
--- a/src/main/java/me/Demon/DemonLevels/manage/LevelManage.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package me.Demon.DemonLevels.manage;
-
-public class LevelManage {
-
- private int min;
- private int max;
-
- public LevelManage(){
-
- }
-}
diff --git a/src/main/java/me/Demon/DemonLevels/manage/MobsManage.java b/src/main/java/me/Demon/DemonLevels/manage/MobsManage.java
index 76388de..ae94859 100644
--- a/src/main/java/me/Demon/DemonLevels/manage/MobsManage.java
+++ b/src/main/java/me/Demon/DemonLevels/manage/MobsManage.java
@@ -23,7 +23,7 @@ public class MobsManage {
maxExp = convertInt(expString);
}
if(Main.Debug){
- System.out.println("[日志 - 输出] MM生物: "+mmKey+" Min: "+this.minExp+" Max: "+this.maxExp);
+ System.out.println("[调试 - 输出] MM生物: "+mmKey+" Min: "+this.minExp+" Max: "+this.maxExp);
}
}
diff --git a/src/main/java/me/Demon/DemonLevels/manage/PlayerManage.java b/src/main/java/me/Demon/DemonLevels/manage/PlayerManage.java
new file mode 100644
index 0000000..bc21802
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/manage/PlayerManage.java
@@ -0,0 +1,57 @@
+package me.Demon.DemonLevels.manage;
+
+import me.Demon.DemonLevels.Main;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.entity.Player;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.UUID;
+
+public class PlayerManage {
+
+ private Player player;
+ private UUID uuid;
+ private int level;
+ private int exp;
+ private BigInteger totalExp;
+ private File file;
+ private FileConfiguration fileConfiguration;
+
+ public PlayerManage(Player player){
+
+ }
+
+ public void createPlayerData(){
+ File file = new File(Main.plugin.getDataFolder()+"/PlayerData",uuid.toString()+".yml");
+ // 如果文件不存在,则创建新的文件
+ if (!file.exists()) {
+ try {
+ file.getParentFile().mkdirs(); // 创建文件夹
+ file.createNewFile(); // 创建文件
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ // 加载文件配置
+ FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
+ yml.set("name",player.getName());
+ yml.set("uuid",player.getUniqueId().toString());
+ yml.set("level",1);
+ 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();
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonLevels/manage/ServerManage.java b/src/main/java/me/Demon/DemonLevels/manage/ServerManage.java
new file mode 100644
index 0000000..3cf668c
--- /dev/null
+++ b/src/main/java/me/Demon/DemonLevels/manage/ServerManage.java
@@ -0,0 +1,26 @@
+package me.Demon.DemonLevels.manage;
+
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
+
+public class ServerManage {
+
+ private double expMultiplicity; // 当前经验倍率
+
+ private boolean LinkDemonVipSystem = false;
+
+ public ServerManage(FileConfiguration yml){
+ expMultiplicity = yml.getDouble("DoubleExp",1.0);
+ if(Bukkit.getPluginManager().getPlugin("DemonVipSystem") != null){
+ LinkDemonVipSystem = true;
+ }
+ }
+
+ public double getExpMultiplicity() {
+ return expMultiplicity;
+ }
+
+ public boolean isLinkDemonVipSystem() {
+ return LinkDemonVipSystem;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonLevels/util/ConfigYml.java b/src/main/java/me/Demon/DemonLevels/util/ConfigYml.java
index cdfb790..f00022f 100644
--- a/src/main/java/me/Demon/DemonLevels/util/ConfigYml.java
+++ b/src/main/java/me/Demon/DemonLevels/util/ConfigYml.java
@@ -15,6 +15,7 @@ public class ConfigYml {
public ConfigYml(FileConfiguration yml){
loadRankTitle(yml);
+ loadMobExperienceManagement(yml);
}
public void loadMobExperienceManagement(FileConfiguration yml){
@@ -27,6 +28,14 @@ public class ConfigYml {
manageHashMap.put(mmKey,new MobsManage(mmKey,yml));
}
}
+
+ public MobsManage getMobsManage(String mmKey){
+ if(this.manageHashMap.get(mmKey) != null){
+ return this.manageHashMap.get(mmKey);
+ }
+ return null;
+ }
+
public void loadRankTitle(FileConfiguration yml){
ConfigurationSection section = yml.getConfigurationSection("CustonName");
if(section == null){