12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package command;
- import common.Message;
- import common.Message.MessageType;
- import server.Client;
- import server.Server;
- public class LeaveChannel extends Command{
- @Override
- public void execute(String[] args, Client caller) throws Exception {
- if (caller.equals(Server.OPClient)){
- caller.send("Client-only command.");
- return;
- }
-
- try {
- Server.getChannelByName(args[0]).remove(caller);
- if (caller.primaryChannel.equals(Server.getChannelByName(args[0])))
- caller.primaryChannel = Server.channels.get(0);
- caller.send(new Message("You left channel " + args[0] + ".", MessageType.COMMAND, false));
- caller.send(new Message("You are now speaking in channel " + caller.primaryChannel.name + ".", MessageType.COMMAND, false));
- } catch(NullPointerException ex) {
- caller.send(new Message("No channel named " + args[0] + ".", MessageType.ERROR, false));
- return;
- }
- }
- @Override
- public String setName() {
- return "leave";
- }
- @Override
- public String setPermission() {
- return "noob.leave";
- }
- @Override
- public String writeDescription() {
- return "Removes caller from specified channel. (/leave <channel>)";
- }
- @Override
- public int setMinArgNumber() {
- return 1;
- }
- }
|