Solved Right click on item

Discussion in 'Plugin Development' started by BlazeEyezz, Nov 11, 2013.

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

    BlazeEyezz

    I want to make a system with bandages, but i don´t know how to do that.
    The things i thought to do:

    @EventHandler
    public void Bandage (InventoryClickEvent) {

    Player p = e.getPlayer();
    p.setItemInHand(null);

    I want to check if the player is in a hashmap, the item has to be paper.
    After the click i want to remove the item and give the player 3 more hearts.
    Can someone help me please?

    Thanks!
     
  2. Offline

    sgavster

    PHP:
    @EventHandler
    public void onSomething(PlayerInteractEvent e) {
    if(
    e.getAction() == Action.RIGHT_CLICK_AIR) {
    if(
    e.getPlayer().getItemInHand().getType() == Material.PAPER) {
    //do something
    }
    }
    }
     
  3. Offline

    BlazeEyezz

    This is what i now have:

    @EventHandler
    public void Bandage (PlayerInteractEvent e) {
    if(e.getAction() == Action.RIGHT_CLICK_AIR) {
    if(e.getPlayer().getItemInHand().getType() == Material.PAPER) {

    Player p = e.getPlayer();
    p.setHealth(+ 6);
    p.setFoodLevel(+ 3);
    p.sendMessage(ChatColor.GRAY + "Verband, dat helpt!");
    p.setItemInHand(null);

    It works, only the p.setFoodLevel(+ 3); and the same for Health doesn't work.
    It sets the Healt to 6 and Food to three.
    I want the food level + 3.
    Any one idee ?
     
  4. Offline

    sgavster

    BlazeEyezz
    use
    p.setHealth(p.getHealth() + 6);
    p.setFoodLeve(p.getFoodLevel() + 3);
     
  5. Offline

    Peary

    If it works please change thread to [Solved] in thread tools
     
  6. Offline

    BlazeEyezz

    Thanks, but i get an error under getHealth.
    It says "the method getHealth() is not avaible for this type player...
     
  7. Offline

    sgavster

  8. Offline

    BlazeEyezz

    this is what i have:

    @EventHandler
    public void Bandage (PlayerInteractEvent e) {
    if(e.getAction() == Action.RIGHT_CLICK_AIR) {
    if(e.getPlayer().getItemInHand().getType() == Material.PAPER) {

    Player p = e.getPlayer();
    p.setHealth(p.getHealth() + 6);
    p.setFoodLevel(p.getFoodLevel() + 3);
    p.sendMessage(ChatColor.GRAY + "Verband, dat helpt!");
    p.setItemInHand(null);
     
  9. Offline

    NinjaWAffles

    Does the red line have, "the method getHealth() is ambiguous to the type Player?" If so, you're probably building your project against a CraftBukkit build. You'll want to build it against Bukkit. This thread will explain that more in depth for you.
     
    sgavster likes this.
  10. Offline

    BlazeEyezz

    Now it works! Thank you!
     
Thread Status:
Not open for further replies.

Share This Page