void is an invalid type for the variable onPlayerUse

Discussion in 'Plugin Development' started by SkiBoy28, Aug 13, 2019.

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

    SkiBoy28

    im trying to make is that when you throw an egg it makes a 11x11 wall of bedrock in front of you that disappears after 20 seconds


    Code:
    package me.SkiBoy28.CustomEggShield;
    
    
    
    import org.bukkit.ChatColor;
    
    import org.bukkit.Material;
    
    import org.bukkit.entity.Player;
    
    import org.bukkit.event.EventHandler;
    
    import org.bukkit.event.EventPriority;
    
    import org.bukkit.event.Listener;
    
    import org.bukkit.event.block.Action;
    
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import org.bukkit.inventory.ItemStack;
    
    import org.bukkit.inventory.meta.ItemMeta;
    
    
    
    public class CESlistener implements Listener {
    
      
    
        public CESlistener(Main Plugin) {      
    
          
    
            ItemStack BedrockWall = new ItemStack(Material.EGG, 1);
    
            ItemMeta meta = BedrockWall.getItemMeta();
    
            meta.setDisplayName(ChatColor.GOLD +"Bedrock Wall");
    
            @EventHandler(priority=EventPriority.HIGH)
    
            public void onPlayerUse; PlayerInteractEvent event; {
    
                Player p = event.getPlayer();
    
        
    
                if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    
                    if(p.getItemInHand().getType() == Material.EGG)
    
                      p.getLocation();
     
    Last edited by a moderator: Aug 18, 2019
  2. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 It seems that your code is not properly formatted and missing pieces, could you post it again?
     
    SkiBoy28 likes this.
  3. Offline

    SkiBoy28

    this is my first plugin and I kind of just winged it and I do kind of realize that my plugin may be all messed up although i do have another class called main.
    Code:
    package me.SkiBoy28.CustomEggShield;
    
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
           
            getLogger().info("BedrockWallPLugin has been activated");
            PluginManager pm = getServer().getPluginManager();
            CESlistener listener = new CESlistener(this);
            pm.registerEvents(listener, this);
           
        }
        @Override
        public void onDisable() {
           
            getLogger().info("BedrockWallPLugin has been DeActivated");
        }
    }
    i was hoping that somebody could point out some of my mistakes that I made here
    @timtower

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 18, 2019
  4. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 Besides the unneeded logging: nothing wrong here.
    Could you post the CESlistener class?
     
    SkiBoy28 likes this.
  5. Offline

    SkiBoy28

    Code:
    package me.SkiBoy28.CustomEggShield;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class CESlistener implements Listener {
       
        public CESlistener(Main Plugin) {       
           
            ItemStack BedrockWall = new ItemStack(Material.EGG, 1);
            ItemMeta meta = BedrockWall.getItemMeta();
            meta.setDisplayName(ChatColor.GOLD +"Bedrock Wall"); 
            @EventHandler(priority=EventPriority.HIGH)
           public void onPlayerUse; PlayerInteractEvent event; {
               Player p = event.getPlayer();
         
               if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                   if(p.getItemInHand().getType() == Material.EGG)
                     p.getLocation();
                 
                       
                              }
                          }
    
    on the line public void onPlayerUse it tells me that onPlayerUse is an invalid variable for the type public void and idk why @timtower
     
  6. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 Because you are trying to put a method in a method.
    That is not possible.
     
    SkiBoy28 likes this.
  7. Offline

    SkiBoy28

    @timtower so do i need to make a new class? what do i need to do to fix it? im very new to making plugins as you can probably tell. also, how do i import the data from one class to another such as the itemstack that i created in my CESListener class?
     
    Last edited: Aug 19, 2019
  8. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 No, you need to pull the event method out of the constructor.
     
  9. Offline

    SkiBoy28

  10. Online

    timtower Administrator Administrator Moderator

  11. Offline

    SkiBoy28

    @timtower is that a good website to learn a lot about creating plugins?
     
  12. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 Learning creating plugins is by doing.
    You are lacking Java knowledge though. You need to know Java before you can make plugins.
     
    Twisted_Panda likes this.
  13. Offline

    SkiBoy28

    ok but when i make a new method for the event i still get the same error message saying that onPlayerUse is an invalid variable for the type public void @timtower
     
  14. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 Then post your new formatted code.
     
  15. Offline

    SkiBoy28

    im not even sure if it is formatted correctly, i dont think it is

    Code:
    package me.SkiBoy28.CustomEggShield;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class CESlistener implements Listener {
       
        public CESlistener(Main Plugin) {       
           
            ItemStack BedrockWall = new ItemStack(Material.EGG, 1);
            ItemMeta meta = BedrockWall.getItemMeta();
            meta.setDisplayName(ChatColor.GOLD +"Bedrock Wall"); 
           
       
    public class CESlistener implements Listener {
       
        public void onPlayerUse; PlayerInteractEvent event; {
            @EventHandler(priority=EventPriority.HIGH)
            Player p = event.getPlayer();
         
               if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                   if(p.getItemInHand().getType() == Material.EGG)
                     p.getLocation();
                 
                       
                              }
                          }       
                       
    
                }
            }   
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  16. Online

    timtower Administrator Administrator Moderator

    @SkiBoy28 Not helping with that.
    You are missing a lot of Java knowledge.
     
  17. Offline

    SkiBoy28

    @timtower yeah i am going to stop bugging you and learn more about java. thanks for helping
     
Thread Status:
Not open for further replies.

Share This Page