Add enchantment map to a series of books?

Discussion in 'Plugin Development' started by r0llingthund3r, Oct 19, 2013.

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

    r0llingthund3r

    I am making a plugin that takes the enchanted item in your hand and breaks it down, giving you books with the enchants the item had. This is my first time working with maps and I'm a bit confused. Let's assume that Map enchants is a map of the enchantments on the item in hand.
    How would I go about iterating through it and adding each enchant to a book?

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
    2. Player p = (Player)sender;
    3. ItemStack is = p.getItemInHand();
    4.  
    5. if(cmd.getName().equalsIgnoreCase("enchantbreak")){
    6. if(is != null){
    7. p.setItemInHand(is);
    8. if(is.getEnchantments().isEmpty()){
    9. p.sendMessage("Item must be enchanted!");
    10. }
    11. else{
    12. Map<Enchantment, Integer> enchants = is.getEnchantments();
    13. convertToBooks(enchants);
    14. }
    15. }
    16. return true;
    17. }
    18.  
    19. return false;
    20. }
    21.  
    22. private Map<Enchantment, Integer> convertToBooks(Map<Enchantment, Integer> enchants) {
    23. // where I need to iterate through enchants and add each enchant to a book
    24. return enchants;
    25. }
    26.  
     
Thread Status:
Not open for further replies.

Share This Page