How To Cancel/Reset Player Metadata on death?

Discussion in 'Plugin Development' started by thegarfish, Aug 26, 2013.

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

    thegarfish

    Hey guys, whenever a player selects a kit, he can never select another (until the server restarts). I know I need to reset/delete the players metadata, but I don't know how to do this..

    Here is my source.
    http://pastebin.com/denm1SRq
     
  2. Offline

    aredherring

    If you create an EventListener to listen to PlayerDeathEvent, you can just call "removeMetadata" on the player, providing you know the keys of the metadata that are set.
     
  3. Offline

    thegarfish

    How would I add that?
    event1.onplayerdeath removeMetadata?
     
  4. Offline

    aredherring

    Er.. not quite.

    Code:java
    1. public class PlayerDeathListener implements Listener {
    2. private JavaPlugin hostPlugin;
    3.  
    4. public PlayerDeathListener(JavaPlugin plugin) { hostPlugin = plugin; }
    5. @EventHandler
    6. public void onPlayerDeath(PlayerDeathEvent event) {
    7. Player plr = event.getEntity();
    8. // Now just remove all the metadata that you have added to the player
    9. plr.removeMetadata("key", hostPlugin);
    10. }
    11.  
    12. }

    If you're confused on how to add events, perhaps it might be better if you read the Plugin tutorial first.
     
Thread Status:
Not open for further replies.

Share This Page