Addition of topspawncount admin command.

This commit is contained in:
MobiusDev
2019-01-10 17:49:26 +00:00
parent 97b4148a7d
commit fdf51df12a
26 changed files with 713 additions and 12 deletions

View File

@@ -528,6 +528,8 @@ INSERT IGNORE INTO `admin_command_access_rights` VALUES
('admin_teleport_reload','3'),
('admin_spawnnight','3'),
('admin_spawnday','3'),
('admin_topspawncount','3'),
('admin_top_spawn_count','3'),
-- Section: Target
('admin_target','3'),

View File

@@ -16,6 +16,9 @@
*/
package com.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@@ -31,6 +34,7 @@ import com.l2jmobius.gameserver.instancemanager.GrandBossManager;
import com.l2jmobius.gameserver.instancemanager.RaidBossSpawnManager;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2NpcInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.sevensigns.SevenSigns;
import com.l2jmobius.gameserver.model.spawn.L2Spawn;
@@ -38,6 +42,7 @@ import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jmobius.gameserver.templates.chars.L2NpcTemplate;
import com.l2jmobius.gameserver.util.BuilderUtil;
import com.l2jmobius.gameserver.util.Util;
/**
* This class handles following admin commands: - show_spawns = shows menu - spawn_index lvl = shows menu for monsters with respective level - spawn_monster id = spawns monster id on target
@@ -59,7 +64,9 @@ public class AdminSpawn implements IAdminCommandHandler
"admin_show_npcs",
"admin_teleport_reload",
"admin_spawnnight",
"admin_spawnday"
"admin_spawnday",
"admin_topspawncount",
"admin_top_spawn_count"
};
public static Logger LOGGER = Logger.getLogger(AdminSpawn.class.getName());
@@ -199,6 +206,52 @@ public class AdminSpawn implements IAdminCommandHandler
TeleportLocationTable.getInstance().reloadAll();
GmListTable.broadcastMessageToGMs("Teleport List Table reloaded.");
}
else if (command.startsWith("admin_topspawncount") || command.startsWith("admin_top_spawn_count"))
{
final StringTokenizer st = new StringTokenizer(command, " ");
st.nextToken();
int count = 5;
if (st.hasMoreTokens())
{
final String nextToken = st.nextToken();
if (Util.isDigit(nextToken))
{
count = Integer.parseInt(nextToken);
}
if (count <= 0)
{
return true;
}
}
final Map<Integer, Integer> npcsFound = new HashMap<>();
for (L2Object obj : L2World.getInstance().getAllVisibleObjects())
{
if (!(obj instanceof L2NpcInstance))
{
continue;
}
final int npcId = ((L2NpcInstance) obj).getNpcId();
if (npcsFound.containsKey(npcId))
{
npcsFound.put(npcId, npcsFound.get(npcId) + 1);
}
else
{
npcsFound.put(npcId, 1);
}
}
BuilderUtil.sendSysMessage(activeChar, "Top " + count + " spawn count.");
for (Entry<Integer, Integer> entry : Util.sortByValue(npcsFound, true).entrySet())
{
count--;
if (count < 0)
{
break;
}
final int npcId = entry.getKey();
BuilderUtil.sendSysMessage(activeChar, NpcTable.getInstance().getTemplate(npcId).getName() + " (" + npcId + "): " + entry.getValue());
}
}
return true;
}

View File

@@ -19,6 +19,10 @@ package com.l2jmobius.gameserver.util;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.gameserver.model.L2Object;
@@ -542,4 +546,26 @@ public final class Util
{
return (objectsSize / pageSize) + ((objectsSize % pageSize) == 0 ? 0 : 1);
}
/**
* This will sort a Map according to the values. Default sort direction is ascending.
* @param <K> keyType
* @param <V> valueType
* @param map Map to be sorted.
* @param descending If you want to sort descending.
* @return A new Map sorted by the values.
*/
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map, boolean descending)
{
if (descending)
{
return map.entrySet().stream().sorted(Map.Entry.comparingByValue(Collections.reverseOrder())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
return map.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map)
{
return map.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
}