Jump to content
  • 0

mass create per ip


Question

Posted (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 by Irrelevant

Recommended Posts

  • 0
Posted
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());

 

  • Thanks 1
  • 0
Posted
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 + ")");
    }

 

  • 0
Posted (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 by melron
  • 0
Posted
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()"

 

ja.JPG

  • 0
Posted
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

  • 0
Posted
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?

  • 0
Posted (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 by Irrelevant
  • 0
Posted

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. 

  • 0
Posted
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

  • 0
Posted
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+)

  • 0
Posted (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 by Irrelevant
  • 0
Posted (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 !

 

1X4XFqx.gif

Edited by Kara
Guest
This topic is now closed to further replies.


  • Posts

    • There is a ready-made option and the possibility to work according to "Wishlist"
    • Contact me, Discord: xbaus
    • WTB GRACIA FINAL INTERFACE
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock