NMS Entities implementing interface

Discussion in 'Spigot Plugin Development' started by Havelka6, May 2, 2017.

  1. Hello, i am having problems with updating old plugin from 1.7.10 to 1.11. The problem is about the Custom Entities that are correctly registered and they even spawn, but the problem starts when i implements custom interface for much more control above entity bahaviour.

    This is class of an Custom Skeleton.

    Code (Text):
    public class CustomSkeleton extends EntitySkeleton implements ICustomEntity {

        private GBrain brain;
        private GEntityDefinition definition;

        private boolean sunBurn = true;


        public CustomSkeleton(World world) {
            super(world);
        }

        /** *                    * **
         *        CUSTOMIZED        *
         * this part is totally new *
         ** *                    * **/

        @Override
        public CraftEntity getBukkitEntity()
        {
            /*if (this.bukkitEntity == null) {
                this.bukkitEntity = new CraftCustomSkeleton(this.world.getServer(), this);
            } TODO May add With class
            */
            return this.bukkitEntity;
        }

        @Override
        public GBrain getBrain()
        {
            return this.brain;
        }

        @Override
        public void setBrain(GBrain brain)
        {
            if (brain == null) return;

            clearPathfinders();

            this.brain = brain.clone();
            this.brain.connectToBody(this, this.goalSelector, this.targetSelector);
            this.brain.uploadConsciousness();
        }

        @Override
        public void clearPathfinders()
        {
            PathFinder.clearPathFinders(this);
        }

        @Override
        public GEntityDefinition getDefinition()
        {
            return definition;
        }

        @Override
        public void setDefinition(GEntityDefinition definition)
        {
            this.definition = definition;
        }

        @Override
        public boolean getSunBurn()
        {
            return sunBurn;
        }

        @Override
        public void setSunBurn(boolean flag)
        {
            sunBurn = flag;
        }
     
    If i try spawn him without implementing the inteface its work with no problems.

    This is the interface.

    Code (Text):
    public interface ICustomEntity
    {
        public GBrain getBrain();
       
        public void setBrain(GBrain brain);
       
        public void clearPathfinders();
       
        public GEntityDefinition getDefinition();
       
        public void setDefinition(GEntityDefinition definition);
       
        public boolean getSunBurn();
       
        public void setSunBurn(boolean flag);
    }
     
    This is used to spawn an entity in world.

    Code (Text):
    net.minecraft.server.v1_11_R1.Entity entity = (net.minecraft.server.v1_11_R1.Entity) ReflectionUtils.getConstructor(entityClass, World.class).newInstance(nmsWorld);
                entity.setLocation(x,y,z,yaw,pitch);
                nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
    Can anyone please help me ?

    Thanks for help, HamAndRock.
     
  2. And the problem is exactly what? all i could recognize is that you have a problem with your interface but you haven't mentioned any errors or similar.
     
  3. Sorry, for late answear the problem occurs when i try to add entity to the nmsWorld. It throws Nullpointer Exception. If i dont implement the interdace it works without problems, but i need to implement it.
     
  4. Would be useful if you could supply the stack trace (Error log) :)
     
  5. Ok i am in school right but ill provide it asap.
     
    • Like Like x 1
  6. This occurs only when i implement the interface to the custom entity class.

    Code (Text):
    [21:53:19] [Server thread/WARN]: java.lang.NullPointerException
    [21:53:19] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callCreatureSpawnEvent(CraftEventFactory.java:280)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.World.addEntity(World.java:1038)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.WorldServer.addEntity(WorldServer.java:1065)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.entity.GEntityManager.spawn(GEntityManager.java:113)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.entity.GEntityManager.spawn(GEntityManager.java:46)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.entity.GEntitySpawner.spawn(GEntitySpawner.java:71)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.entity.GEntitySpawner.check(GEntitySpawner.java:59)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.object.GSpawner.checkAll(GSpawner.java:253)
    [21:53:19] [Server thread/WARN]:     at eu.gatecraft.spawner.GSpawnerManager.run(GSpawnerManager.java:44)
    [21:53:19] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftTask.run(CraftTask.java:71)
    [21:53:19] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:353)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:738)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678)
    [21:53:19] [Server thread/WARN]:     at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576)
    [21:53:19] [Server thread/WARN]:     at java.lang.Thread.run(Unknown Source)
    [21:53:19] [Server thread/WARN]: [GateSpawner] Task #2117 for GateSpawner v1.2 generated an exception
    java.lang.NullPointerException
        at eu.gatecraft.spawner.entity.GEntity.<init>(GEntity.java:54) ~[?:?]
        at eu.gatecraft.spawner.entity.GEntityManager.spawn(GEntityManager.java:49) ~[?:?]
        at eu.gatecraft.spawner.entity.GEntitySpawner.spawn(GEntitySpawner.java:71) ~[?:?]
        at eu.gatecraft.spawner.entity.GEntitySpawner.check(GEntitySpawner.java:59) ~[?:?]
        at eu.gatecraft.spawner.object.GSpawner.checkAll(GSpawner.java:253) ~[?:?]
        at eu.gatecraft.spawner.GSpawnerManager.run(GSpawnerManager.java:44) ~[?:?]
        at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:353) [Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:738) [Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [Spigot.jar:git-Spigot-a3f6ea5-2453830]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
     
  7. Sorry for the slow response.

    Have you checked line 113 of GEntityManager.java?