要实现这个功能,你需要编写一个Bukkit插件,并使用Mythicmobs API来获取和操作怪物。下面是一个简单的示例代码,可以在怪物的名字为特定名字时禁止跟随玩家离开出生的地图:\n\njava\nimport org.bukkit.Bukkit;\nimport org.bukkit.Location;\nimport org.bukkit.World;\nimport org.bukkit.entity.Entity;\nimport org.bukkit.entity.LivingEntity;\nimport org.bukkit.event.EventHandler;\nimport org.bukkit.event.Listener;\nimport org.bukkit.event.player.PlayerChangedWorldEvent;\nimport org.bukkit.event.player.PlayerMoveEvent;\nimport org.bukkit.plugin.java.JavaPlugin;\n\npublic class NoFollowPlugin extends JavaPlugin implements Listener {\n \n private String monsterName = "特定的名字";\n private String birthWorldName = "出生的地图名称";\n \n @Override\n public void onEnable() {\n Bukkit.getPluginManager().registerEvents(this, this);\n }\n \n @EventHandler\n public void onPlayerMove(PlayerMoveEvent event) {\n Location from = event.getFrom();\n Location to = event.getTo();\n \n if (from.getWorld().getName().equals(birthWorldName) && !to.getWorld().getName().equals(birthWorldName)) {\n for (Entity entity : event.getPlayer().getNearbyEntities(10, 10, 10)) {\n if (entity instanceof LivingEntity && entity.getCustomName() != null && entity.getCustomName().equals(monsterName)) {\n // 将怪物传送回出生地图的位置\n World world = Bukkit.getWorld(birthWorldName);\n Location birthLocation = new Location(world, x, y, z); // 替换为出生地图的坐标\n entity.teleport(birthLocation);\n }\n }\n }\n }\n \n @EventHandler\n public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {\n if (!event.getPlayer().getWorld().getName().equals(birthWorldName)) {\n for (Entity entity : event.getPlayer().getWorld().getEntities()) {\n if (entity instanceof LivingEntity && entity.getCustomName() != null && entity.getCustomName().equals(monsterName)) {\n // 将怪物传送回出生地图的位置\n World world = Bukkit.getWorld(birthWorldName);\n Location birthLocation = new Location(world, x, y, z); // 替换为出生地图的坐标\n entity.teleport(birthLocation);\n }\n }\n }\n }\n}\n\n\n请注意,你需要替换示例代码中的特定的名字、出生的地图名称、x、y和z为你实际使用的值。另外,你还需要将插件打包成.jar文件,并将其放入Bukkit服务器的插件文件夹中,然后重新启动服务器以加载插件。


原文地址: https://www.cveoy.top/t/topic/qcXw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录