deusowy_yt 2 Opublikowano 29 czerwca 2018 Udostępnij Opublikowano 29 czerwca 2018 Witam, mam problem z HashMapa, a mianowicie gdy gracz ktory stawia block ma ustawiona zmienna na false to wszyscy gracze tego nie widza, ale gdy gracz ma wiadomosci wlaczono, a drugi wylaczone to i tak mu dziala Prosiłbym o pomoc, prosze kod: package me.neroos.case1; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class onPlaceListeners implements Listener{ public static Map<Player, Boolean> map = new HashMap<Player, Boolean>(); @EventHandler public void onPlace(BlockPlaceEvent e) { Player p = e.getPlayer(); Block b = e.getBlock(); if(b.getType() == Material.CHEST) { ItemMeta im = p.getItemInHand().getItemMeta(); if(im.getDisplayName().equals("§7§k|§a§l§k!§7§k| §a§o§lP§e§l§or§b§l§oe§3§l§om§b§l§oi§b§l§oum§e§l§oC§a§l§oa§b§l§os§3§l§oe §7§k|§a§l§k!§7§k|") && im.getLore().equals(Arrays.asList("§8§m--+------------------------------------+--"," §5§oTen przedmiot jest wyjatkowo Legendarny."," §5§oW srodku tej skrzyni znajduja sie bardzo"," §5§oCenne przedmioty, otworzenie jej spowoduje"," §5§oWielki wybuch, i uwolnienie mocy, co skutkuje", " §5§oWyrzuceniem przedmiotow do Twojego ekwipunku! ", " §e§oChcesz sprobowac swojego szczescia?" , " §e§oSmialo, wez ta skrzynie do reki i ja poloz!", " §f§oJestes ciekawy co wyleci? Wpisz §4§l§o/CASE" ,"§8§m--+------------------------------------+--"))) { e.setCancelled(true); if(p.getInventory().getItemInHand() != null) { ItemStack handItem = p.getInventory().getItemInHand(); handItem.setAmount(handItem.getAmount() - 1); p.getInventory().setItemInHand(handItem); p.updateInventory(); for(Player all : Bukkit.getOnlinePlayers()) if(map.get(p) == Boolean.TRUE) { all.sendMessage(" §a§l»" + "§c§o " + p.getName() + " §7§ootworzyl §7§k|§a§l§k!§7§k| §a§o§lP§e§l§or§b§l§oe§3§l§om§b§l§oi§b§l§oum§e§l§oC§a§l§oa§b§l§os§3§l§oe §7§k|§a§l§k!§7§k|§7§o, i otrzymal§8:"); } if(Math.random() * 100 <= 1) { giveItem(p, Stacki.is); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §4§oRzucane TNT §8§o(1%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is1); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oKlate §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is2); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oButy §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is3); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oHelm §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is4); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oSpodnie §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 4) { giveItem(p, Stacki.is5); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oKilof §c§o10§7/§c§o3§7/§c§o3 §8§o(4%)"); } } if(Math.random() * 100 <= 7) { giveItem(p, Stacki.k1); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oKilof §c§o8§7/§c§o3§7/§c§o3 §8§o(7%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.k2); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oKilof §c§o9§7/§c§o3§7/§c§o3 §8§o(5%)"); } } if(Math.random() * 100 <= 9) { giveItem(p, Stacki.k3); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oKilof §c§o7§7/§c§o3§7/§c§o3 §8§o(9%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.co); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §a§o§lCobblex §8§o(5%)"); } } if(Math.random() * 100 <= 25) { giveItem(p, Stacki.d); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §b§oDiamenty §8§o(25%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.lo); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oLopata §c§o5§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.sie); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oSiekierka §c§o5§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.is6); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oMiecz §c§o6§7/§c§o3§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is7); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §a§oBloki Emeraldu §8§o(10%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is8); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §a§oEmeraldy §8§o(20%)"); } } if(Math.random() * 100 <= 0.05) { giveItem(p, Stacki.is9); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §a§l§oB§e§o§lE§b§o§lA§3§l§oC§b§l§oON §8§o(0.05%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is10); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§oBoyFarmer §8§o(30%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is11); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§oSandFarmer §8§o(30%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is12); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§oKopaczFosy §8§o(30%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is13); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oZelazo §8§o(20%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is14); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oZloto §8§o(20%)"); } } if(Math.random() * 100 <= 35) { giveItem(p, Stacki.is16); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oZelazo §8§o(35%)"); } } if(Math.random() * 100 <= 25) { giveItem(p, Stacki.is17); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oEmeraldy §8§o(25%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is15); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §c§oZloto §8§o(30%)"); } } if(Math.random() * 100 <= 2) { giveItem(p, Stacki.is18); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §5§oSilka §8§o(2%)"); } } if(Math.random() * 100 <= 15) { giveItem(p, Stacki.is19); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oObsydian §8§o(15%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is20); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §d§oObsydian §8§o(20%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is21); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §b§oKoxy §8§o(10%)"); } } if(Math.random() * 100 <= 15) { giveItem(p, Stacki.is22); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §3§oRefile §8§o(15%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.st3); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§lGenerator Kamienia §8§o(10%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.st1); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§lGenerator Kamienia§6§o+ §8§o(5%)"); } } if(Math.random() * 100 <= 3) giveItem(p, Stacki.st2); if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §f§l» §9§lGenerator Kamienia§6§o++ §8§o(3%)"); } } if(map.get(p) == Boolean.TRUE) { p.sendMessage(" §b§l» §aChcesz kupic §a§o§lP§e§l§or§b§l§oe§3§l§om§b§l§oi§b§l§oum§e§l§oC§a§l§oa§b§l§os§3§l§oe§a? Wejdz na strone:"); p.sendMessage(" §b§l» §f§l§oNEROO-SKLEP.XAA.PL"); } } } } private void giveItem(Player player, ItemStack itemToAdd) { int freeSpace = 0; for (ItemStack i : player.getInventory()) { if (i == null) { freeSpace += itemToAdd.getType().getMaxStackSize(); } else if (i.getType() == itemToAdd.getType()) { freeSpace += i.getType().getMaxStackSize() - i.getAmount(); } } if (itemToAdd.getAmount() > freeSpace) { player.getWorld().dropItemNaturally(player.getLocation(), itemToAdd); } else { player.getInventory().addItem(itemToAdd); } player.updateInventory(); } } LloydPL 1 Cytuj Odnośnik do komentarza https://skript.pl/temat/27954-problem-z-hashmapa/ Udostępnij na innych stronach Więcej opcji udostępniania...
0 JanekMaSkrypta_ 117 Opublikowano 29 czerwca 2018 Udostępnij Opublikowano 29 czerwca 2018 (edytowane) if(map.get(p) == Boolean.TRUE) { Bo moze zamiast p daj all ? Edit: I jeszcze zamiast sprawdzac nazwy po prostu daj isSimilar Edytowane 29 czerwca 2018 przez JanekMaSkrypta_ Cytuj Odnośnik do komentarza https://skript.pl/temat/27954-problem-z-hashmapa/#findComment-185197 Udostępnij na innych stronach Więcej opcji udostępniania...
0 deusowy_yt 2 Opublikowano 29 czerwca 2018 Autor Udostępnij Opublikowano 29 czerwca 2018 @JanekMaSkrypta_Juz naprawiłem, ale dzięki za pomoc jeśli jesteś ciekawy to kod teraz wygląda tak: package me.neroos.case1; import java.util.Arrays; import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class onPlaceListeners implements Listener{ public static HashMap<Player, Boolean> map = new HashMap<Player, Boolean>(); @EventHandler public void onPlace(BlockPlaceEvent e) { Player p = e.getPlayer(); Block b = e.getBlock(); if(b.getType() == Material.CHEST) { ItemMeta im = p.getItemInHand().getItemMeta(); if(im.getDisplayName().equals("§7§k|§a§l§k!§7§k| §a§o§lN§e§l§oe§b§l§or§3§l§oo§b§l§oo§e§l§oC§a§l§oa§b§l§os§3§l§oe §7§k|§a§l§k!§7§k|") && im.getLore().equals(Arrays.asList("§8§m--+------------------------------------+--"," §5§oTen przedmiot jest wyjatkowo Legendarny."," §5§oW srodku tej skrzyni znajduja sie bardzo"," §5§oCenne przedmioty, otworzenie jej spowoduje"," §5§oWielki wybuch, i uwolnienie mocy, co skutkuje", " §5§oWyrzuceniem przedmiotow do Twojego ekwipunku! ", " §e§oChcesz sprobowac swojego szczescia?" , " §e§oSmialo, wez ta skrzynie do reki i ja poloz!", " §f§oJestes ciekawy co wyleci? Wpisz §4§l§o/CASE" ,"§8§m--+------------------------------------+--"))) { e.setCancelled(true); if(p.getInventory().getItemInHand() != null) { ItemStack handItem = p.getInventory().getItemInHand(); handItem.setAmount(handItem.getAmount() - 1); p.getInventory().setItemInHand(handItem); p.updateInventory(); for(Player all : Bukkit.getOnlinePlayers()) { if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §a§l»" + "§c§o " + p.getName() + " §7§ootworzyl §7§k|§a§l§k!§7§k| §a§o§lN§e§l§oe§b§l§or§3§l§oo§b§l§oo§e§l§oC§a§l§oa§b§l§os§3§l§oe §7§k|§a§l§k!§7§k|§7§o, i otrzymal§8:"); } if(Math.random() * 100 <= 1) { giveItem(p, Stacki.is); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §4§oRzucane TNT §8§o(1%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is1); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oKlate §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is2); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oButy §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is3); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oHelm §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is4); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oSpodnie §c§o4§7/§c§o3 §8§o(10%)"); } } if(Math.random() * 100 <= 4) { giveItem(p, Stacki.is5); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oKilof §c§o10§7/§c§o3§7/§c§o3 §8§o(4%)"); } } if(Math.random() * 100 <= 7) { giveItem(p, Stacki.k1); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oKilof §c§o8§7/§c§o3§7/§c§o3 §8§o(7%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.k2); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oKilof §c§o9§7/§c§o3§7/§c§o3 §8§o(5%)"); } } if(Math.random() * 100 <= 9) { giveItem(p, Stacki.k3); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oKilof §c§o7§7/§c§o3§7/§c§o3 §8§o(9%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.co); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §a§o§lCobblex §8§o(5%)"); } } if(Math.random() * 100 <= 25) { giveItem(p, Stacki.d); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §b§oDiamenty §8§o(25%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.lo); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oLopata §c§o5§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.sie); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oSiekierka §c§o5§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 8) { giveItem(p, Stacki.is6); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oMiecz §c§o6§7/§c§o3§7/§c§o3 §8§o(8%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is7); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §a§oBloki Emeraldu §8§o(10%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is8); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §a§oEmeraldy §8§o(20%)"); } } if(Math.random() * 100 <= 0.05) { giveItem(p, Stacki.is9); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §a§l§oB§e§o§lE§b§o§lA§3§l§oC§b§l§oON §8§o(0.05%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is10); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§oBoyFarmer §8§o(30%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is11); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§oSandFarmer §8§o(30%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is12); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§oKopaczFosy §8§o(30%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is13); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oZelazo §8§o(20%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is14); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oZloto §8§o(20%)"); } } if(Math.random() * 100 <= 35) { giveItem(p, Stacki.is16); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oZelazo §8§o(35%)"); } } if(Math.random() * 100 <= 25) { giveItem(p, Stacki.is17); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oEmeraldy §8§o(25%)"); } } if(Math.random() * 100 <= 30) { giveItem(p, Stacki.is15); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §c§oZloto §8§o(30%)"); } } if(Math.random() * 100 <= 2) { giveItem(p, Stacki.is18); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §5§oSilka §8§o(2%)"); } } if(Math.random() * 100 <= 15) { giveItem(p, Stacki.is19); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oObsydian §8§o(15%)"); } } if(Math.random() * 100 <= 20) { giveItem(p, Stacki.is20); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §d§oObsydian §8§o(20%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.is21); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §b§oKoxy §8§o(10%)"); } } if(Math.random() * 100 <= 15) { giveItem(p, Stacki.is22); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §3§oRefile §8§o(15%)"); } } if(Math.random() * 100 <= 10) { giveItem(p, Stacki.st3); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§lGenerator Kamienia §8§o(10%)"); } } if(Math.random() * 100 <= 5) { giveItem(p, Stacki.st1); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§lGenerator Kamienia§6§o+ §8§o(5%)"); } } if(Math.random() * 100 <= 3) { giveItem(p, Stacki.st2); if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §f§l» §9§lGenerator Kamienia§6§o++ §8§o(3%)"); } } if(map.get(all) == Boolean.TRUE) { all.sendMessage(" §b§l» §aChcesz kupic §a§o§lP§e§l§or§b§l§oe§3§l§om§b§l§oi§b§l§oum§e§l§oC§a§l§oa§b§l§os§3§l§oe§a? Wejdz na strone:"); all.sendMessage(" §b§l» §f§l§oNEROO-SKLEP.XAA.PL"); } } } } } } private void giveItem(Player player, ItemStack itemToAdd) { int freeSpace = 0; for (ItemStack i : player.getInventory()) { if (i == null) { freeSpace += itemToAdd.getType().getMaxStackSize(); } else if (i.getType() == itemToAdd.getType()) { freeSpace += i.getType().getMaxStackSize() - i.getAmount(); } } if (itemToAdd.getAmount() > freeSpace) { player.getWorld().dropItemNaturally(player.getLocation(), itemToAdd); } else { player.getInventory().addItem(itemToAdd); } player.updateInventory(); } } Cytuj Odnośnik do komentarza https://skript.pl/temat/27954-problem-z-hashmapa/#findComment-185200 Udostępnij na innych stronach Więcej opcji udostępniania...
Pytanie
deusowy_yt 2
Witam, mam problem z HashMapa, a mianowicie gdy gracz ktory stawia block ma ustawiona zmienna na false to wszyscy gracze tego nie widza, ale gdy gracz ma wiadomosci wlaczono, a drugi wylaczone to i tak mu dziala
Prosiłbym o pomoc, prosze kod:
Odnośnik do komentarza
https://skript.pl/temat/27954-problem-z-hashmapa/Udostępnij na innych stronach
2 odpowiedzi na to pytanie
Rekomendowane odpowiedzi
Dołącz do dyskusji
Możesz dodać zawartość już teraz a zarejestrować się później. Jeśli posiadasz już konto, zaloguj się aby dodać zawartość za jego pomocą.