Undefined constructor

Discussion in 'Spigot Plugin Development' started by drhopeness, Apr 16, 2017.

  1. Hi, can you solve this problem?[​IMG]

    It's Main class,

    Code (Text):
    package Main;

    import Main.Ayarlar.Gui;
    import Main.Event.DunyaDegistirme;
    import Main.Event.Farm;
    import Main.Event.Golem;
    import Main.Event.Join;
    import Main.komut.Bolge;
    import Main.komut.Sakla;
    import java.util.logging.Logger;
    import org.bukkit.*;
    import org.bukkit.command.*;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin
        implements Listener
    {

        private FileConfiguration config;

        public void onEnable()
        {
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
            this.config = this.getConfig();
           
            getCommand("sakla").setExecutor(new Sakla(null));
            getCommand("goster").setExecutor(new Sakla(null));
            getCommand("park").setExecutor(new Bolge());
            getCommand("ayarlar").setExecutor(new Gui());
            registerEvents();
            saveDefaultConfig();
           
            Logger logger = getLogger();
            logger.info("|---------------------------------------------------------------------|");
            logger.info("|-----------------------------Eklenti Aktif---------------------------|");
            logger.info("|---------------------------------------------------------------------|");
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String args[])
        {
            Player p = (Player)sender;
            if(label.equalsIgnoreCase("tesreload") && p.hasPermission("teamenders.admin"))
            {
                reloadConfig();
                p.sendMessage(getConfig().getString("reloadmesaj"));
            }
            return true;
        }

        private void registerEvents()
        {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Farm(this), this);
            pm.registerEvents(new DunyaDegistirme(), this);
            pm.registerEvents(new Golem(), this);
            pm.registerEvents(new Join(), this);
        }

        public void onDisable()
        {
            Logger logger = getLogger();
            logger.info("|---------------------------------------------------------------------|");
            logger.info("|-----------------------------Eklenti Pasif---------------------------|");
            logger.info("|---------------------------------------------------------------------|");
            saveConfig();
        }



        String prefix;
    }
    It's Gui.class
    Code (Text):
    package Main.Ayarlar;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import Main.Main;

    public class Gui implements CommandExecutor{

        private FileConfiguration config;
        private Main pl;
       
        private Gui(Main main){
            this.pl = main;
            this.config = this.pl.getConfig();
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player p = (Player) sender;
           
            if(label.equalsIgnoreCase("ayarlar")){
                if(!(p instanceof Player)){
                    p.sendMessage("Oyuncu Olman Sart");
                }else{
                    GuiAc();
                }
            }
           
            return false;
        }

        private void GuiAc(){
            Inventory inv = Bukkit.createInventory(null, this.config.getInt("Ayarlar.Slot"), ChatColor.translateAlternateColorCodes('&', this.config.getString("Ayarlar.Title")));
           
            ItemStack sakla = new ItemStack(Material.INK_SACK, (short) 10);
            ItemMeta saklameta = sakla.getItemMeta();
            ItemStack goster = new ItemStack(Material.INK_SACK, (short) 8);
            ItemMeta gostermeta = goster.getItemMeta();
           
            saklameta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.config.getString("Ayarlar.Saklaisim")));
            gostermeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.config.getString("Ayarlar.Gosterisim")));
           
            sakla.setItemMeta(saklameta);
            goster.setItemMeta(gostermeta);
           
            inv.setItem(3, sakla);
            inv.setItem(5, goster);
           
            }

       

    }
     
     
  2. The Gui class' constructor required a parameter: Main. Change "new Gui()" to "new Gui(this)".
    And it's also private. Remove the "private" keyword when you define the constructor. ("private Gui(Main main){" -> "Gui(Main main){")
     
  3. Mas

    Mas

    • Informative Informative x 1