Bukkit 1.12.1 MythicMobs 禁止怪物跟随玩家离开出生点
你可以使用以下代码来实现禁止怪物跟随玩家离开出生地图:
import com.gmail.woodyc40.mccapturespawn.CaptureSpawnUtil;
import com.gmail.woodyc40.mccapturespawn.RegionData;
import com.gmail.woodyc40.mccapturespawn.RegionDataStore;
import net.elseland.xikage.MythicMobs.MythicMobs;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class NoFollowOutsideSpawn extends JavaPlugin implements Listener {
private RegionData spawnRegion;
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
// 获取出生地点
World world = Bukkit.getWorld("your_world_name");
Location spawnLocation = new Location(world, x, y, z);
// 获取出生地图区域
RegionDataStore regionDataStore = MythicMobs.inst().getAPIHelper().getRegionDataStore();
this.spawnRegion = regionDataStore.getRegionData(spawnLocation);
if (this.spawnRegion == null) {
getLogger().warning("Spawn region data not found!");
return;
}
getLogger().info("NoFollowOutsideSpawn has been enabled.");
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
Entity entity = event.getEntity();
// 检查实体是否为生物
if (entity instanceof Mob) {
Mob mob = (Mob) entity;
// 检查实体是否在出生地图区域外
if (!CaptureSpawnUtil.isInRegion(mob.getLocation(), this.spawnRegion)) {
mob.setTarget(null); // 禁止怪物跟随玩家
}
}
}
}
请注意,你需要将"your_world_name"替换为你的出生地图所在的世界名称,并将"x","y"和"z"替换为出生地点的坐标。
此外,你需要在POM文件中添加Bukkit和Mythicmobs的依赖项,如下所示:
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.woodyc40.mccapturespawn</groupId>
<artifactId>mccapturespawn</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.elseland.xikage</groupId>
<artifactId>MythicMobs</artifactId>
<version>4.6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
请确保你的项目中包含了这些依赖项,并将插件打包为JAR文件后,在服务器上运行。这样,怪物将无法跟随玩家离开出生地图区域。
原文地址: https://www.cveoy.top/t/topic/qcXj 著作权归作者所有。请勿转载和采集!