Solved LevelUp Commands

Discussion in 'Spigot Plugin Development' started by Ninjablader101, Mar 24, 2020.

  1. Code (Java):
    public class LevelUp implements CommandExecutor {

        private String levelup = "LevelUp";

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = (Player) sender;
            if (sender instanceof Player) {
                if (command.getName().equalsIgnoreCase(levelup)) {
                    ItemStack item = player.getItemInHand();
                    ItemMeta meta = item.getItemMeta();
                    ArrayList<String> lore = new ArrayList<String>();
                    if (item.getType() == Material.DIAMOND_SWORD || item.getType() == Material.IRON_SWORD || item.getType() == Material.GOLD_SWORD || item.getType() == Material.STONE_SWORD || item.getType() == Material.WOOD_SWORD) {
                        if (Utils.randomNumber(99)) {
                            lore.add(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "I");
                            meta.setLore(lore);
                            item.setItemMeta(meta);
                            if (lore.equals(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "I")){
                                lore.remove(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "I");
                                lore.add(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "II");
                                meta.setLore(lore);
                                item.setItemMeta(meta);
                            } else if (lore.equals(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "II")){
                                lore.remove(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "II");
                                lore.add(ChatColor.GOLD + "Trap " + ChatColor.AQUA + "III");
                            }
                        }
                    }
                }
            }
        return true;}
    }
     
    Bassicly i want to make it so if a player does /levelup it gives them a chance to have trap. added on there sword (lore) and if someone does it again it has another chance of leveling up. It only works for trap 1 and that is it.
     
  2. Your lore string list is always the same and only contains "Trap I" (which will override the current item lore). You'll also have to use #contains instead of #equals to check if the lore contains the text you want.
     
  3. Thanks worked :)