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?
Save their inventory in an ItemStack[] when they die, and then when they respawn put it back in their armor slots.
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.
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.
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...
TheCrazyCrafter5 I'll give you some helpful code: Code:java HashMap<String, ItemStack[]> hashmap = new HashMap<String, ItemStack[]>(); @EventHandler public void onPlayerDeath(PlayerDeathEvent e) { Player player = e.getEntity(); ItemStack[] armor = player.getInventory().getArmorContents(); hashmap.put(player.getName(), armor); e.getDrops().remove(armor); } @EventHandler public void onPlayerRespawn(PlayerRespawnEvent e) { Player player = e.getPlayer(); ItemStack[] armor = hashmap.get(player.getName()); player.getInventory().addItem(armor); hashmap.remove(player.getName()); }
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. Thanks man, it's much appreciated. Mostly because it'll help me understand the Hashmaps better. <3