Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ProcessMOTD.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2015 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.parser.irc.processors;
  23. import com.dmdirc.parser.events.MOTDEndEvent;
  24. import com.dmdirc.parser.events.MOTDLineEvent;
  25. import com.dmdirc.parser.events.MOTDStartEvent;
  26. import com.dmdirc.parser.interfaces.callbacks.MotdEndListener;
  27. import com.dmdirc.parser.interfaces.callbacks.MotdLineListener;
  28. import com.dmdirc.parser.interfaces.callbacks.MotdStartListener;
  29. import com.dmdirc.parser.irc.IRCParser;
  30. import com.dmdirc.parser.irc.ProcessingManager;
  31. import java.util.Date;
  32. /**
  33. * Process a MOTD Related Line.
  34. */
  35. public class ProcessMOTD extends IRCProcessor {
  36. /**
  37. * Create a new instance of the IRCProcessor Object.
  38. *
  39. * @param parser IRCParser That owns this IRCProcessor
  40. * @param manager ProcessingManager that is in charge of this IRCProcessor
  41. */
  42. public ProcessMOTD(final IRCParser parser, final ProcessingManager manager) {
  43. super(parser, manager, "372", "375", "376", "422");
  44. }
  45. /**
  46. * Process a MOTD Related Line.
  47. *
  48. * @param sParam Type of line to process ("375", "372", "376", "422")
  49. * @param token IRCTokenised line to process
  50. */
  51. @Override
  52. public void process(final String sParam, final String... token) {
  53. switch (sParam) {
  54. case "375":
  55. callMOTDStart(token[token.length - 1]);
  56. break;
  57. case "372":
  58. callMOTDLine(token[token.length - 1]);
  59. break;
  60. default:
  61. callMOTDEnd("422".equals(sParam), token[token.length - 1]);
  62. break;
  63. }
  64. }
  65. /**
  66. * Callback to all objects implementing the MOTDEnd Callback.
  67. *
  68. * @param noMOTD Was this an MOTDEnd or NoMOTD
  69. * @param data The contents of the line (incase of language changes or so)
  70. * @see MotdEndListener
  71. */
  72. protected void callMOTDEnd(final boolean noMOTD, final String data) {
  73. getCallbackManager().publish(new MOTDEndEvent(parser, new Date(), noMOTD, data));
  74. }
  75. /**
  76. * Callback to all objects implementing the MOTDLine Callback.
  77. *
  78. * @see MotdLineListener
  79. * @param data Incomming Line.
  80. */
  81. protected void callMOTDLine(final String data) {
  82. getCallbackManager().publish(new MOTDLineEvent(parser, new Date(), data));
  83. }
  84. /**
  85. * Callback to all objects implementing the MOTDStart Callback.
  86. *
  87. * @see MotdStartListener
  88. * @param data Incomming Line.
  89. */
  90. protected void callMOTDStart(final String data) {
  91. getCallbackManager().publish(new MOTDStartEvent(parser, new Date(), data));
  92. }
  93. }