Plugin Loads with no errors, but does nothing

Discussion in 'Plugin Development' started by Godbrandont, May 20, 2015.

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

    Godbrandont

    Hello, I have recently been developing a plugin and it loads no problem, however it literally does nothing. It's basically a useless plugin and I don't know what's wrong with it. I know it's not something with my code because I basically copied it as a base from one of my older plugins. I've done tests by doing Bukkit.broadcastMessage("test"); at various different points including the OnEnable function, however it does nothing. Has this happened before? Any help would be appreciated. Thanks.
     
  2. Offline

    CoolGamerXD

  3. Offline

    Godbrandont

    Main.java
    Code:
    package me.Godbrandont.Retribution;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
       
        public void OnEnable()
        {
            Bukkit.broadcastMessage("test");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Bukkit.getServer().getPluginManager().registerEvents(new Events(this), this);
            registerListeners();
        }
       
        public void registerListeners()
        {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Events(this), this);
        }
    
       
       
       
       
    }   
        
    Events.java
    Code:
    package me.Godbrandont.Retribution;
    
    import org.bukkit.event.Listener;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class Events implements Listener{
       
        static Main plugin;
       
        public Events(Main pl) {
            plugin = pl;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e)
        {
            Player p = e.getPlayer();
            p.sendMessage("Test");
            p.getInventory().setContents(null);
            p.getInventory().addItem(new ItemStack(Material.COCOA, 1));
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e)
        {
            Player p = e.getPlayer();
            if((e.getAction() == Action.RIGHT_CLICK_AIR)||(e.getAction() == Action.RIGHT_CLICK_BLOCK))
            {
                p.sendMessage("Test 2");
                if(e.getItem().getType() == Material.COCOA)
                {
                    p.sendMessage("Test 3");
                    Arrow a = p.launchProjectile(Arrow.class);
                    a.setVelocity(p.getLocation().getDirection().multiply(1D)); // <-- lol 1D
                    a.getWorld().playSound(a.getLocation(), Sound.FIREWORK_BLAST, 10, 1);
                }
                Arrow a = p.launchProjectile(Arrow.class);
                a.setVelocity(p.getLocation().getDirection().multiply(1D)); // <-- lol 1D
                a.getWorld().playSound(a.getLocation(), Sound.FIREWORK_BLAST, 10, 1);
            }
        }
       
    }
    
     
  4. Offline

    CoolGamerXD

    @Godbrandont Why do you register your events multiple times? You can just do it with single code
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(new Events(this), this)
     
  5. Offline

    Godbrandont

    @CoolGamerXD Yes well done, please don't criticise my code and focus on the actual topic of the thread. I was testing things as I was trying to fix it myself but I couldn't find a solution so I came here.
     
  6. Online

    timtower Administrator Administrator Moderator

    @Godbrandont onEnable starts with a lowercase. Same for onDisable. Casing is pretty important here.
     
  7. Offline

    Godbrandont

    Oh crap! Yeah thanks a lot Tim haha. I always find it's the most simple of errors.
     
  8. Please mark it as Solved
     
  9. Offline

    teej107

    This here is a great example on why you should use the @Override annotation.
     
Thread Status:
Not open for further replies.

Share This Page