LeaveChannel.java 1.0 KB

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