Custom Villagers - NoSuchMethodException

Discussion in 'Plugin Help/Development/Requests' started by Unica, May 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Unica

    Good day,

    I've stumbled on a very weird error which fires when a player joins.
    Basically, I have these custom villagers, and on certain locations (random? idk) they
    despawn when I join the game, and fire an NoSuchMethodException.

    If anyone could enlighten me.

    Stack:
    Code:
    [20:20:10 WARN]: java.lang.NoSuchMethodException: io.unica.mechanics.NPCVillage
    r.<init>(net.minecraft.server.v1_8_R2.World)
    [20:20:10 WARN]:        at java.lang.Class.getConstructor0(Unknown Source)
    [20:20:10 WARN]:        at java.lang.Class.getConstructor(Unknown Source)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.EntityTypes.a(SourceFile
    :182)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.ChunkRegionLoader.loadEn
    tities(ChunkRegionLoader.java:410)
    [20:20:10 WARN]:        at org.bukkit.craftbukkit.v1_8_R2.chunkio.ChunkIOProvide
    r.callStage2(ChunkIOProvider.java:46)
    [20:20:10 WARN]:        at org.bukkit.craftbukkit.v1_8_R2.chunkio.ChunkIOProvide
    r.callStage2(ChunkIOProvider.java:1)
    [20:20:10 WARN]:        at org.bukkit.craftbukkit.v1_8_R2.util.AsynchronousExecu
    tor$Task.finish(AsynchronousExecutor.java:188)
    [20:20:10 WARN]:        at org.bukkit.craftbukkit.v1_8_R2.util.AsynchronousExecu
    tor.finishActive(AsynchronousExecutor.java:347)
    [20:20:10 WARN]:        at org.bukkit.craftbukkit.v1_8_R2.chunkio.ChunkIOExecuto
    r.tick(ChunkIOExecutor.java:34)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.MinecraftServer.A(Minecr
    aftServer.java:729)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.DedicatedServer.A(Dedica
    tedServer.java:368)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.MinecraftServer.z(Minecr
    aftServer.java:651)
    [20:20:10 WARN]:        at net.minecraft.server.v1_8_R2.MinecraftServer.run(Mine
    craftServer.java:554)
    [20:20:10 WARN]:        at java.lang.Thread.run(Unknown Source)
    [20:20:10 WARN]: Skipping Entity with id Villager
    Code (NPCVillager.class)
    Code:
    public class NPCVillager extends EntityVillager{
       
        private static Set<NPCVillager> activeNPC = new HashSet<>();
        private World w;
        public NPCVillager(org.bukkit.World world) {
            super(((CraftWorld) world).getHandle());
            this.w = ((CraftWorld) world).getHandle();
            activeNPC.add(this);
        }
       
        @Override
        public void g(double x, double y, double z){return;}
       
        /**
         * Spawn a villager that is unpushable
         * @param name Name for the villager
         * @param loc Location
         */
        @SuppressWarnings("deprecation")
        public final void spawnNPC( Location loc, Profession p){
            spawnIn(w);
            setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            setProfession(p.getId());
            w.addEntity(this);
            ((Villager)this.getBukkitEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 10));
            activeNPC.add(this);
        }
       
        public static final void spawnNPC(ClassType type, Location loc){
            new NPCVillager(loc.getWorld()).spawnNPC(loc, Profession.BLACKSMITH);
        }
       
        public void removeNpc(){
            this.getBukkitEntity().remove();
        }
       
        public static final void clearEntities(){
            for(NPCVillager npc : activeNPC){
                npc.removeNpc();
            }
        }
    }
    PS: If anyone could me give the method to override to cancel the villager from walking away, so i won't have to use potioneffect.slow ;)
     
  2. Offline

    mine-care

    What version are you building against?
    Also to avoid having to add slow effect you can remove movement related pathfinder goals from the custom entity.
     
  3. Offline

    Unica

    @mine-care

    1.8.3.

    I read something online about a constructor I have to fix or something.
    And how would I remove pathfinder goals :)?
     
  4. Offline

    Unica

    Bump, sorry ;/
     
Thread Status:
Not open for further replies.

Share This Page