Deprecated

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

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

    Reynergodoy

    this
    Code:
              p.updateInventory();
    is deprecated, what is the other way to make it?
    my full code
    Code:
        @EventHandler
          public void ChangeLevel(PlayerLevelChangeEvent ev)
          {
            Player p = ev.getPlayer();
            PlayerInventory inv = p.getInventory();
            if ((ev.getNewLevel() == 1) &&
              (KitAPI.Strafe.contains(p.getName())))
            {
              p.getInventory().remove(Material.WOOD_SWORD);
              ItemStack sword = new ItemStack(Material.GOLD_SWORD);
              inv.addItem(new ItemStack[] { sword });
              p.updateInventory();
              p.sendMessage(ChatColor.BLUE + "You've changed sword!");
            }
     
  2. Offline

    Konato_K

  3. Offline

    Reynergodoy

    but that does not remove the deprectaed method '-'
     
  4. Offline

    Msrules123

    It automatically does it for you. The method doesn't change what happens with your code.
     
  5. Offline

    Konato_K

    @Reynergodoy updating the inventory is needed when the inventory, for one reason or another, doesn't update.

    To my knowledge, the setItem and addItem(ItemStack) methods effectively update the inventory, meaning that you don't have to do it manually.

    Besides, deprecated doesn't mean it doesn't work, it just means it shouldn't be used for one reason or another, anyway, that method has existed since the CB builds before Minecraft 1.0, I hardly think it's going to be removed.

    Anyway, as I said, just remove the method and add the item, the inventory should not need to be updated.
     
    Reynergodoy likes this.
  6. Offline

    Reynergodoy

    i have another error
    when i reach lv 5 exp, the sword does not change more:
    Code:
    package AccelPvP.Habilidades;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerLevelChangeEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import AccelPvP.Main;
    import AccelPvP.Listeners.KitAPI;
    
    public class Strafe implements CommandExecutor, Listener {
       
        public Strafe(Main main) {
        }
       
        public Strafe() {
        }
    
          @SuppressWarnings("deprecation")
        @EventHandler
          public void ChangeLevel(PlayerLevelChangeEvent ev)
          {
            Player p = ev.getPlayer();
            PlayerInventory inv = p.getInventory();
            if ((ev.getNewLevel() == 1) &&
              (KitAPI.Strafe.contains(p.getName())))
            {
              p.getInventory().remove(Material.WOOD_SWORD);
              ItemStack sword = new ItemStack(Material.GOLD_SWORD);
              inv.addItem(new ItemStack[] { sword });
              p.updateInventory();
              p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
            }
            if ((ev.getNewLevel() == 2) &&
                (KitAPI.Strafe.contains(p.getName())))
            {
              p.getInventory().remove(Material.GOLD_SWORD);
              ItemStack sword = new ItemStack(Material.STONE_SWORD);
              inv.addItem(new ItemStack[] { sword });
              p.updateInventory();
              p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
            }
            if ((ev.getNewLevel() == 3) &&
                (KitAPI.Strafe.contains(p.getName())))
            {
              p.getInventory().remove(Material.STONE_SWORD);
              ItemStack sword = new ItemStack(Material.IRON_SWORD);
              inv.addItem(new ItemStack[] { sword });
              p.updateInventory();
              p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
            }
            if (ev.getNewLevel() == 4)
              if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.IRON_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                if (ev.getNewLevel() == 5)
                  if (KitAPI.Strafe.contains(p.getName()))
                  {
                p.getInventory().remove(Material.DIAMOND_SWORD);
                ItemStack sword = new ItemStack(Material.IRON_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
                sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                if (ev.getNewLevel() == 6)
                   if (KitAPI.Strafe.contains(p.getName()))
                   {
                p.getInventory().remove(Material.IRON_SWORD);
                ItemStack sword = new ItemStack(Material.IRON_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 3);
                sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                if (ev.getNewLevel() == 7)
                   if (KitAPI.Strafe.contains(p.getName()))
                     {
                p.getInventory().remove(Material.IRON_SWORD);
                ItemStack sword = new ItemStack(Material.IRON_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 4);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                    if (ev.getNewLevel() == 8)
                      if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.IRON_SWORD);
                ItemStack sword = new ItemStack(Material.IRON_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 1);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                        if (ev.getNewLevel() == 9)
                          if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.IRON_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                inv.addItem(new ItemStack[] { sword });
                p.updateInventory();
                p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
              }
                            if (ev.getNewLevel() == 10)
                              if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.DIAMOND_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                inv.addItem(new ItemStack[] { sword });
              }
                                if (ev.getNewLevel() == 20)
                                  if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.DIAMOND_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 3);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                inv.addItem(new ItemStack[] { sword });
              }
                                    if (ev.getNewLevel() == 30)
                                      if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.DIAMOND_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 4);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                inv.addItem(new ItemStack[] { sword });
              }
                                        if (ev.getNewLevel() == 40)
                                          if (KitAPI.Strafe.contains(p.getName()))
              {
                p.getInventory().remove(Material.DIAMOND_SWORD);
                ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
                sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                inv.addItem(new ItemStack[] { sword });
              }
                                            if (ev.getNewLevel() == 60)
                                              if (KitAPI.Strafe.contains(p.getName()))
                {
                  p.getInventory().remove(Material.DIAMOND_SWORD);
                  ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                  sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
                  sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                  sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                  inv.addItem(new ItemStack[] { sword });
                  ItemStack main = new ItemStack(Material.POTION);
                  main.setDurability((short)16428);
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { main });
                  p.updateInventory();
                  p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
                }
                                                if (ev.getNewLevel() == 100)
                                                  if (KitAPI.Strafe.contains(p.getName()))
                {
                  p.getInventory().remove(Material.DIAMOND_SWORD);
                  ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                  sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
                  sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                  sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                  inv.addItem(new ItemStack[] { sword });
                  ItemStack main = new ItemStack(Material.POTION);
                  main.setDurability((short)16428);
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { main });
                  p.updateInventory();
                  p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
                }
                                                    if (ev.getNewLevel() == 200)
                                                      if (KitAPI.Strafe.contains(p.getName()))
                {
                  p.getInventory().remove(Material.DIAMOND_SWORD);
                  ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
                  sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
                  sword.addEnchantment(Enchantment.KNOCKBACK, 2);
                  sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                  inv.addItem(new ItemStack[] { sword });
                  ItemStack main = new ItemStack(Material.POTION);
                  main.setDurability((short)16428);
                  ItemStack mainn = new ItemStack(Material.POTION);
                  main.setDurability((short)16420);
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { main });
                  inv.addItem(new ItemStack[] { mainn });
                  inv.addItem(new ItemStack[] { mainn });
                  p.updateInventory();
                  p.sendMessage(ChatColor.BLUE + "Voce trocou de espada!");
                }
              }
         
        public boolean onCommand(CommandSender Sender, Command Cmd, String Label, String[] Args)
        {
            if (Label.equalsIgnoreCase("Strafe")) {
                Player p = (Player)Sender;
               
                if (KitAPI.Habilidade.contains(p.getName())) {
                p.sendMessage(ChatColor.GOLD + "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                p.sendMessage(ChatColor.DARK_RED + "Você não pode pegar mais de 1 kit por vida!");
                p.sendMessage(ChatColor.GOLD + "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                return true;
                }
                if (!p.hasPermission("Kit.Strafe")) {
                p.sendMessage(ChatColor.DARK_RED + "Você não comprou VIP ou o KIT ainda!");
                return true;
                }
               
                ItemStack Livro = new ItemStack(Material.WOOD_SWORD);
                ItemMeta kLivro = Livro.getItemMeta();
                Livro.setItemMeta(kLivro);
               
                p.sendMessage(ChatColor.DARK_GREEN + "Você escolheu o kit:" + ChatColor.RED + " Specialist");
                p.playSound(p.getLocation(), Sound.ANVIL_LAND, 7.0F, 7.0F);
                p.getInventory().clear();
                p.getInventory().setArmorContents(null);
               
                p.getInventory().setItem(1, Livro);
                KitAPI.AddRecraft(p);
                KitAPI.Strafe.add(p.getName());
                KitAPI.Habilidade.add(p.getName());
            }
            return false;
        }
           @EventHandler
           public void Interact(PlayerDeathEvent e) {
               {
                   Player p = e.getEntity();
               KitAPI.Strafe.remove(p.getName());
               }
          }
        @EventHandler
        public void Interact(PlayerQuitEvent e) {
           {
           Player p = e.getPlayer();
               KitAPI.Strafe.remove(p.getName());
    }}}
        
     
  7. Instead of using so many IF try using ELSE IF
    Code:
    if(ev.getNewLevel == 1) {
       //Stuff
    } else if(ev.getNewLevel == 2) {
      //Stuff
    } else if { ...
    
    I think you can simply do this to add a item in player inventory:
    Code:
    inv.addItem(sword);
    
     
    Last edited: May 1, 2015
    Reynergodoy likes this.
  8. Offline

    Reynergodoy

    yes, that kit is not from my authory, its a base to other kits
    and thx

    yes, but instead i just added supress warnings :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  9. Then don't use it, it have really bad code.
     
  10. Offline

    Reynergodoy

    yes i know, 90% of the base codes that i found are made by kids '-'
    im trying to edit these codes to suit my plugin needs

    that is the better ive found

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

    mythbusterma

    @Reynergodoy

    The method is deprecated because what the method actually does shouldn't need to be done, and Bukkit was going to be changed so that the method was no longer needed.

    Unfortunately, this never happened (likely due to something preventing a change from working) so this method is still required to ensure that the player's inventory is updated correctly on the client side. Otherwise, it tends to be very temperamental.

    Continue using the method, and suppress the warnings if you want.
     
Thread Status:
Not open for further replies.

Share This Page