以下是一个使用Java编写的Bukkit插件,它基于Mythicmobs,当怪物的名字为特定的名字时,禁止它们跟随玩家离开出生的地图:

package com.example.plugin;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {
    private String restrictedMobName = 'RestrictedMob';
    private World restrictedWorld;

    @Override
    public void onEnable() {
        // 注册事件监听器
        getServer().getPluginManager().registerEvents(this, this);
        
        // 获取出生的地图
        restrictedWorld = Bukkit.getWorld('world');
    }

    @EventHandler
    public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
        World fromWorld = event.getFrom();
        World toWorld = event.getPlayer().getWorld();

        if (fromWorld == restrictedWorld && toWorld != restrictedWorld) {
            // 玩家离开出生的地图

            // 获取所有实体
            for (Entity entity : fromWorld.getEntities()) {
                if (entity instanceof LivingEntity) {
                    LivingEntity livingEntity = (LivingEntity) entity;
                    if (livingEntity.getCustomName() != null && livingEntity.getCustomName().equals(restrictedMobName)) {
                        // 怪物名字为特定的名字时,禁止跟随玩家离开出生的地图
                        livingEntity.setAI(false);
                    }
                }
            }
        }
    }
}

请注意,你需要在插件的onEnable方法中指定你的出生地图名称,以及将restrictedMobName设置为你要禁止跟随玩家离开的怪物的名称。

Bukkit 1.12.2 MythicMobs 插件:限制特定怪物跟随玩家离开出生地图

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

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