AdminTeleport.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
net.sf.l2j.gameserver.handler.admincommandhandlers |
![]() |
![]() |
L2J |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* $Header: /cvsroot/l2j/L2_Gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTeleport.java,v 1.3 2004/11/19 08:54:42 l2chef Exp $
*
* $Author: l2chef $
* $Date: 2004/11/19 08:54:42 $
* $Revision: 1.3 $
* $Log: AdminTeleport.java,v $
* Revision 1.3 2004/11/19 08:54:42 l2chef
* database is now used
*
* Revision 1.2 2004/11/02 14:38:18 nuocnam
* introduced world regions
*
* Revision 1.1 2004/10/25 15:51:24 nuocnam
* new admin command handlers
*
*
*
* 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.io.IOException;
import java.util.StringTokenizer;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.serverpackets.TeleportToLocation;
/**
* This class handles following admin commands:
* - show_moves
* - show_teleport
* - teleport_to_character
* - move_to
* - teleport_character
*
* @version $Revision: 1.3 $ $Date: 2004/11/19 08:54:42 $
*/
public class AdminTeleport implements IAdminCommandHandler {
private static String[] _adminCommands = {
"admin_show_moves",
"admin_show_teleport",
"admin_teleport_to_character",
"admin_move_to",
"admin_teleport_character"
};
private static final int REQUIRED_LEVEL = 100;
public boolean useAdminCommand(String command, L2PcInstance activeChar) throws IOException {
if (!(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false;
if (command.equals("admin_show_moves"))
{
AdminHelpPage.showHelpPage(activeChar, "teleports.htm");
}
else if (command.equals("admin_show_teleport"))
{
showTeleportCharWindow(activeChar);
}
else if (command.equals("admin_teleport_to_character"))
{
teleportToCharacter(activeChar);
}
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
}
}
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);
TeleportToLocation tele = new TeleportToLocation(activeChar, x,y,z);
activeChar.sendPacket(tele);
activeChar.setX(x);
activeChar.setY(y);
activeChar.setZ(z);
activeChar.updateCurrentWorldRegion();
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("<html><title>Teleport Character</title>");
replyMSG.append("<body>");
replyMSG.append("The character you will teleport is " + player.getName() + ".");
replyMSG.append("<br>");
replyMSG.append("Co-ordinate x");
replyMSG.append("<edit var=\"char_cord_x\" width=110>");
replyMSG.append("Co-ordinate y");
replyMSG.append("<edit var=\"char_cord_y\" width=110>");
replyMSG.append("Co-ordinate z");
replyMSG.append("<edit var=\"char_cord_z\" width=110>");
replyMSG.append("<button value=\"Teleport\" action=\"bypass -h admin_teleport_character $char_cord_x $char_cord_y $char_cord_z\" width=60 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
replyMSG.append("<button value=\"Teleport near you\" action=\"bypass -h admin_teleport_character " + activeChar.getX() + " " + activeChar.getY() + " " + activeChar.getZ() + "\" width=115 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
replyMSG.append("<center><button value=\"Back\" action=\"bypass -h admin_current_player\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>");
replyMSG.append("</body></html>");
adminReply.setHtml(replyMSG.toString());
activeChar.sendPacket(adminReply);
}
private void teleportCharacter(L2PcInstance activeChar , String Cords)
{
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;
}
if (player.getName().equals(activeChar.getName()))
{
SystemMessage sm = new SystemMessage(614);
sm.addString("You cannot teleport your character.");
player.sendPacket(sm);
}
else
{
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);
//Common character information
SystemMessage sm = new SystemMessage(614);
sm.addString("Admin is teleporting you.");
player.sendPacket(sm);
TeleportToLocation tele = new TeleportToLocation(player, x,y,z);
player.sendPacket(tele);
player.setX(x);
player.setY(y);
player.setZ(z);
player.updateCurrentWorldRegion();
//Admin information
SystemMessage smA = new SystemMessage(614);
smA.addString("Character " + player.getName() + " teleported to "+ x + " " + y + " "+z);
activeChar.sendPacket(smA);
}
}
private void teleportToCharacter(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;
}
if (player.getName().equals(activeChar.getName()))
{
SystemMessage sm = new SystemMessage(614);
sm.addString("You cannot self teleport.");
activeChar.sendPacket(sm);
}
else
{
int x = player.getX();
int y = player.getY();
int z = player.getZ();
TeleportToLocation tele = new TeleportToLocation(activeChar, x,y,z);
activeChar.sendPacket(tele);
activeChar.setX(x);
activeChar.setY(y);
activeChar.setZ(z);
activeChar.updateCurrentWorldRegion();
SystemMessage sm = new SystemMessage(614);
sm.addString("You have teleported to character " + player.getName() + ".");
activeChar.sendPacket(sm);
}
}
}
The table below shows all metrics for AdminTeleport.java.




