Solved Why my code doesn't work?

Discussion in 'Spigot Plugin Development' started by MarkerGamer, Mar 3, 2020.

  1. This is all my code
    Code (Java):
    package me.minicraftstudio.Test;

    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class RPGInventoryFixed extends JavaPlugin{
     
        @Override
        public void onEnable() {
            Bukkit.getServer().getLogger().info("[Test] Plugin is working :3");
        }
     
        @EventHandler
        public void onCloseInventory(InventoryCloseEvent event){
            String inv_name =  event.getView().getTitle();
            Bukkit.getServer().broadcastMessage(inv_name);
        }
     
    }
    I'm beginner java devoloper this is my first plugin
    but when i open chest and closed or open inventory and closed
    it nothing any show message :cry::cry:

    Please Help me, Thank you very much :oops:
    ( sorry, i'm not good at english )


    ( Spigot 1.15.2 , JavaSE-1.8)
     
  2. public class RPGInventoryFixed extends JavaPlugin implements Listener{

    and also add this to onEnable

    getServer().getPluginManager().registerEvents(this, this);
     
    • Agree Agree x 1
  3. Thank you very much, it work!
    Would you please explain it to me?
     
  4. "Implements Listener" allows the class to listen to minecraft events(when something happens),second parts us registering your event modification where you grab the name of inventory broadcast it and such..
     
    • Like Like x 1
  5. Thank you :D