添加了MM怪物刷新的代码
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package com.yuyu.srwildentity.conditionCheck;
|
||||
|
||||
import com.yuyu.srwildentity.config.condition.EntityCondition;
|
||||
import com.yuyu.srwildentity.config.condition.EntitySite;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* @BelongsProject: SrWildEntity
|
||||
* @BelongsPackage: com.yuyu.srwildentity.conditionCheck
|
||||
* @FileName: ConditionCheck
|
||||
* @Author: 峰。
|
||||
* @Date: 2024/4/4-14:50
|
||||
* @Version: 1.0
|
||||
* @Description: 用于检查是否通过
|
||||
*/
|
||||
public class ConditionCheck {
|
||||
/**
|
||||
* 检查entity生成位置是否符合
|
||||
* 1.位置
|
||||
* 2.亮度
|
||||
* 3.刷新的世界的时间
|
||||
* 4.高度
|
||||
* @param world
|
||||
* @param location
|
||||
* @param entityCondition
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkEntityRefresh(World world, Location location, EntityCondition entityCondition){
|
||||
|
||||
return checkLocation(world,location,entityCondition.getEntitySite())
|
||||
&& checkLight(world,location,entityCondition.getLight())
|
||||
&& checkTimed(world,entityCondition.getStartTiming(), entityCondition.getEndTimeing())
|
||||
&& checkY(location,entityCondition.getyMax(), entityCondition.getyMin());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查刷新位置
|
||||
* @param world
|
||||
* @param location
|
||||
* @param entitySite
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkLocation(World world, Location location, EntitySite entitySite){
|
||||
|
||||
if (entitySite == null || world == null || location == null){
|
||||
throw new RuntimeException("checkLocation接收的参数错误");
|
||||
}
|
||||
|
||||
if (entitySite == EntitySite.ON_GROUND){
|
||||
Block blockAt = world.getBlockAt(location);
|
||||
return blockAt.getType().name().equals(Material.AIR.name());
|
||||
|
||||
}
|
||||
if (entitySite == EntitySite.NULL){
|
||||
return true;
|
||||
}
|
||||
if (entitySite == EntitySite.ON_WATER){
|
||||
Block blockAt = world.getBlockAt(location);
|
||||
return blockAt.getType().name().equals(Material.WATER.name());
|
||||
}
|
||||
if (entitySite == EntitySite.ON_MAGMA){
|
||||
Block blockAt = world.getBlockAt(location);
|
||||
return blockAt.getType().name().equals(Material.MAGMA.name());
|
||||
}
|
||||
if (entitySite == EntitySite.UNDER_GROUND){
|
||||
Block blockAt = world.getBlockAt(location);
|
||||
Block block = world.getBlockAt(new Location(world,location.getX(),location.getY()+1,location.getZ()));
|
||||
return blockAt.getType().name().equals(Material.AIR.name()) && block.getType().name().equals(Material.AIR.name());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查亮度
|
||||
* @param world
|
||||
* @param location
|
||||
* @param light
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkLight(World world, Location location, int light){
|
||||
|
||||
if (world == null || location == null || location == null){
|
||||
throw new RuntimeException("checkLight接收的参数错误");
|
||||
}
|
||||
|
||||
Block blockAt = world.getBlockAt(location);
|
||||
int lightLevel = blockAt.getLightLevel();
|
||||
return lightLevel <= light;//若方块位置的亮度小于或者等于设定值,则通过
|
||||
}
|
||||
|
||||
public static boolean checkTimed(World world ,long stimed,long etimed){
|
||||
if (world == null ){
|
||||
throw new RuntimeException("checkTime参数错误");
|
||||
}
|
||||
long time = world.getTime();
|
||||
|
||||
return time > stimed && time < etimed;
|
||||
}
|
||||
|
||||
public static boolean checkY(Location location,int yMax,int yMin){
|
||||
if (location == null){
|
||||
throw new RuntimeException("checkY接收参数错误");
|
||||
}
|
||||
int blockY = location.getBlockY();
|
||||
return blockY >= yMin && blockY <= yMax;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.yuyu.srwildentity.config.condition;
|
||||
|
||||
public enum SpawnEntityType {
|
||||
PROTOGENESIS(0),//mc原生实体
|
||||
MMENTITY(1),//MM怪物
|
||||
GERMENTITY(2),
|
||||
NULL(199999);//萌芽怪物
|
||||
|
||||
private final int id;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
SpawnEntityType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public static SpawnEntityType fromId(int id) {
|
||||
for (SpawnEntityType type : SpawnEntityType.values()) {
|
||||
if (type.getId() == id) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.yuyu.srwildentity.pojo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @BelongsProject: SrWildEntity
|
||||
* @BelongsPackage: com.yuyu.srwildentity.pojo
|
||||
* @FileName: PlayerRefreshinfo
|
||||
* @Author: 峰。
|
||||
* @Date: 2024/4/4-17:35
|
||||
* @Version: 1.0
|
||||
* @Description: 储存玩家相关的刷新信息
|
||||
*/
|
||||
public class PlayerRefreshinfo {
|
||||
private final String playerName;
|
||||
private Integer nums;
|
||||
private List<UUID> entityList;
|
||||
|
||||
public void addEntityList(UUID uuid){
|
||||
this.entityList.add(uuid);
|
||||
}
|
||||
|
||||
public void delEntityList(UUID uuid){
|
||||
|
||||
this.entityList.remove(uuid);
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public Integer getNums() {
|
||||
return nums;
|
||||
}
|
||||
|
||||
public void setNums(Integer nums) {
|
||||
this.nums = nums;
|
||||
}
|
||||
|
||||
public List<UUID> getEntityList() {
|
||||
return entityList;
|
||||
}
|
||||
|
||||
public void setEntityList(List<UUID> entityList) {
|
||||
this.entityList = entityList;
|
||||
}
|
||||
|
||||
public PlayerRefreshinfo(String playerName, Integer nums,List<UUID> uuids) {
|
||||
this.playerName = playerName;
|
||||
this.nums = nums;
|
||||
this.entityList = uuids;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user