Something simple.

Discussion in 'Plugin Development' started by Desle, Jul 11, 2013.

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

    Desle

    Code:
        @EventHandler
        public void onPlayerDeathEvent(PlayerDeathEvent event){
                Player player = event.getEntity();
                ItemStack boots = player.getInventory().getBoots();
                ItemStack helmet = player.getInventory().getHelmet();
                ItemStack chestplate = player.getInventory().getChestplate();
                ItemStack leggings = player.getInventory().getLeggings();
    This is what i have.
    I can get their armor when they die, altho.. how do i disable them from dropping their armor upon death, and then be able to respawn their armor in their inventory upon respawn?
     
  2. Offline

    seemethere

    For the drops you can do:

    Code:java
    1. event.getDrops().clear();
     
  3. Offline

    drtshock

    Save their inventory in an ItemStack[] when they die, and then when they respawn put it back in their armor slots.
     
    TheCrazyCrafter5 likes this.
  4. May I ask how that should be done? I'm curious, because, to my knowledge, it takes two methods to do what you're describing; PlayerDeathEvent and PlayerRespawnEvent. Methods only receive information that's within themselves, so how could I make them transfer information? Sorry if this is a nooby question, but I've been very confused about this.
     
  5. Offline

    Tirelessly

    Global variables! Specifically, a HashMap would be useful. Even more specifically, a HashMap<String, ItemStack[]>.

    You can google most of those words and get useful results which are much more in depth than anything I could write right now.
     
    TheCrazyCrafter5 likes this.
  6. Thank you for your reply. I guess i'll look at a tutorial. It figures it'd be hashmaps, lol. I've gotten the hang of basic syntax for Minecraft plugins in Java, but Hashmaps are something I haven't even looked at yet. I guess that's about to change...
     
  7. Offline

    xTrollxDudex

    TheCrazyCrafter5 and drtshock like this.
  8. Offline

    Compressions

    TheCrazyCrafter5 I'll give you some helpful code:
    Code:java
    1. HashMap<String, ItemStack[]> hashmap = new HashMap<String, ItemStack[]>();
    2.  
    3. @EventHandler
    4. public void onPlayerDeath(PlayerDeathEvent e) {
    5. Player player = e.getEntity();
    6. ItemStack[] armor = player.getInventory().getArmorContents();
    7. hashmap.put(player.getName(), armor);
    8. e.getDrops().remove(armor);
    9. }
    10.  
    11. @EventHandler
    12. public void onPlayerRespawn(PlayerRespawnEvent e) {
    13. Player player = e.getPlayer();
    14. ItemStack[] armor = hashmap.get(player.getName());
    15. player.getInventory().addItem(armor);
    16. hashmap.remove(player.getName());
    17. }
     
    TheCrazyCrafter5 likes this.
  9. Well, I actually have a source for learning java. Many are probably familiar with TheNewBoston, right? Yeah, that's where I've learned from. I've only watched like 25 videos about Java beginner tutorials, but it was enough to help me make basic programs. I really should revise my knowledge, cause I do have trouble with calling seperate methods and classes, which is very important as a developer. Also, I do use google and bukkit often. :D

    Thanks man, it's much appreciated. Mostly because it'll help me understand the Hashmaps better. <3
     
Thread Status:
Not open for further replies.

Share This Page