Server Crashes When Trying To Clone Player

Discussion in 'Spigot Plugin Development' started by ReadySetPawn, Aug 16, 2015.

  1. So I was messing around on my test server and decided to try spawning in a clone of a specified player. Here's the method I used:

    Code (Java):
    public void spawnPlayer(Player player){

            MinecraftServer minecraftServer = ((CraftServer) getServer()).getServer();
            WorldServer worldServer = minecraftServer.getWorldServer(0);
            GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
            World world = ((CraftWorld) player.getWorld()).getHandle();
            PlayerInteractManager playerInteractManager = new PlayerInteractManager(world);

            EntityPlayer entityPlayer = new EntityPlayer(minecraftServer, worldServer, gameProfile, playerInteractManager);

            Location l = player.getLocation();

            entityPlayer.setLocation(l.getX(), l.getY(), l.getZ(), 0, 0);
            world.addEntity(entityPlayer);

        }
    Right before the server crashes and kicks me, I see that the clone actually spawned in no problem. Here's the error:

    [​IMG]

    And the message I get when kicked is "Server closed"
     
  2. Is it possible that you can extend EntityHuman yourself? EntityPlayer has a lot of references to its PlayerConnection that would be null in your case. Which is probably why it's throwing an NPE on trying to send a packet to itself ;)
     
  3. Oh yeah I didn't think about that. I'll try using EntityHuman.
     
  4. Weird, I'm getting a ClassCastException now...

    [​IMG]

    Method:

    Code (Java):
    public void spawnPlayer(Player player){

            //MinecraftServer minecraftServer = ((CraftServer) getServer()).getServer();
            //WorldServer worldServer = minecraftServer.getWorldServer(0);
            GameProfile gameProfile = new GameProfile(player.getUniqueId(), player.getName());
            World world = ((CraftWorld) player.getWorld()).getHandle();
            //PlayerInteractManager playerInteractManager = new PlayerInteractManager(world);

            EntityHuman entityHuman = new Clone(world, gameProfile);

            Location l = player.getLocation();

            entityHuman.setLocation(l.getX(), l.getY(), l.getZ(), 0, 0);
            world.addEntity(entityHuman);

        }
    Clone class:

    Code (Java):
    public class Clone extends EntityHuman {

        public Clone(World world, GameProfile gameProfile){
            super(world, gameProfile);
        }

        public boolean v(){
            return false;
        }

    }
     
  5. It depends on what do you want to do with him. If you want to add it to online-players list, then this will not work, as HumanEntity is parent of Player, not viceversa.

    EDIT: What do you exactly want to do?
     
  6. I'm just experimenting around to see if I can spawn in a clone lol No real objective
     
  7. You might try to `implements Player`.
     
  8. That's Bukkit =/ It wouldn't work.

    Hmm, I'll try that tomorrow. Super tired tonight. Thanks :)
     
  9. What do you mean it won't work with Bukkit? Spigot is bukkit with added features!
     
    • Funny Funny x 1
  10. I meant that it wouldn't work because Player is part of the API and it's just an interface :D
     
  11. I worked on that last year and I rememeber, that you have to send a PacketPlayOutNamedEntitySpawn with a EntityHuman as paramater, and then send it.