Problem with onPlayerInteract and onInventoryClick

Discussion in 'Plugin Development' started by pinkitty1, Mar 27, 2014.

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

    pinkitty1

    Hi, so I recently gotten into coding Minecraft plugins and I'm having troubles with both onPlayerInteract and onInventoryClick and I noticed I wasn't the only person having troubles with this plugin I was hoping the plugin dev that helped with the server I play on to help, but he hasn't been on in a very long time (probably because he is working on his own server). here is the code
    Code:java
    1. @EventHandler
    2. public void onInventoryClick;
    3. InventoryClickEvent event;
    4. {

    And
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract;
    3. PlayerInteractEvent e;
    4. {

    I'm hoping the dev can help :) Garris0n
     
  2. Offline

    xTigerRebornx

    pinkitty1 So.....exactly what is the problem?
     
  3. Offline

    The Fancy Whale

    Not really sure what the problem is but just going to guess you forgot to register events...
     
  4. Offline

    pinkitty1

    I am getting this whenever I hover my mouse over the errors "void is an invalid type for the variable onInventoryClick" and the same thing for onPlayerInteract
     
  5. Offline

    xTigerRebornx

    pinkitty1 I suggest you go and learn basic Java if you want to understand the problem, and try and begin coding plugins. You'll have a hard time understanding most things if you don't
     
  6. Offline

    Gater12

  7. Offline

    JBoss925

    You didn't set up the event right.
     
  8. Offline

    Jalau

    @EventHandler
    public void interact(PlayerInteractEvent e) {
    }
    Job done :p
     
  9. Offline

    pinkitty1

    I think it might have to deal with something I did wrong (most likely case, and I'm hoping that is the case) here is a look at a little amount of the code and the picture with the errors in it
    [​IMG]
    [​IMG]
     
  10. Offline

    Jalau

    What is the error if you hover over it? ;)
     
  11. Offline

    pinkitty1

    Sadly the same thing :/
     
  12. Offline

    Anerdson

    I think it is a problem with your syntax.
     
  13. Offline

    EnchantedMiners

    pinkitty1
    can you post you're full class here so we can look over it? it would be easier
     
  14. Offline

    pinkitty1

    Lol alright but keep in mind I recently got into coding plugins and let alone I really don't know java well, because so far the most complex plugin I made was you do /freeze and it freezes every player including you
    Code:java
    1. package com.pinkitty1.CustomInv;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.inventory.InventoryClickEvent;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15.  
    16. public class CustomInv extends org.bukkit.plugin.java.JavaPlugin implements
    17. Listener {
    18.  
    19. public void onEnable() {
    20. getServer().getPluginManager().registerEvents(this, this);
    21.  
    22. }
    23.  
    24. private void openGUI(Player player) {
    25. Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN
    26. + "Chest Selector");
    27.  
    28. Inventory chest1inv = Bukkit.createInventory(null, 54,
    29. ChatColor.DARK_GREEN + "Double Chest 1");
    30. ItemStack chest1 = new ItemStack(Material.CHEST);
    31. ItemMeta chest1Meta = chest1.getItemMeta();
    32.  
    33. ItemStack chest2 = new ItemStack(Material.ACACIA_STAIRS);
    34. ItemMeta chest2Meta = chest2.getItemMeta();
    35. Inventory chest2inv = Bukkit.createInventory(null, 54,
    36. ChatColor.DARK_GREEN + "Double Chest 2");
    37.  
    38. ItemStack chest3 = new ItemStack(Material.APPLE);
    39. ItemMeta chest3Meta = chest3.getItemMeta();
    40. Inventory chest3inv = Bukkit.createInventory(null, 54,
    41. ChatColor.DARK_GREEN + "Double Chest 3");
    42.  
    43. ItemStack chest4 = new ItemStack(Material.BAKED_POTATO);
    44. ItemMeta chest4Meta = chest4.getItemMeta();
    45. Inventory chest4inv = Bukkit.createInventory(null, 54,
    46. ChatColor.DARK_GREEN + "Double Chest 4");
    47.  
    48. ItemStack chest5 = new ItemStack(Material.BIRCH_WOOD_STAIRS);
    49. ItemMeta chest5Meta = chest5.getItemMeta();
    50. Inventory chest5inv = Bukkit.createInventory(null, 54,
    51. ChatColor.DARK_GREEN + "Double Chest 5");
    52.  
    53. ItemStack chest6 = new ItemStack(Material.BONE);
    54. ItemMeta chest6Meta = chest6.getItemMeta();
    55. Inventory chest6inv = Bukkit.createInventory(null, 54,
    56. ChatColor.DARK_GREEN + "Double Chest 6");
    57.  
    58. ItemStack chest7 = new ItemStack(Material.BOOK);
    59. ItemMeta chest7Meta = chest7.getItemMeta();
    60. Inventory chest7inv = Bukkit.createInventory(null, 54,
    61. ChatColor.DARK_GREEN + "Double Chest 7");
    62.  
    63. ItemStack chest8 = new ItemStack(Material.BOWL);
    64. ItemMeta chest8Meta = chest8.getItemMeta();
    65. Inventory chest8inv = Bukkit.createInventory(null, 54,
    66. ChatColor.DARK_GREEN + "Double Chest 8");
    67.  
    68. ItemStack chest9 = new ItemStack(Material.BUCKET);
    69. ItemMeta chest9Meta = chest9.getItemMeta();
    70. Inventory chest9inv = Bukkit.createInventory(null, 54,
    71. ChatColor.DARK_GREEN + "Double Chest 9");
    72.  
    73. chest1Meta.setDisplayName(ChatColor.DARK_RED + "Chest 1");
    74. chest1.setItemMeta(chest1Meta);
    75.  
    76. chest2Meta.setDisplayName(ChatColor.DARK_RED + "Chest 2");
    77. chest2.setItemMeta(chest2Meta);
    78.  
    79. chest1Meta.setDisplayName(ChatColor.DARK_RED + "Chest 3");
    80. chest3.setItemMeta(chest3Meta);
    81.  
    82. chest4Meta.setDisplayName(ChatColor.DARK_RED + "Chest 4");
    83. chest4.setItemMeta(chest4Meta);
    84.  
    85. chest5Meta.setDisplayName(ChatColor.DARK_RED + "Chest 5");
    86. chest5.setItemMeta(chest5Meta);
    87.  
    88. chest6Meta.setDisplayName(ChatColor.DARK_RED + "Chest 6");
    89. chest6.setItemMeta(chest6Meta);
    90.  
    91. chest7Meta.setDisplayName(ChatColor.DARK_RED + "Chest 7");
    92. chest7.setItemMeta(chest7Meta);
    93.  
    94. chest8Meta.setDisplayName(ChatColor.DARK_RED + "Chest 8");
    95. chest8.setItemMeta(chest8Meta);
    96.  
    97. chest9Meta.setDisplayName(ChatColor.DARK_RED + "Chest 9");
    98. chest9.setItemMeta(chest9Meta);
    99.  
    100. inv.setItem(0, chest1);
    101. inv.setItem(1, chest2);
    102. inv.setItem(2, chest3);
    103. inv.setItem(3, chest4);
    104. inv.setItem(4, chest5);
    105. inv.setItem(5, chest6);
    106. inv.setItem(6, chest7);
    107. inv.setItem(7, chest8);
    108. inv.setItem(8, chest9);
    109.  
    110. player.openInventory(inv);
    111. {
    112. @EventHandler
    113. public void invclick(
    114. InventoryClickEvent event){
    115.  
    116. if (ChatColor.stripColor(event.getInventory().getName())
    117. .equalsIgnoreCase("Chest Selector"))
    118. return;
    119. Player player1 = (Player) event.getWhoClicked();
    120. event.setCancelled(true);
    121.  
    122. if (event.getCurrentItem() == null
    123. || event.getCurrentItem().getType() == Material.AIR
    124. || !event.getCurrentItem().hasItemMeta()) {
    125. player1.closeInventory();
    126. return;
    127.  
    128. switch (event.getCurrentItem().getType()) {
    129. case CHEST:
    130. player1.openInventory(chest1inv);
    131. break;
    132. case ACACIA_STAIRS:
    133. player1.openInventory(chest2inv);
    134. break;
    135. case APPLE:
    136. player1.openInventory(chest3inv);
    137. break;
    138. case BAKED_POTATO:
    139. player1.openInventory(chest4inv);
    140. break;
    141. case BIRCH_WOOD_STAIRS:
    142. player1.openInventory(chest5inv);
    143. break;
    144. case BONE:
    145. player1.openInventory(chest6inv);
    146. break;
    147. case BOOK:
    148. player1.openInventory(chest7inv);
    149. break;
    150. case BOWL:
    151. player1.openInventory(chest8inv);
    152. break;
    153. case BUCKET:
    154. player1.openInventory(chest9inv);
    155. break;
    156.  
    157. default:
    158. player.closeInventory();
    159. break;
    160.  
    161. }
    162.  
    163. @EventHandler
    164. public void interact(PlayerInteractEvent e) {
    165.  
    166. Action a = e.getAction();
    167. ItemStack is = e.getItem();
    168.  
    169. if (a == Action.PHYSICAL || is == null
    170. || is.getType() == Material.AIR)
    171. return;
    172.  
    173. if (is.getType() == Material.FEATHER)
    174. openGUI(e.getPlayer());
    175. }
    176. }
    177. }
    178. }
    179. }
    180. }
    181.  
    and yes I know the } brackets are in the wrong places but I didn't want to go over the video I used again for the custom gui I was in fact lazy :p
     
  15. Offline

    EnchantedMiners

    pinkitty1
    you really should keep learning java and the bukki api tell a friend to help you out on it or look on TheBCBros tutorials they are really helpful
     
  16. Offline

    pinkitty1

    I used TheBCBros video on custom gui's but out of all of my friends none of them even know how to code D: but I guess I will go over the video again
     
  17. Offline

    pinkitty1

    EnchantedMiners
    So I tried to fix what was wrong but now I am getting errors here
    Code:java
    1. switch (event.getCurrentItem().getType()) {
    2. case CHEST:
    3. player1.openInventory(chest1inv);
    4. break;
    5. case ACACIA_STAIRS:
    6. player1.openInventory(chest2inv);
    7. break;
    8. case APPLE:
    9. player1.openInventory(chest3inv);
    10. break;
    11. case BAKED_POTATO:
    12. player1.openInventory(chest4inv);
    13. break;
    14. case BIRCH_WOOD_STAIRS:
    15. player1.openInventory(chest5inv);
    16. break;
    17. case BONE:
    18. player1.openInventory(chest6inv);
    19. break;
    20. case BOOK:
    21. player1.openInventory(chest7inv);
    22. break;
    23. case BOWL:
    24. player1.openInventory(chest8inv);
    25. break;
    26. case BUCKET:
    27. player1.openInventory(chest9inv);
    28. break
    and also here
    Code:java
    1. Inventory chest1inv = Bukkit.createInventory(null, 54,
    2. ChatColor.DARK_GREEN + "Double Chest 1");
    3. ItemStack chest1 = new ItemStack(Material.CHEST);
    4. ItemMeta chest1Meta = chest1.getItemMeta();
    5.  
    6. ItemStack chest2 = new ItemStack(Material.ACACIA_STAIRS);
    7. ItemMeta chest2Meta = chest2.getItemMeta();
    8. Inventory chest2inv = Bukkit.createInventory(null, 54,
    9. ChatColor.DARK_GREEN + "Double Chest 2");
    10.  
    11. ItemStack chest3 = new ItemStack(Material.APPLE);
    12. ItemMeta chest3Meta = chest3.getItemMeta();
    13. Inventory chest3inv = Bukkit.createInventory(null, 54,
    14. ChatColor.DARK_GREEN + "Double Chest 3");
    15.  
    16. ItemStack chest4 = new ItemStack(Material.BAKED_POTATO);
    17. ItemMeta chest4Meta = chest4.getItemMeta();
    18. Inventory chest4inv = Bukkit.createInventory(null, 54,
    19. ChatColor.DARK_GREEN + "Double Chest 4");
    20.  
    21. ItemStack chest5 = new ItemStack(Material.BIRCH_WOOD_STAIRS);
    22. ItemMeta chest5Meta = chest5.getItemMeta();
    23. Inventory chest5inv = Bukkit.createInventory(null, 54,
    24. ChatColor.DARK_GREEN + "Double Chest 5");
    25.  
    26. ItemStack chest6 = new ItemStack(Material.BONE);
    27. ItemMeta chest6Meta = chest6.getItemMeta();
    28. Inventory chest6inv = Bukkit.createInventory(null, 54,
    29. ChatColor.DARK_GREEN + "Double Chest 6");
    30.  
    31. ItemStack chest7 = new ItemStack(Material.BOOK);
    32. ItemMeta chest7Meta = chest7.getItemMeta();
    33. Inventory chest7inv = Bukkit.createInventory(null, 54,
    34. ChatColor.DARK_GREEN + "Double Chest 7");
    35.  
    36. ItemStack chest8 = new ItemStack(Material.BOWL);
    37. ItemMeta chest8Meta = chest8.getItemMeta();
    38. Inventory chest8inv = Bukkit.createInventory(null, 54,
    39. ChatColor.DARK_GREEN + "Double Chest 8");
    40.  
    41. ItemStack chest9 = new ItemStack(Material.BUCKET);
    42. ItemMeta chest9Meta = chest9.getItemMeta();
    43. Inventory chest9inv = Bukkit.createInventory(null, 54,
    44. ChatColor.DARK_GREEN + "Double Chest 9");
    The error messages are "chest1inv cannot be resolved to a variable" and "The value of the local variable chest1inv is not used" if you think you can fix this I will be very happy :D
     
  18. Offline

    GaaTavares

    "The value of the local variable chest1inv is not used" is not an error ,is just a 'tip'.
    All errors you are/were getting could be easily fixed with a bit knowledge about Java. I'm not saying you need to stop asking for help, what I am saying is that you must at least know java to code a plugin. Bukkit has nothing to do with the errors that you are getting, actually you don't really need to learn java to know what "chest1inv cannot be resolved to a variable" means (you must know English for that). So I really recommend either watching more videos or try to learn java (again, I guess you tried once). Good luck.
     
  19. Offline

    pinkitty1

    Yea I know I'm just a bit hesitant I guess since I already coded a minecraft mod without knowing java
     
  20. Offline

    EnchantedMiners

    pinkitty1 can you tell me what you actually want to do with you're plugin ? so i can make a quick code for you
     
Thread Status:
Not open for further replies.

Share This Page