Material

Discussion in 'Plugin Development' started by Echo, Oct 8, 2014.

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

    Echo

    Hello,

    I've been making an Inventory plugin, and as some of you will guess, is a modified version from pogostick's tutorial. I'm having 3 issues:
    1. Players cannot blocks around in their regular inventorys.
    2. I have the lore for all set as:
    Code:java
    1. im.setLore(Arrays.asList(ChatColor.RED + "Opens the " + ChatColor.YELLOW + name.toLowerCase() + ChatColor.RED + " menu!"));

    This needs to be per-item.
    3. The blocks are defined as WOOL blocks, I need there to be materials and potion stacks.

    Code:
    Code:java
    1. public class Menu implements Listener {
    2.  
    3. private Inventory em;
    4. private ItemStack e, a, c;
    5.  
    6. public Menu(Plugin p) {
    7. em = Bukkit.getServer().createInventory(null, 9, "Oracle Menu");
    8.  
    9. e = createItem(DyeColor.GREEN, ChatColor.DARK_RED + "Effects");
    10. a = createItem(DyeColor.YELLOW, ChatColor.YELLOW + "Addons");
    11. c = createItem(DyeColor.RED, ChatColor.GRAY + "Close");
    12.  
    13. em.setItem(2, e);
    14. em.setItem(4, c);
    15. em.setItem(6, a);
    16.  
    17. Bukkit.getServer().getPluginManager().registerEvents(this, p);
    18. }
    19.  
    20. private ItemStack createItem(DyeColor dc, String name) {
    21. ItemStack i = new Wool(dc).toItemStack(1);
    22. ItemMeta im = i.getItemMeta();
    23. im.setDisplayName(name);
    24. im.setLore(Arrays.asList(ChatColor.RED + "Opens the " + ChatColor.YELLOW + name.toLowerCase() + ChatColor.RED + " menu!"));
    25. i.setItemMeta(im);
    26. return i;
    27. }
    28.  
    29. public void show(Player p) {
    30. p.openInventory(em);
    31. }
    32.  
    33. @EventHandler
    34. public void onInventoryClick(InventoryClickEvent e) {
    35. if (!e.getInventory().getName().equalsIgnoreCase(em.getName())) return;
    36. if (e.getCurrentItem().getItemMeta() == null) return;
    37. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Effects")) {
    38. e.setCancelled(true);
    39. ((CommandSender) e.getWhoClicked()).sendMessage(ChatColor.RED + "Opening EffectsMenu...");
    40. // Do stuff
    41. e.getWhoClicked().closeInventory();
    42. }
    43. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Addons")) {
    44. e.setCancelled(true);
    45. ((CommandSender) e.getWhoClicked()).sendMessage(ChatColor.RED + "Opening AddonsMenu...");
    46. // Do stuff
    47. e.getWhoClicked().closeInventory();
    48. }
    49. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Close")) {
    50. e.setCancelled(true);
    51. ((CommandSender) e.getWhoClicked()).sendMessage(ChatColor.RED + "Closing OracleMenu");
    52. e.getWhoClicked().closeInventory();
    53. }
    54. }
    55. }

    (This is my mainmenu and I use a different class to summon the inventory.)

    So if anybody knows how to fix those issues, I'd be very greatful!:)

    Thanks:D
     
  2. Offline

    fireblast709

    Echo
    2. Add a parameter for lore
    3. Material.POTION for potions
     
  3. Offline

    Echo

    Hey,

    Would you be able to give me some more info on this? E.g what is the parameter for lore, and could you do an example line for the MATERIAL? :)

    Thanks
     
  4. Offline

    fireblast709

    Echo create an ItemStack with as first parameter Material.POTION. The parameter for lore is something you need to add yourself. It's just like the parameter for the name.
     
Thread Status:
Not open for further replies.

Share This Page