Condition.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.model.conditions;
  16. import com.l2jserver.gameserver.model.stats.Env;
  17. /**
  18. * The Class Condition.
  19. * @author mkizub
  20. */
  21. public abstract class Condition implements ConditionListener
  22. {
  23. private ConditionListener _listener;
  24. private String _msg;
  25. private int _msgId;
  26. private boolean _addName = false;
  27. private boolean _result;
  28. /**
  29. * Sets the message.
  30. * @param msg the new message
  31. */
  32. public final void setMessage(String msg)
  33. {
  34. _msg = msg;
  35. }
  36. /**
  37. * Gets the message.
  38. * @return the message
  39. */
  40. public final String getMessage()
  41. {
  42. return _msg;
  43. }
  44. /**
  45. * Sets the message id.
  46. * @param msgId the new message id
  47. */
  48. public final void setMessageId(int msgId)
  49. {
  50. _msgId = msgId;
  51. }
  52. /**
  53. * Gets the message id.
  54. * @return the message id
  55. */
  56. public final int getMessageId()
  57. {
  58. return _msgId;
  59. }
  60. /**
  61. * Adds the name.
  62. */
  63. public final void addName()
  64. {
  65. _addName = true;
  66. }
  67. /**
  68. * Checks if is adds the name.
  69. * @return true, if is adds the name
  70. */
  71. public final boolean isAddName()
  72. {
  73. return _addName;
  74. }
  75. /**
  76. * Sets the listener.
  77. * @param listener the new listener
  78. */
  79. void setListener(ConditionListener listener)
  80. {
  81. _listener = listener;
  82. notifyChanged();
  83. }
  84. /**
  85. * Gets the listener.
  86. * @return the listener
  87. */
  88. final ConditionListener getListener()
  89. {
  90. return _listener;
  91. }
  92. /**
  93. * Test.
  94. * @param env the env
  95. * @return true, if successful
  96. */
  97. public final boolean test(Env env)
  98. {
  99. boolean res = testImpl(env);
  100. if ((_listener != null) && (res != _result))
  101. {
  102. _result = res;
  103. notifyChanged();
  104. }
  105. return res;
  106. }
  107. /**
  108. * Test impl.
  109. * @param env the env
  110. * @return true, if successful
  111. */
  112. public abstract boolean testImpl(Env env);
  113. @Override
  114. public void notifyChanged()
  115. {
  116. if (_listener != null)
  117. {
  118. _listener.notifyChanged();
  119. }
  120. }
  121. }