1.5.6
This commit is contained in:
commit
8cef5e004f
47
pom.xml
Normal file
47
pom.xml
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?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>com.yaohun.main</groupId>
|
||||
<artifactId>DemonMmKillsMoney</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>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>2.2.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.lumine.xikage.mythicmobs</groupId>
|
||||
<artifactId>MythicMobs</artifactId>
|
||||
<version>4.11.0-008</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.serverct.ersha.jd</groupId>
|
||||
<artifactId>AttributePlus</artifactId>
|
||||
<version>2.3.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
71
src/main/java/me/Demon/DemonMmKillsMoney/Main.java
Normal file
71
src/main/java/me/Demon/DemonMmKillsMoney/Main.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package me.Demon.DemonMmKillsMoney;
|
||||
|
||||
import me.Demon.DemonMmKillsMoney.data.KillEcoData;
|
||||
import me.Demon.DemonMmKillsMoney.listener.KillMobs;
|
||||
import me.Demon.DemonMmKillsMoney.manage.DataManager;
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
public static Main plugin;
|
||||
private static DataManager dataManager;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
saveDefaultConfig();
|
||||
dataManager = new DataManager();
|
||||
getServer().getPluginManager().registerEvents(new KillMobs(dataManager), plugin);
|
||||
Bukkit.getConsoleSender().sendMessage("§b[击杀掉金币] §f插件成功载入Server!");
|
||||
Bukkit.getConsoleSender().sendMessage("§b[击杀掉金币] §f妖魂: §a1763917516");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getDataManager().saveDataManger();
|
||||
Bukkit.getConsoleSender().sendMessage("§b[击杀掉金币] §c插件已正常关闭!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
|
||||
if (Command.equalsIgnoreCase("dmmkm") && sender.isOp()) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("§e------- ======= §6击杀掉落金币 §e======= -------");
|
||||
sender.sendMessage("§2/dmmkm stats §f- §2查看经济数据");
|
||||
sender.sendMessage("§2/dmmkm reload §f- §2重载配置文件");
|
||||
sender.sendMessage("§e------- ======= §6击杀掉落金币 §e======= -------");
|
||||
sender.sendMessage("");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("reload")){
|
||||
getDataManager().reloadDataManger();
|
||||
DemonAPI.sendMessage(sender,"配置文件已重载.");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("stats")){
|
||||
getDataManager().saveDataManger();
|
||||
FileConfiguration yml = getConfig();
|
||||
int day = 0;
|
||||
double totalMoney = 0;
|
||||
if(yml.getConfigurationSection("DropLog") != null) {
|
||||
for (String time : yml.getConfigurationSection("DropLog").getKeys(false)) {
|
||||
double money = yml.getDouble("DropLog." + time);
|
||||
totalMoney = totalMoney + money;
|
||||
day++;
|
||||
}
|
||||
}
|
||||
DemonAPI.sendMessage(sender,"据统计§e[" + day + "天]§a内通过击杀掉落金币总计: §6§l"+(int) totalMoney+"金币");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static DataManager getDataManager() {
|
||||
return dataManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package me.Demon.DemonMmKillsMoney.data;
|
||||
|
||||
import me.Demon.DemonPlugin.Util.RandomUtil;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class KillEcoData {
|
||||
|
||||
private HashMap<String,valueData> dataHashMap = new HashMap<>();
|
||||
|
||||
public KillEcoData(String worldName,ConfigurationSection configurationSection){
|
||||
ConfigurationSection section = configurationSection.getConfigurationSection(worldName);
|
||||
for (String key : section.getKeys(false)) {
|
||||
dataHashMap.put(key,new valueData(section.getString(key)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 判断这个怪物是否能掉落金币
|
||||
public boolean isKillsMobsDropExit(String customName){
|
||||
for (String mmName : dataHashMap.keySet()){
|
||||
if(customName.contains(mmName)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public double getRandonValue(String customName){
|
||||
for (String mmName : dataHashMap.keySet()){
|
||||
if(customName.contains(mmName)){
|
||||
valueData valueData = this.dataHashMap.get(mmName);
|
||||
return valueData.getRandomValue();
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public class valueData {
|
||||
private double min;
|
||||
private double max;
|
||||
public valueData(String string){
|
||||
if(string.contains("~")) {
|
||||
String[] split = string.split("~");
|
||||
min = Double.parseDouble(split[0]);
|
||||
max = Double.parseDouble(split[1]);
|
||||
} else {
|
||||
min = Double.parseDouble(string);
|
||||
max = Double.parseDouble(string);
|
||||
}
|
||||
}
|
||||
|
||||
public double getRandomValue() {
|
||||
double randomValue = RandomUtil.getRandomDouble(min, max, 2) / 100;
|
||||
return Math.round(randomValue * 100) / 100.0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package me.Demon.DemonMmKillsMoney.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class KillsMobsMoneyEvent extends Event {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private Player player;
|
||||
private Entity target;
|
||||
private double dropMoney;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {return handlers;}
|
||||
|
||||
public static HandlerList getHandlerList(){return handlers;}
|
||||
|
||||
public KillsMobsMoneyEvent(Player player, Entity target, double dropMoney) {
|
||||
this.player = player;
|
||||
this.target = target;
|
||||
this.dropMoney = dropMoney;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public double getDropMoney() {
|
||||
return dropMoney;
|
||||
}
|
||||
}
|
121
src/main/java/me/Demon/DemonMmKillsMoney/listener/KillMobs.java
Normal file
121
src/main/java/me/Demon/DemonMmKillsMoney/listener/KillMobs.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
package me.Demon.DemonMmKillsMoney.listener;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import me.Demon.DemonMmKillsMoney.data.KillEcoData;
|
||||
import me.Demon.DemonMmKillsMoney.Main;
|
||||
import me.Demon.DemonMmKillsMoney.event.KillsMobsMoneyEvent;
|
||||
import me.Demon.DemonMmKillsMoney.manage.DataManager;
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.Demon.DemonPlugin.Util.AreaType;
|
||||
import me.Demon.DemonPlugin.Util.RandomUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.serverct.ersha.jd.AttributeAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KillMobs implements Listener {
|
||||
|
||||
private DataManager dataManager;
|
||||
private String attributeKey = "猎金达人:";
|
||||
|
||||
public KillMobs(DataManager dataManager) {
|
||||
this.dataManager = dataManager;
|
||||
if(DemonAPI.getAreaType() == AreaType.TaiWan){
|
||||
attributeKey = "獵金達人:";
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onkills(MythicMobDeathEvent e){
|
||||
if (e.getKiller() instanceof Player) {
|
||||
Player player = (Player)e.getKiller();
|
||||
Entity entity = e.getEntity();
|
||||
if (entity.getCustomName() != null) {
|
||||
// 击杀掉落金币概率为50%
|
||||
if(DemonAPI.getRandomInt(100,1) >= 50) {
|
||||
// 获取玩家所在世界名
|
||||
World world = player.getWorld();
|
||||
String worldName = world.getName();
|
||||
// 判断这个世界是否会掉落金币
|
||||
if(dataManager.isWorldDataExit(worldName)){
|
||||
// 获取死亡MM怪的自定义名字并去掉颜色符号
|
||||
String customName = entity.getCustomName().replaceAll("§[a-zA-Z0-9]", "");
|
||||
KillEcoData killEcoData = dataManager.getEcoData(worldName);
|
||||
// 判断这个怪是否会掉落金币
|
||||
if(killEcoData.isKillsMobsDropExit(customName)){
|
||||
// 获取本次击杀掉落多少金币
|
||||
double value = killEcoData.getRandonValue(customName);
|
||||
if (AttributeAPI.getAttrData(player).getAttributeValue().get(attributeKey) != null) {
|
||||
value = value * (1 + (AttributeAPI.getAttrData(player).getAttributeValue().get(attributeKey) / 100.0D));
|
||||
}
|
||||
DemonAPI.giveMoney(player.getUniqueId(),value);
|
||||
dataManager.addTodayGetGold(value);
|
||||
|
||||
// ************ 疑似卡顿内容~**********
|
||||
Item item = world.dropItemNaturally(entity.getLocation(),itemMoney(player.getName(),value));
|
||||
item.setPickupDelay(0);
|
||||
item.setMetadata("goldLoot", new FixedMetadataValue(Main.plugin, System.currentTimeMillis()));
|
||||
// **3秒(60 ticks)后删除物品**
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (item.isValid() && !item.isDead()) {
|
||||
item.remove();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(Main.plugin, 60L); // 60 ticks = 3秒
|
||||
|
||||
// 玩家点券月卡进行了关联
|
||||
KillsMobsMoneyEvent event = new KillsMobsMoneyEvent(player,entity,value);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Item item = event.getItem();
|
||||
if (item.hasMetadata("goldLoot")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
ItemStack stack = item.getItemStack();
|
||||
if(!DemonAPI.itemIsNull(stack)) {
|
||||
if (item.getItemStack().getType() == Material.GOLD_NUGGET) {
|
||||
event.setCancelled(true);
|
||||
event.getItem().remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack itemMoney(String playerName,double money){
|
||||
ItemStack item = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§p§i§c§k§e$"+String.format("%.1f",money)+" §7[§a"+playerName+"§7]");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§8#money");
|
||||
lore.add("§8"+ RandomUtil.getRandomInt(5000,500000));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package me.Demon.DemonMmKillsMoney.manage;
|
||||
|
||||
import me.Demon.DemonMmKillsMoney.data.KillEcoData;
|
||||
import me.Demon.DemonMmKillsMoney.Main;
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
private double todayGetGold = 0.0;
|
||||
private HashMap<String, KillEcoData> ecoDataMap = new HashMap<>();
|
||||
|
||||
public DataManager() {
|
||||
loadTodayDropLog();
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
ConfigurationSection section = yml.getConfigurationSection("MoneyData");
|
||||
if(section == null){return;}
|
||||
for (String worldName : section.getKeys(false)) {
|
||||
ecoDataMap.put(worldName, new KillEcoData(worldName,section));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTodayDropLog(){
|
||||
File file = new File(Main.plugin.getDataFolder(),"DropLog.yml");
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
todayGetGold = configuration.getDouble("DropLog."+DemonAPI.getTime("dd"));
|
||||
}
|
||||
|
||||
public void reloadDataManger(){
|
||||
Main.plugin.reloadConfig();
|
||||
Main.plugin.saveConfig();
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
ConfigurationSection section = yml.getConfigurationSection("MoneyData");
|
||||
if(section == null){return;}
|
||||
for (String worldName : section.getKeys(false)) {
|
||||
ecoDataMap.put(worldName, new KillEcoData(worldName,section));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDataManger(){
|
||||
File file = new File(Main.plugin.getDataFolder(),"DropLog.yml");
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
String dd = DemonAPI.getTime("dd");
|
||||
configuration.set("DropLog."+dd,null);
|
||||
configuration.set("DropLog."+dd,todayGetGold);
|
||||
try {
|
||||
configuration.save(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addTodayGetGold(double money) {
|
||||
this.todayGetGold += money;
|
||||
}
|
||||
|
||||
public boolean isWorldDataExit(String worldName) {
|
||||
if(ecoDataMap.containsKey(worldName)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public KillEcoData getEcoData(String worldName) {
|
||||
return ecoDataMap.get(worldName);
|
||||
}
|
||||
}
|
34
src/main/resources/config.yml
Normal file
34
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
MoneyData:
|
||||
#<世界名>:
|
||||
# 怪物名包含内容: 最小金币~最大金币
|
||||
lrzs:
|
||||
"✪十年灵兽✪": 100~500
|
||||
"✪百年灵兽✪": 500~1000
|
||||
"✪千年灵兽✪": 1000~8000
|
||||
"✪万年灵兽✪": 8000~25000
|
||||
xdsl:
|
||||
"✪十年灵兽✪": 100~500
|
||||
"✪百年灵兽✪": 500~1000
|
||||
"✪千年灵兽✪": 1000~8000
|
||||
"✪万年灵兽✪": 10000~50000
|
||||
jhby:
|
||||
"✪千年灵兽✪": 2000~6000
|
||||
"✪万年灵兽✪": 8000~40000
|
||||
bhlyy:
|
||||
"✪珍贵仙草✪": 5000~100000
|
||||
"✪万年灵兽✪": 10000~50000
|
||||
slds:
|
||||
"❃异变灵兽❃": 15000~50000
|
||||
"✪灵帝✪": 15000~50000
|
||||
"✪灵圣✪": 20000~50000
|
||||
whd:
|
||||
"❁器魂殿❁守卫器师": 15000~50000
|
||||
"❁器魂殿❁巡逻器师": 20000~50000
|
||||
"❁器魂殿❁殿堂器师": 25000~50000
|
||||
"❁器魂殿❁精英器师": 30000~60000
|
||||
fsjk:
|
||||
"✪封神九考✪怒血刺蟹": 10000~60000
|
||||
"考守护者": 30000~80000
|
||||
shenyu:
|
||||
"✪神域灵兽✪": 20000~60000
|
||||
"❁神域❁": 10000~80000
|
9
src/main/resources/plugin.yml
Normal file
9
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
name: DemonMmKillsMoney
|
||||
main: me.Demon.DemonMmKillsMoney.Main
|
||||
version: 1.5.6
|
||||
depend:
|
||||
- DemonAPI
|
||||
- AttributePlus
|
||||
- MythicMobs
|
||||
commands:
|
||||
dmmkm:
|
Loading…
Reference in New Issue
Block a user