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

    • Website: https://l2elixir.org/ Discord: https://discord.gg/5ydPHvhbxs    
    • L2-LORENA x100 MID RATE   Interlude Nostalgia Meets Modern Gameplay   OFFICIAL OPENING:  April 4 (Saturday)  19:00 UTC+1 ⸻  MAIN INFORMATION  Adena: x5  Drop: x10  Spoil: x10  Raid Boss: x10  Seal Stones: x2  Quests: x10 ⸻  FEATURES  GM Shop up to B-Grade  Full Buffer  Premium System (x2 bonuses)  AutoFarm – FREE for everyone ⸻  SERVER CONCEPT  Classic Interlude nostalgia  Enhanced with modern interface & mechanics  Balanced PvP & PvE gameplay  Active development & custom features ⸻  WHY JOIN L2-LORENA?  No Pay-to-Win  Smooth gameplay & stable server  Competitive PvP environment  Friendly & active community ⸻  JOIN US NOW L2-LORENA 100X <<< LINK Discord: https://discord.gg/TYZ88Tgx4b  Facebook: https://www.facebook.com/share/18kwbkaYZY/?mibextid=wwXIfr   L2-LORENA Link << Discord: https://discord.gg/TYZ88Tgx4b  Facebook: https://www.facebook.com/share/18kwbkaYZY/?mibextid=wwXIfr
    • https://web.archive.org/web/20260306183214/https://maxcheaters.com/topic/241828-l2j-l2damage/page/3/ https://l2topzone.com/forum/l2-server-support-problems/9/l2damage-stopped/30514 Also we will try to push longer seasons ever ! (1135-100)/9 = 115 online
    • ONE SIDE – AND EVERYTHING BREAKS ▪ Looks like a simple case: Florida DL, back side, barcode – “clean and minimal”. ▪ In reality, these are exactly the tasks that fail most often. – data provided as plain text – request only for the back side – focus on the barcode (PDF417) ▪ And here’s the key point: ▪ A barcode is not just a “picture on the back”. It’s compressed logic of the entire document. ▪ If it doesn’t match the front, format, and data structure – the system flags it instantly. ▪ Many create a “similar-looking” code. But systems don’t read “similar” – they read by specification. ▪ In cases like this, it’s not about design. It’s about correct data assembly and how it behaves inside the format. ▪ Today only – 15% off for verification cases. ▪ Want it to pass, not just look right? Describe your case – we’ll show where even clean files break. › TG: @mustang_service ( https:// t.me/ mustang_service ) › Channel: Mustang Service ( https:// t.me/ +JPpJCETg-xM1NjNl ) #editing #photoshop #documents #verification #case
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..