001 /**
002 * Jetrix TetriNET Server
003 * Copyright (C) 2001-2004 Emmanuel Bourg
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019
020 package net.jetrix.commands;
021
022 import java.util.*;
023
024 import net.jetrix.*;
025 import net.jetrix.messages.*;
026 import net.jetrix.messages.channel.CommandMessage;
027 import net.jetrix.messages.channel.PlineMessage;
028
029 /**
030 * Teleport a player to another channel.
031 *
032 * @author Emmanuel Bourg
033 * @version $Revision: 798 $, $Date: 2009-02-18 16:24:28 +0100 (Wed, 18 Feb 2009) $
034 */
035 public class TeleportCommand extends AbstractCommand implements ParameterCommand
036 {
037 public TeleportCommand()
038 {
039 setAccessLevel(AccessLevel.OPERATOR);
040 }
041
042 public String[] getAliases()
043 {
044 return (new String[] { "teleport", "tp" });
045 }
046
047 public String getUsage(Locale locale)
048 {
049 return "/teleport <" + Language.getText("command.params.player_name_num", locale) + "> <" + Language.getText("command.params.channel_name_num", locale) + ">";
050 }
051
052 public int getParameterCount()
053 {
054 return 2;
055 }
056
057 public void execute(CommandMessage m)
058 {
059 Client client = (Client) m.getSource();
060
061 String targetName = m.getParameter(0);
062 Client target = m.getClientParameter(0);
063
064 if (target == null)
065 {
066 // no player found
067 client.send(new PlineMessage("command.player_not_found", targetName));
068 }
069 else
070 {
071 // player found
072 Channel channel = m.getChannelParameter(1);
073
074 if (channel != null)
075 {
076 if (channel.isFull())
077 {
078 // sending channel full message
079 PlineMessage channelfull = new PlineMessage();
080 channelfull.setKey("command.join.full");
081 client.send(channelfull);
082 }
083 else
084 {
085 // adding the ADDPLAYER message to the queue of the target channel
086 AddPlayerMessage move = new AddPlayerMessage(target);
087 channel.send(move);
088
089 PlineMessage teleported = new PlineMessage();
090 teleported.setKey("command.teleport.message", target.getUser().getName(), channel.getConfig().getName());
091 client.send(teleported);
092 }
093 }
094 }
095 }
096 }