How to make an item usable on both Air and Blocks?

Discussion in 'Plugin Development' started by xxCoderForLifexx, May 1, 2015.

Thread Status:
Not open for further replies.
  1. Here is what I have gotten so far. It is either air or block. I can't use both, I would like to be able to use it on both.
    Code:
     if ((this.plugin.getConfig().getBoolean("Drugs.Enabled.melons")) &&
          (p.hasPermission("drugs.melons")) &&
          (e.getAction().equals(Action.RIGHT_CLICK_AIR))  && (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand().equals(new ItemStack(Material.MELON))))
        {
          p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, this.plugin.getConfig().getInt("Drugs.Effect.length"), 1), true);
          p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, this.plugin.getConfig().getInt("Drugs.Effect.length"), 1), true);
          p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, this.plugin.getConfig().getInt("Drugs.Effect.length"), 1), true);
          p.sendMessage(ChatColor.AQUA + "Ecstasy!!!");
          p.getItemInHand();
          p.setItemInHand(null);
    This is what I am using it does not work at all.
    Code:
          (e.getAction().equals(Action.RIGHT_CLICK_AIR))  && (e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
     
  2. Offline

    Garnetty

    Change && to ||, you're specifying that they need to be clicking air and a block at the same time, which will never run. Use || for "or"
     
  3. I tried the "or" statement but it always came up void. As if Eclipse was not verifying it as a real code.
    I will try again and let you know if it worked. Thanks for the advice.
     
  4. Offline

    Garnetty

    No problem, and if eclipse brings up that shit tell me
     
  5. So far it is accepting the "||". Haven't tested it yet..Exporting it now.
     
  6. Offline

    Eballer48

    @xxCoderForLifexx
    @Garnetty

    Garnetty is completely right! In the programming language Java, symbols (also referred to as 'operators') can be used to represent statements.

    For Example:
    Code:
    int pieLeft= 0;
    String variableName = (pieLeft < 1 ? "There is no pie left!" : "Pie remaing: " + String.valueOf(pieLeft));
    
    Although my example demonstrates operators this while defining a variable, they may also be used within If Statements

    To solve your answer..
    Code:
    Action a = e.getAction();
    # This says 'if action is right clicking air OR if it is right clicking a block
    if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    
    # This says 'if action is right clicking air AND it is right clicking a block
    if (a == Action.RIGHT_CLICK_AIR && a == Action.RIGHT_CLICK_BLOCK) {
    
    If you're interested in learning more about operators you can check out THIS page!


    EDIT:

    I just noticed this line in your code..
    Code:
    p.getItemInHand();
    
    Whats up with that?
     
    Last edited: May 1, 2015
  7. Thanks it worked but, I have ran into a new problem. All the commands are executed when only one item is in my hand.
    Ex. I have wheat *right click*. All other "drugs" are activated.
    More then likely a piece of code I am over-looking but if you guys know anything. Let me know.
     
  8. Offline

    Garnetty

    Code:
    (p.getItemInHand().equals(new ItemStack(Material.MELON)
    Try doing
    Code:
    (p.getItemInHand().getType() == Material.MELON)
     
  9. Same thing as before.

    Could there be another way to be able to use the item on both block and air?

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

Share This Page