Solved Plugin wont show up in game when i type /pl

Discussion in 'Plugin Development' started by Baklava, Jul 18, 2019.

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

    Baklava

    Hello! I am currently learing to write bukkit plugins and as an exercise i tried making a soup PVP plugin. But when i put the jar in my plugins folder, start my server and type /pl it wont show up. Of course the plugin isn't working either.

    Here is a screenshot of what all the different files in the project are called:
    [​IMG]
    Here is the code in Mainclass.java:
    Code:
    package me.Baklava.PvPEssentials;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.Baklava.PvPEssentials.events.Events;
    
    
    public class Mainclass extends JavaPlugin    {
       
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new Events(), this);
        }
       
        public void onDisable() {
            System.out.println("PvPEssentials has been disabled");
        }
       
    }
    Here is the code in Event.Java:
    Code:
    package me.Baklava.PvPEssentials.events;
    
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    
    public class Events implements Listener {
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
           
            if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
                event.getPlayer().setHealth((double)event.getPlayer().getHealth() + (double)10);
                event.getPlayer().getInventory().setItemInHand(new ItemStack(Material.BOWL,1));
            }
           
        }
    }
    
    Here is the Plugin.yml: (i didnt use tabs)

    name: PvPEssentials
    version: 1.0
    main: me.Baklava.PvPEssentials.Mainclass

    And here is the nice error message i'm greeted with when i open the console:
    18.07 11:39:20 [Server] ERROR Could not load 'plugins/pvpessentials.jar' in folder 'plugins'
    18.07 11:39:20 [Server] INFO org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.baklava.pvpessentials.Mainclass'

    Apperently it can't find the Main class. I tried checking if i spelled it correctly, but i couldn't see any spelling errors. All help would be greatly appreciated!
     
  2. Online

    timtower Moderator Moderator

    @Baklava 1. Funny that you made a screenshot from a screenshot :p
    2. Please open up the exported jar with a zip program and see if the files are there.
     
  3. Offline

    Baklava

    (Haha took only 1 screenshot this time :) )
    Yes, files seem to be there. If i check in me/Baklava/PvPEssentials my Mainclass class is there. There is also another package/folder there called Events containing my events class. Could that be the problem? [​IMG]
     
  4. Offline

    CraftCreeper6

    @Baklava
    Post your Plugin.yml, despite what the stacktrace says, it's worth a check.
     
  5. Online

    timtower Moderator Moderator

    It is in his first post already.
     
  6. Offline

    CraftCreeper6

    @timtower
    Completely missed that.

    @Baklava
    I've got honestly no idea. The only thing I can think of, and it's pretty dumb, but removing capital letters from your package name. Granted it's only convention and not necessary; it's genuinely the only thing that springs to mind.
     
  7. Offline

    Baklava

    Yep, ill try removing capital letters. Thanks!
    Btw are there any obvious errors with the code you can easily spot? Thanks again!
     
  8. Offline

    CraftCreeper6

    @Baklava
    Looks fine, only way to find out is to test it.
     
  9. Offline

    Baklava

    Yes haha, this worked! the plugin is now showing up in /pl, but the code isnt working xD, could you be so nice and help me just a little more?

    Here is all the code in Mainclass:
    Code:
    package me.baklava.enhancedpvp;
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.baklava.enhancedpvp.events.Events;
    
    public class Mainclass extends JavaPlugin    {
       
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents((Listener) new Events(), this);
        }
    }
    Here is everything in the Events class:
    Code:
    package me.baklava.enhancedpvp.events;
    
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    
    public class Events implements Listener {
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
           
            if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
                event.getPlayer().setHealth((double)event.getPlayer().getHealth() + (double)10);
                event.getPlayer().getInventory().setItemInHand(new ItemStack(Material.BOWL,1));
            }
           
        }
    }
    
    Nothing is beeing underlined with red, and right/left clicking with soup does nothing

    Thanks!
     
  10. Offline

    CraftCreeper6

    @Baklava
    Wow, that was a long shot lol.


    Add some debugs, does the event actually fire? Is the if statement satisfied?
     
  11. Offline

    Baklava

    Yep, it was indeed. This is my first forum post ever lol
    The original problem is hereby solved
    Thanks for the help and have a nice day!
     
    CraftCreeper6 likes this.
Thread Status:
Not open for further replies.

Share This Page