LeaveChannel.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package command;
  2. import common.Message;
  3. import common.Message.MessageType;
  4. import server.Client;
  5. import server.Server;
  6. public class LeaveChannel extends Command{
  7. @Override
  8. public void execute(String[] args, Client caller) throws Exception {
  9. if (caller.equals(Server.OPClient)){
  10. caller.send("Client-only command.");
  11. return;
  12. }
  13. try {
  14. Server.getChannelByName(args[0]).remove(caller);
  15. if (caller.primaryChannel.equals(Server.getChannelByName(args[0])))
  16. caller.primaryChannel = Server.channels.get(0);
  17. caller.send(new Message("You left channel " + args[0] + ".", MessageType.COMMAND, false));
  18. caller.send(new Message("You are now speaking in channel " + caller.primaryChannel.name + ".", MessageType.COMMAND, false));
  19. } catch(NullPointerException ex) {
  20. caller.send(new Message("No channel named " + args[0] + ".", MessageType.ERROR, false));
  21. return;
  22. }
  23. }
  24. @Override
  25. public String setName() {
  26. return "leave";
  27. }
  28. @Override
  29. public String setPermission() {
  30. return "noob.leave";
  31. }
  32. @Override
  33. public String writeDescription() {
  34. return "Removes caller from specified channel. (/leave <channel>)";
  35. }
  36. @Override
  37. public int setMinArgNumber() {
  38. return 1;
  39. }
  40. }