测试版

This commit is contained in:
yaohunya 2024-07-13 21:39:00 +08:00
parent effbed02d1
commit 8b7880a1b0
10 changed files with 405 additions and 38 deletions

View File

@ -36,6 +36,11 @@
<artifactId>DemonBank</artifactId> <artifactId>DemonBank</artifactId>
<version>1.4</version> <version>1.4</version>
</dependency> </dependency>
<dependency>
<groupId>io.lumine.xikage.mythicmobs</groupId>
<artifactId>MythicMobs</artifactId>
<version>1.12.2</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,36 +0,0 @@
package com.io.yaohun.worldbosshurt;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.configuration.file.FileConfiguration;
public class BossUtil {
/*
* 获取每月数据刷新时间
* */
public static String getTimeMonthly(){
FileConfiguration yml = Main.plugin.getConfig();
if(yml.getString("Timemonth") != null){
return yml.getString("Timemonth");
}
return "2022/04";
}
/*
* 判断本月数据是否刷新
* */
public static boolean isTimeMonthly(){
FileConfiguration yml = Main.plugin.getConfig();
if(!getTimeMonthly().equalsIgnoreCase(DemonAPI.getTime("yyyy/MM"))){
return true;
}
return false;
}
/*
* 结算上月累积击杀十万年次数排行
* */
public static void settlementRankingRewards(){
}
}

View File

@ -1,16 +1,33 @@
package com.io.yaohun.worldbosshurt; package com.io.yaohun.worldbosshurt;
import com.io.yaohun.worldbosshurt.listener.SpawnPut;
import com.io.yaohun.worldbosshurt.mangage.BossManage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
public static Main plugin; public static Main plugin;
public static BossManage bossManage;
@Override @Override
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
getCommand("bossspawner").setExecutor(new BossSpawnerCMD()); File Datafile = new File("plugins/WorldBossHurt", "MobData.yml");
bossManage = new BossManage(YamlConfiguration.loadConfiguration(Datafile));
getServer().getPluginManager().registerEvents(new SpawnPut(),this);
} }
@Override
public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
if(Command.equalsIgnoreCase("bosspz")){
}
return false;
}
} }

View File

@ -1,6 +1,6 @@
package com.io.yaohun.worldbosshurt.command; package com.io.yaohun.worldbosshurt.command;
import com.io.yaohun.worldbosshurt.BossUtil; import com.io.yaohun.worldbosshurt.util.BossUtil;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -0,0 +1,68 @@
package com.io.yaohun.worldbosshurt.data;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
public class BossData {
private String bossKey;
private String bossName;
private int bossArmor;
private String killsReward;
private String topReward;
private String locString;
private String bc;
private String bc_vv;
public BossData(String bossKey,FileConfiguration yml){
String str = "BossData."+bossKey+".";
this.bossKey = bossKey;
this.bossName = yml.getString(str+"name").replace("&","§");
this.bossArmor = yml.getInt(str+"boss_armor") * 10000;
this.killsReward = null;
if(yml.getString(str+"reward_kills") != null) {
this.killsReward = yml.getString(str + "reward_kills");
}
this.topReward = null;
if(yml.getString(str+"reward_top") != null){
this.topReward = yml.getString(str+"reward_top");
}
this.locString = yml.getString(str+"loc");
this.bc = yml.getString(str+"bc").replace("&","§");
this.bc_vv = yml.getString(str+"bc_vv").replace("&","§");
}
public Location getLocation() {
String[] sp = this.locString.split(",");
String worldName = sp[0];
World world = Bukkit.getWorld(worldName);
int x = Integer.parseInt(sp[1]);
int y = Integer.parseInt(sp[2]);
int z = Integer.parseInt(sp[3]);
return new Location(world,x,y,z);
}
public String getBossKey() {return bossKey;}
public int getBossArmor() {
return bossArmor;
}
public String getKillsReward() {
return killsReward;
}
public String getTopReward() {
return topReward;
}
public String getBossName() {return bossName;}
public String getLocString() {
return locString;
}
public String getBc() {return bc;}
public String getBc_vv() {return bc_vv;}
}

View File

