Solved Hiding the Respawn Screen and Setting the Inventory

Discussion in 'Plugin Development' started by exload, Aug 16, 2013.

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

    exload

    So I have recently been looking into the best ways to cancel the respawn screen and the method that seemed genuinely accepted as the best was this:
    Code:java
    1. public static void cancelRespawnScreen(Player p)
    2. {
    3. Packet205ClientCommand packet = new Packet205ClientCommand();
    4. packet.a = 1;
    5. ((CraftPlayer) p).getHandle().playerConnection.a(packet);
    6. }

    So that is what I use.

    My issue, however, is not with that method, it is with giving players items in their inventory after they "respawn." The plugin will give the player the items, but the items are not actually there. Anytime this player tries to move an item around in his inventory all the items disappear.

    I am settings the player's inventory by using the giveKit (line 72) method in Kit.class (https://github.com/exload/VArenas/blob/master/src/net/vectorgaming/varenas/framework/kits/Kit.java). I can assure you everything in the class works 100%.

    I cannot seem to figure this issue out and any additional input is welcomed.
     
  2. Offline

    ibWill

    exload, To cancel the respawn screen just teleport the player right after death
    EDIT: This is an easier way to do it, it just sets the health back to full, and teleports the player to a given location. It effectively stops the player from seeing the respawn screen

    Code:java
    1. @EventHandler
    2. public void onDeath(EntityDeathEvent e){
    3. if(e.getEntity() instanceof Player){
    4. Player p = (Player) e.getEntity();
    5. p.setHealth(20.0);
    6. p.teleport(LOCATION);
    7. //Code for what you want to add to their inventory
    8. }
    9. }
     
  3. Offline

    exload

    Odd. I tested this method out and it did not work before. Of course, when I finally decide to post it decides to work :p Anyways thank you for making me go back and re-test. And now no NMS code!

    Actually hold up. It still won't add the items into the player's inventory. The method is called, however, nothing is added into the inventory.

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

    rsod

    Don't add items in death event. Use a task to do it and run it from death event using Bukkit.runTask(plugin, task). Don't forget to call p.updateInventory() method after messing around with his items.
     
  5. Offline

    macguy8

    This is generally bad coding practice as you can be forgetting to reset things such as food, saturation, potion effects, tc. Your method also does not call PlayerRespawnEvent, so it will generally conflict with plugins that change a player's spawn point.
     
  6. Offline

    ibWill

    macguy8, It's Not bad code practice, its just my way of quickly showing it, he's not supposed to just copy and paste
     
  7. Offline

    macguy8

    How is it not bad code practice? It will break many other plugins such as spawn setting plugins, and a lot of values (such as if the player's on fire, etc) will break. If the OP simply uses the other method posted, minecraft has a method which resets all of this for us and that we won't manually have to update in the future if some new bar / level gets added into the game.
     
  8. Offline

    exload

    Let's not get off topic.. I am still unable to add anything to the players inventory after I force a respawn using either method. Any idea why this might be?
     
  9. Offline

    exload

    still having this issue.. bump
     
  10. Offline

    callum.thepro

    use event.setCancelled() at the death event before anything happens
     
  11. Offline

    CakePvP

    I had to use a scheduler to change the inventory/add potion effects, it just seems you have to delay it by a tick or so.
     
  12. Offline

    exload

    The death event is not cancelled silly! :p

    I will try that and let you know how it goes

    This has fixed the issue. Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page