sKNIGHT 1 Opublikowano 25 listopada 2017 Udostępnij Opublikowano 25 listopada 2017 Mam oto taki kod: W komendzie /items @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Player p = (Player) sender; if(command.getName().equalsIgnoreCase("items")){ List<ItemStack> items = new ArrayList<ItemStack>(); for(String itemsx : FileManager.getConfig().getStringList("drops")){ items.add(Utils.parseItemStack(itemsx)); } for(ItemStack is : items){ p.getInventory().addItem(is); } } } Klasa Utils: public static boolean isInt(String s){ try{ Integer.parseInt(s); return true; } catch (NumberFormatException ex) {} return false; } public static String replace(String text, String searchString, String replacement){ if ((text == null) || (text.isEmpty()) || (searchString.isEmpty()) || (replacement == null)) { return text; } int start = 0; int max = -1; int end = text.indexOf(searchString, start); if (end == -1) { return text; } int replacedLength = searchString.length(); int increase = replacement.length() - replacedLength; increase = increase < 0 ? 0 : increase; increase *= (max > 64 ? 64 : max < 0 ? 16 : max); StringBuilder sb = new StringBuilder(text.length() + increase); while (end != -1){ sb.append(text.substring(start, end)).append(replacement); start = end + replacedLength; max--; if (max == 0) { break; } end = text.indexOf(searchString, start); } sb.append(text.substring(start)); return sb.toString(); } public static ItemStack parseItemStack(String itemStack){ ItemStack is = new ItemStack(Material.AIR); String[] strings = itemStack.split(" "); String[] item = strings[0].split(":"); if (item.length > 1){ Material m = Material.getMaterial(Integer.parseInt(item[0])); is.setType(m); is.setDurability(Short.parseShort(item[1])); }else if (isInt(item[0])){ Material m = Material.getMaterial(Integer.parseInt(item[0])); is.setType(m); }else{ Material m = Material.getMaterial(item[0]); is.setType(m); } int amount = 1; if (isInt(strings[1])) { amount = Integer.parseInt(strings[1]); } is.setAmount(amount); for (int i = 2; i < strings.length; i++){ String s = strings[i]; String[] trim = s.split(":"); if (trim.length >= 1) { if (trim[0].equalsIgnoreCase("name")){ ItemMeta im = is.getItemMeta(); String name = c(replace(trim[1], "_", " ")); im.setDisplayName(name); is.setItemMeta(im); }else if (trim[0].equalsIgnoreCase("lore")){ ItemMeta im = is.getItemMeta(); trim[1] = replace(trim[1], "_", " "); String[] lorestring = trim[1].split("&nl"); List<String> lore = new ArrayList<String>(); for (String s1 : lorestring) { lore.add(c(s1)); } im.setLore(lore); is.setItemMeta(im); }else if (trim[0].equalsIgnoreCase("x")){ }else{ Enchantment e = Enchantments.getByName(trim[0]); if (e != null){ int lvl = Integer.parseInt(trim[1]); ItemMeta im = is.getItemMeta(); is.setItemMeta(im); is.addUnsafeEnchantment(e, lvl); } } } } return is; } public static String c (String s){ return ChatColor.translateAlternateColorCodes('&', s); } Plik config.yml drops: - "1 name:&6xd" - "1 name:&6aa" Odnośnik do komentarza https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/ Udostępnij na innych stronach Więcej opcji udostępniania...
0 Gość Usunięty#12473 Opublikowano 25 listopada 2017 Udostępnij Opublikowano 25 listopada 2017 Ten temat został przeniesiony. Odnośnik do komentarza https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/#findComment-157807 Udostępnij na innych stronach Więcej opcji udostępniania...
0 young_koiczek 25 Opublikowano 25 listopada 2017 Udostępnij Opublikowano 25 listopada 2017 nie opisałeś problemu Odnośnik do komentarza https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/#findComment-157808 Udostępnij na innych stronach Więcej opcji udostępniania...
0 sKNIGHT 1 Opublikowano 25 listopada 2017 Autor Udostępnij Opublikowano 25 listopada 2017 No problem jest w tym że nie działa Temat do zamknięcia / usunięcia! Odnośnik do komentarza https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/#findComment-157816 Udostępnij na innych stronach Więcej opcji udostępniania...
0 Gość Ewald Opublikowano 25 listopada 2017 Udostępnij Opublikowano 25 listopada 2017 Ten temat został zamknięty. Odnośnik do komentarza https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/#findComment-157820 Udostępnij na innych stronach Więcej opcji udostępniania...
Pytanie
sKNIGHT 1
Mam oto taki kod: W komendzie /items
Klasa Utils:
Plik config.yml
drops: - "1 name:&6xd" - "1 name:&6aa"Odnośnik do komentarza
https://skript.pl/temat/23196-dodawanie-item%C3%B3w-do-eq-poprzez-stringliste/Udostępnij na innych stronach
4 odpowiedzi na to pytanie
Rekomendowane odpowiedzi