Plugin with openGui not Starting

Discussion in 'Plugin Development' started by Ghost105, Dec 3, 2017.

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

    Ghost105

    Hi,
    Was working on a God stick to use as a trolling/mod tool, and my plugin simply didn't start. No idea why it would be doing this. I have a command in the Main class of the main package that is supposed to print a message to the console when starting up, and for whatever reason, it doesn't send this message; when I do /pl the plugin doesn't show up. Any help on how to fix this?

    Main:
    Code:
    package me.GhostAssasin105.GodStick;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
            System.out.println("(!) GodStick Plugin Active");
            Bukkit.getServer().getPluginManager().registerEvents(new Stick(), this);
            this.getCommand("sticksel").setExecutor((CommandExecutor)new Stick());
        }
    
        public void onDisable() {
            System.out.println("(!) GodStick Plugin Deactivated");
        }
    }
    Stick code:
    Code:
    package me.GhostAssasin105.GodStick;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Stick extends JavaPlugin implements Listener {
    
        private void openGui(Player player) {
    
                ItemStack filler = new ItemStack(Material.STAINED_GLASS_PANE);
                ItemMeta fillermeta = filler.getItemMeta();
                filler.setItemMeta(fillermeta);
                fillermeta.setDisplayName("§0§LEmpty Slot");
            
                ItemStack hunter = new ItemStack(Material.STONE_HOE);
                ItemMeta huntermeta = hunter.getItemMeta();
                huntermeta.setDisplayName("§8§LExplode");
                hunter.setItemMeta(huntermeta);
            
                ItemStack notdone = new ItemStack(Material.BARRIER);
                ItemMeta notdonemeta = notdone.getItemMeta();
                notdonemeta.setDisplayName("§4§LInDev");
                notdone.setItemMeta(notdonemeta);
            
                Inventory inv = Bukkit.createInventory(null, 62, ChatColor.DARK_RED + "GodStick Select");
                inv.setItem(0, filler);
                inv.setItem(1, filler);
                inv.setItem(2, filler);
                inv.setItem(3, filler);
                inv.setItem(4, filler);
                inv.setItem(5, filler);
                inv.setItem(6, filler);
                inv.setItem(7, filler);
                inv.setItem(8, filler);
                inv.setItem(9, filler);
                inv.setItem(10, hunter);
                inv.setItem(11, notdone);
                inv.setItem(12, notdone);
                inv.setItem(13, notdone);
                inv.setItem(14, notdone);
                inv.setItem(15, notdone);
                inv.setItem(16, notdone);
                inv.setItem(17, filler);
                inv.setItem(18, filler);
                inv.setItem(19, notdone);
                inv.setItem(20, notdone);
                inv.setItem(21, notdone);
                inv.setItem(22, notdone);
                inv.setItem(23, notdone);
                inv.setItem(24, notdone);
                inv.setItem(25, notdone);
                inv.setItem(26, filler);
                inv.setItem(27, filler);
                inv.setItem(28, notdone);
                inv.setItem(29, notdone);
                inv.setItem(30, notdone);
                inv.setItem(31, notdone);
                inv.setItem(32, notdone);
                inv.setItem(33, notdone);
                inv.setItem(34, notdone);
                inv.setItem(35, filler);
                inv.setItem(36, filler);
                inv.setItem(37, notdone);
                inv.setItem(38, notdone);
                inv.setItem(39, notdone);
                inv.setItem(40, notdone);
                inv.setItem(41, notdone);
                inv.setItem(42, notdone);
                inv.setItem(43, notdone);
                inv.setItem(44, filler);
                inv.setItem(45, filler);
                inv.setItem(46, notdone);
                inv.setItem(47, notdone);
                inv.setItem(48, notdone);
                inv.setItem(49, notdone);
                inv.setItem(50, notdone);
                inv.setItem(51, notdone);
                inv.setItem(52, notdone);
                inv.setItem(53, filler);
                inv.setItem(54, filler);
                inv.setItem(55, filler);
                inv.setItem(56, filler);
                inv.setItem(57, filler);
                inv.setItem(58, filler);
                inv.setItem(59, filler);
                inv.setItem(60, filler);
                inv.setItem(61, filler);
                inv.setItem(62, filler);
            
                player.openInventory(inv);
        }
    
        
    
        @EventHandler
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("sticksel")) {
                openGui(player);
            }
            return false;
        }
    } 
     
  2. Offline

    Zombie_Striker

    @Ghost105
    There are a lot of reasons why your plugin would not load:
    1. Only one class can extend JavaPlugin. Remove the extends syntax from Stick.
    2. The reason the editor gave you an error when setting the executor is because Stick does not implement CommandExecutor. Replace Listener with CommandExecutor.
    3. Don't blindly cast sender to a player. Consoles, command blocks, and other plugins can use commands as well. Make sure sender is a player before casting/
     
  3. Has the issue been fixed?
     
  4. Offline

    Prasun

    For the fillermeta, you have set the display name AFTER you set the item meta. Might want to fix that. If you want the blocks to do anything on click, you would have to open an event under onInventoryClick and use the switch method.
     
  5. That is incorrect. You can't use item.getItemMeta().setDisplayName(), or item.setItemMeta(meta) and then meta.setDisplayName(); it has to be meta.setDisplayName() and then item.setDisplayName(meta).
     
  6. Offline

    Prasun

    Oh wait, I meant to say before. Sorry for any inconvenience.
     
  7. Offline

    Ghost105

    I actually copied the event code and created a new Main class, and the GUI is now opening fine. However, I'm trying to make it a selection menu, and I've been unable to do this so far. Anyone know how I would be able to do this?
     
Thread Status:
Not open for further replies.

Share This Page