/* * This program 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 2, or (at your option) * any later version. * * This program 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver.handler.admincommandhandlers; import java.util.StringTokenizer; import java.util.logging.Logger; import net.sf.l2j.Config; import net.sf.l2j.gameserver.NpcTable; import net.sf.l2j.gameserver.SpawnTable; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; import net.sf.l2j.gameserver.model.L2NpcInstance; import net.sf.l2j.gameserver.model.L2Object; import net.sf.l2j.gameserver.model.L2PcInstance; import net.sf.l2j.gameserver.model.L2Spawn; import net.sf.l2j.gameserver.model.L2World; import net.sf.l2j.gameserver.serverpackets.ActionFailed; import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.serverpackets.SystemMessage; import net.sf.l2j.gameserver.templates.L2NpcTemplate; /** * This class handles following admin commands: * - show_moves * - show_teleport * - teleport_to_character * - move_to * - teleport_character * * @version $Revision: 1.3.2.6.2.4 $ $Date: 2005/04/11 10:06:06 $ */ public class AdminTeleport implements IAdminCommandHandler { private static final Logger _log = Logger.getLogger(AdminTeleport.class.getName()); private static String[] _adminCommands = { "admin_teleport_to_character", "admin_teleport_character_to", "admin_teleport_character", "admin_show_moves_other", "admin_show_teleport", "admin_teleportto", "admin_show_moves", "admin_recall_npc", "admin_move_to", "admin_recall", "admin_failed", "teleportto", "recall" }; private static final int REQUIRED_LEVEL = Config.GM_TELEPORT; public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (!(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false; if (command.equals("admin_show_moves")) { AdminHelpPage.showHelpPage(activeChar, "teleports.htm"); } if (command.equals("admin_show_moves_other")) { AdminHelpPage.showHelpPage(activeChar, "tele/other.html"); } else if (command.equals("admin_show_teleport")) { showTeleportCharWindow(activeChar); } else if (command.equals("admin_recall_npc")) { recallNPC(activeChar); } else if (command.equals("admin_teleport_to_character")) { teleportToCharacter(activeChar, activeChar.getTarget()); } else if (command.startsWith("admin_move_to")) { try { String val = command.substring(14); teleportTo(activeChar, val); } catch (StringIndexOutOfBoundsException e) { //Case of empty co-ordinates SystemMessage sm = new SystemMessage(614); sm.addString("Wrong or no Co-ordinates given."); activeChar.sendPacket(sm); } } else if (command.startsWith("admin_teleport_character")) { try { String val = command.substring(25); teleportCharacter(activeChar, val); } catch (StringIndexOutOfBoundsException e) { //Case of empty co-ordinates SystemMessage sm = new SystemMessage(614); sm.addString("Wrong or no Co-ordinates given."); activeChar.sendPacket(sm); showTeleportCharWindow(activeChar); //back to character teleport } } else if (command.startsWith("admin_teleport_character_to ")) { String[] data = command.split(" "); if(data.length==5) { String playerName=data[1]; int x=Integer.parseInt(data[2]); int y=Integer.parseInt(data[3]); int z=Integer.parseInt(data[4]); L2PcInstance player = L2World.getInstance().getPlayer(playerName); if(player!=null) { teleportCharacter(player,x,y,z); } } } else if (command.startsWith("admin_teleportto ")) { String targetName = command.substring(17); L2PcInstance player = L2World.getInstance().getPlayer(targetName); teleportToCharacter(activeChar, player); } else if (command.startsWith("admin_recall ")) { String targetName = command.substring(13); L2PcInstance player = L2World.getInstance().getPlayer(targetName); teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ()); } else if (command.startsWith("admin_failed")) { SystemMessage sm = new SystemMessage(614); sm.addString("Trying ActionFailed..."); activeChar.sendPacket(sm); activeChar.sendPacket(new ActionFailed()); } return true; } public String[] getAdminCommandList() { return _adminCommands; } private boolean checkLevel(int level) { return (level >= REQUIRED_LEVEL); } private void teleportTo(L2PcInstance activeChar, String Cords) { StringTokenizer st = new StringTokenizer(Cords); String x1 = st.nextToken(); int x = Integer.parseInt(x1); String y1 = st.nextToken(); int y = Integer.parseInt(y1); String z1 = st.nextToken(); int z = Integer.parseInt(z1); activeChar.teleToLocation(x, y, z); SystemMessage sm = new SystemMessage(614); sm.addString("You have been teleported to " + Cords); activeChar.sendPacket(sm); } private void showTeleportCharWindow(L2PcInstance activeChar) { L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance)target; } else { SystemMessage sm = new SystemMessage(614); sm.addString("Incorrect target."); activeChar.sendPacket(sm); return; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("