Suppressing warnings for .updateInventory()

Discussion in 'Plugin Development' started by xXRobbie21Xx, Aug 19, 2014.

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

    xXRobbie21Xx

    Ok guys, I am attempting to add an ammo feature to a basic guns plugin I am creating and when I try to remove a bullet, or a golden nugget in this case, it is telling me that I must suppress the warnings upon updating the inventory once removing the itemstack. After doing some research about this, a bukkit staff member stated that you should never suppress warnings without fully understanding what you are suppressing, and generally avoiding it would be preferable.

    So here is my code :
    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            ItemStack ammo = new ItemStack(Material.GOLD_NUGGET, 1 );
            Player p = e.getPlayer();
            Action action = e.getAction();
     
            if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getType() == Material.DIAMOND_HOE) {
                    if (p.getInventory().contains(Material.GOLD_NUGGET)) {
                        Snowball snowball = (p.launchProjectile(Snowball.class));
                        snowball.setVelocity(snowball.getVelocity().multiply(2));
                        p.sendMessage("Works");
                        p.getInventory().removeItem(ammo);
                        p.updateInventory();
                       
                       
                    }
                    else {
                        p.sendMessage("You dont have ammo!");
                    }
                }
     
            }
     
        }
    
    If anyone has some ideas please let me know, i cant seem to find a way to work around this but if someone else can enlighten me, it would be greatly appreciated!
     
  2. Offline

    McMhz

    @SuppressWarnings("deprecation")
    ^ Is that the "code" it is adding?
    If so, It's basically just a Warning.

    xXRobbie21Xx

    --
    Browser can't edit..

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

    xXRobbie21Xx

    McMhz Well yeah when i add p.updateInventory() it asks me to add @SuppressWarnings("deprecation")
    However after some research, people are saying its a bad practice and should be avoided, so im wondering if anyone knows if suppressing warnings in this situation is allright and if not how can i work around it
     
  4. Offline

    MCMatters

    xXRobbie21Xx @SuppressWarnings("deprecation") means that it is deprecated therefore the method should not be used, p.updateInventory(); is no longer needed so you can remove that line
     
  5. Offline

    xXRobbie21Xx

    MCMatters Allright, in that case im going to go make sure everything is up to date and get back to you.
     
  6. Offline

    mythbusterma

    MCMatters xXRobbie21Xx

    Fairly certain it still is needed, I had to use it in the last plugin I made built and run on 1.7.9 bukkit builds.

    It's deprecated because it's a hacky, but necessary work around that doesn't really solve the issue, and they're planning to fix it later.
     
    drpk and xXRobbie21Xx like this.
  7. Offline

    xXRobbie21Xx

    mythbusterma Okay, so if i leave the deprecation in there, its fine?

    Edit: Leaving it there is the only way it will work.
     
  8. Offline

    mythbusterma

    xXRobbie21Xx

    Yes, as long as you understand the reason, in this case mostly that you should update your code when a fix is available (unlikely to ever happen, as it has been this way since at least 2012).
     
  9. Offline

    McMhz

    Yeah, That's what I meant.
    Deprecated is basically telling you to "avoid" it, for example, the getServer()#getPlayer(String name); has been deprecated since the UUID thing came along.
     
  10. Offline

    Necrodoom

    McMhz that specific deprecation is to warn that you shouldn't use it for storage since names can change. Using getPlayer by name is still fine.
     
    McMhz likes this.
Thread Status:
Not open for further replies.

Share This Page