connect event with command

Discussion in 'Plugin Development' started by nongman1, Jan 3, 2015.

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

    nongman1

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label ,String args){
    if(label.equalsIgnoreCase("hh")){
    Player player= (Player) sender;
    player.getLocation().getBlock().setType(Material.LAPIS_BLOCK);
    }
    return false;
    }
    
    @EventHandler
          public void onInteract(PlayerInteractEvent e)
      {
        Action a = e.getAction();
        if((a.equals(Action.RIGHT_CLICK_BLOCK) || 
          a.equals(Action.RIGHT_CLICK_AIR)) && e.getPlayer().getInventory().getItemInHand().getType() == Material.COAL)
    {
          Player player32 = e.getPlayer();
          player32.getServer().dispatchCommand(Bukkit.getConsoleSender(), "/hh");[/FONT]
    }
    
    i rightclick coal console say unkown command.
    how can i player says commands???
     
    Last edited by a moderator: Jan 4, 2015
  2. Offline

    xTrollxDudex

    @nongman1
    1) That will never work, you're casting Player to the sender even though its the console. Dispatch the command as the player that is right clicking instead.
    2) Have you registered your events and commands? Is the command in the plugin.yml?
     
  3. Offline

    HeadGam3z

    Nope.

    Edit: Meh, forgot to add what I was going to say...
    Anyway, String args is an array, so add those brackets. String[] args.
     
  4. Offline

    nongman1

    i write things under the right click timer doesn't work..
    so i want to
    if console enter the "hh"
    Player player=getHandItem(COAL);
    ??
    like this it is possible?
    may it is possible please teach me detail thanks~
     
  5. Offline

    timtower Administrator Administrator Moderator

    @nongman1 There is no player when the console types that. Nor is it clear what you want
     
Thread Status:
Not open for further replies.

Share This Page