Error with .registerEvents

Discussion in 'Plugin Development' started by TheDaann, Sep 30, 2019.

  1. Offline

    TheDaann

    Error: The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (gamemode, gamemode)

    Can anyone help me with this?
    At line 22

    Code:
    package me.thedaann.potgrond;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class gamemode implements CommandExecutor {
    
        private Inventory Inv;
       
        @EventHandler
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Inv = Bukkit.createInventory(null, 27, ChatColor.YELLOW + "Potgrond Gamemode");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("gm")){
                Player p = (Player) sender;
               
                if(p.isOp()){
                   
                    ItemStack item = new ItemStack(Material.RED_GLAZED_TERRACOTTA);
                    ItemMeta meta = item.getItemMeta();
                    meta.setDisplayName(ChatColor.DARK_RED + "Creative");
                    item.setItemMeta(meta);
                   
                    ItemStack item2 = new ItemStack(Material.ORANGE_GLAZED_TERRACOTTA);
                    ItemMeta meta2 = item2.getItemMeta();
                    meta2.setDisplayName(ChatColor.DARK_RED + "Survival");
                    item2.setItemMeta(meta2);
                   
                    ItemStack item3 = new ItemStack(Material.YELLOW_GLAZED_TERRACOTTA);
                    ItemMeta meta3 = item3.getItemMeta();
                    meta3.setDisplayName(ChatColor.DARK_RED + "Spectator");
                    item3.setItemMeta(meta3);
                   
                    Inv.setItem(11, item);
                    Inv.setItem(13, item2);
                    Inv.setItem(15, item3);
                   
                    p.openInventory(Inv);
                   
                    p.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Potgrond » " + ChatColor.WHITE + "Gamemode menu succesvol geopend!");
                   
                   
                }
                if(!p.isOp()){
                    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Potgrond Error » " + ChatColor.WHITE + "Je hebt geen permissies voor dit command.");
                }
               
               
            }
            return false;
        }
    }
    
    
     
  2. Offline

    timtower Moderator Moderator

    @TheDaann Your gamemode class is 1. Not a plugin, 2. Not a listener, 3. Nor does it has any events.
     
  3. Offline

    TheDaann

    @timtower

    So what do I have to adjust now?
     
  4. Offline

    timtower Moderator Moderator

    Start by figuring out what your main class is. Because I don't think that it is the posted one.
    So no onEnable for that one.
    It needs to implements Listener if it needs to handle events.
     
  5. Offline

    TheDaann

    I have a main.java I have now added an event what should I remove or add to remove the error?

    Code:
    package me.thedaann.potgrond;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class gamemode implements CommandExecutor {
    
        private Inventory Inv;
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Inv = Bukkit.createInventory(null, 27, ChatColor.YELLOW + "Potgrond Gamemode");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("gm")){
                Player p = (Player) sender;
               
                if(p.isOp()){
                   
                    ItemStack item = new ItemStack(Material.RED_GLAZED_TERRACOTTA);
                    ItemMeta meta = item.getItemMeta();
                    meta.setDisplayName(ChatColor.DARK_RED + "Creative");
                    item.setItemMeta(meta);
                   
                    ItemStack item2 = new ItemStack(Material.ORANGE_GLAZED_TERRACOTTA);
                    ItemMeta meta2 = item2.getItemMeta();
                    meta2.setDisplayName(ChatColor.DARK_RED + "Survival");
                    item2.setItemMeta(meta2);
                   
                    ItemStack item3 = new ItemStack(Material.YELLOW_GLAZED_TERRACOTTA);
                    ItemMeta meta3 = item3.getItemMeta();
                    meta3.setDisplayName(ChatColor.DARK_RED + "Spectator");
                    item3.setItemMeta(meta3);
                   
                    Inv.setItem(11, item);
                    Inv.setItem(13, item2);
                    Inv.setItem(15, item3);
                   
                    p.openInventory(Inv);
                   
                    p.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Potgrond » " + ChatColor.WHITE + "Gamemode menu succesvol geopend!");
                   
                   
                }
                if(!p.isOp()){
                    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Potgrond Error » " + ChatColor.WHITE + "Je hebt geen permissies voor dit command.");
                }
               
               
            }
            return false;
        }
       
        @EventHandler
        public void onClickGameModeInv(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
           
            if(e.getInventory().getName().equalsIgnoreCase(Inv.getName())){
                e.setCancelled(true);
               
               
                if(e.getCurrentItem().getType() == Material.RED_GLAZED_TERRACOTTA){
                    p.setGameMode(GameMode.CREATIVE);
                    p.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Potgrond » " + ChatColor.WHITE + "Je bent succesvol in " + ChatColor.GOLD + "CREATIVE" + ChatColor.WHITE + " gezet.");
                   
                }
               
                if(e.getCurrentItem().getType() == Material.ORANGE_GLAZED_TERRACOTTA){
                    p.setGameMode(GameMode.SURVIVAL);
                    p.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Potgrond » " + ChatColor.WHITE + "Je bent succesvol in " + ChatColor.GOLD + "SURVIVAL" + ChatColor.WHITE + " gezet.");
                }
               
                if(e.getCurrentItem().getType() == Material.YELLOW_GLAZED_TERRACOTTA){
                    p.setGameMode(GameMode.SPECTATOR);
                    p.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Potgrond » " + ChatColor.WHITE + "Je bent succesvol in " + ChatColor.GOLD + "SPECTATOR" + ChatColor.WHITE + " gezet.");
                }
               
            }
        }
    }
    
    
    
    @timtower
     
  6. Offline

    timtower Moderator Moderator

    @TheDaann Does still not implement Listener
    You still have an onEnable, that only works for the main class.
    Give it a constructor.
     
  7. Offline

    TheDaann

    And how is that supposed to be? @timtower
     
  8. Offline

    timtower Moderator Moderator

  9. Offline

    TheDaann

    @timtower
    I'm not the best Java Developer yet, so don't understand everything. This is not my main class, but a command. Can't say what to add? Or remove it if necessary.
     
  10. Offline

    timtower Moderator Moderator

    I know.
    And I won't change your code.
    It is your code.
    Add a constructor.
     
  11. Offline

    TheDaann

    Ok

    You can close this topic

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 30, 2019
  12. Online

    robertlit

    Please mark your thread as solved
     

Share This Page