From 76d2724786c5a25d4d46a98f03906aaec45dadcf Mon Sep 17 00:00:00 2001 From: yuyu <124714592@qq.com> Date: Sun, 7 Apr 2024 21:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86MM=E6=80=AA=E7=89=A9?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conditionCheck/ConditionCheck.java | 111 ++++++++++++++++++ .../config/condition/SpawnEntityType.java | 24 ++++ .../srwildentity/pojo/PlayerRefreshinfo.java | 54 +++++++++ target/classes/biome.yml | 63 ++++++++++ target/classes/biomeEntity.yml | 6 + target/classes/config.yml | 3 + target/classes/plugin.yml | 17 +++ 7 files changed, 278 insertions(+) create mode 100644 src/main/java/com/yuyu/srwildentity/conditionCheck/ConditionCheck.java create mode 100644 src/main/java/com/yuyu/srwildentity/config/condition/SpawnEntityType.java create mode 100644 src/main/java/com/yuyu/srwildentity/pojo/PlayerRefreshinfo.java create mode 100644 target/classes/biome.yml create mode 100644 target/classes/biomeEntity.yml create mode 100644 target/classes/config.yml create mode 100644 target/classes/plugin.yml diff --git a/src/main/java/com/yuyu/srwildentity/conditionCheck/ConditionCheck.java b/src/main/java/com/yuyu/srwildentity/conditionCheck/ConditionCheck.java new file mode 100644 index 0000000..161f938 --- /dev/null +++ b/src/main/java/com/yuyu/srwildentity/conditionCheck/ConditionCheck.java @@ -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; + } + +} diff --git a/src/main/java/com/yuyu/srwildentity/config/condition/SpawnEntityType.java b/src/main/java/com/yuyu/srwildentity/config/condition/SpawnEntityType.java new file mode 100644 index 0000000..f6e1024 --- /dev/null +++ b/src/main/java/com/yuyu/srwildentity/config/condition/SpawnEntityType.java @@ -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; + } +} diff --git a/src/main/java/com/yuyu/srwildentity/pojo/PlayerRefreshinfo.java b/src/main/java/com/yuyu/srwildentity/pojo/PlayerRefreshinfo.java new file mode 100644 index 0000000..ba82b0d --- /dev/null +++ b/src/main/java/com/yuyu/srwildentity/pojo/PlayerRefreshinfo.java @@ -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 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 getEntityList() { + return entityList; + } + + public void setEntityList(List entityList) { + this.entityList = entityList; + } + + public PlayerRefreshinfo(String playerName, Integer nums,List uuids) { + this.playerName = playerName; + this.nums = nums; + this.entityList = uuids; + } +} diff --git a/target/classes/biome.yml b/target/classes/biome.yml new file mode 100644 index 0000000..7f0c084 --- /dev/null +++ b/target/classes/biome.yml @@ -0,0 +1,63 @@ +biome: + - OCEAN + - PLAINS + - DESERT + - EXTREME_HILLS + - FOREST + - TAIGA + - SWAMPLAND + - RIVER + - HELL + - SKY + - FROZEN_OCEAN + - FROZEN_RIVER + - ICE_FLATS + - ICE_MOUNTAINS + - MUSHROOM_ISLAND + - MUSHROOM_ISLAND_SHORE + - BEACHES + - DESERT_HILLS + - FOREST_HILLS + - TAIGA_HILLS + - SMALLER_EXTREME_HILLS + - JUNGLE + - JUNGLE_HILLS + - JUNGLE_EDGE + - DEEP_OCEAN + - STONE_BEACH + - COLD_BEACH + - BIRCH_FOREST + - BIRCH_FOREST_HILLS + - ROOFED_FOREST + - TAIGA_COLD + - TAIGA_COLD_HILLS + - REDWOOD_TAIGA + - REDWOOD_TAIGA_HILLS + - EXTREME_HILLS_WITH_TREES + - SAVANNA + - SAVANNA_ROCK + - MESA + - MESA_ROCK + - MESA_CLEAR_ROCK + - VOID + - MUTATED_PLAINS + - MUTATED_DESERT + - MUTATED_EXTREME_HILLS + - MUTATED_FOREST + - MUTATED_TAIGA + - MUTATED_SWAMPLAND + - MUTATED_ICE_FLATS + - MUTATED_JUNGLE + - MUTATED_JUNGLE_EDGE + - MUTATED_BIRCH_FOREST + - MUTATED_BIRCH_FOREST_HILLS + - MUTATED_ROOFED_FOREST + - MUTATED_TAIGA_COLD + - MUTATED_REDWOOD_TAIGA + - MUTATED_REDWOOD_TAIGA_HILLS + - MUTATED_EXTREME_HILLS_WITH_TREES + - MUTATED_SAVANNA + - MUTATED_SAVANNA_ROCK + - MUTATED_MESA + - MUTATED_MESA_ROCK + - MUTATED_MESA_CLEAR_ROCK \ No newline at end of file diff --git a/target/classes/biomeEntity.yml b/target/classes/biomeEntity.yml new file mode 100644 index 0000000..349b809 --- /dev/null +++ b/target/classes/biomeEntity.yml @@ -0,0 +1,6 @@ +DESERT: #群系名称,下方标出该群系需要刷新的entity + ENTITY: [ZOMBIE,PIG_ZOMBIE] #该群系刷新的entity,具体的怪物刷新配置需要去entityConfig.yml中配置,!!注意此处的实体配置一定要在实体配置文件中存在,否则会不会刷新! + + +ROOFED_FOREST: #群系名称,下方标出该群系需要刷新的entity + ENTITY: [ZOMBIE,PIG_ZOMBIE] #该群系刷新的entity,具体的怪物刷新配置需要去entityConfig.yml中配置,!!注意此处的实体配置一定要在实体配置文件中存在,否则会不会刷新! diff --git a/target/classes/config.yml b/target/classes/config.yml new file mode 100644 index 0000000..5779930 --- /dev/null +++ b/target/classes/config.yml @@ -0,0 +1,3 @@ +RefreshTime: 10 #刷新时间,单位为s +total: 12 #每个玩家每次刷新的实体数量 +num: 4 #单次刷新的数量,每RefreshTime秒刷新的数量 \ No newline at end of file diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100644 index 0000000..00ed38d --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,17 @@ +name: SrWildEntity +version: '1.0-SNAPSHOT' +main: com.yuyu.srwildentity.SrWildEntity +description: 实体刷新插件 +authors: [Yuyu] +commands: + despawn: + usage: / + aliases: [dsp] + description: 只有op能使用的插件 + permission: op + permission-message: 你没有使用权限! + srwildentity: + usage: / + description: 只有op能使用的插件 + permission: op + permission-message: 你没有使用权限!