Spawning Player Entities.

Discussion in 'Plugin Development' started by xigsag, Jul 30, 2013.

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

    xigsag

    I have googled over and over, even searched the devpage with it's search engine, trying out different keywords.
    The only threads I found gave a few possible solutions, but not actually telling you how to do it.

    Those who have tried to spawn player entities using

    .spawn(location, EntityType.PLAYER.getEntityClass());
    .spawnEntity(location, EntityType.PLAYER);

    know that, even though those work with EntityType.COW or EntityType.PIG,
    using EntityType.PLAYER would give an error :
    Code:java
    1. 14:53:09 [INFO] xigsag issued server command: /spawnplayer
    2. 14:53:09 [SEVERE] null
    3. org.bukkit.command.CommandException: Unhandled exception executing command 'spaw
    4. nplayer' in plugin PlayerEntity v0.1
    5. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    6. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    7. 9)
    8. at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    9. r.java:523)
    10. at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon
    11. nection.java:962)
    12. at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j
    13. ava:880)
    14. at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    15. :837)
    16. at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
    17. at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    18. )
    19. at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    20. :116)
    21. at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    22. at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    23. 0)
    24. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    25. 90)
    26. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    27. 26)
    28. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    29. 86)
    30. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    31. :419)
    32. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    33. 82)
    34. Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bu
    35. kkit.entity.Player
    36. at org.bukkit.craftbukkit.v1_6_R2.CraftWorld.spawn(CraftWorld.java:1024)
    37.  
    38. at org.bukkit.craftbukkit.v1_6_R2.CraftWorld.spawn(CraftWorld.java:792)
    39. at org.bukkit.craftbukkit.v1_6_R2.CraftWorld.spawnEntity(CraftWorld.java
    40. :339)
    41. at xig.playerentity.main.onCommand(main.java:17)
    42. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    43. ... 15 more


    Is nobody curious about how Citizens did it?

    Hoping someone could share with me, and others how this is done.
     
  2. Offline

    ZeusAllMighty11

    Take a look at this thread.
     
  3. Offline

    xTrollxDudex

    xigsag
    I made a utility class, it does require some NMS importing but it theoretically should work.
    PHP:
    public class NPCSpawner{

            List<
    Utilityceptionnpcs = new ArrayList<Utilityception>();

            public 
    NPCSpawner(Player p){

                   
    Location l p.getLocation();
                   
    String s ""
                   
    WorldServer wS = ((CraftWorldl.getWorld()).getHandle();

                   
    NPCthing t = new NPCthing(((CraftServerBukkit.getServer()).getServer(), wSs, new PlayerInteractManager(wS));

                   
    t.setPositionRotation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());

                   
    wS.addEntity(t);

                   
    Utilityception u = new NPCUtilities(t);

                   
    u.setNum(npcs.size() + 1);
                   
    ncps.add(u);

                   return 
    u;
            }

            private class 
    NPCthing extends EntityPlayer{

                    public 
    NPCthing(MinecraftServer seWorld wString sPlayerInteractManager mng){
                            
    super(sewsmng);
                    }
            }

            private class 
    NPCUtilities extends Utilityception{

                    public 
    NPCUtilities(NPCthing thing){
                            
    super(thing);
                    }

                    public 
    void animateArmSwing() {
                            ((
    WorldServergetEntity().world).tracker.a(getEntity(), new Packet18ArmAnimation(getEntity(), 1));
                    }

                    public 
    void actAsHurt() {
                            ((
    WorldServergetEntity().world).tracker.a(getEntity(), new Packet18ArmAnimation(getEntity(), 2));
                    }

                    public 
    void setItemInHand(Material mshort damage) {
                            ((
    HumanEntitygetEntity().getBukkitEntity()).setItemInHand(new ItemStack(m1damage));
                    }
            }

            private class 
    Utilityception{

                    
    Entity ent;
                    
    int id;

                    public 
    Utilityception(Entity ent){
                            
    this.ent ent;
                    }

                    public 
    Entity getEntity(){
                            return 
    ent;
                    }
                    
                    public 
    void getId(){
                            return 
    id;
                    }
                    public 
    void setId(int id){
                            
    this.id id;
                    }

                    public 
    void remove(Utilityception util){
                            if(
    ncps.get(util) != null){
                                    
    Utilityception ncp ncps.get(util);
                                    
    ncps.remove(util);
                                    
    ncp.removeFromWorld();
                            }
                    }
                    public 
    void remove(int id){
                            for(
    Utilityception u npcs){
                                    if(
    u.getId().equals(id){
                                            
    Utilityception ncp ncps.get(u);
                                            
    ncps.remove(u);
                                            
    ncp.removeFromWorld();
                                    }
                            }
                    }
            }
    }
     
    xigsag likes this.
  4. Offline

    xigsag

    This is what I was hoping for. Thanks.

    xTrollxDudex
    I couldn't understand 80% of what you wrote due to all the errors, but I pretty much got the jist of it.
    But tested it and it failed.
    Got the same error, PLUS it crashed the server. (Thank god it was just a localhost test server.)

    Anymore ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. Offline

    xTrollxDudex

    xigsag
    90% of your errors were probably import errors because this code is really messily done.
    The basic idea is the spawn an entity from a class that extends EntityPlayer. Good luck.
     
  6. Offline

    xigsag

    xTrollxDudex
    Yeah, about that. I did try to make a class that extended EntityPlayer, and I did try to spawn that in, but that didn't work either.
     
  7. Offline

    xTrollxDudex

    xigsag
    Try looking at Jacek 's post in the resources section, it is titled "Changing the behavior of mobs" it does have a part on spawning your custom mob
     
  8. Offline

    xigsag

    xTrollxDudex
    Alright then, onto a different topic, could you tell me how I could FREEZE a mob entity?

    It's late where I am, so I'll be going off. So I would normally check this post in about 10-12 hours time.
     
  9. Offline

    xTrollxDudex

    xigsag
    The only real way is to teleport them back to the same location if they moved with a timer. Maybe with some nms but I'll look it up
     
  10. Offline

    xigsag

    I have taken a few peeks at Citizens's source code, RemoteEntities's source code, and found that their custom EntityPlayer extended classes require network managers. For Citizens, they created empty sockets and an empty network handler.

    I have no idea how to do that, but I'll try to decipher that on my own. Wish me luck.
     
Thread Status:
Not open for further replies.

Share This Page