Condition.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.skills.conditions;
  16. import com.l2jserver.gameserver.skills.Env;
  17. /**
  18. * The Class Condition.
  19. *
  20. * @author mkizub
  21. */
  22. public abstract class Condition implements ConditionListener
  23. {
  24. private ConditionListener _listener;
  25. private String _msg;
  26. private int _msgId;
  27. private boolean _addName = false;
  28. private boolean _result;
  29. /**
  30. * Sets the message.
  31. *
  32. * @param msg the new message
  33. */
  34. public final void setMessage(String msg)
  35. {
  36. _msg = msg;
  37. }
  38. /**
  39. * Gets the message.
  40. *
  41. * @return the message
  42. */
  43. public final String getMessage()
  44. {
  45. return _msg;
  46. }
  47. /**
  48. * Sets the message id.
  49. *
  50. * @param msgId the new message id
  51. */
  52. public final void setMessageId(int msgId)
  53. {
  54. _msgId = msgId;
  55. }
  56. /**
  57. * Gets the message id.
  58. *
  59. * @return the message id
  60. */
  61. public final int getMessageId()
  62. {
  63. return _msgId;
  64. }
  65. /**
  66. * Adds the name.
  67. */
  68. public final void addName()
  69. {
  70. _addName = true;
  71. }
  72. /**
  73. * Checks if is adds the name.
  74. *
  75. * @return true, if is adds the name
  76. */
  77. public final boolean isAddName()
  78. {
  79. return _addName;
  80. }
  81. /**
  82. * Sets the listener.
  83. *
  84. * @param listener the new listener
  85. */
  86. void setListener(ConditionListener listener)
  87. {
  88. _listener = listener;
  89. notifyChanged();
  90. }
  91. /**
  92. * Gets the listener.
  93. *
  94. * @return the listener
  95. */
  96. final ConditionListener getListener()
  97. {
  98. return _listener;
  99. }
  100. /**
  101. * Test.
  102. *
  103. * @param env the env
  104. * @return true, if successful
  105. */
  106. public final boolean test(Env env)
  107. {
  108. boolean res = testImpl(env);
  109. if (_listener != null && res != _result)
  110. {
  111. _result = res;
  112. notifyChanged();
  113. }
  114. return res;
  115. }
  116. /**
  117. * Test impl.
  118. *
  119. * @param env the env
  120. * @return true, if successful
  121. */
  122. public abstract boolean testImpl(Env env);
  123. /* (non-Javadoc)
  124. * @see com.l2jserver.gameserver.skills.conditions.ConditionListener#notifyChanged()
  125. */
  126. @Override
  127. public void notifyChanged()
  128. {
  129. if (_listener != null)
  130. _listener.notifyChanged();
  131. }
  132. }