You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoCommand.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.auto;
  23. import com.google.auto.value.AutoValue;
  24. import java.util.Optional;
  25. import javax.annotation.Nonnull;
  26. /**
  27. * Describes a command that is executed automatically in response to either the client opening, or a
  28. * server connecting.
  29. */
  30. @AutoValue
  31. public abstract class AutoCommand {
  32. AutoCommand() {
  33. }
  34. public abstract Optional<String> getServer();
  35. public abstract Optional<String> getNetwork();
  36. public abstract Optional<String> getProfile();
  37. public abstract String getResponse();
  38. public abstract AutoCommandType getType();
  39. public static AutoCommand create(
  40. final Optional<String> server,
  41. final Optional<String> network,
  42. final Optional<String> profile,
  43. @Nonnull final String response) {
  44. final AutoCommandType type;
  45. if (!server.isPresent() && !network.isPresent()) {
  46. type = AutoCommandType.GLOBAL;
  47. } else if (server.isPresent() && !network.isPresent()) {
  48. type = AutoCommandType.SERVER;
  49. } else if (!server.isPresent()) {
  50. type = AutoCommandType.NETWORK;
  51. } else {
  52. type = AutoCommandType.UNKNOWN;
  53. }
  54. return new AutoValue_AutoCommand(server, network, profile, response, type);
  55. }
  56. }