-
Ilość zawartości
61 -
Rejestracja
-
Ostatnia wizyta
Treść opublikowana przez Virosel
-
Dalej nie działa
-
Teraz nie da się w ogóle sprzedać Może Map.... ench = is.getEnchantments(); im.addEnchantments(ench);
-
Podkreśla mi ImmutableList.Of() Edit: Jednak jest dobrze, tylko of z małych
-
Ale nadal jest mały problem, podczas sprzedaży plugin "pomija" enchanty. Mam na myśli, że można sprzedawać nie enchantowane przedmioty, w miejscu, gdzie powinny być enchantowane
-
Nie, ale teraz usunąłem i działa, dzięki
-
nadal to samo może zmienić to: Map<Enchantment, Integer> map = new HashMap<>(); for (String s : Main.getInst().getConfig().getStringList(path + ".enchantments")) { Enchantment ench = Enchantment.getByName(s.split(":")[0].toUpperCase()); if (ench == null) continue; int level = Integer.parseInt(s.split(":")[1]); map.put(ench, level); } na to: Map<Enchantment, Integer> map = new HashMap<>(); for (String s : String.join("\n", Main.getInst().getConfig().getStringList(path + ".enchantments"))) { Enchantment ench = Enchantment.getByName(s.split(":")[0].toUpperCase()); if (ench == null) continue; int level = Integer.parseInt(s.split(":")[1]); map.put(ench, level); }
-
https://prnt.sc/t1h7mz
-
No i błąd... Wszystko było ok, póki nie postanowiłem sprawdzić enchantów. XD Treść: Cannot load plugins\vShop\config.yml org.bukkit.configuration.InvalidConfigurationException: while scanning for the next token found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation) in 'string', line 71, column 1: - 'durability:3' ^ at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:57) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:188) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:162) [spigot.jar:git-Spigot-db6de12-18fbb24] at pl.viroz.shop.Main.onEnable(Main.java:26) [vShop2-1.0.jar:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24] at java.lang.Thread.run(Unknown Source) [?:1.8.0_231] Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation) in 'string', line 71, column 1: - 'durability:3' ^ at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.yaml.snakeyaml.Yaml.load(Yaml.java:369) ~[spigot.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[spigot.jar:git-Spigot-db6de12-18fbb24] Sorry za wysłanie 2 błędów
-
Ok, działa, teraz trzeba zrobić jeszcze kupno, ale raczej sobie z tym poradzę, ewentualnie będę pytał
-
ItemStack remove = new ItemStack(is.getType(), 1, is.getDurability()); może zmienić to '1' na is.getAmount?
-
Sprzedaje, ale tylko po jednym
-
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) { ItemStack is = e.getCurrentItem(); ItemStack remove = new ItemStack(is.getType(), 1, is.getDurability()); if (!ItemManager.items.containsKey(is)) { } int amount = is.getAmount(); if(p.getInventory().containsAtLeast(is, is.getAmount())){ CoinsManager.addMoney(p, price); String msg = String.join("\n", Main.getInst().getConfig().getStringList("sellSuccess")); msg = msg.replace("{ITEM}", is.getType().toString()); msg = msg.replace("{AMOUNT}", String.valueOf(amount)); msg = msg.replace("{MONEY}", String.valueOf(price)); p.getInventory().removeItem(is); p.sendMessage(Utils.fixColor(msg)); }else{ p.closeInventory(); Utils.sendTitle(p, Utils.fixColor(Main.getInst().getConfig().getString("titles.tag"))); Utils.sendSubTitle(p, Utils.fixColor(Main.getInst().getConfig().getString("titles.notEnounghtItems"))); } e.setCancelled(true);
-
Itemki się dodają, ale podczas sprzedaży wyświetla się komunikat o braku wystarczającej ilości przedmiotów
-
Więc tak, Przy ładowaniu przedmiotów z configu chcę załadować tylko przedmioty(cenę wyciągam w innym miejscu). Generalnie, cena działa. Chodzi mi o metodę, która wrzuciłbym itemki z mapy do gui
-
Tak, ale nie przy ładowaniu przedmiotów
-
W jakiej innej zmiennej to zrobić? Niby jest zmienna slot, ale nie wiem jak działa
-
public static Map<ItemStack, Integer> items = new HashMap<>(); public static void loadConfig(){ int i = 0; for (final String a : Main.getInst().getConfig().getConfigurationSection("Items.Sell").getKeys(false)) { final String path = "Items.Sell." + a; final ItemStack item = new ItemStack(Material.getMaterial(Main.getInst().getConfig().getString(path + ".material"))); item.setAmount(Main.getInst().getConfig().getInt(path + ".amount")); ItemMeta met = item.getItemMeta(); met.setDisplayName(Utils.fixColor(Main.getInst().getConfig().getString(path + ".name"))); List<String> lore = Main.getInst().getConfig().getStringList(path + ".lore") .stream() .map(s -> ChatColor.translateAlternateColorCodes('&', s).replace("<<", "«").replace(">>", "»")) .collect(Collectors.toList()); met.setLore(lore); item.setItemMeta(met); int price = Main.getInst().getConfig().getInt(path+".price"); Map<Enchantment, Integer> map = new HashMap<>(); for (String s : Main.getInst().getConfig().getStringList(path + ".enchantments")) { Enchantment ench = Enchantment.getByName(s.split(":")[0].toUpperCase()); if (ench == null) continue; int level = Integer.parseInt(s.split(":")[1]); map.put(ench, level); } item.addUnsafeEnchantments(map); items.put(item, i); i++; } } Tu jest metoda loadConfig
-
Stworzyłem mapę <ItemStack, Integer> - Integer to slot. I teraz nasuwa się pytanie, w jaki sposób dodać to do inventory. (nie pracowałem wcześniej z mapami, więc nie wiem jak to działa).
-
Zrobiłem to tak: Stworzyłem klasę ItemManager (kod niżej): public static Map<ItemStack, Integer> map = new HashMap<>(); public static int getItemPrice(ItemStack is){ int price = map.get(is); return price; } public static void setItem(ItemStack is, int price){ map.put(is, price); } W evencie kliknięcia: @EventHandler public boolean onInventoryClick(InventoryClickEvent e) { Player p = (Player) e.getWhoClicked(); String shopinvname = Main.getInst().getConfig().getString("shopSellName"); if (e.getInventory().getTitle().equals(Utils.fixColor(shopinvname))) { if (e.getCurrentItem().getItemMeta() != null) { if (e.getCurrentItem().getItemMeta().getDisplayName() != null) { e.setCancelled(true); ItemStack is = e.getCurrentItem(); ItemMeta meta = is.getItemMeta(); if (!ItemManager.map.containsKey(is)) { } int price = ItemManager.getItemPrice(is); meta.setLore(new ArrayList<>()); meta.setDisplayName(null); is.setItemMeta(meta); Material mat = is.getType(); int amount = is.getAmount(); if(p.getInventory().containsAtLeast(is, amount)){ CoinsManager.addMoney(p, price); String msg = String.join("\n", Main.getInst().getConfig().getStringList("sellSuccess")); msg = msg.replace("{ITEM}", is.getType().toString()); msg = msg.replace("{MONEY}", String.valueOf(amount)); p.getInventory().removeItem(is); p.sendMessage(Utils.fixColor(msg)); }else{ p.closeInventory(); Utils.sendTitle(p, Utils.fixColor(Main.getInst().getConfig().getString("titles.tag"))); Utils.sendSubTitle(p, Utils.fixColor(Main.getInst().getConfig().getString("titles.notEnounghtItems"))); } } } } return true; } } I jeszcze kod z klasy otwierającej zakladkę sklepu: else if (e.getCurrentItem().getItemMeta().getDisplayName().equals(r)) { e.setCancelled(true); Inventory inv = Bukkit.createInventory(null, 27, Utils.fixColor(Main.getInst().getConfig().getString("shopSellName"))); int i = 0; for (final String a : Main.getInst().getConfig().getConfigurationSection("Items.Sell").getKeys(false)) { final String path = "Items.Sell." + a; final ItemStack item = new ItemStack(Material.getMaterial(Main.getInst().getConfig().getString(path + ".material"))); item.setAmount(Main.getInst().getConfig().getInt(path + ".amount")); ItemMeta met = item.getItemMeta(); met.setDisplayName(Utils.fixColor(Main.getInst().getConfig().getString(path + ".name"))); List<String> lore = Main.getInst().getConfig().getStringList(path + ".lore") .stream() .map(s -> ChatColor.translateAlternateColorCodes('&', s).replace("<<", "«").replace(">>", "»")) .collect(Collectors.toList()); met.setLore(lore); item.setItemMeta(met); int price = Main.getInst().getConfig().getInt(path+".price"); Map<Enchantment, Integer> map = new HashMap<>(); for (String s : Main.getInst().getConfig().getStringList(path + ".enchantments")) { Enchantment ench = Enchantment.getByName(s.split(":")[0].toUpperCase()); if (ench == null) continue; int level = Integer.parseInt(s.split(":")[1]); map.put(ench, level); } item.addUnsafeEnchantments(map); inv.setItem(i, item); ItemManager.setItem(item, i); i++; } p.openInventory(inv); } Wszystko niby działa, ale tylko podczas pierwszej sprzedaży, później czyści się meta przedmiotu (w GUI) i kolejna sprzedaż jest nie możliwa. Pewnie jest to jakiś głupi błąd logiczny, którego nie mogę znaleźć. Po usunięciu elementu "is.setItemMeta(meta);" po kliknięciu nie można tego sprzedać ani razu. Najłatwiej chyba byłoby otworzyć całe GUI od nowa po każdej sprzedaży, lub utworzyć nowy ItemStack, który będzie równy temu, który gracz kliknął (ItemStack is1 = is; )
-
Ok. tą mapę chyba najlepiej będzie stworzyć w miejscu, gdzie plugin wyciąga itemki z configu. Jutro sprawdzę
-
Czyli cały ten kod skopiować, czy tylko to, co jest w evencie?
-
Ok, dzięki
-
Jeszcze jedno pytanie, w jaki sposób mogę sprawdzić jaka jest cena danego itemku w evencie kliknięcia? Resztę pewnie będę wiedział jak zrobić.
-
Chodzi mi bardziej o to, żeby wyciągnąć te enchanty z configu.
-
Póki nie zamknęli pytania to poruszę jeszcze jeden wątek, nie wiesz może w jaki sposób dodać enchanty do tych itemków?
