Invalid Method???(and adding commands via config)

Discussion in 'Plugin Development' started by Ethan Rocks 365, Mar 5, 2016.

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

    Ethan Rocks 365

    Hey Im Making a plugin but when i load it i get this in the console
    Code:
    [16:50:59] [Server thread/ERROR]: [CustomGUI] CustomGUI v0.1 attempted to register an invalid EventHandler method signature "public void me.ethanrocks356.gui.EthanRocks365.ClickBlock(org.bukkit.event.player.PlayerInteractEvent,org.bukkit.plugin.Plugin,org.bukkit.entity.Player,org.bukkit.block.Block)" in class me.ethanrocks356.gui.EthanRocks365
    My code for the method is
    Code:
    @EventHandler
        public void ClickBlock(PlayerInteractEvent e, Plugin plugin, Player p,Block b) {
            p = e.getPlayer();
            b = e.getClickedBlock();
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (b.getLocation() == plugin.getConfig().get("Location.world"));{
                if (b.getLocation() == plugin.getConfig().get("Location.x"));{
                    if (b.getLocation() == plugin.getConfig().get("Location.y"));{
                        if (b.getLocation() == plugin.getConfig().get("Location.z"));{
                            openGUI(p, this);
                        }
                    }
                }
            }
      }
        else
            return;
        }
    and my class is
    Code:
    package me.ethanrocks365.customgui.plugin;
    
    //imports
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    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.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    //class starts here
    public class CustomGUI extends JavaPlugin implements Listener {  
        //On enable void
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
        //Creating the gui
        @SuppressWarnings("unused")
        private void openGUI(Player player, Plugin plugin) {
            Inventory inv = Bukkit.createInventory(null, 27, ChatColor.RED + "Select something!");
    
            ItemStack chest = new ItemStack(Material.CHEST);
            ItemMeta chestMeta = chest.getItemMeta();
    
            ItemStack key = new ItemStack(Material.TRIPWIRE_HOOK);
            ItemMeta keyMeta = key.getItemMeta();
          
            chestMeta.setDisplayName(ChatColor.GOLD + "Treasure");
            chest.setItemMeta(chestMeta);
            keyMeta.setDisplayName(ChatColor.GREEN + "Treasure chest key!");
            key.setItemMeta(keyMeta);
        }
        //What the in-gui buttons do
        @EventHandler
      public void onInventoryClickEvent(InventoryClickEvent e){
          if(!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Select something!"))
          return;
          Player player = (Player) e.getWhoClicked();
          e.setCancelled(true);
        
          if(e.getCurrentItem() == null || e.getCurrentItem().getType() ==Material.AIR || !e.getCurrentItem().hasItemMeta()){
              player.closeInventory();
                return;
          }
                switch (e.getCurrentItem().getType()){
                case CHEST:
                    player.closeInventory();
                    player.sendMessage(String.format(ChatColor.RED + "Opening chest"));
                    player.performCommand("treasurechest open");
                    break;
                case TRIPWIRE_HOOK:
                    player.closeInventory();
                    player.sendMessage(String.format(ChatColor.RED + "Getting a key"));
                    player.performCommand("buykey");
                    break;
                default:
                    player.closeInventory();break;
                }
              
          }
        //opening the gui on a set chest
        @EventHandler
        public void ClickBlock(PlayerInteractEvent e, Plugin plugin, Player p,Block b) {
            p = e.getPlayer();
            b = e.getClickedBlock();
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (b.getLocation() == plugin.getConfig().get("Location.world"));{
                if (b.getLocation() == plugin.getConfig().get("Location.x"));{
                    if (b.getLocation() == plugin.getConfig().get("Location.y"));{
                        if (b.getLocation() == plugin.getConfig().get("Location.z"));{
                            openGUI(p, this);
                        }
                    }
                }
            }
      }
        else
            return;
        }
        //the command to set the chest
         public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args, Player p, Plugin plugin){
                if(commandLable.equalsIgnoreCase("chestsave") || (theSender instanceof Player))
                {
                    if (!(theSender instanceof Player)) {
                        theSender.sendMessage("Hey your not a player!");
                    if (theSender.hasPermission("chestgui.set")){
                    plugin.getConfig().set("Location.world", p.getLocation().getWorld());
                    plugin.getConfig().set("Location.x", p.getLocation().getX());
                    plugin.getConfig().set("Location.y", p.getLocation().getY());
                    plugin.getConfig().set("Location.z", p.getLocation().getZ());
                    theSender.sendMessage("Chest Location set! Right clicking this chest will open the gui!");
                 return true;
       }
         }
         }
                return false;
    }
    }
     
  2. Offline

    webbhead

    Code:
    @EventHandler
        public void ClickBlock(PlayerInteractEvent e, Plugin plugin, Player p,Block b) {
    Because that is not an event. Just use:
    Code:
    @EventHandler
    public void clickBlock(PlayerInteractEvent e) {
    
    }
    Then use variables from the class for the Plugin... Block and Player are already in PlayerInteractEvent
     
  3. Offline

    Ethan Rocks 365

  4. Offline

    Ethan Rocks 365

    BUMP
    EDIT: ok off topic but can someone help me with adding commands via a config
    So like a player I game does /chicken. And they get a no command message.
    Then they go to the config and add
    Code:
    Commands:
        Command: 'chicken'
        Message: 'Is food'
    Then ingame they reload the server and do
    /chicken and get Is food
     
    Last edited: Mar 6, 2016
  5. Offline

    cluter123

    Why are you bumping this?
     
  6. Offline

    Ethan Rocks 365

    Why not, and because I have a new question and the OQ is not answered
     
  7. Offline

    Gerov

  8. Offline

    cluter123

    Oh I didn't see your edit.
     
  9. Offline

    Ethan Rocks 365

    @Gerov you might have sent me the wrong thing. I don't need plugin.yaml. I need config.yaml
     
  10. Offline

    Gerov

  11. Offline

    Ethan Rocks 365

    @Gerov thanks for the help. I see I'm not being clear. I'll re explain it.
    So do you know the plugin myCommands? You add commands via config. That's what I'm trying to do. Maybe also adding buttons to GUIs via config such as in ultimate hub and such
     
  12. Offline

    Lordloss

    You could check in the CommandPreprocessEvent if that event exists in your config. But please learn how to use events first...
     
  13. Offline

    Ethan Rocks 365

    Can someone tell me what is wrong with the Original problem please
     
  14. Offline

    mythbusterma

    Ethan Rocks 365 likes this.
  15. Offline

    Ethan Rocks 365

    Oh I would use
    Code:
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getAction.equals(Action.RIGHT_CLICK_BLOCK)) {
            if(event.getClickedBlock().getType() == Material.CHEST) {
               openGUI(Player)
            }
        }
    }
    To set it to all chests
     
Thread Status:
Not open for further replies.

Share This Page