void is an invalid type for the variable "x"

Discussion in 'Plugin Development' started by JhonnyKPL, Aug 17, 2014.

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

    JhonnyKPL

    Whats wrong with this code!?
    When I put the mouse arrow on clickInventory it says: "void is an invalid type for the variable clickInventory". I don't know why! Please help me :'(

    Here's the code:

    Code:java
    1. public void clickInventory(InventoryClickEvent e)


    Here's the full code:

    Code:java
    1. package com.JhonnyKPL.ExplodingArrows;
    2.  
    3. import java.util.Arrays;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Effect;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.inventory.InventoryClickEvent;
    16. import org.bukkit.inventory.Inventory;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.meta.ItemMeta;
    19. import org.bukkit.plugin.Plugin;
    20.  
    21. public class ExplodingArrowsInv implements Listener,CommandExecutor {
    22.  
    23. private ExplodingArrows plugin;
    24. private Inventory inv;
    25. private ItemStack item1, true1, true2, false1, false2;
    26. public ExplodingArrowsInv(ExplodingArrows plugin){
    27. this.plugin = plugin;
    28. }
    29.  
    30. public ExplodingArrowsInv(Plugin plugin) {
    31.  
    32.  
    33. inv = Bukkit.getServer().createInventory(null, 27,ChatColor.BOLD + "Freccie Esplosive");
    34.  
    35.  
    36. //Freccia al centro
    37. item1 = new ItemStack(Material.ARROW);
    38. ItemMeta im1 = item1.getItemMeta();
    39. im1.setDisplayName(ChatColor.BOLD + "Freccie esplosive");
    40. im1.setLore(Arrays.asList("Clicca per attivare o disattivare","merdonelorenzole" + ChatColor.UNDERLINE + "freccie esplosive"));
    41. inv.setItem(14, item1);
    42.  
    43. //Colorante verde
    44. true1 = new ItemStack(351, 1, (short)10);
    45. ItemMeta imt1 = true1.getItemMeta();
    46. imt1.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Attive");
    47.  
    48. //Colorante rosso
    49. false1 = new ItemStack(351, 1, (short)1);
    50. ItemMeta imf1 = false1.getItemMeta();
    51. imf1.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Disattive");
    52.  
    53. inv.setItem(13, false1);
    54.  
    55. inv.setItem(15, false1);
    56.  
    57.  
    58. Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
    59. }
    60.  
    61. /* @EventHandler
    62. public void Kit(AsyncPlayerChatEvent e){
    63. String str = e.getMessage();
    64. if(str.contains("/kit")){
    65. e.setCancelled(true);
    66. e.getPlayer().sendMessage("TEST");
    67. show(e.getPlayer());
    68. }
    69. }
    70. @EventHandler
    71. public void test(PlayerInteractEvent e){
    72. Player p = e.getPlayer();
    73. Action a = e.getAction();
    74. if(a == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.BLAZE_ROD){
    75. show(p);
    76.  
    77. }
    78. } */
    79.  
    80.  
    81.  
    82. @Override
    83. public boolean onCommand(CommandSender sender, Command command, String label,
    84. String[] args) {
    85. if(sender instanceof Player == false){
    86. sender.sendMessage(ChatColor.RED + "Devi essere un player per utilizzare questo comando");
    87. return false;
    88. }
    89. Player p = (Player) sender;
    90. String playerName = p.getName();
    91. if (plugin.enabledPlayers.contains(playerName)){
    92.  
    93.  
    94. p.openInventory(inv);
    95.  
    96. }
    97. @EventHandler
    98. public void clickInventory(InventoryClickEvent e) {
    99. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return false;
    100.  
    101. if (e.getCurrentItem().getItemMeta() == null) return false;
    102.  
    103. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Freccie Esplosive")) {
    104. e.setCancelled(true);
    105. plugin.enabledPlayers.remove(playerName);
    106. e.getWhoClicked().closeInventory();
    107. p.sendMessage(ChatColor.RED + "Le freccie esplosive sono state disabilitate per " + ChatColor.BOLD + "" + playerName);
    108. }
    109. }
    110. if (!plugin.enabledPlayers.contains(playerName)){
    111.  
    112. p.openInventory(inv);
    113. }
    114.  
    115. @EventHandler
    116. public void clickInventory(InventoryClickEvent e) {
    117. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return false;
    118.  
    119. if (e.getCurrentItem().getItemMeta() == null) return false;
    120.  
    121. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Freccie Esplosive")) {
    122. e.setCancelled(true);
    123. plugin.enabledPlayers.add(playerName);
    124. e.getWhoClicked().closeInventory();
    125. p.sendMessage(ChatColor.GREEN + "Le freccie esplosive sono state abilitate per " + ChatColor.BOLD + "" + playerName);
    126. }
    127. }
    128.  
    129.  
    130. return false;
    131. }
    132. }
    133.  
     
  2. Offline

    mythbusterma

    Because JhonnyKPL , EventHandlers are methods, and methods cannot be declared inside other methods, such as command handlers.
     
  3. Offline

    JhonnyKPL

    So what I can do?
     
  4. Offline

    teej107

  5. Offline

    SpaceManiac

    Your braces are mismatched so you're trying to put one method inside another, which isn't allowed. You just need to rearrange your code and add missing braces.
     
Thread Status:
Not open for further replies.

Share This Page