Removing item from hand?

Discussion in 'Bukkit Help' started by Jakkeren, Jan 4, 2017.

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

    Jakkeren

    I'm trying to get the plugin to remove the item that the player is currently holding, doesn't seem to work...

    Code:
    package com.bukkit.jakkeren;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class TrixoHand extends JavaPlugin {
       
        @Override
        public void onEnable() {
            getLogger().info(ChatColor.GREEN + "Dette plugin er blevet aktiveret");
           
        }
       
        @Override
        public void onDisable() {
            getLogger().info(ChatColor.RED +"Dette plugin er blevet deaktiveret");
       
        }
    
        @EventHandler
        public void onPlayerClickEvent(PlayerInteractEvent event) {
         
        final Player player = event.getPlayer();
       
        }
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if(cmd.getName().equalsIgnoreCase("handclear")) {
               
                Player player = (Player) sender;
                player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
               
            }
           
            if(cmd.getName().equalsIgnoreCase("hclear")) {
               
                Player player = (Player) sender;
                player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
    
            }
           
            if(cmd.getName().equalsIgnoreCase("hc")) {
               
                Player player = (Player) sender;
                player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
               
            }
           
            return false;
           
            }
           
           
        }
     
    Last edited by a moderator: Jan 4, 2017
  2. Offline

    timtower Ninja on the waves Moderator

  3. Offline

    Zombie_Striker

    Use another package. You do not own bukkit.com, so you should not use it. Only use domains you own, your email adress, or use the format "me.<yourname>.<yourproject>"

    Don't log your own plugins. Bukkit does that for you.

    Always check if the sender is a player before casting .What if the console sends that command? What about another plugin or a commandblock?
     
  4. Offline

    TheEnderman

    Use
    Code:
    player.getInventory().setItemInMainHand(new ItemStack(Material.AIR))
     
  5. Offline

    Jakkeren

    First of all, thanks ;)
    Second of all, if i should do as you say, (me.<yourname>.<yourproject>), should i then write the same in my plugin.yml file?

    This might sound dumb, but where should i insert that? I'm kind of new to coding, so...

    I'll try that in a second :)

    I tried it, and it did not work. It hits me with the error "The constructor ItemStack(Material) is undenified".

    EDIT: Never mind, the error suddenly disappeared! :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 5, 2017
Thread Status:
Not open for further replies.

Share This Page