Custom Gui

Discussion in 'Plugin Development' started by ItsMees, Nov 26, 2013.

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

    ItsMees

    Hi Guys,
    I got an problem with my plugin!
    I want it to make that when you have an sign and you right click it you will see an gui with an diamond block. That works! Code:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event){
    3. final Player p = event.getPlayer();
    4. if(p.hasPermission("class.gui")){
    5.  
    6. Block block = event.getClickedBlock();
    7.  
    8. switch(block.getType()) {
    9. case SIGN_POST:
    10. case WALL_SIGN:
    11. case SIGN:
    12. if(((Sign) block.getState()).getLine(0).equalsIgnoreCase("[kit]")){
    13. Inventory inv = Bukkit.getServer().createInventory(p, 54, "Classes");
    14.  
    15. ItemStack zero_is = new ItemStack(Material.DIAMOND_BLOCK);
    16. ItemMeta zero_im = zero_is.getItemMeta();
    17. zero_im.setDisplayName(ChatColor.GREEN + "Fighter" + ChatColor.WHITE + " - " + ChatColor.RED + "$100");
    18. zero_is.setItemMeta(zero_im);
    19. inv.setItem(0, zero_is);
    20.  
    21. p.openInventory(inv);
    22. }
    23. break;
    24. default:
    25. break;
    26. }
    27. }
    28. }

    But than I want it to make that when you click the diamond block you get items! But my code doesnt work! My code:
    Code:java
    1. @EventHandler
    2. public void inventoryclick(InventoryClickEvent e){
    3. if (e.getInventory().getName().equalsIgnoreCase("Classes")){
    4. if (e.getRawSlot() < 54 && e.getRawSlot() > -1){
    5. ItemStack cursor = e.getCursor();
    6. ItemStack itemclicked = e.getCurrentItem();
    7. Player p = (Player) e.getWhoClicked();
    8. e.setCancelled(true);
    9. if (cursor.getType() == Material.DIAMOND_BLOCK){
    10. p.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
    11. p.getInventory().addItem(new ItemStack(Material.PORK, 16));
    12. p.getInventory().addItem(new ItemStack(Material.ARROW, 1));
    13. ItemStack bow = new ItemStack(Material.BOW, 1);
    14. bow.addEnchantment(Enchantment.ARROW_INFINITE,1);
    15. p.getInventory().addItem(bow);
    16.  
    17. p.sendMessage(ChatColor.RED + "[C-Kits]" + ChatColor.WHITE + "You both the " + ChatColor.YELLOW + "Fighter" + ChatColor.WHITE + " class!");
    18. p.closeInventory();
    19. }
    20. }
    21. }
    22. }
    23.  

    I hope someone can help me out!
    Bye!
     
  2. Offline

    calebbfmv

    ItsMees
    Check if the currentitem !=null, then check what it is, then do whatever you need.
     
Thread Status:
Not open for further replies.

Share This Page