添加了MM怪物刷新的代码

This commit is contained in:
yuyu 2024-04-07 21:03:27 +08:00
parent 84859f7fe6
commit f2e77098e9
8 changed files with 249 additions and 39 deletions

View File

@ -4,7 +4,9 @@
<root url="file://$PROJECT_DIR$/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/GermPlugin-Snapshot-4.3.9-20.jar!/" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
</library>
</component>

124
.idea/uiDesigner.xml generated Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

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

View File

@ -47,6 +47,7 @@ public class BiomeEntityRefreshSettings {
List<String> 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());

View File

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

View File

@ -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<String> 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<UUID> entityList = refreshPlayer.get(name).getEntityList();
for (UUID uuid : entityList){
//删除储存的实体信息
entityUUIDToPlayer.remove(uuid);
}
// List<UUID> 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<nums && c < 10 && sum <= num &&
playerRefreshinfo.getEntityList().size() < configManager.getTotal();
c++) {
@ -376,7 +413,19 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
//判断位置是否符合
if (ConditionCheck.checkEntityRefresh(world, location, entityCondition)) {
//通过则生成
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();
@ -392,24 +441,6 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}
}
// Location location = new Location(world, x, y + 1, z);
//
// //判断位置是否符合
// if (ConditionCheck.checkEntityRefresh(world, location, entityCondition)) {
// //通过则生成
// Entity entity = world.spawnEntity(location, EntityType.valueOf(entityCondition.getEntityName()));
// logger.info(ChatColor.GOLD+""+x+" "+y+" "+z+"位置刷新了"+entityName);
// UUID uniqueId = entity.getUniqueId();
//
// //存入玩家对应的刷新的实体集合便于寻找
// entityUUIDToPlayer.put(uniqueId,name);
//
// //存入
// playerRefreshinfo.addEntityList(uniqueId);
//
// sum++;
//
// }
}
}
}
@ -425,6 +456,7 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
return noRefreshPlayer;
}
public void setConfigManager(ConfigManager configManager) {
this.configManager = configManager;
}
}

View File

@ -1,5 +1,6 @@
DESERT:
ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物,不能为空!
site: 1 #刷新位置,数字代表不同的刷新位置
light: 15 #刷新亮度
startTiming: 0 #刷新怪物的时间注意这里需要用mc中的时间格式来表示而不是现实中的时间
@ -9,6 +10,7 @@ DESERT:
yMin: 60 #最小刷新高度
ROOFED_FOREST:
ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物
site: 1 #刷新位置,数字代表不同的刷新位置
light: 15 #刷新亮度
startTiming: 0 #刷新怪物的时间注意这里需要用mc中的时间格式来表示而不是现实中的时间
@ -18,6 +20,7 @@ ROOFED_FOREST:
yMin: 60 #最小刷新高度
PIG_ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物
site: 1 #刷新位置,数字代表不同的刷新位置
light: 15 #刷新亮度
startTiming: 0 #刷新怪物的时间注意这里需要用mc中的时间格式来表示而不是现实中的时间

View File

@ -10,3 +10,8 @@ commands:
description: 只有op能使用的插件
permission: op
permission-message: 你没有使用权限!
srwildentity:
usage: /<command>
description: 只有op能使用的插件
permission: op
permission-message: 你没有使用权限!