测试版
This commit is contained in:
commit
a924275cdf
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
/out/
|
||||
/.idea/
|
42
pom.xml
Normal file
42
pom.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>DemonMmKillsDrop</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>public-rpg</id>
|
||||
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.lumine.xikage.mythicmobs</groupId>
|
||||
<artifactId>MythicMobs</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,40 @@
|
|||
package me.Demon.DemonMmKillsDrop.Event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class KillsMobsDropEvent extends Event {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private Player player;
|
||||
private String item_type;
|
||||
private int item_amount;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers(){
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList(){
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public KillsMobsDropEvent(Player player, String item_type, int item_amount){
|
||||
this.player = player;
|
||||
this.item_type = item_type;
|
||||
this.item_amount = item_amount;
|
||||
}
|
||||
|
||||
public Player getPlayer(){
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getItem_type(){
|
||||
return item_type;
|
||||
}
|
||||
|
||||
public int getItem_amount() {
|
||||
return item_amount;
|
||||
}
|
||||
}
|
50
src/main/java/me/Demon/DemonMmKillsDrop/KillDropAPI.java
Normal file
50
src/main/java/me/Demon/DemonMmKillsDrop/KillDropAPI.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package me.Demon.DemonMmKillsDrop;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KillDropAPI {
|
||||
|
||||
public static ItemStack getItems(String key, int amount){
|
||||
ItemStack item = new ItemStack(Material.DIAMOND,64);
|
||||
if (Main.ItemsListID.contains(key)) {
|
||||
item = Main.plugin.getConfig().getItemStack("ItemsData."+key).clone();
|
||||
item.setAmount(amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
//获取今日掉落物数量
|
||||
public static int getDayAmount(String key){
|
||||
int time = Integer.parseInt(Main.getTime("dd"));
|
||||
return Main.dropLogG.getInt("DropItems."+time+"."+key);
|
||||
}
|
||||
|
||||
//增加今日掉落物数量
|
||||
public static void addDayAmount(String key,int amount){
|
||||
int time = Integer.parseInt(Main.getTime("dd"));
|
||||
Main.dropLogG.set("DropItems."+time+"."+key,(getDayAmount(key)+amount));
|
||||
Main.saveDropLogConfig();
|
||||
}
|
||||
|
||||
public static ItemStack getItemData(String key){
|
||||
ItemStack item = new ItemStack(Material.STONE);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§c§l掉落物错误X");
|
||||
item.setItemMeta(meta);
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
if(yml.getString("ItemsData."+key) != null){
|
||||
item = yml.getItemStack("ItemsData."+key).clone();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
252
src/main/java/me/Demon/DemonMmKillsDrop/Main.java
Normal file
252
src/main/java/me/Demon/DemonMmKillsDrop/Main.java
Normal file
|
@ -0,0 +1,252 @@
|
|||
package me.Demon.DemonMmKillsDrop;
|
||||
|
||||
import me.Demon.DemonMmKillsDrop.listener.ItemBaoHu;
|
||||
import me.Demon.DemonMmKillsDrop.listener.KillMobsDrop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
public static Main plugin;
|
||||
public static double drop_double = 1.0;
|
||||
public static HashMap<String,MobsPer> pps = new HashMap<>();
|
||||
public static HashMap<String,StatsPer> statsMap = new HashMap<>();
|
||||
public static List<String> ItemsListID = new ArrayList<>();
|
||||
public static File Datafile = new File("plugins/DemonMmKillsDrop", "MobsData.yml");
|
||||
public static FileConfiguration DataG = YamlConfiguration.loadConfiguration(Datafile);
|
||||
public static void saveDataConfig(){ try { DataG.save(Datafile); } catch (IOException e) { e.printStackTrace(); } }
|
||||
public static File DropLogfile = new File("plugins/DemonMmKillsDrop", "DropItemLog.yml");
|
||||
public static FileConfiguration dropLogG = YamlConfiguration.loadConfiguration(DropLogfile);
|
||||
public static void saveDropLogConfig(){ try { dropLogG.save(DropLogfile); } catch (IOException e) { e.printStackTrace(); } }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
saveDefaultConfig();
|
||||
if(isRefreshUpdata()){
|
||||
dropLogG.set("Todaytime",getTime("yyyy/MM/dd"));
|
||||
int time = Integer.parseInt(getTime("dd"));
|
||||
Main.dropLogG.set("DropItems."+time,null);
|
||||
Main.saveDropLogConfig();
|
||||
Bukkit.getConsoleSender().sendMessage("§d[KillMobDrop] §6已清理今日所有掉落数据~");
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("§b[KillMobDrop] §a插件成功载入Server!");
|
||||
Bukkit.getConsoleSender().sendMessage("§b[KillMobDrop] §a妖魂QQ:1763917516");
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getPluginManager().registerEvents(new KillMobsDrop(),this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemBaoHu(),this);
|
||||
if(getConfig().getString("ItemsData") != null) {
|
||||
ItemsListID.addAll(getConfig().getConfigurationSection("ItemsData").getKeys(false));
|
||||
}
|
||||
for (String WorldName : getConfig().getConfigurationSection("MobsDrop").getKeys(false)){
|
||||
int amount = 0;
|
||||
for (String Mob_key : getConfig().getConfigurationSection("MobsDrop."+WorldName).getKeys(false)){
|
||||
Main.pps.put(Mob_key, new MobsPer(Mob_key));
|
||||
amount++;
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("§a- 世界: "+WorldName+" 导入: "+amount+"个怪物");
|
||||
}
|
||||
}
|
||||
public void onDisable() {
|
||||
for (String WorldName : getConfig().getConfigurationSection("MobsDrop").getKeys(false)){
|
||||
int amount = 0;
|
||||
for (String Mob_key : getConfig().getConfigurationSection("MobsDrop."+WorldName).getKeys(false)) {
|
||||
if (Main.pps.get(Mob_key) != null) {
|
||||
Main.pps.get(Mob_key).savePlayerData();
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("§a- 世界: "+WorldName+" 已保存: "+amount+"个怪物死亡数据");
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("§b[KillMobDrop] §c插件已正常关闭!");
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
|
||||
if (Command.equalsIgnoreCase("dmmdrop") && sender.isOp()) {
|
||||
if(args.length == 0){
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("§e------- ======= §6偙国掉落物 §e======= -------");
|
||||
sender.sendMessage("§2/dmmdrop open §f- §2打开掉落物仓库");
|
||||
sender.sendMessage("§2/dmmdrop stats §f- §2查看材料掉落统计");
|
||||
sender.sendMessage("§2/dmmdrop clear §f- §2清理材料掉落统计");
|
||||
sender.sendMessage("§2/dmmdrop statshh §f- §2查看灵环掉落统计");
|
||||
sender.sendMessage("§2/dmmdrop dropzf §e[倍率] §f- §2设置掉落物倍率");
|
||||
sender.sendMessage("§2/dmmdrop give §e[物品] §2<数量> {玩家} §f- §2给予玩家物品");
|
||||
sender.sendMessage("§e------- ======= §6偙国掉落物 §e======= -------");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("save")){
|
||||
for (String WorldName : getConfig().getConfigurationSection("MobsDrop").getKeys(false)) {
|
||||
for (String Mob_key : getConfig().getConfigurationSection("MobsDrop." + WorldName).getKeys(false)) {
|
||||
if (Main.pps.get(Mob_key) != null) {
|
||||
Main.pps.get(Mob_key).savePlayerData();
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§7[§c消息§7] §a成功手动保存数据.");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("clear")){
|
||||
FileConfiguration yml = Main.dropLogG;
|
||||
yml.set("DropItems",null);
|
||||
Main.saveDropLogConfig();
|
||||
sender.sendMessage("§7[§c消息§7] §a成功清理历史掉落数据。");
|
||||
}
|
||||
if(args.length == 2 && args[0].equalsIgnoreCase("dropzf")){
|
||||
drop_double = Double.parseDouble(args[1]);
|
||||
sender.sendMessage("§7[§c消息§7] §a当前服务器掉落率增幅为: §e"+((drop_double-1)*100)+"%");
|
||||
}
|
||||
//dmmdrop give [key] [amount] <player>
|
||||
if(args.length == 4 && args[0].equalsIgnoreCase("give")){
|
||||
if (ItemsListID.contains(args[1])) {
|
||||
ItemStack item = getConfig().getItemStack("ItemsData."+args[1]).clone();
|
||||
int amount;
|
||||
try {
|
||||
amount = Integer.parseInt(args[2]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("§7[§6掉落库§7] §c数量参数必须是整数");
|
||||
return true;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
if (player == null) {
|
||||
sender.sendMessage("§7[§6掉落库§7] §c目标玩家不在线无法给予");
|
||||
return true;
|
||||
}
|
||||
item.setAmount(amount);
|
||||
player.getInventory().addItem(item);
|
||||
sender.sendMessage("§7[§6掉落库§7] §f成功给予玩家"+ player.getName()+" "+args[1]+" "+amount+"个");
|
||||
}else{
|
||||
sender.sendMessage("§7[§6掉落库§7] §c物品不存在.");
|
||||
}
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("open")){
|
||||
OpenItemsGui((Player) sender);
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("stats")){
|
||||
FileConfiguration yml = Main.dropLogG;
|
||||
List<String> keyId_List = new ArrayList<>();
|
||||
int day = 0;
|
||||
if(yml.getConfigurationSection("DropItems") != null) {
|
||||
for (String time : yml.getConfigurationSection("DropItems").getKeys(false)) {
|
||||
if (yml.getConfigurationSection("DropItems." + time) != null) {
|
||||
for (String keyId : yml.getConfigurationSection("DropItems." + time).getKeys(false)) {
|
||||
if (!keyId_List.contains(keyId)) {
|
||||
keyId_List.add(keyId);
|
||||
}
|
||||
int amount = yml.getInt("DropItems." + time + "." + keyId);
|
||||
if (Main.statsMap.get(keyId) == null) {
|
||||
Main.statsMap.put(keyId, new StatsPer(keyId));
|
||||
}
|
||||
Main.statsMap.get(keyId).addAmount(amount);
|
||||
}
|
||||
}
|
||||
day++;
|
||||
}
|
||||
sender.sendMessage("§a战争领域§e[" + day + "天]§a内的掉落物数据统计: ");
|
||||
for (int i = 0; i < keyId_List.size(); i++) {
|
||||
String keyId = keyId_List.get(i);
|
||||
int amount = Main.statsMap.get(keyId).getAmount();
|
||||
sender.sendMessage("§7[§b" + keyId + "§7] §f§l- §a" + amount + "个");
|
||||
}
|
||||
sender.sendMessage("§f[§c消息§f] §a目前服务器掉落物总计: §e" + keyId_List.size() + "样");
|
||||
Main.statsMap.clear();
|
||||
}
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("reload")){
|
||||
reloadConfig();
|
||||
Main.pps.clear();
|
||||
for (String WorldName : getConfig().getConfigurationSection("MobsDrop").getKeys(false)){
|
||||
int amount = 0;
|
||||
for (String Mob_key : getConfig().getConfigurationSection("MobsDrop."+WorldName).getKeys(false)){
|
||||
Main.pps.put(Mob_key, new MobsPer(Mob_key));
|
||||
amount++;
|
||||
}
|
||||
sender.sendMessage("§a- 世界: "+WorldName+" 导入: "+amount+"个怪物");
|
||||
}
|
||||
sender.sendMessage("§7[§c消息§7] §a重载配置完成.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int getRandomInt(int max, int min) {
|
||||
return (int) (Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
public static boolean itemIsNull(ItemStack item){
|
||||
return item == null || item.getType() == Material.AIR;
|
||||
}
|
||||
public static boolean itemIsLore(ItemStack item){ return item.getItemMeta().getLore()==null; }
|
||||
public static String getTime(String Format){
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
SimpleDateFormat datatime = new SimpleDateFormat(Format);
|
||||
return datatime.format(date);
|
||||
}
|
||||
|
||||
|
||||
public void OpenItemsGui(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null,54,"§i§r§m§i§r掉落物集成库");
|
||||
for (String key : getConfig().getConfigurationSection("ItemsData").getKeys(false)) {
|
||||
ItemStack item = getConfig().getItemStack("ItemsData." + key).clone();
|
||||
item.setAmount(1);
|
||||
inv.addItem(item);
|
||||
}
|
||||
p.openInventory(inv);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e){
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if(e.getInventory() != null && "§i§r§m§i§r掉落物集成库".equalsIgnoreCase(e.getInventory().getTitle())){
|
||||
e.setCancelled(true);
|
||||
if(e.getRawSlot() >= 0 && e.getRawSlot() < 54){
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if(!itemIsNull(item)) {
|
||||
if(e.getClick() == ClickType.LEFT) {
|
||||
item.setAmount(1);
|
||||
p.getInventory().addItem(item);
|
||||
}else if(e.getClick() == ClickType.RIGHT){
|
||||
item.setAmount(10);
|
||||
p.getInventory().addItem(item);
|
||||
}else if(e.getClick() == ClickType.MIDDLE){
|
||||
item.setAmount(64);
|
||||
p.getInventory().addItem(item);
|
||||
}
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG,1,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//獲取上次每周數據刷新的時間 年/月/日
|
||||
public static String getTodaytime() {
|
||||
FileConfiguration yml = Main.dropLogG;
|
||||
if(yml.getString("Todaytime") != null){
|
||||
return yml.getString("Todaytime");
|
||||
}
|
||||
return "2023/06/24";
|
||||
}
|
||||
|
||||
//判斷是否今天是數據刷新的壹天
|
||||
public static boolean isRefreshUpdata() {
|
||||
if(!getTodaytime().equalsIgnoreCase(getTime("yyyy/MM/dd"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
32
src/main/java/me/Demon/DemonMmKillsDrop/MobsPer.java
Normal file
32
src/main/java/me/Demon/DemonMmKillsDrop/MobsPer.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package me.Demon.DemonMmKillsDrop;
|
||||
|
||||
public class MobsPer {
|
||||
|
||||
private String Mobkey;
|
||||
private int killAmount;
|
||||
|
||||
public MobsPer(String Mob_key){
|
||||
this.Mobkey = Mob_key;
|
||||
this.killAmount = Main.DataG.getInt("Kill_Mobs_Data."+Mobkey);;
|
||||
|
||||
}
|
||||
|
||||
public void savePlayerData(){
|
||||
Main.DataG.set("Kill_Mobs_Data."+Mobkey,getKillAmount());
|
||||
Main.saveDataConfig();
|
||||
}
|
||||
|
||||
//小麦
|
||||
public int getKillAmount(){
|
||||
return this.killAmount;
|
||||
}
|
||||
public void addKillAmount(int amount){
|
||||
this.killAmount += amount;
|
||||
}
|
||||
public void takeKillAmount(int amount){
|
||||
this.killAmount -= amount;
|
||||
}
|
||||
public void setKillAmount(int amount){
|
||||
this.killAmount = amount;
|
||||
}
|
||||
}
|
20
src/main/java/me/Demon/DemonMmKillsDrop/StatsPer.java
Normal file
20
src/main/java/me/Demon/DemonMmKillsDrop/StatsPer.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package me.Demon.DemonMmKillsDrop;
|
||||
|
||||
public class StatsPer {
|
||||
|
||||
private String DropKey;
|
||||
private int Amount;
|
||||
|
||||
public StatsPer(String DropKey){
|
||||
this.DropKey = DropKey;
|
||||
this.Amount = 0;
|
||||
|
||||
}
|
||||
|
||||
public int getAmount(){
|
||||
return this.Amount;
|
||||
}
|
||||
public void addAmount(int amount){
|
||||
this.Amount += amount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package me.Demon.DemonMmKillsDrop.listener;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.MythicMobs;
|
||||
import me.Demon.DemonMmKillsDrop.manager.DamageManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ItemBaoHu implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPickupItem(PlayerPickupItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Item item = event.getItem();
|
||||
if (item.hasMetadata("owner") && item.hasMetadata("time")) {
|
||||
String u = null;
|
||||
long time = 0L;
|
||||
for (MetadataValue metadataValue : item.getMetadata("owner")) {
|
||||
u = metadataValue.asString();
|
||||
}
|
||||
for (MetadataValue metadataValue : item.getMetadata("time")) {
|
||||
time = metadataValue.asLong();
|
||||
}
|
||||
if (u == null || time == 0) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(u);
|
||||
if (time + (1000L * 10) > System.currentTimeMillis()) {
|
||||
if (!player.getUniqueId().equals(uuid)) {
|
||||
Vector v = player.getLocation().toVector().subtract(item.getLocation().toVector()).normalize().multiply(1).setY(0.1);
|
||||
player.setVelocity(v);
|
||||
player.sendMessage("§7[§6掉落保护§7] §f你无法拾取此物品!!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
if (!(damager instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (!MythicMobs.inst().getAPIHelper().isMythicMob(entity) || !(entity instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
double damage = event.getDamage();
|
||||
if (damage > livingEntity.getHealth()) {
|
||||
damage = livingEntity.getHealth();
|
||||
}
|
||||
DamageManager.damage(damager.getUniqueId(), entity.getUniqueId(), damage);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package me.Demon.DemonMmKillsDrop.listener;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter;
|
||||
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import me.Demon.DemonMmKillsDrop.Event.KillsMobsDropEvent;
|
||||
import me.Demon.DemonMmKillsDrop.KillDropAPI;
|
||||
import me.Demon.DemonMmKillsDrop.Main;
|
||||
import me.Demon.DemonMmKillsDrop.manager.DamageManager;
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KillMobsDrop implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onkills(MythicMobDeathEvent e) {
|
||||
if (e.getKiller() instanceof Player) {
|
||||
Player p = (Player) e.getKiller();
|
||||
if (e.getEntity().getCustomName() != null) {
|
||||
//获取玩家所在世界名
|
||||
String worldName = p.getWorld().getName();
|
||||
//获取怪物的MM代号
|
||||
String mobsKey = e.getMob().getType().getInternalName();
|
||||
if (Main.pps.get(mobsKey) != null) {
|
||||
Main.pps.get(mobsKey).addKillAmount(1);
|
||||
//获取这只魂兽当前被击杀次数
|
||||
int amount = Main.pps.get(mobsKey).getKillAmount();
|
||||
int fujia_gailv = 0;
|
||||
if (amount >= 20) {
|
||||
fujia_gailv = amount;
|
||||
}
|
||||
boolean isdrop = false;
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
for (String DropKey : yml.getConfigurationSection("MobsDrop." + worldName + "." + mobsKey).getKeys(false)) {
|
||||
int gailv = yml.getInt("MobsDrop." + worldName + "." + mobsKey + "." + DropKey);
|
||||
double newgailv = (gailv * 0.7) * Main.drop_double;
|
||||
if (p.hasPermission("vip2.use")) {
|
||||
newgailv = (gailv * 0.85) * Main.drop_double;
|
||||
}
|
||||
int random = Main.getRandomInt(1000, 1);
|
||||
double addDrop = 1.0;
|
||||
if (random <= ((newgailv + fujia_gailv) * addDrop)) {
|
||||
isdrop = true;
|
||||
if (DropKey.contains("#")) {
|
||||
String ItemsKey = DropKey.split("#")[0];
|
||||
ItemStack dropItem = KillDropAPI.getItemData(ItemsKey);
|
||||
int max = Integer.parseInt(DropKey.split("#")[1]);
|
||||
int d_amount = Main.getRandomInt(max, 1);
|
||||
dropItem.setAmount(d_amount);
|
||||
itemStacks.add(dropItem);
|
||||
// 事件
|
||||
KillDropAPI.addDayAmount(ItemsKey, d_amount);
|
||||
KillsMobsDropEvent event = new KillsMobsDropEvent(p, ItemsKey, d_amount);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
} else {
|
||||
// 将东西发送至队长背包
|
||||
ItemStack dropItem = KillDropAPI.getItemData(DropKey);
|
||||
itemStacks.add(dropItem);
|
||||
// 事件
|
||||
KillDropAPI.addDayAmount(DropKey, 1);
|
||||
KillsMobsDropEvent event = new KillsMobsDropEvent(p, DropKey, 1);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isdrop) {
|
||||
if (p.hasPermission("vip2.use")) {
|
||||
DemonAPI.sendActionBar(p, "§6§l§k|||§r §b!副本爆率增幅生效中! §6§l§k|||§r");
|
||||
}
|
||||
Main.pps.get(mobsKey).setKillAmount(0);
|
||||
UUID entityUUID = e.getMob().getUniqueId();
|
||||
Map<UUID, Double> map = DamageManager.getEntityDamageMap(entityUUID);
|
||||
List<Map.Entry<UUID, Double>> list = getEntries(map);
|
||||
Location location = BukkitAdapter.adapt(e.getMob().getLocation());
|
||||
if (!list.isEmpty()) {
|
||||
UUID one = list.get(0).getKey();
|
||||
itemStacks.forEach(i -> {
|
||||
Item item = location.getWorld().dropItem(location, i);
|
||||
item.setPickupDelay(0);
|
||||
item.setMetadata("owner", new FixedMetadataValue(Main.plugin, one.toString()));
|
||||
item.setMetadata("time", new FixedMetadataValue(Main.plugin, System.currentTimeMillis()));
|
||||
item.setVelocity(new Vector(getRandomDouble(0.5), getRandomDouble(0.1), getRandomDouble(0.5)));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Map.Entry<UUID, Double>> getEntries(Map<UUID, Double> map) {
|
||||
List<Map.Entry<UUID, Double>> list = new ArrayList<>(map.entrySet());
|
||||
list.sort((arg0, arg1) -> {
|
||||
if (arg0.getValue() > arg1.getValue()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private double getRandomDouble(double max) {
|
||||
int pow = (int) Math.pow(10, 2);
|
||||
return Math.floor((Math.random() * (max - 0.01) + 0.01) * pow) / pow;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package me.Demon.DemonMmKillsDrop.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DamageManager {
|
||||
|
||||
private static Map<UUID, Map<UUID, Double>> damageMap = new HashMap<>();
|
||||
|
||||
public static Map<UUID, Map<UUID, Double>> getDamageMap() {
|
||||
return damageMap;
|
||||
}
|
||||
|
||||
public static Map<UUID, Double> getEntityDamageMap(UUID entity) {
|
||||
Map<UUID, Double> map = new HashMap<>();
|
||||
damageMap.forEach((p, m) -> {
|
||||
if (m.containsKey(entity)) {
|
||||
map.put(p, m.get(entity));
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
public static double getDamage(UUID player, UUID entity) {
|
||||
if (!damageMap.containsKey(player)) {
|
||||
return 0;
|
||||
}
|
||||
return damageMap.get(player).getOrDefault(entity, (double) 0);
|
||||
}
|
||||
|
||||
public static void damage(UUID player, UUID entity, double damage) {
|
||||
Map<UUID, Double> map = damageMap.getOrDefault(player, new HashMap<>());
|
||||
map.put(entity, map.getOrDefault(entity, (double) 0) + damage);
|
||||
damageMap.put(player, map);
|
||||
}
|
||||
|
||||
public static void clearEntity(UUID entity) {
|
||||
damageMap.forEach((p, map)->{
|
||||
if (map.containsKey(entity)) {
|
||||
map.remove(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
2
src/main/resources/DropItemLog.yml
Normal file
2
src/main/resources/DropItemLog.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
Todaytime: 2021/03/31
|
||||
DropItems: {}
|
1
src/main/resources/MobsData.yml
Normal file
1
src/main/resources/MobsData.yml
Normal file
|
@ -0,0 +1 @@
|
|||
Kill_Mobs_Data: {}
|
5
src/main/resources/config.yml
Normal file
5
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
# 若全服玩家击杀该 怪物 总次数达到50次 该怪物的战利品掉率增加 击杀次数-50 = 附加概率
|
||||
# 如果在击杀次数积累过程中有人掉落 则次数重置
|
||||
# 材料后面的数字为默认掉率 比例为 1000:1
|
||||
MobsDrop: {}
|
||||
ItemsData: {}
|
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: DemonMmKillsDrop
|
||||
main: me.Demon.DemonMmKillsDrop.Main
|
||||
version: 1.4.9
|
||||
commands:
|
||||
dmmdrop:
|
Loading…
Reference in New Issue
Block a user