When creating Multiple Classes W/ IconMenus The Code "Fails"

Discussion in 'Spigot Plugin Development' started by Surprisejedi, Apr 26, 2017.

  1. So, I am following the IconMenu tutorial that Nisovin put out a while ago (https://bukkit.org/threads/icon-menu.108342/) And Then I got into Multiple Classes... Everything Collapsed. When trying to add the IconMenu Object to one of my Classes (not the main one) everything turned red! It doesn't error when I add
    But, as I am using multiple classes, I can't do that.
    Here is my Error:
    Code (Java):
    The constructor IconMenu(String, int, new IconMenu.OptionClickEventHandler(){}, Ban) is undefined
    Here is my Main Class:
    Code (Java):
    package me.surprisejedi.mains;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    import me.surprisejedi.mains.Ban;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin{ //Extending JavaPlugin so that Bukkit knows its the main class...

        private static Plugin plugin;

        public void onEnable() {
            plugin = this;
            getCommand("pb").setExecutor(new Ban());
            getCommand("fr").setExecutor(new Effects());
        }

        public void onDisable() {

        }

        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners) {
                Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
        }

        //To access the plugin variable from other classes
        public static Plugin getPlugin() {
            return plugin;
        }

    }
     
    And My "Ban" class:

    Code (Java):

    package me.surprisejedi.mains;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import me.surprisejedi.mains.Main;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    class Ban implements CommandExecutor {
        public static IconMenu im;
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents((Listener) im, (Plugin) this);
        }
        IconMenu menu = new IconMenu("Ban A Player", 9, new IconMenu.OptionClickEventHandler() {
            @SuppressWarnings({ "static-access" })
     
            @Override
            public void onOptionClick(IconMenu.OptionClickEvent event) {
                if(event.getPosition() == 3){
             
                    //target.setBanned(true);
                    banReason = "PvP Hacking or Similar";
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + args[0] + " " + banReason);
                    //target.kickPlayer(ChatColor.DARK_RED + "» " + ChatColor.RED + "You have been PERMENTALLY banned for " + "[" + banReason + "]" + "!");
                    Bukkit.broadcastMessage(ChatColor.DARK_RED + "» " + ChatColor.BOLD.WHITE + "BANNED PLAYER " + ChatColor.BOLD.DARK_RED + "[" + args[0] + "]" + ChatColor.BOLD.WHITE + " For " + ChatColor.BOLD.DARK_RED + "[" + banReason + "]");
                }
                if(event.getPosition() == 4) {
                    //target.setBanned(true);
                    banReason = "Fly Hacking or Similar";
                    //target.kickPlayer(ChatColor.DARK_RED + "» " + ChatColor.RED + "You have been PERMENTALLY banned for " + "[" + banReason + "]" + "!");
                    Bukkit.broadcastMessage(ChatColor.DARK_RED + "» " + ChatColor.BOLD.WHITE + "BANNED PLAYER " + ChatColor.BOLD.DARK_RED + "[" + args[0] + "]" + ChatColor.BOLD.WHITE + " For " + ChatColor.BOLD.DARK_RED + "[" + banReason + "]");
                }
                if(event.getPosition() == 5) {
                    //target.setBanned(true);
                    banReason = "X-Ray Hacking or Similar";
                    //target.kickPlayer(ChatColor.DARK_RED + "» " + ChatColor.RED + "You have been PERMENTALLY banned for " + "[" + banReason + "]" + "!");
                    Bukkit.broadcastMessage(ChatColor.DARK_RED + "» " + ChatColor.BOLD.WHITE + "BANNED PLAYER " + ChatColor.BOLD.DARK_RED + "[" + args[0] + "]" + ChatColor.BOLD.WHITE + " For " + ChatColor.BOLD.DARK_RED + "[" + banReason + "]");
                }
                event.getPlayer().sendMessage("You have chosen " + event.getName());
                event.setWillClose(true);
                event.setWillDestroy(true);
            }
        }, this)
                .setOption(3, new ItemStack(Material.IRON_SWORD, 1), "Ban A Player For PvP Hacking", "Or Similar")
                .setOption(4, new ItemStack(Material.FEATHER, 1), "Ban A Player For Fly Hacking", "Or Similar")
                .setOption(5, new ItemStack(Material.DIAMOND_ORE, 1), "Ban A Player For X-Ray Hacking", "Or Similar");


        String banReason;
        public boolean onCommand(CommandSender s, Command cmd, String cl, String[] args) {
            Player p = (Player) s;
            Player target = Bukkit.getServer().getPlayer(args[0]);
            if(cl.equalsIgnoreCase("pb")) {
                s. sendMessage(ChatColor.DARK_RED + "» " + ChatColor.RED + "Please Specify a Player");
                if(args.length == 1) {
                    if (target == null) {
                        s.sendMessage(ChatColor.DARK_RED + "» " + ChatColor.RED + "Could not find player " + ChatColor.BOLD + "[" + args[0] + "]" + "!");
                        return false;
                    }
                    if(!target.isOp()){
                        menu.open(p);
                        return true;
                    }
         
                    if (target.isOp()) {
                        s.sendMessage(ChatColor.DARK_RED + "» " + ChatColor.RED + "You can't ban ops!");
                        return false;
                    }
                return true;
                }
         
                return false;
            }
        }
    }
     
    #1 Surprisejedi, Apr 26, 2017
    Last edited: Apr 27, 2017
  2. I'm not completely sure, but try putting it inside a method. I also don't think that CommandExecutors use onEnable.
    So something like
    Code (Java):
    IconMenu menu
    Ban(){//Constructor method, called when a new instance is created
        menu = new IconMenu(/*Parameters*/);
    }
     
  3. What are you even trying to do with this? There is no onCommand method to override, and do you actually understand anonymous classes?
     
    • Like Like x 1
  4. "Everything turns red" - Please provide the message the compiler/IDE gives you. Provide detailed information.
     
    • Like Like x 1
  5. Hmm... Doesn't Work, still produces the same error...
    Sorry, here is the error:
    Code (Java):
    The constructor IconMenu(String, int, new IconMenu.OptionClickEventHandler(){}, Ban) is undefined
     
  6. Learn basic java, it would help you so much.. Regardless of what you may think, you do not know basic java. Copying and pasting will not get you anywhere.
     
    • Agree Agree x 1