世界BOSS

This commit is contained in:
yaohunya 2024-07-14 01:04:25 +08:00
parent 60f7c9891d
commit e22728ab08
5 changed files with 107 additions and 7 deletions

View File

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

View File

@ -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<String, Integer> 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<Map.Entry<String, Integer>> 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<Map.Entry<String, Integer>> getTimeMonthTopHashMap(){
FileConfiguration yml = Main.plugin.getConfig();
double totalAmount = 0;
HashMap<String, Integer> 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<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
list.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue()));
return list;
}
}

View File

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

View File

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

View File

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