Jump to content
  • 0

prohibit dualbox IP or HWID onEnter zone


Question

Posted (edited)

Hello guys. I am looking for code/line that prohibit dualbox inside a zone ..
Like when player enter in a Zone (L2RaidBoss as example) check Ip or HWID and not allow to a second char to enter and teleport back ..

Spoiler

    protected void onEnter(final L2Character character)
    {
        if (_enabled)
        {
            if (character instanceof L2PcInstance)
            {
                // Thread.dumpStack();
                L2PcInstance player = (L2PcInstance) character;
                
                if (player.isGM() || Config.ALLOW_DIRECT_TP_TO_BOSS_ROOM)
                {
                    player.sendMessage("You entered " + _zoneName);

 

Thank you in advance
Edit: i just see one more guy just LF that aswell (i guess perfect timming)

L2jfrozen 1132. java 7

Edited by scraw

15 answers to this question

Recommended Posts

  • 0
Posted (edited)
@Override
	protected void onEnter(final L2Character character)
	{
		if (character instanceof L2PcInstance)
		{
			final L2PcInstance player = character.getActingPlayer();
			if (L2World.getInstance().getAllPlayers().stream().filter(p->p.isInsideZone(L2Character.ZONE_PEACE) && p.getIpAddress()!=null && p.getIpAddress().equals(player.getIpAddress())).count() > 0)
			{
				player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
				return;
			}
			player.setInsideZone(L2Character.ZONE_PEACE, true);
		}
	}

Instead of zone_peace you should put your desired zone. Also in L2PcInstance

 

public String getIpAddress()
	{
		if (getClient()==null)
			return null;
		
		return getClient().getConnection().getInetAddress().getHostAddress();
	}

 

 

Edited by Zake
  • 0
Posted

@Zake thanks for reply.. i just need this line to java 1.7 
 

Spoiler

 if (L2World.getInstance().getAllPlayers().stream().filter(p>p.isInsideZone(L2Character.ZONE_PEACE) && p.getIpAddress()!=null && p.getIpAddress().equals(player.getIpAddress())).count() > 0)
 

 

  • 0
Posted (edited)
15 minutes ago, scraw said:

@Zake thanks for reply.. i just need this line to java 1.7 
 

  Hide contents

 if (L2World.getInstance().getAllPlayers().stream().filter(p>p.isInsideZone(L2Character.ZONE_PEACE) && p.getIpAddress()!=null && p.getIpAddress().equals(player.getIpAddress())).count() > 0)
 

 

Lel i though java streams were introduced in java 7. nvm

 

@Override
	protected void onEnter(final L2Character character)
	{
		if (character instanceof L2PcInstance)
		{
			final L2PcInstance player = character.getActingPlayer();
			int count=0;
			for (L2PcInstance p : L2World.getInstance().getAllPlayers())
			{
				if (p == null || p.getIpAddress() ==null || p.getObjectId() == player.getObjectId() || !p.isInsideZone(L2Character.ZONE_PEACE) || p.getIpAddress()!= player.getIpAddress())
					continue;
				
				count++;
			}
			if (count > 0)
			{
				player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
				return;
			}
			player.setInsideZone(L2Character.ZONE_PEACE, true);
		}
	}

 

Edited by Zake
  • 0
Posted
8 minutes ago, scraw said:

@Zakecode has no error (i havent build yet) i just cant find what zone is the bosszone ..i go to l2character and there is no boss_zone :/

If there is not you should create one.

  • 0
Posted
Just now, Zake said:

If there is not you should create one.

im my zones.xml is BossZone ..but ZONE_BOSS or BOSS_ZONE isnt working  :/ in L2Character isnt that zone at all..any way i will insert into another zone to check and if it works i will find the way (i think)

@Zake https://ibb.co/XJd6H6h

  • 0
Posted (edited)
4 hours ago, scraw said:

im my zones.xml is BossZone ..but ZONE_BOSS or BOSS_ZONE isnt working  :/ in L2Character isnt that zone at all..any way i will insert into another zone to check and if it works i will find the way (i think)

@Zake https://ibb.co/XJd6H6h

 

The error is very clearly. An object of type L2ChestInstance cannot be casted as L2PcInstance.

Java basically is trying to cast a furniture as a human. It's not same type therefore you get this error.

 

5 hours ago, Zake said:






@Override
	protected void onEnter(final L2Character character)
	{
		if (character instanceof L2PcInstance)
		{
			final L2PcInstance player = character.getActingPlayer();
			if (L2World.getInstance().getAllPlayers().stream().filter(p->p.isInsideZone(L2Character.ZONE_PEACE) && p.getIpAddress()!=null && p.getIpAddress().equals(player.getIpAddress())).count() > 0)
			{
				player.teleToLocation(MapRegionTable.TeleportWhereType.Town);
				return;
			}
			player.setInsideZone(L2Character.ZONE_PEACE, true);
		}
	}

 

 

And no this is not how you use count() or isPresent(). 

 

You need to read the documentations of newer java versions and their methods. 

 

anyMatch will quit after it find an element. isPresent() and count() iterates the whole stream and cause further delay for no reason.

 

L2World.getInstance().getPlayers().stream().anyMatch(s -> s.getIPAddress() == target.getIPAddress());

 

In addition why go though all L2World players and not simply the one contained in zone?

 

Also you don't need to check for null... both equal and == does a null check like instanceof 

 

@scraw Install java 8. You don't need any special engine to parse external java files or py. We live in 2021. JDK 7 is banned.

 

 

Edited by Kara
  • 0
Posted
9 hours ago, Kara said:

 

The error is very clearly. An object of type L2ChestInstance cannot be casted as L2PcInstance.

Java basically is trying to cast a furniture as a human. It's not same type therefore you get this error.

 

 

there is a check which he apparently missed

if (character instanceof L2PcInstance)

so there is no need to count furnitures

 

9 hours ago, Kara said:

And no this is not how you use count() 

 

If you are referring to Collectors.counting() this is the exact same way to count elements in a stream. There are also 5(+?) more ways, none of them makes an actual difference

9 hours ago, Kara said:

In addition why go though all L2World players and not simply the one contained in zone?

You have to store them upon enter/remove upon exit .If this guy wants to create 100 raid(custom?) zones, there would be like 100 concurrent maps/lists(whatever he wants to use) in memory, unfortunately most of them empty. This is still a faster road for a cpu though (especially for high player counts), but almost redundant.

9 hours ago, Kara said:

Also you don't need to check for null

 

this is indeed unnecessary, my apologies

  • 0
Posted
13 minutes ago, Zake said:

 

You have to store them upon enter/remove upon exit .If this guy wants to create 100 raid(custom?) zones, there would be like 100 concurrent maps/lists(whatever he wants to use) in memory, unfortunately most of them empty. This is still a faster road for a cpu though (especially for high player counts), but almost redundant.

Doesn't frozen have getPlayersInside/getCharactersInside method? :yeih:

  • 0
Posted
3 minutes ago, melron said:

Doesn't frozen have getPlayersInside/getCharactersInside method? :yeih:

Oh my apologies too then, i didn't expect that frozen would store them. 

  • Haha 1
  • 0
Posted
1 minute ago, Zake said:

Oh my apologies too then, i didn't expect that frozen would store them. 

To be honest, i didn't too... :P

  • 0
Posted (edited)

When a person is telling you that anyMatch iterate until it find an element while yours keep busy the stream until all elements scanned and your logic is "It works so it's fine" then OK

Edited by Kara
  • 0
Posted
16 minutes ago, Kara said:

When a person is telling you that anyMatch iterate until it find an element while yours keep busy the stream until all elements scanned and your logic is "It works so it's fine" then OK

Lol, i NEVER said that anyMatch() or count() do not iterate through all the elements of a stream. I also never said that this is the optimal way to do, this was just a quick example written in np++ using just a method of l2jfrozen's svn.

  • 0
Posted
6 minutes ago, Zake said:

Lol, i NEVER said that anyMatch() or count() do not iterate through all the elements of a stream. I also never said that this is the optimal way to do, this was just a quick example written in np++ using just a method of l2jfrozen's svn.

 

wkM3q6E.gif

  • 0
Posted
5 minutes ago, Kara said:

 

wkM3q6E.gif

Still never said any of these 2, you may read the posts above and confirm on your own. Nevermind topic locked

  • Thanks 1
Guest
This topic is now closed to further replies.
×
×
  • Create New...