Help! I want to spawn NPC/EntityHuman, but it says error...

Discussion in 'Plugin Development' started by derox, Jun 18, 2017.

  1. derox

    derox New Member

    Jun 18, 2017
    1
    0
    1
    Hi! I want to spawn NPC for my project, but I have this error:
    java.lang.RuntimeException: java.lang.NullPointerException
    at cn.nukkit.plugin.PluginManager.enablePlugin(PluginManager.java:450)
    at cn.nukkit.Server.enablePlugin(Server.java:633)
    at cn.nukkit.Server.enablePlugins(Server.java:622)
    at cn.nukkit.Server.<init>(Server.java:469)
    at cn.nukkit.Nukkit.main(Nukkit.java:68)
    Caused by: java.lang.NullPointerException
    at cn.nukkit.entity.EntityHuman.initEntity(EntityHuman.java:97)
    at cn.nukkit.entity.Entity.init(Entity.java:375)
    at cn.nukkit.entity.Entity.<init>(Entity.java:273)
    at cn.nukkit.entity.EntityLiving.<init>(EntityLiving.java:31)
    at cn.nukkit.entity.EntityCreature.<init>(EntityCreature.java:12)
    at cn.nukkit.entity.EntityHumanType.<init>(EntityHumanType.java:28)
    at cn.nukkit.entity.EntityHuman.<init>(EntityHuman.java:59)
    at ru.stalmine.server.component.npc.sNPC.spawnEntity(sNPC.java:76)
    at ru.stalmine.server.component.npc.sNPC.onLoad(sNPC.java:35)
    at ru.stalmine.server.component.Component.loadAll(Component.java:20)
    at ru.stalmine.server.Main.loadComponents(Main.java:26)
    at ru.stalmine.server.Main.onEnable(Main.java:19)
    at cn.nukkit.plugin.PluginBase.setEnabled(PluginBase.java:89)
    at cn.nukkit.plugin.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:119)
    at cn.nukkit.plugin.PluginManager.enablePlugin(PluginManager.java:446)
    ... 4 more

    Im using this code:

    Code:
    public void spawnEntity(int count){
            Random rand = new Random();
    
            int x = (int) getMain().getServer().getDefaultLevel().getSafeSpawn().getX();
            int y = (int) getMain().getServer().getDefaultLevel().getSafeSpawn().getY();
            int z = (int) getMain().getServer().getDefaultLevel().getSafeSpawn().getZ();
    
            for (int i = 0; i < count; i++){
    
    
                //getMain().getLogger().info(this.getMain().getDataFolder().getAbsolutePath() + "/skin.png");
                Skin skin = new Skin(new File(this.getMain().getDataFolder().getAbsolutePath() + "/skin.png"));
                Position source = new Position(x, y, z, getMain().getServer().getDefaultLevel());
                FullChunk chunk = source.getLevel().getChunk((int) source.x >> 4, (int) source.z >> 4, true);
                if (!chunk.isGenerated()) {
                    getMain().getServer().getScheduler().scheduleDelayedTask(new sNPCSpawnTask(this), 250);
                    return;
                }
                if (!chunk.isPopulated()) {
                    getMain().getServer().getScheduler().scheduleDelayedTask(new sNPCSpawnTask(this), 250);
                    return;
                }
    
                CompoundTag nbt = new CompoundTag().putList(new ListTag<Tag>("Pos").add(new DoubleTag("", source.x)).add(new DoubleTag("", source.y + 0.5)).add(new DoubleTag("", source.z)))
                        .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
                        .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("",  0))
                                .add(new FloatTag("",  0))).putString("NameTag", "Бяка");
    
                EntityHuman entity = null;
                entity = new EntityHuman(chunk, nbt);
                entity.setSkin(skin);
                entity.setScale(2);
                entity.setMaxHealth(333);
                entity.setHealth(222);
                entity.spawnToAll();
                getMain().getServer().getScheduler().scheduleDelayedTask(new sNPCSpawnTask(this), 250);
            }
        }
    Please, help me, I really need it.


     
  2. xISRAPILx

    xISRAPILx New Member

    Show where you have 97 line...