joao100101 Postado Abril 3, 2017 Denunciar Compartilhar Postado Abril 3, 2017 Olá, queria saber como faço uma lista de itens pela config (pra add os itens da config em uma gui), se possivel explicar como funciona e tals. Link para o comentário Compartilhar em outros sites More sharing options...
Hard Postado Abril 3, 2017 Denunciar Compartilhar Postado Abril 3, 2017 Você pode colocar dados sobre o comando em YAML como bloco, nome lore etc getConfig().getConfigurationSection("commands").getValues(false) Comece quantos "comandos estão na configuração" (comprimento do jogo) e então calcule, quantos 9 entalhes você necessita caso que o comando 10 você necessite o entalhe 2x 9 (1 fileira no inventário) Crie então o inventário e adicione o contest para todos os comandos public static Inventory myInventory = Bukkit.createInventory(null, rows, "MyUltraCommands"); E, em seguida, colocar comandos no arraylist que você vai loop int actual = 0; for(String comm : commands) { ItemStack is = new ItemStack(config.get("commands."+comm+".id"),1,0); //wathever stuff with is myInventory.setItem(actual, is); actual++; } E, em seguida, se você tiver comandos no registrador de registro de matriz para InventoryClickEvent e você pode verificar o estoque e item e, em seguida, executar o que quiser Bukkit().getServer().dispatchCommand(player, cmd); 1 Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 3, 2017 Denunciar Compartilhar Postado Abril 3, 2017 (editado) config Items: 0: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 código Inventory inventory; public static void loadInventory(){ //coloca no onEnable inventory = getServer().createInventory(null, 9, "Inventory"); getConfig().getConfigurationSection("Items").getKeys(false).forEach(slot -> inventory.setItem(Integer.parseInt(slot), makeItem(slot))); } private static ItemStack makeItem(String slot){ int id = getConfig().getInt("Items." + slot + ".Id"); int data = getConfig().getInt("Items." + slot + ".Data"); int amount = getConfig().getInt("Items." + slot + ".Amount"); String name = getConfig().getString("Items." + slot + ".Name"); List<String> lore = getConfig().getStringList("Items." + slot + ".Lore"); ItemStack toReturn = new ItemStack( id , amount , (short) data ); ItemMeta itemMeta = toReturn.getItemMeta(); itemMeta.setDisplayName(name); itemMeta.setLore(lore); toReturn.setItemMeta(itemMeta); return toReturn; } //onCommand, event, slá.. para abrir só usar isso p.openInventory(inventory); Editado Abril 3, 2017 por zAth 2 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 7, 2017 Autor Denunciar Compartilhar Postado Abril 7, 2017 config Items: 0: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 código Inventory inventory; public static void loadInventory(){ //coloca no onEnable inventory = getServer().createInventory(null, 9, "Inventory"); getConfig().getConfigurationSection("Items").getKeys(false).forEach(slot -> inventory.setItem(Integer.parseInt(slot), makeItem(slot))); } private static ItemStack makeItem(String slot){ int id = getConfig().getInt("Items." + slot + ".Id"); int data = getConfig().getInt("Items." + slot + ".Data"); int amount = getConfig().getInt("Items." + slot + ".Amount"); String name = getConfig().getString("Items." + slot + ".Name"); List<String> lore = getConfig().getStringList("Items." + slot + ".Lore"); ItemStack toReturn = new ItemStack( id , amount , (short) data ); ItemMeta itemMeta = toReturn.getItemMeta(); itemMeta.setDisplayName(name); itemMeta.setLore(lore); toReturn.setItemMeta(itemMeta); return toReturn; } //onCommand, event, slá.. para abrir só usar isso p.openInventory(inventory); deu um erro ali: http://imgur.com/a/w6fhx Erro: void[] is an invalid type && illegal modifier for parameter loadInventory; only final is permited Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 7, 2017 Denunciar Compartilhar Postado Abril 7, 2017 (editado) deu um erro ali: http://imgur.com/a/w6fhx Erro: void[] is an invalid type && illegal modifier for parameter loadInventory; only final is permited O método você coloca fora do onEnable ;-; só coloque loadInventory(); no onEnable Se ainda der erro, remove os static. Editado Abril 7, 2017 por zAth 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 O método você coloca fora do onEnable ;-; só coloque loadInventory(); no onEnable Se ainda der erro, remove os static. xD agora abriu, mas não ta pegando as informações da config (msgs/itens) Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 xD agora abriu, mas não ta pegando as informações da config (msgs/itens) config.yml e plugin.yml tem que estar dentro da src, eles estão dentro do plugin mas fora da src. 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 (editado) config.yml e plugin.yml tem que estar dentro da src, eles estão dentro do plugin mas fora da src. Tentei fazer isso mas não funcionou. Então dei undo e agora o plugin não está mais gerando a pasta da config. (O plugin não está pegando nada da config) Editado Abril 8, 2017 por joao100101 Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Tentei fazer isso mas não funcionou. Então dei undo e agora o plugin não está mais gerando a pasta da config. (O plugin não está pegando nada da config) Esqueçe o que eu disse xd, config.yml e plugin.yml tem que estar fora da src mesmo. coloca isso no onEnable() , antes do saveDefaultConfig(); File file = new File(getDataFolder(), "config.yml"); if (!(file.exists())) { try { saveResource("config.yml", false); } catch (Exception ignored) { } } saveDefaultConfig(); se ainda não der, manda print de como está. 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 (editado) Esqueçe o que eu disse xd, config.yml e plugin.yml tem que estar fora da src mesmo. coloca isso no onEnable() , antes do saveDefaultConfig(); File file = new File(getDataFolder(), "config.yml"); if (!(file.exists())) { try { saveResource("config.yml", false); } catch (Exception ignored) { } } saveDefaultConfig(); se ainda não der, manda print de como está. Continua sem criar a pasta Print: Metodo getInstance(): public static Main getInstance() { return (Main) Bukkit.getPluginManager().getPlugin("BurkingMarket"); } Editado Abril 8, 2017 por joao100101 Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Continua sem criar a pasta Print: Metodo getInstance(): public static Main getInstance() { return (Main) Bukkit.getPluginManager().getPlugin("BurkingMarket"); } coloca @Override em cima do onEnable? @Override public void onEnable() { se não for isso.. 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 coloca @Override em cima do onEnable? @Override public void onEnable() { se não for isso.. Acabei de ver que deu um erro na hora de carregar o plugin Erro: - https://hastebin.com/aripefeqoq.sql Classe Main: - https://hastebin.com/ogamugobep.java Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Acabei de ver que deu um erro na hora de carregar o plugin Erro: - https://hastebin.com/aripefeqoq.sql Classe Main: - https://hastebin.com/ogamugobep.java verifica se a sua config está nesse formato Items: 0: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 se não tem nenhum caracter inválido. E se não tem nenhum nome tipo assim Name: 'Displ'ay name' ou se tem algum " , não pode ter nada disso 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 verifica se a sua config está nesse formato Items: 0: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 se não tem nenhum caracter inválido. E se não tem nenhum nome tipo assim Name: 'Displ'ay name' ou se tem algum " , não pode ter nada disso ta tudo certo na config. Será que pode ser por eeu estar usando a 1.5.2? Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 ta tudo certo na config. Será que pode ser por eeu estar usando a 1.5.2? Caused by: unacceptable character '?' (0xFFFD) special characters are not allowed in "<string>", position 23 passa a sua config para mim enta1 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 Caused by: unacceptable character '?' (0xFFFD) special characters are not allowed in "<string>", position 23 passa a sua config para mim enta1 Mensagens: Prefixo: '§7[§6§lB§7urking§6§lS§7hop§7]' Welcome: '§7Voce entrou na loja!' Comprado: '§7Voce comprou um §2@item §7por §2@preco' Items: 1: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 Price: 100 Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Mensagens: Prefixo: '§7[§6§lB§7urking§6§lS§7hop§7]' Welcome: '§7Voce entrou na loja!' Comprado: '§7Voce comprou um §2@item §7por §2@preco' Items: 1: Name: 'Item' Lore: - '' - 'lore' Id: 7 Data: 0 Amount: 1 Price: 100 hmm talvez tem algum *tab* ae ;-; tenta escrever isso tudo denovo manualmente, sem *tab*, espaços apenas 1 Link para o comentário Compartilhar em outros sites More sharing options...
leonardosc Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Da uma olhada https://gist.github.com/leonardosnt/ea205f7e4f1bfaf841af639985054761 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 8, 2017 Autor Denunciar Compartilhar Postado Abril 8, 2017 Da uma olhada https://gist.github.com/leonardosnt/ea205f7e4f1bfaf841af639985054761 Isso seria outro metodo pra pegar os items da config? hmm talvez tem algum *tab* ae ;-; tenta escrever isso tudo denovo manualmente, sem *tab*, espaços apenas Não tem nenhum tab =/ Link para o comentário Compartilhar em outros sites More sharing options...
leonardosc Postado Abril 8, 2017 Denunciar Compartilhar Postado Abril 8, 2017 Isso seria outro metodo pra pegar os items da config? Não tem nenhum tab =/ Seria pra converter as string em um item... Pra pegar a lista de items é só usar o getStringList(), ai fazer um foreach e transformar pra item usando esse código que eu mostrei. 1 Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 9, 2017 Autor Denunciar Compartilhar Postado Abril 9, 2017 Seria pra converter as string em um item... Pra pegar a lista de items é só usar o getStringList(), ai fazer um foreach e transformar pra item usando esse código que eu mostrei. Não entendi muito bem, poderia me dar um exemplo? Link para o comentário Compartilhar em outros sites More sharing options...
joao100101 Postado Abril 9, 2017 Autor Denunciar Compartilhar Postado Abril 9, 2017 Consegui resolver sozinho. Metodo usado public static Map<ItemStack, Double> prices = new HashMap<>(); public void onEnable(){ getCommand("lojinha").setExecutor(this); if (!new File(getDataFolder(), "config.yml").exists()) { saveDefaultConfig(); } loadItems(); } public static void openShop(Player p) { Inventory inv = Bukkit.createInventory(null, 54, "Loja de Cash"); for (ItemStack i : prices.keySet()) inv.addItem(new ItemStack[] { i }); p.openInventory(inv); } public static void loadItems() { for (String key : Main.getInstance().getConfig().getConfigurationSection("Items").getKeys(false)) { String name = Main.getInstance().getConfig().getString("Items." + key + ".Name").replace("&", "§"); int quant = Main.getInstance().getConfig().getInt("Items." + key + ".Amount"); double price = Main.getInstance().getConfig().getInt("Items." + key + ".Price"); ItemStack item; if (Main.getInstance().getConfig().getString("Items." + key + ".Item").contains(":")) { int id = Integer.parseInt(Main.getInstance().getConfig().getString("Items." + key + ".Item").split(":")[0]); int data = Integer.parseInt(Main.getInstance().getConfig().getString("Items." + key + ".Item").split(":")[1]); item = new ItemStack(Material.getMaterial(id), quant, (short) data); } else { int id = Integer.parseInt(Main.getInstance().getConfig().getString("Items." + key + ".Item").split(":")[0]); item = new ItemStack(Material.getMaterial(id), quant); } ItemMeta itemMeta = item.getItemMeta(); itemMeta.setDisplayName(name); if (Main.getInstance().getConfig().contains("Items." + key + ".Lore")) { List<String> lore = new ArrayList<>(); for (String str : Main.getInstance().getConfig().getStringList("Items." + key + ".Lore")) { lore.add(str.replace("&", "§")); } itemMeta.setLore(lore); } if (Main.getInstance().getConfig().contains("Items." + key + ".Enchants")) { for (String enchants : Main.getInstance().getConfig().getStringList("Items." + key + ".Enchants")) { String enchant = enchants.split(":")[0]; int level = Integer.parseInt(enchants.split(":")[1]); item.addUnsafeEnchantment(org.bukkit.enchantments.Enchantment.getByName(enchant), level); } } item.setItemMeta(itemMeta); getPrices().put(item, Double.valueOf(price)); } } public static Map<ItemStack, Double> getPrices() { return prices; } public static Main getInstance() { return (Main)Bukkit.getServer().getPluginManager().getPlugin("SlainCash"); } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if(!(sender instanceof Player)){ sender.sendMessage("§cEsse comando nao funfa no console"); return true; } if(cmd.getName().equalsIgnoreCase("lojinha")){ Player p = (Player) sender; openShop(p); } return false; } } Config Items: 2: Item: "278:0" Price: 100 Amount: 1 Name: "&cPicareta top" Lore: - "&4&4&lQ&cuantidade: &4&l1" - "&4&4&lE&csse item custa &4&l100 real" Creditos ao jeta (Peguei esse metodo de um plugin dele) caso queira que eu remova o codigo chamar mp Link para o comentário Compartilhar em outros sites More sharing options...
Gutyerrez Postado Abril 10, 2017 Denunciar Compartilhar Postado Abril 10, 2017 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
joao100101
Olá, queria saber como faço uma lista de itens pela config (pra add os itens da config em uma gui), se possivel explicar como funciona e tals.
Link para o comentário
Compartilhar em outros sites
22 respostass a esta questão
Posts Recomendados