Solved 1.8.9 Auto-Respawn

Discussion in 'Plugin Development' started by flash110, Jun 1, 2016.

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

    flash110

    I know how to make the player auto respawn with packets and NMS in the previous versions, but I can not seem to get it to work without using any libraries in 1.8.9. Any help would be appreciated. I fixed it with this:
    Code:
     
        @EventHandler
        public void findDeath(EntityDamageEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if(e.getDamage() >= p.getHealth()) {
                    e.setCancelled(true);
                    p.setHealth(20D);
                    Bukkit.broadcastMessage(ChatColor.GREEN + p.getDisplayName() + " died from " + p.getLastDamageCause().getEntityType().name());
                    p.getPlayer().getLocation().getWorld().playEffect(e.getEntity().getLocation().add(0.0D, 1.0D, 0.0D), Effect.STEP_SOUND, 152);
                }
            }
        }
     
    Last edited: Jun 2, 2016
  2. Offline

    Zombie_Striker

    @flash110
    Can you post what you have tried? Do you still have the link to the libraries you tried?
     
  3. Offline

    flash110

    I didn't try any Libraries, I just do not want to have to use them. I tried:
    Code:
     
    @EventHandler
        public void death(PlayerDeathEvent e) {
            Player player = e.getEntity();
             Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                 @Override
                 public void run() {
                     PacketPlayInClientCommand packet = new PacketPlayInClientCommand();
                     packet.a = 1;
                     ((CraftPlayer) player).getHandle().playerConnection.a(packet);
                 }
             }, 1L);
        }
    
    I know this does not work for 1.8.9, and like I said, I have no clue at all how to use packets.
     
  4. Offline

    Zombie_Striker

    @flash110
    The reason this does not work is because you are sending an in packet out to a player. Packets are either sent to the server (In) or to the player (out). A player does not have anything to do with server commands, so this packet gets ignored. Are you sure you're using the right packet?
     
  5. Offline

    flash110

    I do not know if it is the right packet, I got the code from a 1.7 thread and the packet no longer exists
    In 1.8. So I was trying a bunch of different things myself (Once again have no clue how to use packets :p) and what you see above was the last thing I tried before posting a thread.
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    flash110

    Thanks! I'll check it out now. If I still seem to have a problem I'll post back here

    Would you use the Packet titled "Click window" to send a packet to the server saying the player clicked the respawn button, or would you use that Packet titled "Respawn"
    And figure out if the player is dead and make them
    Respawn? I don't see the second option working becaus the respawn packet is just to set where they respawn.

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

    timtower Administrator Administrator Moderator

    @flash110 Have you tried just not letting the player die in the first place?
     
  9. Offline

    flash110

    I would like the player to die so I can test for the death events, and I think I found the right packet and (kind of) how to do it. I would use image.png and send the server a packet saying the player clicked the respawn button 1 tick after that player died. The only problem is, I do not know how to utilize this information that I found.
     
  10. Offline

    timtower Administrator Administrator Moderator

    @flash110 Then the server knows, but the client doesn't.
    Try the bed leave thingy send from the player.
     
  11. Offline

    flash110

    This will be for a minigame, so the player will not be respawning at a bed. Do you have any resources or tutorials to help people format packets in their code? Or if you know can I see an example so I know how to use them in my code? I know "spoon feeding" is frowned upon, but their isn't much on packets on the Internet.
     
    Last edited: Jun 2, 2016
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    flash110

    I meant like resources to help me understand, as I noted above I would rather not use a library. I also already looked through the code for protocol lib for anything that would help and looked at the docs for it.

    I found this in the bukkit code:
    Code:
    public void a(PacketPlayInWindowClick packetplayinwindowclick) {
            this.player.v();
            if (this.player.activeContainer.windowId == packetplayinwindowclick.c() && this.player.activeContainer.c(this.player)) {
                ItemStack itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), packetplayinwindowclick.h(), this.player);
    
                if (ItemStack.matches(packetplayinwindowclick.g(), itemstack)) {
                    this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), true));
                    this.player.g = true;
                    this.player.activeContainer.b();
                    this.player.broadcastCarriedItem();
                    this.player.g = false;
                } else {
                    this.n.a(this.player.activeContainer.windowId, Short.valueOf(packetplayinwindowclick.f()));
                    this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), false));
                    this.player.activeContainer.a(this.player, false);
                    ArrayList arraylist = new ArrayList();
    
                    for (int i = 0; i < this.player.activeContainer.c.size(); ++i) {
                        arraylist.add(((Slot) this.player.activeContainer.c.get(i)).getItem());
                    }
    
                    this.player.a(this.player.activeContainer, arraylist);
                }
            }
        }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  14. Offline

    Xerox262

    @flash110 Setting the player's health back to greater than 1 in the death event normally cancels death and still calls death events, or you could just call the death event manually.

    If you are dead set on using packets you could look up what protocol that protocol lib uses, they have their code available on github.
    https://github.com/aadnk/ProtocolLib
     
  15. Offline

    flash110

    @Xerox262 Ok, I'm trying something with packets really quick, I'll respond here with the code if it works!
     
Thread Status:
Not open for further replies.

Share This Page