测试版
This commit is contained in:
parent
40544a6ca0
commit
b79e7b93f6
15
pom.xml
15
pom.xml
|
@ -36,6 +36,21 @@
|
|||
<artifactId>PlaceholderAPI</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.lumine.xikage.mythicmobs</groupId>
|
||||
<artifactId>MythicMobs</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.serverct.ersha</groupId>
|
||||
<artifactId>AttributePlus</artifactId>
|
||||
<version>2.3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonTeam</groupId>
|
||||
<artifactId>DemonTeam</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -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);
|
||||
|
|
4
src/main/java/me/Demon/DemonLevels/api/DLevelAPI.java
Normal file
4
src/main/java/me/Demon/DemonLevels/api/DLevelAPI.java
Normal file
|
@ -0,0 +1,4 @@
|
|||
package me.Demon.DemonLevels.api;
|
||||
|
||||
public abstract class DLevelAPI {
|
||||
}
|
47
src/main/java/me/Demon/DemonLevels/event/ShareExpEvent.java
Normal file
47
src/main/java/me/Demon/DemonLevels/event/ShareExpEvent.java
Normal file
|
@ -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<String> ShareList;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
public ShareExpEvent(Player player, int ShareExp, List<String> ShareList) {
|
||||
this.player = player;
|
||||
this.ShareExp = ShareExp;
|
||||
this.ShareList = ShareList;
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getShareExp() {
|
||||
return ShareExp;
|
||||
}
|
||||
|
||||
public List<String> getShareList() {
|
||||
return ShareList;
|
||||
}
|
||||
|
||||
}
|
159
src/main/java/me/Demon/DemonLevels/listener/MobDeath.java
Normal file
159
src/main/java/me/Demon/DemonLevels/listener/MobDeath.java
Normal file
|
@ -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<TeamData, Double> 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<String> 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<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 <= 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;
|
||||
}
|
||||
}
|
16
src/main/java/me/Demon/DemonLevels/listener/QuitEvent.java
Normal file
16
src/main/java/me/Demon/DemonLevels/listener/QuitEvent.java
Normal file
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package me.Demon.DemonLevels.manage;
|
||||
|
||||
public class LevelManage {
|
||||
|
||||
private int min;
|
||||
private int max;
|
||||
|
||||
public LevelManage(){
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
57
src/main/java/me/Demon/DemonLevels/manage/PlayerManage.java
Normal file
57
src/main/java/me/Demon/DemonLevels/manage/PlayerManage.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
26
src/main/java/me/Demon/DemonLevels/manage/ServerManage.java
Normal file
26
src/main/java/me/Demon/DemonLevels/manage/ServerManage.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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){
|
||||
|
|
Loading…
Reference in New Issue
Block a user