@ -0,0 +1,36 @@
package com.io.yaohun.worldbosshurt.listener;
import com.io.yaohun.worldbosshurt.Main;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobSpawnEvent;
import io.lumine.xikage.mythicmobs.mobs.MythicMob;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SpawnPut implements Listener {
public static List<UUID> WhiteBossList = new ArrayList<>();
@EventHandler
public void onSpawnBlockEvent(MythicMobSpawnEvent e) {
if (e.getEntity() instanceof org.bukkit.entity.LivingEntity) {
// 获取怪物
MythicMob mythicMob = e.getMobType();
// 获取怪物的名字
String customName = mythicMob.getDisplayName().get();
if(Main.bossManage.isCustomNameContains(customName)) {
Entity entity = e.getEntity();
// 获取BOSS的uuid
UUID uuid = entity.getUniqueId();
// 将Boss存入 HashMap
WhiteBossList.add(uuid);
Bukkit.getConsoleSender().sendMessage("[日志-UUID导入] Boss "+customName+" §r已被录入List");
}
}
}
}

View File

@ -0,0 +1,36 @@
package com.io.yaohun.worldbosshurt.mangage;
import com.io.yaohun.worldbosshurt.Main;
import com.io.yaohun.worldbosshurt.data.BossData;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashMap;
import java.util.List;
public class BossManage {
private List<String> customNameList; // 获取boss名列表
private final HashMap<String,BossData> bossDataMap = new HashMap<>();
public BossManage(FileConfiguration yml) {
for (String bossKey : yml.getConfigurationSection("BossData").getKeys(false)){
bossDataMap.put(bossKey,new BossData(bossKey,yml));
String customName = yml.getString("BossData."+bossKey+".name");
customNameList.add(customName);
}
Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f已导入Boss: §a" + customNameList.size() + "");
}
public boolean isCustomNameContains(String customName){
for (String name : this.customNameList){
if(customName.contains(name)){
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,92 @@
package com.io.yaohun.worldbosshurt.mangage;
import com.io.yaohun.worldbosshurt.Main;
import com.io.yaohun.worldbosshurt.listener.SpawnPut;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.Plugin;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.UUID;
public class DamageManage implements Listener {
private HashMap<Player,Double> damageMap = new HashMap<>();
private void addPlayerDamage(Player player,double damage){
double newDamage = damage / 1000;
if(damageMap.get(player) == null){
damageMap.put(player,newDamage);
return;
}
double addDamage = newDamage + damageMap.get(player);
damageMap.put(player,addDamage);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDamageByPlayer(EntityDamageByEntityEvent e) {
if(e.getDamager() instanceof Player){
Entity entity = e.getEntity();
String customName = entity.getCustomName();
if(customName != null && Main.bossManage.isCustomNameContains(customName)){
Player p = (Player) e.getDamager();
String worldName = p.getWorld().getName();
if(!worldName.equalsIgnoreCase("teamDungee")) {
if(customName.contains("§t§e§a§m")){
e.getEntity().remove();
Bukkit.getConsoleSender().sendMessage("[世界boss-日志] 因 "+customName+" §r离开团队副本,此Boss已清理.");
return;
}
UUID Mob_uuid = e.getEntity().getUniqueId();
if(!SpawnPut.WhiteBossList.contains(Mob_uuid)){
e.getEntity().remove();
Bukkit.broadcastMessage("§6[§4公告§6] §a"+customName+"§a被卷入了异次元时空.");
return;
}
double damage = e.getDamage();
DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage));
addPlayerDamage(p,e.getDamage());
}
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDamageByProjectile(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) e.getDamager();
if (projectile.getShooter() instanceof Player) {
Entity entity = e.getEntity();
String customName = entity.getCustomName();
if (customName != null && Main.bossManage.isCustomNameContains(customName)) {
Player p = (Player) projectile.getShooter();
String worldName = p.getWorld().getName();
if (!worldName.equalsIgnoreCase("teamDungee")) {
if (customName.contains("§t§e§a§m")) {
e.getEntity().remove();
Bukkit.getConsoleSender().sendMessage("[世界boss-日志] 因 " + customName + " §r离开团队副本,此Boss已清理.");
return;
}
UUID Mob_uuid = e.getEntity().getUniqueId();
if (!SpawnPut.WhiteBossList.contains(Mob_uuid)) {
e.getEntity().remove();
Bukkit.broadcastMessage("§6[§4公告§6] §a" + customName + "§a被卷入了异次元时空.");
return;
}
double damage = e.getDamage();
DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage));
addPlayerDamage(p, e.getDamage());
}
}
}
}
}
}

View File

@ -0,0 +1,48 @@
package com.io.yaohun.worldbosshurt.util;
import com.io.yaohun.worldbosshurt.Main;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import java.util.*;
import java.util.stream.Collectors;
public class BossStack {
public static NBTTagCompound getNBT(ItemStack Equipment) {
net.minecraft.server.v1_12_R1.ItemStack nmsEquipment = CraftItemStack.asNMSCopy(Equipment);
return nmsEquipment.hasTag() && nmsEquipment.getTag() != null ? nmsEquipment.getTag() : new NBTTagCompound();
}
public static ItemStack setNBT(ItemStack item, NBTTagCompound nbtEquipment) {
net.minecraft.server.v1_12_R1.ItemStack nmsEquipment = CraftItemStack.asNMSCopy(item);
nmsEquipment.setTag(nbtEquipment);
return CraftItemStack.asBukkitCopy(nmsEquipment);
}
/*
* 增加玩家每月Boss击杀数
* */
public static ItemStack BossSlashProof(String bossName){
ItemStack item = new ItemStack(Material.PAPER,1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§c§l猎杀凭证 §f("+bossName+")");
List<String> lore = new ArrayList<>();
lore.add("§c§l★§7通过猎杀§c十万年级§7以上");
lore.add("§7灵兽§a掉落§7的凭证,§a集齐多张");
lore.add("§7可兑换§c十万年级§7以上灵环!");
lore.add("§b§l✪§7务必要妥善保管此凭证!");
meta.setLore(lore);
item.setItemMeta(meta);
NBTTagCompound nbt = getNBT(item);
nbt.setString("stex","cailiao_68");
return setNBT(item,nbt);
}
}

View File

@ -0,0 +1,101 @@
package com.io.yaohun.worldbosshurt.util;
import com.io.yaohun.worldbosshurt.Main;
import me.Demon.DemonBanK.BankAPI;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class BossUtil {
/*
* 增加玩家每月Boss击杀数
* */
public static void addMonthlyKillBoss(String name){
FileConfiguration yml = Main.plugin.getConfig();
int killAmount = yml.getInt("MonthlyKillsTop."+name);
yml.set("MonthlyKillsTop."+name,(killAmount+1));
Main.plugin.saveConfig();
}
/*
* 获取每月数据刷新时间
* */
public static String getTimeMonthly(){
FileConfiguration yml = Main.plugin.getConfig();
if(yml.getString("Timemonth") != null){
return yml.getString("Timemonth");
}
return "2022/04";
}
/*
* 判断本月数据是否刷新
* */
public static boolean isTimeMonthly(){
FileConfiguration yml = Main.plugin.getConfig();
if(!getTimeMonthly().equalsIgnoreCase(DemonAPI.getTime("yyyy/MM"))){
return true;
}
return false;
}
/*
* 结算上月累积击杀十万年次数排行
* */
public static void settlementRankingRewards() {
FileConfiguration yml = Main.plugin.getConfig();
yml.set("TimeMonth", DemonAPI.getTime("yyyy/MM")); // 设置本月时间
HashMap<String, Integer> hashMap = new HashMap<>(); // 统计击杀boss次数
if (yml.getConfigurationSection("MonthlyKillsTop") != null) {
for (String name : yml.getConfigurationSection("MonthlyKillsTop").getKeys(false)){
int killAmount = yml.getInt("MonthlyKillsTop."+name); // 获取击杀boss次数
hashMap.put(name,killAmount); // put次数
}
// yml.set("MonthlyKillsTop",null); // 清理本地数据
}
if(hashMap.size() >= 1){
// 为HashMap中数值进行降序排序
LinkedHashMap<String, Integer> sortedMap = hashMap.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
LinkedHashMap::new
));
// 遍历sortedMap中的数据
int rank = 1;
for (String name : sortedMap.keySet()){
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);
}else if(rank == 2){
Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx750");
// 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);
}else if(rank == 4){
Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx250");
// 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);
break;
}
rank++;
}
}
Main.plugin.saveConfig(); // 保存本地数据
Bukkit.getConsoleSender().sendMessage("[日志 - 世界BOSS] 成功结算上月玩家的Boss总击杀榜.");
}
}