1.7.10 can't remove item from hand.

Discussion in 'Plugin Development' started by PROwolfpcgames, Nov 26, 2014.

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

    PROwolfpcgames

    in 1.7.10 0f bukkit i cant use
    Code:java
    1. player.setItemInHand( new ItemStack( Material.AIR) );

    or
    Code:java
    1. player.setItemInHand(null);


    to clear the item in hand of a player.

    I don't know what to do I have read other threads but they don't work.
    please help
     
  2. Offline

    Totom3

    PROwolfpcgames How come you can't use it? Do you get any errors? Stack-traces? If so, post it with the full class so we can help you.
     
  3. Offline

    PROwolfpcgames

    Totom3 i can use it but it dosent work no stack traces or any thing it just does not work.
     
  4. Offline

    Totom3

    PROwolfpcgames Did you try debugging to make sure the method is effectively called? Print a message to the console; if it doesn't show up, then the code is not invoked.
     
  5. Offline

    PROwolfpcgames

    Totom3 yes I did, I did all the basic testing stuff
     
  6. Offline

    fireblast709

  7. Offline

    PROwolfpcgames

    the method for doing the clearing and powering up

    Code:java
    1. public void powerUp(EggPlayer player, String powerUp){
    2.  
    3. if(powerUp == "speed"){
    4. if(player.getPlayer().getInventory().getItemInHand().getAmount() > 1){
    5. player.getPlayer().getInventory().getItemInHand().setAmount(player.getPlayer().getItemInHand().getAmount() - 1);
    6. player.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 25, 3));
    7. player.sendMessage(powerUp);
    8. }else{
    9. //where i need it to clear hand. yes it does get to this part i have tried
    10. }
    11. }
    12. }


    the event to call that method

    Code:java
    1. @EventHandler
    2. public void Click(PlayerInteractEvent event){
    3.  
    4. Player player = event.getPlayer();
    5.  
    6. if (event.getAction() == Action.RIGHT_CLICK_AIR && player.getItemInHand().getType() == Material.BAKED_POTATO || event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.BAKED_POTATO){
    7. EggMain.game.powerUp(new EggPlayer(player), "speed");
    8. }
    9.  
    10. }


    fireblast709 Totom3
     
  8. Offline

    teej107

    PROwolfpcgames
    powerUp == "speed"

    Use .equals() to compare Objects. As for clearing the hand, try updating the inventory after you clear it, else just remove the item that the player is currently selecting, etc.
     
  9. Offline

    PROwolfpcgames

    teej107 I am not clearing the inventory i am trying to remove just the item in the players hand. also i did update the inventory after you told me and it did not work.
     
  10. Offline

    teej107

    PROwolfpcgames Show the lines if code where you are clearing the player's hand.
     
  11. Offline

    moo3oo3oo3

    This:
    Code:java
    1. player.getItemInHand().setDurability((short) 0);
    2. player.getItemInHand().setType(Material.AIR);

    or this:
    Code:java
    1. player.getItemInHand().setType(null);
     
  12. Offline

    BillyGalbreath

    Code:java
    1.  
    2. public void powerUp(EggPlayer player, String powerUp) {
    3. ItemStack item = player.getItemInHand();
    4. if(powerUp == "speed") {
    5. if (item == null || item.getType().equals(Material.AIR)) {
    6. // player is not holding an item
    7. return;
    8. }
    9. int amount = item.getAmount();
    10. if(amount > 1) {
    11. item.setAmount(amount - 1);
    12. } else {
    13. item = new ItemStack(Material.AIR);
    14. }
    15. player.setItemInHand(item);
    16. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 25, 3));
    17. player.sendMessage(powerUp);
    18. }
    19. }
    20.  
     
Thread Status:
Not open for further replies.

Share This Page