diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml
index fa8838a..9148c9b 100644
--- a/.idea/libraries/lib.xml
+++ b/.idea/libraries/lib.xml
@@ -4,7 +4,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/yuyu/srwildentity/SrWildEntity.java b/src/main/java/com/yuyu/srwildentity/SrWildEntity.java
index f8609cd..bcf1609 100644
--- a/src/main/java/com/yuyu/srwildentity/SrWildEntity.java
+++ b/src/main/java/com/yuyu/srwildentity/SrWildEntity.java
@@ -4,6 +4,9 @@ import com.yuyu.srwildentity.config.ConfigManager;
import com.yuyu.srwildentity.listener.EntityRefreshListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
/**
@@ -15,9 +18,9 @@ import org.bukkit.plugin.java.JavaPlugin;
* 6.玩家周边生成的最大数量, 是否达到上限 (papi, 跟危险度相关,需要导入危险度插件,配置文件中定义最大生成等)
*/
-public final class SrWildEntity extends JavaPlugin {
+public final class SrWildEntity extends JavaPlugin implements CommandExecutor {
- private ConfigManager configManager;
+ private EntityRefreshListener entityRefreshListener;
@Override
@@ -27,23 +30,56 @@ public final class SrWildEntity extends JavaPlugin {
//TODO(注册监听类,测试)
- EntityRefreshListener entityRefreshListener = new EntityRefreshListener(this.getLogger(),configManager,this);
+ this.entityRefreshListener = new EntityRefreshListener(this.getLogger(),onload(),this);
Bukkit.getPluginManager().registerEvents(entityRefreshListener,this);
this.getCommand("despawn").setExecutor(entityRefreshListener);
+ this.getCommand("SrWildEntity").setExecutor(this::onCommand);
}
/**
*
*/
- public void onload(){
- this.configManager = new ConfigManager(this);
+ public ConfigManager onload(){
+ return new ConfigManager(this);
}
+
+
@Override
public void onDisable() {
- // Plugin shutdown logic
}
+
+ /**
+ * 重载插件
+ * @param commandSender
+ * @param command
+ * @param s
+ * @param strings
+ * @return
+ */
+ public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings){
+ if (!commandSender.isOp()){
+ getLogger().info(ChatColor.RED+"只有OP能执行此指令!");
+ }
+ if (!s.equalsIgnoreCase("srwildentity")){
+ //前缀不通过
+ return false;
+ } else {
+ if (strings.length == 0){
+ commandSender.sendMessage(ChatColor.RED+"请加上reload操作");
+ }else {
+ if (strings[0].equalsIgnoreCase("reload")){
+ getLogger().info(ChatColor.AQUA+"SrWildEntity重新读取配置文件");
+ commandSender.sendMessage(ChatColor.YELLOW+"SrWildEntity重新读取配置文件");
+ entityRefreshListener.setConfigManager(this.onload());
+
+ }
+ }
+ }
+ return false;
+ }
+
}
diff --git a/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java b/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java
index 3feb14e..0cd91a5 100644
--- a/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java
+++ b/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java
@@ -47,6 +47,7 @@ public class BiomeEntityRefreshSettings {
List entities = this.biomeEntityMap.get(biomeName);
for (String entityName : entities){
+ SpawnEntityType spawnEntityType = SpawnEntityType.fromId(config.getInt(biomeName + "." + entityName + ".type"));
EntitySite entitySite = EntitySite.fromId(config.getInt(biomeName + "." + entityName + ".site"));
int light = config.getInt(biomeName+"."+entityName+".light");
long stime = config.getLong(biomeName+"."+entityName+".startTiming");
@@ -54,7 +55,7 @@ public class BiomeEntityRefreshSettings {
int nums = config.getInt(biomeName+"."+entityName+".nums");
int yMax = config.getInt(biomeName+"."+entityName+".yMax");
int yMin = config.getInt(biomeName+"."+entityName+".yMin");
- EntityCondition entityCondition = new EntityCondition(entityName, biomeName, entitySite, light, stime,etime, nums, yMax, yMin);
+ EntityCondition entityCondition = new EntityCondition(entityName, biomeName, spawnEntityType,entitySite, light, stime,etime, nums, yMax, yMin);
plugin.getLogger().info(ChatColor.AQUA+entityCondition.toString());
diff --git a/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java b/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java
index 9b3098b..4cbf9b6 100644
--- a/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java
+++ b/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java
@@ -12,6 +12,7 @@ package com.yuyu.srwildentity.config.condition;
public class EntityCondition {
private final String entityName;//实体的名字
private final String biome;//实体刷新的群系
+ private final SpawnEntityType spawnEntityType;//实体的来源
private final EntitySite entitySite;//刷新位置
private final int light;//刷新亮度
private final long startTiming;//刷新时间
@@ -20,9 +21,10 @@ public class EntityCondition {
private final int yMax;
private final int yMin;
- public EntityCondition(String entityName, String biome, EntitySite entitySite, int light, long startTiming,long endTiming, int nums, int yMax, int yMin) {
+ public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite, int light, long startTiming, long endTiming, int nums, int yMax, int yMin) {
this.entityName = entityName;
this.biome = biome;
+ this.spawnEntityType = spawnEntityType;
this.entitySite = entitySite;
this.light = light;
this.startTiming = startTiming;
@@ -32,6 +34,10 @@ public class EntityCondition {
this.yMin = yMin;
}
+ public SpawnEntityType getEntityType() {
+ return spawnEntityType;
+ }
+
public String getEntityName() {
return entityName;
}
@@ -73,6 +79,7 @@ public class EntityCondition {
return "EntityCondition{" +
"entityName='" + entityName + '\'' +
", biome='" + biome + '\'' +
+ ", spawnEntityType=" + spawnEntityType +
", entitySite=" + entitySite +
", light=" + light +
", startTiming=" + startTiming +
diff --git a/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java b/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java
index d751ba9..4ed905f 100644
--- a/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java
+++ b/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java
@@ -1,6 +1,7 @@
package com.yuyu.srwildentity.listener;
+import com.germ.germplugin.GermPlugin;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.event.PlayerEnterTownEvent;
import com.palmergames.bukkit.towny.event.PlayerLeaveTownEvent;
@@ -9,8 +10,10 @@ import com.yuyu.srwildentity.conditionCheck.ConditionCheck;
import com.yuyu.srwildentity.config.ConfigManager;
import com.yuyu.srwildentity.config.condition.EntityCondition;
import com.yuyu.srwildentity.config.condition.EntitySite;
+import com.yuyu.srwildentity.config.condition.SpawnEntityType;
import com.yuyu.srwildentity.pojo.PlayerRefreshinfo;
-import jdk.management.resource.internal.inst.FileOutputStreamRMHooks;
+import io.lumine.xikage.mythicmobs.MythicMobs;
+import io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.*;
import org.bukkit.block.Biome;
@@ -53,6 +56,8 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
private List noRefreshPlayer;//记录不需要刷新的玩家
private Plugin plugin;
+ private MythicMobs mythicMobs;
+ private GermPlugin germPlugin;
@@ -66,6 +71,9 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
this.flag = true;
this.noRefreshPlayer = new ArrayList<>();
this.plugin = plugin;
+ //用于获取MM插件和萌芽的实例对象
+ this.mythicMobs = MythicMobs.inst();
+ this.germPlugin = GermPlugin.getPlugin();
logger.info(ChatColor.DARK_GREEN+"SrWildEntity定时任务触发");
@@ -162,6 +170,19 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}
+ public void reloadSearch(){
+ Collection extends Player> onlinePlayers = plugin.getServer().getOnlinePlayers();
+ for (Player player : onlinePlayers){
+ String name = player.getName();
+ Town town = TownyAPI.getInstance().getTown(player.getLocation());
+ if (town == null){
+ PlayerRefreshinfo playerRefreshinfo = new PlayerRefreshinfo(name, 0, new ArrayList<>());
+ refreshPlayer.put(name, playerRefreshinfo);
+ }
+ logger.info(ChatColor.GREEN+"所有在野外的玩家开始刷新实体");
+ }
+ }
+
/**
* 玩家进入城镇,
* @param event
@@ -170,11 +191,11 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
public void onPlayerInTown(PlayerEnterTownEvent event) {
if (flag){
String name = event.getPlayer().getName();
- List entityList = refreshPlayer.get(name).getEntityList();
- for (UUID uuid : entityList){
- //删除储存的实体信息
- entityUUIDToPlayer.remove(uuid);
- }
+// List entityList = refreshPlayer.get(name).getEntityList();
+// for (UUID uuid : entityList){
+// //删除储存的实体信息
+// entityUUIDToPlayer.remove(uuid);
+// }
refreshPlayer.remove(name);
logger.info(name + "开始停止怪物");
}
@@ -245,7 +266,7 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
if (flag){
LivingEntity entity = event.getEntity();
UUID uniqueId = entity.getUniqueId();
- if (entityUUIDToPlayer.containsKey(uniqueId)) {
+ if (entityUUIDToPlayer.containsKey(uniqueId) && refreshPlayer.containsKey(entityUUIDToPlayer.get(uniqueId))) {
//通过死亡实体的uuid获取玩家姓名然后删除uuid
String playerName = entityUUIDToPlayer.get(uniqueId);
refreshPlayer.get(playerName).delEntityList(uniqueId);
@@ -284,6 +305,9 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
if (flag) {
int num = configManager.getNum();//每次执行时刷新的总数
for (String name : refreshPlayer.keySet()) {
+ if (noRefreshPlayer.contains(name)){
+ continue;
+ }
int sum = 0;//用于记录此次刷新生成的总数
//获取玩家信息
Player player = plugin.getServer().getPlayer(name);
@@ -347,7 +371,21 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
//判断位置是否符合
if (ConditionCheck.checkEntityRefresh(world, location, entityCondition)) {
//通过则生成
- Entity entity = world.spawnEntity(location, EntityType.valueOf(entityCondition.getEntityName()));
+// Entity entity = world.spawnEntity(location, EntityType.valueOf(entityCondition.getEntityName()));
+ Entity entity;
+ //MC原生实体
+ if (entityCondition.getEntityType() == SpawnEntityType.PROTOGENESIS){
+ entity = world.spawnEntity(location, EntityType.valueOf(entityCondition.getEntityName()));
+ }else {
+ //刷新MM怪物
+ try {
+ entity = mythicMobs.getAPIHelper().spawnMythicMob(entityName, location);
+ } catch (InvalidMobTypeException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
logger.info(ChatColor.GOLD + "在" + x + " " + y + " " + z + "位置刷新了" + entityName);
UUID uniqueId = entity.getUniqueId();
@@ -362,7 +400,6 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}
} else {
//不刷新在地上,在定义的范围内随机高度,概率生成实体,
- int range = entityCondition.getyMax() - entityCondition.getyMin() + 1;
for (int c = 0; i
+ description: 只有op能使用的插件
+ permission: op
+ permission-message: 你没有使用权限!