Solved Can I make a method?

Discussion in 'Plugin Development' started by Legocowchaser, Nov 16, 2013.

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

    Legocowchaser

    Here is what I have. Can I make it so that when each item is clicked such as a helmet and chestplate it put it in its proper armor slot? Can I replace the Material with a method that gets the item clicked and makes it a helmet or whatever it should be? Or do I need to have different inventories like one for helmets and one for chestplates? So that it will know what armor slot it goes in because I would define it below. Could I make in the same inventory? Do I have the right idea or are methods just not possible here? Thanks in advance. :)
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. Player player = (Player) event.getWhoClicked();
    4. ItemStack clicked = event.getCurrentItem();
    5. Inventory inventory = event.getInventory();
    6. if (inventory.getName().equals(myInventory.getName())) {
    7. if (clicked.getType() == Material.LEATHER_HELMET) {
    8. event.setCancelled(true);
    9. player.closeInventory();
    10. player.getInventory().getHelmet().setType(Material.LEATHER_HELMET);
    11. }
    12. }
    13. }
     
  2. Offline

    FadedMystery

    Code:java
    1. public static void checkItem(Player player, ItemStack clicked) {
    2.  
    3. if(clicked.getType() == Material.LEATHER_HELMET) {
    4.  
    5. player.setHelmet(Material.LEATHER_HELMER);
    6.  
    7. }
    8.  
    9. if(clicked.getType() == Material.LEATHER_CHESPLATE) {
    10.  
    11. player.setHelmet(Material.LEATHER_CHESTPLATE);
    12.  
    13. }
    14.  
    15. }
    16.  


    and so on.. that's probally one way you could do it :)
     
  3. Offline

    Legocowchaser

    FadedMystery Ok thanks. I had tried copying pasting that whole thing earlier and got errors. I tried to copy and paste the eventhandler. Thanks this help me a lot! and makes it shorter than I expected.:)[diamond]
    btw how do you make code appear in that boxband make it say your post was read?
     
  4. Offline

    Garris0n

    http://gyazo.com/1f19a46e18e5c5d34a7fec7c5d5beccd
    If that's what you meant.
     
  5. Offline

    Legocowchaser

Thread Status:
Not open for further replies.

Share This Page