diff --git a/src/main/java/com/io/yaohun/worldbosshurt/Main.java b/src/main/java/com/io/yaohun/worldbosshurt/Main.java index bb2baed..3f6f9a6 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/Main.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/Main.java @@ -5,6 +5,7 @@ import com.io.yaohun.worldbosshurt.listener.*; import com.io.yaohun.worldbosshurt.mangage.BossManage; import com.io.yaohun.worldbosshurt.mangage.RewardManage; import com.io.yaohun.worldbosshurt.util.BossStack; +import com.io.yaohun.worldbosshurt.util.BossUtil; import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -46,7 +47,11 @@ public class Main extends JavaPlugin { @Override public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) { - if(Command.equalsIgnoreCase("bossreload")){ + if(Command.equalsIgnoreCase("bossreload") && sender.isOp()){ + if(args.length == 1 && args[0].equalsIgnoreCase("test")){ + BossUtil.settlementRankingRewards(); + return true; + } reloadMobDataYml(); DemonAPI.sendMessage(sender,"配置文件已重载."); return true; diff --git a/src/main/java/com/io/yaohun/worldbosshurt/api/BossHurtAPI.java b/src/main/java/com/io/yaohun/worldbosshurt/api/BossHurtAPI.java index 00c2678..a748138 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/api/BossHurtAPI.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/api/BossHurtAPI.java @@ -2,6 +2,14 @@ package com.io.yaohun.worldbosshurt.api; import com.io.yaohun.worldbosshurt.Main; import com.io.yaohun.worldbosshurt.mangage.BossManage; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public abstract class BossHurtAPI { @@ -13,4 +21,45 @@ public abstract class BossHurtAPI { } return false; } + + //获取本月猎杀排行榜排行榜 + public static void sendTimeMonthTopMessage(Player p){ + FileConfiguration yml = Main.plugin.getConfig(); + double totalAmount = 0; + HashMap map = new HashMap<>(); + for (String playName : yml.getConfigurationSection("MonthlyKillsTop").getKeys(false)) { + int amount = yml.getInt("MonthlyKillsTop."+playName); + map.put(playName, amount); + totalAmount = totalAmount + amount; + } + List> list = new ArrayList<>(map.entrySet()); + list.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue())); + int count = Math.min(list.size(), 10); + int rank = 1; + p.sendMessage("§c§M §6§m §e§m §a§m §b§m §C§L▍ §c§l猎§6§l杀§E§L统§A§l计§B§L表 §C§l▍§b§M §a§M §e§M §6§m §c§m §r"); + p.sendMessage("§e本月世界级boss猎杀排名如下:"); + for (int i = 0; i < count; i++) { + if (rank == 11) { + break; + } + String top_Name = list.get(i).getKey(); + p.sendMessage("§e第" + rank + "名 - §c" + top_Name + " §e总计猎杀: §c" + list.get(i).getValue() + "只 §e猎杀占总比: §c" + new DecimalFormat("0.00").format(list.get(i).getValue() / totalAmount * 100) + "%"); + ++rank; + } + p.sendMessage("§c§M §6§m §e§m §a§m §b§m §C§L▍ §c§l猎§6§l杀§E§L统§A§l计§B§L表 §C§l▍§b§M §a§M §e§M §6§m §c§m §r"); + } + + public static List> getTimeMonthTopHashMap(){ + FileConfiguration yml = Main.plugin.getConfig(); + double totalAmount = 0; + HashMap map = new HashMap<>(); + for (String playName : yml.getConfigurationSection("MonthlyKillsTop").getKeys(false)) { + int amount = yml.getInt("MonthlyKillsTop."+playName); + map.put(playName, amount); + totalAmount = totalAmount + amount; + } + List> list = new ArrayList<>(map.entrySet()); + list.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue())); + return list; + } } diff --git a/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDamageEvent.java b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDamageEvent.java new file mode 100644 index 0000000..13695e5 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDamageEvent.java @@ -0,0 +1,43 @@ +package com.io.yaohun.worldbosshurt.event; + +import com.io.yaohun.worldbosshurt.data.BossData; +import com.io.yaohun.worldbosshurt.data.RewardData; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import java.util.LinkedHashMap; + +public class WorldBossDamageEvent extends Event { + + private static HandlerList handlers = new HandlerList(); + private Player player; + private double damage; + private BossData bossData; + + @Override + public HandlerList getHandlers() { + return handlers; + } + public static HandlerList getHandlerList() { + return handlers; + } + public WorldBossDamageEvent(Player player,BossData bossData,double damage) { + this.player = player; + this.bossData = bossData; + this.damage = damage; + } + + public Player getPlayer() {return player;} + public String getBossKey(){return bossData.getBossKey();} + public String getMobName() { + return bossData.getBossName(); + } + public BossData getBossData() { + return bossData; + } + + public double getDamage() { + return damage * 1000; + } +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java index affc4a1..346ac0e 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java @@ -3,6 +3,7 @@ package com.io.yaohun.worldbosshurt.listener; import com.io.yaohun.worldbosshurt.Main; import com.io.yaohun.worldbosshurt.data.BossData; import com.io.yaohun.worldbosshurt.data.RewardData; +import com.io.yaohun.worldbosshurt.event.WorldBossDamageEvent; import com.io.yaohun.worldbosshurt.event.WorldBossDeathEvent; import com.io.yaohun.worldbosshurt.mangage.BossManage; import com.io.yaohun.worldbosshurt.util.BossStack; @@ -73,6 +74,8 @@ public class BossKillsDeath implements Listener { totalDamage += damage; // 统计玩家造成总计伤害 hashMap.put(player.getName(), damage); // 将玩家名和伤害存储 playerList.add(player); // 将玩家存入在线玩家列表 + WorldBossDamageEvent worldBossDamageEvent = new WorldBossDamageEvent(player,bossData,damage); + Bukkit.getPluginManager().callEvent(worldBossDamageEvent); } } if (hashMap.size() < 1) { return; } diff --git a/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java index a82e9e8..bd2bcf1 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java @@ -63,7 +63,7 @@ public class BossUtil { int killAmount = yml.getInt("MonthlyKillsTop."+name); // 获取击杀boss次数 hashMap.put(name,killAmount); // put次数 } - // yml.set("MonthlyKillsTop",null); // 清理本地数据 + yml.set("MonthlyKillsTop",null); // 清理本地数据 } if(hashMap.size() >= 1){ // 为HashMap中数值进行降序排序 @@ -82,19 +82,19 @@ public class BossUtil { int kill_amount = sortedMap.get(name); if(rank == 1) { Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx1000"); - // BankAPI.addPoints(name,1000); + BankAPI.addPoints(name,1000); }else if(rank == 2){ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx750"); - // BankAPI.addPoints(name,750); + BankAPI.addPoints(name,750); }else if(rank == 3){ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx500"); - // BankAPI.addPoints(name,500); + BankAPI.addPoints(name,500); }else if(rank == 4){ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx250"); - // BankAPI.addPoints(name,250); + BankAPI.addPoints(name,250); }else if(rank == 5){ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx100"); - // BankAPI.addPoints(name,100); + BankAPI.addPoints(name,100); break; } rank++;