Solved Wanting to remove armour whilst holding air

Discussion in 'Plugin Development' started by MajorSkillage, Oct 4, 2014.

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

    MajorSkillage

    It removes my armour like i want it to when i am not holding the specific item or air, i want it to remove armour while i am holding air though :O
    Code:
      @EventHandler
      public void onSlotChange(PlayerItemHeldEvent e) {
          p = e.getPlayer();
          String w = p.getWorld().getName();
          ItemStack item = new ItemStack(id);
        if (p.getInventory().getItem(e.getNewSlot()).equals(item) && !getConfig().getStringList("disabled_worlds").contains(w)){
          ItemStack dhelmet = new ItemStack(getConfig().getInt("helmet on hold"));
          ItemStack dchest = new ItemStack(getConfig().getInt("chestplate on hold"));
          ItemStack dlegs = new ItemStack(getConfig().getInt("leggings on hold"));
          ItemStack dboots = new ItemStack(getConfig().getInt("boots on hold"));
          p.getInventory().setHelmet(dhelmet);
          p.getInventory().setChestplate(dchest);
          p.getInventory().setLeggings(dlegs);
          p.getInventory().setBoots(dboots);
        } else if (getConfig().getBoolean("remove armour after pvp") == true && !getConfig().getStringList("disabled_worlds").contains(w) && p.getItemInHand().getTypeId() != id || p.getItemInHand().equals(null)) {
                ItemStack air = new ItemStack(Material.AIR);
          p.getInventory().setHelmet(air);
          p.getInventory().setChestplate(air);
          p.getInventory().setLeggings(air);
          p.getInventory().setBoots(air);
        }
      }
    Also id = getConfig().getInt("id");

    anyone? Halp D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  2. Offline

    CaptainUniverse

    Sorry can you explain a little more I am not sure what you want MajorSkillage
     
  3. Offline

    MajorSkillage

    pretty much someone can pvp while holding the item from the config and it lets them select which armour is being added and such so it should be working when i change to a diamond sword it puts me in diamond armour which it does but then when i go to air nothing happens but if i go to anything that isn't air or that diamond sword then it removes the armour which i want the armour removed when i go to air (in my hotbar)
     
  4. Offline

    CaptainUniverse

    Code:java
    1. @EventHandler
    2. public void hotbar(PlayerItemHeldEvent e) {
    3. if (!e.getPlayer().getInventory().getItem(e.getNewSlot()).getType().equals(Material.AIR) || !e.getPlayer().getInventory().getItem(e.getNewSlot()).getType().equals(Material.DIAMOND_SWORD)) {
    4. //do your stuff and remove their armour
    5. }else{
    6. //do whatever else it is you wanted do to
    7. }
    8. }
     
  5. Offline

    MajorSkillage

    exactly what i tried but it wont seem to work when holding nothing
    The code i have in there is after a few things ive tried null, Material.AIR, ItemStack ._.

    i just realised in the else if(section i do not need !e.getPlayer().getInventory().getItem(e.getNewSlot()).getType().equals(Material.AIR) || !e.getPlayer().getInventory().getItem(e.getNewSlot()).getType().equals(Material.DIAMOND_SWORD)
    because if it even reaches else then we know that it isn't the id already but it is still not working D:

    here is my new code still has same problem
    Code:
        if (!p.getInventory().getItem(e.getNewSlot()).equals(item) && !getConfig().getStringList("disabled_worlds").contains(w)){
            ItemStack air = new ItemStack(Material.AIR);
      p.getInventory().setHelmet(air);
      p.getInventory().setChestplate(air);
      p.getInventory().setLeggings(air);
      p.getInventory().setBoots(air);
        } else if(!getConfig().getStringList("disabled_worlds").contains(w)){
          ItemStack dhelmet = new ItemStack(getConfig().getInt("helmet on hold"));
          ItemStack dchest = new ItemStack(getConfig().getInt("chestplate on hold"));
          ItemStack dlegs = new ItemStack(getConfig().getInt("leggings on hold"));
          ItemStack dboots = new ItemStack(getConfig().getInt("boots on hold"));
          p.getInventory().setHelmet(dhelmet);
          p.getInventory().setChestplate(dchest);
          p.getInventory().setLeggings(dlegs);
          p.getInventory().setBoots(dboots);
        }
    is there seriously no way to check if the player is holding air? -.- i would gladly make a boolean value to stop pvp and all that if i could that way :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. Offline

    xepisolonxx

    MajorSkillage
    Ya its a bug it would not notice your not holding air then best thing i can say is have a runnable that loops checking if they don't air in there hands then do what you want.
     
  7. Offline

    Caprei

    MajorSkillage

    From what I can see, you're having trouble detecting when the player is holding nothing? I think you have to check for null:

    Code:java
    1. if(player.getItemInHand() == null){
    2. //Do stuff
    3. }
     
  8. Offline

    MajorSkillage

    lets give that a try :)
    if("this code works"){
    System.out.println("Caprei is awesome!");
    } else {
    System.out.println("Capreei is almost awesome!");
    }

    console: Caprei is almost awesome!
    me: D:

    it works with PlayerInteractEvent but not ItemHeldEvent D:<

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  9. Offline

    rbrick

    MajorSkillage
    Code:java
    1. @EventHandler
    2. public void onSlotchange(PlayerItemHeldEvent e) {
    3. if( e.getPlayer().getInventory().getItem(e.getNewSlot()) != null && e.getPlayer().getInventory().getItem(e.getNewSlot()).getType() == Material.DIAMOND) {
    4. e.getPlayer().getInventory().setHelmet(new ItemStack(Material.GLASS));
    5. } else if(e.getPlayer().getInventory().getItem(e.getNewSlot()) == null) {
    6. e.getPlayer().getInventory().setHelmet(new ItemStack(Material.AIR));
    7. e.getPlayer().sendMessage("lol wat even");
    8. }
    9. }


    works for me.
    Show Spoiler

    [​IMG]
     
    MajorSkillage likes this.
  10. Offline

    MajorSkillage

Thread Status:
Not open for further replies.

Share This Page