Spawning HumanEntities

Discussion in 'Plugin Development' started by Numenorean95, Jul 27, 2012.

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

    Numenorean95

    So im trying make plugin too complicated to describe here, but it involves spawning NPCs, but when i try to, i get this error:

    Code:
    Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bu
    kkit.entity.HumanEntity
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:963)
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:782)
            at net.lotrcraft.scbuildings.barracks.Soldier.spawn(Soldier.java:23)
            at net.lotrcraft.strategycraft.BaseListener.onPlayerInteract(BaseListener.java:63)
    ...
    My code:

    Code:
    e = arg0.getWorld().spawn(arg0, HumanEntity.class);
    (arg0 being a legitimate Location)

    I tried the same code but Zombie, which other than the zombie immediately dissapperating worked fine.

    I have also tried this with CraftPlayerEntity, but it fails as well. Does anyone know what the correct way to make an NPC is?
     
  2. Offline

    Jogy34

    It would be more helpful if you posted the entire stack trace
     
  3. Offline

    McLuke500

  4. Offline

    Numenorean95

    I dissagree, the stacktrace will not help in this case. Nevertheless,, here it is:

    Code:
    15:50:13 [SEVERE] Could not pass event PlayerInteractEvent to StrategyCraft
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:460)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:177)
            at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.j
    ava:287)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:636)
            at net.minecraft.server.Packet15Place.handle(SourceFile:39)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bu
    kkit.craftbukkit.entity.CraftHumanEntity
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:963)
            at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:782)
            at net.lotrcraft.scbuildings.barracks.Soldier.spawn(Soldier.java:24)
            at net.lotrcraft.strategycraft.BaseListener.onPlayerInteract(BaseListene
    r.java:63)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
            ... 12 more
    >
     
  5. Offline

    Firefly

    Throws:IllegalArgumentException - if either parameter is null or the Entity requested cannot be spawned

    I'm guessing that it either can't be spawned, or either one of your parameters is null.
     
  6. Offline

    Jogy34

    This is the line I was looking for:
    Code:
    Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bu
    kkit.craftbukkit.entity.CraftHumanEntity
    
    Either way just use the link that McLuke500 gave
     
  7. Offline

    Numenorean95


    neither are null, unless HumanEntity doesnt have a class. And yes i did try CraftHumanEntity. The location is valid, it throws an NPE if it equals null. Ergo it just doesnt like HumanEntity, and that is what im asking about.

    That line was in the original post, but whatever. I will try his link, but i would prefer to do it myself, i try not to use 3rd party code. Thanks McLuke500

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  8. Offline

    McLuke500

    Code:
    e = arg0.getWorld().spawn(arg0, HumanEntity.class);
    What is arg0? If its a location ok but how do you get the arg0 not from a command I hope?
     
  9. Offline

    Numenorean95

    ...
    .....
    I swear i will start beating my head on a wall.
    arg0 is a LEGITIMATE NOT NULL LOCATION OBJECT. Im not lying to you, i have tested and added in checks to ENSURE that arg0 is indeed what i say it is. If it is null, the code never gets called. Note i said it WORKS with Zombie.class instead of HumanEntity.class

    Sorry for the caps, but i have said several times now the problem is not with the location
     
  10. Offline

    Jogy34

    You could try using the Player class. I think Citizens just spawns fake players if I am remembering it right.
     
  11. Offline

    Numenorean95

    Tried it, CraftPlayerEntity
     
  12. Offline

    Jogy34

    I meant just Player not CraftPlayerEntity
     
  13. Offline

    Numenorean95

    A good idea, but i tried that too.
     
  14. You can't simply spawn a NPC. HumanEntity is a interface for players and (iirc) zombies.
    You could spawn a zombie or use the NPC library. If you really want to do it for yourself see how the NPC library does it, but it's way more easy to just use that lib.
     
  15. Offline

    Jogy34

    Well, Zombie is an interface and that apparently works.

    Anyways, I rarely spawn mobs into the game in my plugins but the one time I did I did it like this:
    Code:
    world.spawnCreature(loc, EntityType.ZOMBIE);
    
    and that worked just fine. I looked at the EntityType enum and there is PLAYER in it so you could try that
     
  16. Offline

    Numenorean95

    Hmm, good idea, ill try that.
     
  17. Offline

    The_Coder

    with the new bukkit update you have to use:
    Code:
    world.spawnEntity(location, EntityType.ZOMBIE);
     
  18. Offline

    Numenorean95

    I noticed, and i tried with EntityType.Player but it didnt work
     
  19. Offline

    r0306

    Numenorean95
     
  20. Offline

    Numenorean95

    Thank you, i did see that, i have just been hoping that there might be a workaround someone might have found. It would be nice if Bukkit were able to accomplish this with the spawnEntity, since i did look at the code for the lib and it is much more complicated.
     
  21. Offline

    r0306

    Numenorean95
    Before Monsters were removed, it may have been possible but now, the only way to spawn them is through a NPC library. :\
     
Thread Status:
Not open for further replies.

Share This Page