Condition.java 2.7 KB

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