If the player does not Have the specific item remove potion effect

Discussion in 'Plugin Development' started by Ula492, Jun 10, 2014.

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

    Ula492

    So im making this plugin for a guy and i have never done this type of plugin. If the player does not have a CHEST in his/her inventory it will remove a potion effect i have added. I tried the code below but it no work! PLEASE HELP ASAP
    Code:java
    1. if(!(player.getInventory().contains(Material.CHEST));
    2. player.removePotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0);
     
  2. Offline

    Adriani6

    I don't think CHEST is a Material... try Material.DIAMOND_CHESTPLATE ?

    Edit:
    It actually is a material. But not what you want to check for. You can check for a specific iteam (if the inventory contains it) or check if the chestplate armour is worn.
     
  3. Offline

    Ula492

    Im using CHEST for my code and if they player has the chest it will make them slow.... so i need help with if the player does not have the chest the potion effect goes away
     
  4. Offline

    The Fancy Whale

    Well when do you run this code?
    Can you post the full code?
     
  5. Offline

    Ula492

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (sender instanceof Player) {
    3. Player player = (Player)sender;
    4.  
    5. if (cmd.getName().equalsIgnoreCase("TradeChest")) {
    6. if(!player.hasPermission("cie.trade.chest")) {
    7. sender.sendMessage(ChatColor.RED + "You Do Not Have Permission To use this Command");
    8. return true;
    9. }
    10. player.sendMessage(ChatColor.GREEN + "You Know have Chest");
    11. player.getInventory().clear();
    12. ItemStack HeavyChest = new ItemStack(Material.CHEST);
    13. ItemMeta meta1 = (ItemMeta) HeavyChest.getItemMeta();
    14. meta1.setDisplayName(ChatColor.GREEN + "TradeChest");
    15. HeavyChest.setItemMeta(meta1);
    16. player.getInventory().addItem(HeavyChest);
    17. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0));
    18. }
    19. if(!(player.getInventory().contains(Material.CHEST));
    20. player.removePotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0);
    21.  
    22.  
    23. } return false;
    24. }
    25. }
    The Fancy Whale
     
  6. Offline

    xTigerRebornx

    Ula492 Player#removePotionEffect() only takes in one arguement (which is the PotionEffectType)
     
    The Fancy Whale likes this.
  7. Offline

    The Fancy Whale

    First of all check this line:
    Code:java
    1. if(!(player.getInventory().contains(Material.CHEST));

    Next as of now you always get the chest if you do or do not have the chest. (not sure if you intended that)
    Also, if you use .equalsIgnoreCase() you shouldn't use capitals in there (just a syntax thing)
    But your main issue is the line I pointed out above.

    EDIT: Also as xTigerRebornx pointed out you are using removePotionEffect() wrong.
     
  8. Offline

    Ula492

    So how do i fix it so it detects if the player has the chest or dosent? and if it does it keeps the Potion effect and if it dosent it will remove the potion effect and i also need help so i dont need to use a command give a chest slowness
     
  9. Offline

    The Fancy Whale

    Please re-read this line and tell me if you see anything wrong:
    Code:java
    1. if(!(player.getInventory().contains(Material.CHEST));

    To be honest it seems you do not have too much knowledge of java at the moment. I suggest learning java before jumping into coding plugins. I made that mistake at first as well.
     
  10. Offline

    Ula492

    IK i tried that just incase it was right ik it is wrong thats why i posted this and not to be shited on
     
  11. Offline

    The Fancy Whale

    Look at the end. It is an IF statement. You do not end an IF statement with a semicolon. Also, swearing was not really necessary I am just trying to help. Also, if you expect a response please do tahg me.
     
  12. Offline

    Ula492

    The Fancy Whale OK! I kinda figured it out But i still ned help with the potion remove :/
    Code:java
    1. if(player.getItemInHand(Material.CHEST))
    2. player.removePotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0);
     
  13. Offline

    The Fancy Whale

    xTigerRebornx likes this.
Thread Status:
Not open for further replies.

Share This Page