Solved PacketPlayOutSpawnEntityLiving Update

Discussion in 'Plugin Development' started by Agentleader1, Jul 8, 2015.

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

    Agentleader1

    Oh boy, more NMS!

    Anyways, I've coded a PacketPlayOutSpawnEntityLiving, and made morphs and disguises out of it fairly easy. Now I'm wondering though, how I update it. Everytime the packet is sent with a different entity id, it does not show the disguise unless I move enough. What I mean is, when I get disguised into any other EntityLiving, it doesn't show the disguise until I move enough. A mimimum vector of 0.3 is required, but how do I make it so it doesn't require sending vectors?

    I don't really feel comfortable of showing my code.
    Thanks for the help!

    Solution (open)

     
    Last edited: Jul 13, 2015
  2. Offline

    Zombie_Striker

    @Agentleader1
    Yeah, since we can't see your code we can't figure out why you need a "minimum velocity". Can you show us your code just for that method/event so we can figure out why it's not constantly updating. We are not able to see whats wrong with your code if we can't see it.
     
  3. Offline

    Agentleader1

    @Zombie_Striker
    Very sorry, but I'm on my phone right now. What All that I did was make a new EntityLiving based on an argument, and if it's a wither, it's an EntityWither. then send the spawn packet (except the disguised player). That's all that I do.

    //Edit:
    Code:
    public Disguise(EntityLiving type, Player disguiser){
            this.player = disguiser;
            this.packet = new PacketPlayOutSpawnEntityLiving(type);
        }
    public void send(){
            FieldManager.setField(this.packet, "a", player.getEntityId());
            for(Player pl : Bukkit.getOnlinePlayers()){
                if(!(pl.getName().equalsIgnoreCase(this.player.getName()))){
                    ((CraftPlayer) pl).getHandle().playerConnection.sendPacket(packet);
                }
            }
        }
     
    Last edited: Jul 9, 2015
  4. Offline

    Agentleader1

  5. Offline

    Zombie_Striker

    @Agentleader1
    When does Disguise.send() get sent? Is it in it's own thread/runnable?
     
  6. Offline

    Agentleader1

    @Zombie_Striker
    I sent it directly after the constructor was called. And all together did 2 actions (constructor and method) in command
     
  7. @Agentleader1
    So the disguises are of the same entity id as the player? If so, you need to put a delay between despawning and spawning, or the client will show it invisible for a little while.
     
  8. Offline

    Agentleader1

    @megamichiel
    Can you elaborate more on that? I'm not sure what you meant by despawn and spawn. Thank you.
     
  9. @Agentleader1
    Despawn -> Send the player's despawn packet
    Spawn -> Send the disguise's spawn packet
     
  10. Offline

    Agentleader1

    @megamichiel
    I never had a PacketPlayOutEntityDestroy. Is that required?
     
  11. @Agentleader1
    Yes, else it will not show properly. If the client recieves a spawn packet with an entity id that is the same as another, it's invisible for a little while.
     
  12. Offline

    Agentleader1

    @megamichiel Thanks. So I must put a delay on the PacketPlayOutSpawnEntity like 1 tick after PacketPlayOutEntityDestroy?

    //edit:
    Doesn't seem to work :/
    Code:
    int peid = player.getEntityId();
                        PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(peid);
                        for(Player pl : Bukkit.getOnlinePlayers()){
                            ((CraftPlayer) pl).getHandle().playerConnection.sendPacket(destroy);
                        }
                        try{
                            Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.instance, new Runnable(){
                                public void run(){
                                    Disguise disguise = new Disguise(EnumDisguiseType.getTypeFromString(args[1]), player);
                                    disguise.send();
                                }
                            },1);
                        }catch(IllegalArgumentException ex){
                            player.sendMessage(prefix + ChatColor.RED + "That entity type is unsupported!");
                        }
    //Edit 2: It works now, need a bigger delay! Thanks! Appreciates! :D
     
    Last edited: Jul 13, 2015
Thread Status:
Not open for further replies.

Share This Page