Irrelevant Posted February 28, 2021 Share Posted February 28, 2021 (edited) hello ..i have a problem . I tried to add the code when admin create mass item only 1window per ip can receive. i add this: Spoiler Collection <L2PcInstance> pls = L2World.getInstance (). getAllPlayers (); for (L2PcInstance p: pls) { final String ip = p.getClient().getConnection().getInetAddress().getHostAddress(); if (ips.contains(ip)) continue; blablabla but it doesnt work :/ any help ? code hasnt errors, just in game doesnt work :/ edit: i use arraylist not hash Edited February 28, 2021 by Irrelevant Link to comment Share on other sites More sharing options...
0 melron Posted March 1, 2021 Share Posted March 1, 2021 3 minutes ago, Irrelevant said: you said about bots ,and i had an offline shop in server ,i disconnect it and now it work.BUT i have a question, does that mean that if someone use offline shop noone else will awarded? That was it. No, create the next method private boolean isClientOk(L2PcInstance player) { try { player.getClient().getConnection().getInetAddress().getHostAddress(); } catch (Exception e) { return false; } return true; } and then, change this line final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers(); to final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers().stream().filter(p -> isClientOk(p)).collect(Collectors.toList()); 1 Link to comment Share on other sites More sharing options...
0 melron Posted March 1, 2021 Share Posted March 1, 2021 Show us the whole code Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 4 minutes ago, melron said: Show us the whole code Spoiler List<String> ips = new ArrayList<>(); Collection <L2PcInstance> pls = L2World.getInstance (). getAllPlayers (); for (L2PcInstance p: pls) { final String ip = p.getClient().getConnection().getInetAddress().getHostAddress(); if (ips.contains(ip)) continue; p.sendMessage("Admin is rewarding all online players."); item = p.getInventory().addItem("Admin", id, num, null, null); final InventoryUpdate iu = new InventoryUpdate(); iu.addItem(item); p.sendPacket(iu); final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2); sm.addItemName(item.getItemId()); sm.addNumber(num); p.sendPacket(sm); i++; ips.add(ip); } activeChar.sendMessage("Mass-created items in the inventory of " + i + " player(s)."); LOGGER.info("GM " + activeChar.getName() + " mass_created item Id: " + id + " (" + num + ")"); } Link to comment Share on other sites More sharing options...
0 melron Posted March 1, 2021 Share Posted March 1, 2021 (edited) 18 minutes ago, Irrelevant said: Reveal hidden contents List<String> ips = new ArrayList<>(); Collection <L2PcInstance> pls = L2World.getInstance (). getAllPlayers (); for (L2PcInstance p: pls) { final String ip = p.getClient().getConnection().getInetAddress().getHostAddress(); if (ips.contains(ip)) continue; p.sendMessage("Admin is rewarding all online players."); item = p.getInventory().addItem("Admin", id, num, null, null); final InventoryUpdate iu = new InventoryUpdate(); iu.addItem(item); p.sendPacket(iu); final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2); sm.addItemName(item.getItemId()); sm.addNumber(num); p.sendPacket(sm); i++; ips.add(ip); } activeChar.sendMessage("Mass-created items in the inventory of " + i + " player(s)."); LOGGER.info("GM " + activeChar.getName() + " mass_created item Id: " + id + " (" + num + ")"); } final int id = 57; final int num = 5000000; final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers(); final HashSet<Object> seen = new HashSet<>(); players.removeIf(e -> !seen.add(e.getClient().getConnection().getInetAddress().getHostAddress())); players.forEach(player -> player.addItem("Admin-Reward", id, num, null, true)); activeChar.sendMessage(String.format("Mass-created items in the inventory of %s player(s)",players.size())); LOGGER.info(String.format("GM %s mass_created item Id: %s ( %s )",activeChar.getName(),id, num)); If you need the number of the players who did not get the reward, you can get them by "seen.getSize()" Edited March 1, 2021 by melron Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 22 minutes ago, melron said: final int id = 57; final int num = 5000000; final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers(); final HashSet<Object> seen = new HashSet<>(); players.removeIf(e -> !seen.add(e.getClient().getConnection().getInetAddress().getHostAddress())); players.forEach(player -> player.addItem("Admin-Reward", id, num, null, true)); activeChar.sendMessage(String.format("Mass-created items in the inventory of %s player(s)",players.size())); LOGGER.info(String.format("GM %s mass_created item Id: %s ( %s )",activeChar.getName(),id, num)); If you need the number of the players who did not get the reward, you can get them by "seen.getSize()" Link to comment Share on other sites More sharing options...
0 melron Posted March 1, 2021 Share Posted March 1, 2021 Do you have bots? Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 2 minutes ago, melron said: Do you have bots? i dont know what do you exactly mean ,i use dualbox to check it :/ Link to comment Share on other sites More sharing options...
0 melron Posted March 1, 2021 Share Posted March 1, 2021 10 minutes ago, Irrelevant said: i dont know what do you exactly mean ,i use dualbox to check it :/ Strange, debug it .... before the current code, add this one. System.out.println("Players online " + L2World.getAllPlayersCount()); L2World.getInstance().getAllPlayers().forEach(p -> System.out.println(String.format("Player %s , ip %s", p.getName(), p.getClient().getConnection().getInetAddress().getHostAddress()))); and when you click mass create, check the console i need the output Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 5 minutes ago, melron said: Strange, debug it .... before the current code, add this one. System.out.println("Players online " + L2World.getAllPlayersCount()); L2World.getInstance().getAllPlayers().forEach(p -> System.out.println(String.format("Player %s , ip %s", p.getName(), p.getClient().getConnection().getInetAddress().getHostAddress()))); and when you click mass create, check the console i need the output you said about bots ,and i had an offline shop in server ,i disconnect it and now it work.BUT i have a question, does that mean that if someone use offline shop noone else will awarded? Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 (edited) 34 minutes ago, melron said: That was it. No, create the next method private boolean isClientOk(L2PcInstance player) { try { player.getClient().getConnection().getInetAddress().getHostAddress(); } catch (Exception e) { return false; } return true; } and then, change this line final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers(); to final Collection<L2PcInstance> players = L2World.getInstance().getAllPlayers().stream().filter(p -> isClientOk(p)).collect(Collectors.toList()); It works PERFECTLY , i add again the offline shop and test it,its working properly(no errors and reward 1char per ip)!!Thanks dude! P.S my code was worked too after i disconnect offline shop . but i kept yours, its better :) Edited March 1, 2021 by Irrelevant Link to comment Share on other sites More sharing options...
0 Kara Posted March 1, 2021 Share Posted March 1, 2021 I wrote you a more organized and 1 line code. (Consider i just giving you a different perspective of java). The code the other guy gave you it's good and java proof for sure but it's very messy. L2World.getInstance().getPlayers().stream().filter(s -> Objects.nonNull(s.getClient().getConnection())).collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getClient().getConnection().getInetAddress().getHostAddress())))).forEach(s -> s.addItem(getClass().getSimpleName(), 57, 100, s, true)); It check for offline shops (since offline player has null connection while assigned a client) and remove duplicate base on their host name, you can change that to IP or whatever you want. I would also advice you to make a public method which retrieve the IP and the Host Name for a player and it's safe. Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 3 minutes ago, Kara said: I wrote you a more organized and 1 line code. (Consider i just giving you a different perspective of java). The code the other guy gave you it's good and java proof for sure but it's very messy. L2World.getInstance().getPlayers().stream().filter(s -> Objects.nonNull(s.getClient().getConnection())).collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getClient().getConnection().getInetAddress().getHostAddress())))).forEach(s -> s.addItem(getClass().getSimpleName(), 57, 100, s, true)); It check for offline shops (since offline player has null connection while assigned a client) and remove duplicate base on their host name, you can change that to IP or whatever you want. I would also advice you to make a public method which retrieve the IP and the Host Name for a player and it's safe. i will give a try on that .thanks :D Link to comment Share on other sites More sharing options...
0 Kara Posted March 1, 2021 Share Posted March 1, 2021 1 minute ago, Irrelevant said: i will give a try on that .thanks Consider this is just the way i write java. Clear and short. It doesn't mean you have to use it. But for sure you can experiment. (Also i believe it require java 10+) Link to comment Share on other sites More sharing options...
0 Irrelevant Posted March 1, 2021 Author Share Posted March 1, 2021 (edited) 10 minutes ago, Kara said: Consider this is just the way i write java. Clear and short. It doesn't mean you have to use it. But for sure you can experiment. (Also i believe it require java 10+) if it requires above java 8 ,i will not try xd (borring to update java again,l2jfrozen uses java 6-7 XDXDXD) Edited March 1, 2021 by Irrelevant Link to comment Share on other sites More sharing options...
0 Kara Posted March 1, 2021 Share Posted March 1, 2021 (edited) 6 minutes ago, Irrelevant said: if it requires above java 8 ,i will not try xd (borring to update java again,l2jfrozen uses java 6-7 XDXDXD) Ah alright then, i didn't know. For sure you should upgrade to java 8 since scripting engine is still supported and java 8 has some future proof features and it's the current stable java version. I don't see the reason why you stick with Java 7 in 2021. Saying you're lazy and you spend 10 minutes writing in this topic while updating java only take 5. So vouch for java 8 ! Edited March 1, 2021 by Kara Link to comment Share on other sites More sharing options...
Question
Irrelevant
hello ..i have a problem . I tried to add the code when admin create mass item only 1window per ip can receive.
i add this:
Collection <L2PcInstance> pls = L2World.getInstance (). getAllPlayers ();
for (L2PcInstance p: pls)
{
final String ip = p.getClient().getConnection().getInetAddress().getHostAddress();
if (ips.contains(ip))
continue;
blablabla
but it doesnt work :/ any help ?
code hasnt errors, just in game doesnt work :/
edit: i use arraylist not hash
Edited by IrrelevantLink to comment
Share on other sites
16 answers to this question
Recommended Posts