Skip to content

Admin Command Mass Hero

Featured Replies

Solved by ^Wyatt

  • Solution

omg :D

 

L2World.getInstance().getAllPlayers().values(new L2PcInstance[0]) red line .... xdin datapack

as sweets said remove the {}

just use L2World.getInstance().getAllPlayersArray()

 

just..

package handlers.admincommandhandlers;

import com.l2jserver.gameserver.handler.IAdminCommandHandler;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.SocialAction;

public class AdminMassHero implements IAdminCommandHandler
{
	
	@Override
	public String[] getAdminCommandList()
	{
		return ADMIN_COMMANDS;
	}
	
	@Override
	public boolean useAdminCommand(String command, L2PcInstance activeChar)
	{
		if (activeChar == null)
		{
			return false;
		}
		
		if (command.startsWith("admin_masshero"))
		{
			for (L2PcInstance player : L2World.getInstance().getAllPlayersArray())
			{
				if (!player.isHero() || !player.isInOlympiadMode())
				{
					player.setHero(true);
					player.sendMessage("Admin is rewarding all online players with Hero Status.");
					player.broadcastPacket(new SocialAction(player.getObjectId(), 16));
					player.broadcastUserInfo();
				}
				player = null;
			}
		}
		return true;
	}
	
	private static String[] ADMIN_COMMANDS =
	{
		"admin_masshero"
	};
}

This will only get the first value of pc instance tho

Nope, it gets all player values, at least since few months it was doing so, if it's not changed.

 

 

edit: yep it was changed, but like 1-2months ago it was working Q_Q

 

2pages for this stupid code  :rage:

Edited by ^Wyatt

Nope, it gets all player values, at least since few months it was doing so, if it's not changed.

edit: yep it was changed, but like 1-2months ago it was working Q_Q

 

2pages for this stupid code  :rage:

 

There is no way it was possibly able to get all players while the new class L2PcInstance use a static value 0 in order to get the players. It could work if you add all the players in a list and by getting the size of the list you added the i value in a normal for loop combined to an enhanced one.

 

 

 

naj5.jpg
 
Uploaded with ImageShack.us

 

Log 3 players online and try to do it. The Gm char was already hero so the code picked the only char online.

PS: This commend is for the first new L2PcInstance[0] idea

Edited by Elfocrash

player = null 

 

why ?  garbage collector will take care of it

player = null 

 

why ?  garbage collector will take care of it

 

L2JFrozen adaptation, don't ask. There was also an L2PcInstance instance check on a array storing only L2PcInstance.

@Elfo

It was working, I had it in some codes since l2jhidden and ofc tested, now it's not working anymore, eclipse marks it with red line

He is using the getAllPlayersArray() in that screen he posted.

Edited by ^Wyatt

The funny thing is they reverted all that crap about arrays to reuse L2J IL stuff on latest.

public Collection<L2PcInstance> getPlayers()
{
	return _allPlayers.values();
}

@Elfo

It was working, I had it in some codes since l2jhidden and ofc tested, now it's not working anymore, eclipse marks it with red line

He is using the getAllPlayersArray() in that screen he posted.

 

 

why ? every pack has an all online L2PcInstances into collections as List or Map, so you just use getAllPlayers() if its a list or getAllPlayers().values() if its a map

  • Author

all work thx share ! Locked Topic . :))

Edited by Dominion

why ? every pack has an all online L2PcInstances into collections as List or Map, so you just use getAllPlayers() if its a list or getAllPlayers().values() if its a map

Don't remember but... some months ago I had it somewhere... I think in voterewards and so... were using that method, but who cares if now can't be used anymore.

 

Locked.

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.