Skip to content
Snippets Groups Projects
Commit ac7f895a authored by Nos's avatar Nos
Browse files

BETA: Ported `AdminScan` to java so L2J can run on both java 7 and 8 since...

BETA: Ported `AdminScan` to java so L2J can run on both java 7 and 8 since javascript engine API has changed on future versions.
	* Added missing main method in `Q00382_KailsMagicCoin`.
	
Reviewed by: Zoey76
parent ead6bd91
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,6 @@
# Load Handlers
handlers/MasterHandler.java
handlers/admincommandhandlers/AdminScan.js
# AI Section
......
......@@ -108,6 +108,7 @@ import handlers.admincommandhandlers.AdminReload;
import handlers.admincommandhandlers.AdminRepairChar;
import handlers.admincommandhandlers.AdminRes;
import handlers.admincommandhandlers.AdminRide;
import handlers.admincommandhandlers.AdminScan;
import handlers.admincommandhandlers.AdminShop;
import handlers.admincommandhandlers.AdminShowQuests;
import handlers.admincommandhandlers.AdminShutdown;
......@@ -374,6 +375,7 @@ public class MasterHandler
AdminRepairChar.class,
AdminRes.class,
AdminRide.class,
AdminScan.class,
AdminShop.class,
AdminShowQuests.class,
AdminShutdown.class,
......
/*
* Copyright (C) 2004-2014 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package handlers.admincommandhandlers;
import java.util.StringTokenizer;
import com.l2jserver.gameserver.datatables.SpawnTable;
import com.l2jserver.gameserver.handler.IAdminCommandHandler;
import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2Spawn;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
/**
* @author Nos
*/
public class AdminScan implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_scan",
"admin_deleteNpcByObjectId"
};
private static final int DEFAULT_RADIUS = 500;
@Override
public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
final StringTokenizer st = new StringTokenizer(command, " ");
final String actualCommand = st.nextToken();
switch (actualCommand.toLowerCase())
{
case "admin_scan":
{
int radius = DEFAULT_RADIUS;
if (st.hasMoreElements())
{
try
{
radius = Integer.parseInt(st.nextToken());
}
catch (NumberFormatException e)
{
activeChar.sendMessage("Usage: //scan [radius]");
return false;
}
}
sendNpcList(activeChar, radius);
break;
}
case "admin_deletenpcbyobjectid":
{
if (!st.hasMoreElements())
{
activeChar.sendMessage("Usage: //deletenpcbyobjectid <object_id>");
return false;
}
try
{
int objectId = Integer.parseInt(st.nextToken());
final L2Object target = L2World.getInstance().findObject(objectId);
final L2Npc npc = target instanceof L2Npc ? (L2Npc) target : null;
if (npc == null)
{
activeChar.sendMessage("NPC does not exist or object_id does not belong to an NPC");
return false;
}
npc.deleteMe();
final L2Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.stopRespawn();
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getId()))
{
RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
}
else
{
SpawnTable.getInstance().deleteSpawn(spawn, true);
}
}
activeChar.sendMessage(npc.getName() + " have been deleted.");
}
catch (NumberFormatException e)
{
activeChar.sendMessage("object_id must be a number.");
return false;
}
sendNpcList(activeChar, DEFAULT_RADIUS);
break;
}
}
return true;
}
private void sendNpcList(L2PcInstance activeChar, int radius)
{
final NpcHtmlMessage html = new NpcHtmlMessage();
html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/scan.htm");
final StringBuilder sb = new StringBuilder();
for (L2Character character : activeChar.getKnownList().getKnownCharactersInRadius(radius))
{
if (character instanceof L2Npc)
{
sb.append("<tr>");
sb.append("<td width=\"54\">" + character.getId() + "</td>");
sb.append("<td width=\"54\">" + character.getName() + "</td>");
sb.append("<td width=\"54\">" + Math.round(activeChar.calculateDistance(character, false, false)) + "</td>");
sb.append("<td width=\"54\"><a action=\"bypass -h admin_deleteNpcByObjectId " + character.getObjectId() + "\"><font color=\"LEVEL\">Delete</font></a></td>");
sb.append("<td width=\"54\"><a action=\"bypass -h admin_move_to " + character.getX() + " " + character.getY() + " " + character.getZ() + "\"><font color=\"LEVEL\">Go to</font></a></td>");
sb.append("</tr>");
}
}
html.replace("%data%", sb.toString());
activeChar.sendPacket(html);
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}
/*
* Copyright (C) 2004-2014 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
importPackage(java.util);
importPackage(java.lang);
importPackage(com.l2jserver.gameserver.cache);
importPackage(com.l2jserver.gameserver.datatables);
importPackage(com.l2jserver.gameserver.handler);
importPackage(com.l2jserver.gameserver.instancemanager);
importPackage(com.l2jserver.gameserver.model);
importPackage(com.l2jserver.gameserver.model.actor);
importPackage(com.l2jserver.gameserver.model.actor.instance);
importPackage(com.l2jserver.gameserver.network.serverpackets);
importPackage(com.l2jserver.gameserver.util);
/**
* @author UnAfraid
*/
AdminCommandHandler.getInstance().registerHandler(new JavaAdapter(IAdminCommandHandler,
{
// Override useAdminCommand() method.
useAdminCommand : function(command, player)
{
var st = new StringTokenizer(command, " ");
if (st.hasMoreTokens())
{
var cmd = st.nextToken();
if (cmd == 'admin_scan')
{
var radius = 500;
if (st.hasMoreTokens())
{
var obj = st.nextToken();
if (Util.isDigit(obj))
{
radius = obj;
}
}
var htm = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/admin/scan.htm");
var sb = new StringBuilder();
var it = player.getKnownList().getKnownCharactersInRadius(radius).iterator();
while (it.hasNext())
{
var character = it.next();
if (character instanceof L2Npc)
{
sb.append("<tr>");
sb.append("<td width=\"54\">" + character.getId() + "</td>");
sb.append("<td width=\"54\">" + character.getName() + "</td>");
sb.append("<td width=\"54\">" + Math.round(player.calculateDistance(character, false, false)) + "</td>");
sb.append("<td width=\"54\"><a action=\"bypass -h admin_deleteNpcByObjectId " + character.getObjectId() + "\"><font color=\"LEVEL\">Delete</font></a></td>");
sb.append("<td width=\"54\"><a action=\"bypass -h admin_move_to " + character.getX() + " " + character.getY() + " " + character.getZ() + "\"><font color=\"LEVEL\">Go to</font></a></td>");
sb.append("</tr>");
}
}
htm = htm.replaceAll("%data%", sb.toString());
player.sendPacket(new NpcHtmlMessage(0, htm));
}
else if (cmd = 'admin_deleteNpcByObjectId' && st.hasMoreTokens())
{
var objectId = st.nextToken();
if (Util.isDigit(objectId))
{
var it = player.getKnownList().getKnownCharacters().iterator();
while (it.hasNext())
{
var character = it.next();
if ((character instanceof L2Npc) && (character.getObjectId() == objectId))
{
character.deleteMe();
var spawn = character.getSpawn();
if (spawn != null)
{
spawn.stopRespawn();
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getId()))
{
RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
}
else
{
SpawnTable.getInstance().deleteSpawn(spawn, true);
}
}
player.sendMessage(character.getName() + " have been deleted.");
this.useAdminCommand("admin_scan", player);
}
}
}
}
}
return true;
},
// Override getAdminCommandList() method.
getAdminCommandList : function()
{
return new Array("admin_scan", "admin_deleteNpcByObjectId");
}
}));
\ No newline at end of file
......@@ -134,4 +134,9 @@ public final class Q00382_KailsMagicCoin extends Quest
}
return super.onKill(npc, killer, isSummon);
}
public static void main(String[] args)
{
new Q00382_KailsMagicCoin();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment