View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.gui.action;
18  
19  import java.awt.event.ActionEvent;
20  import java.awt.event.ActionListener;
21  
22  import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
23  import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
24  
25  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
26  import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealWaypoint;
27  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Respawn;
28  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
29  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
30  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
31  
32  /**
33   * Interface wrapper for the respawn action. Can be used anywhere an action
34   * listener is expected.
35   * 
36   * Assumes a connection exists.
37   * 
38   * @author M.P. Korstanje
39   * 
40   */
41  public class RespawnAction implements ActionListener {
42  
43  	private final Player player;
44  	// TODO: Use listeners to set this
45  	private final WaypointBox navpoints;
46  
47  	public RespawnAction(Player player, WaypointBox navpoints) {
48  		this.player = player;
49  		this.navpoints = navpoints;
50  	}
51  
52  	@Override
53  	public void actionPerformed(ActionEvent e) {
54  		ServerController controller = ServerController.getInstance();
55  		IUT2004Server server = controller.getServer();
56  		assert server != null;
57  
58  		Waypoint waypoint = navpoints.getSelected();
59  		Location location = null;
60  		if (waypoint != null) {
61  			location = waypoint.getLocation();
62  		}
63  
64  		Respawn respawn = new Respawn(player.getId(), location, null);
65  		server.getAct().act(respawn);
66  	}
67  
68  }