Condition.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * @author mkizub
  19. *
  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. public final void setMessage(String msg)
  29. {
  30. _msg = msg;
  31. }
  32. public final String getMessage()
  33. {
  34. return _msg;
  35. }
  36. public final void setMessageId(int msgId)
  37. {
  38. _msgId = msgId;
  39. }
  40. public final int getMessageId()
  41. {
  42. return _msgId;
  43. }
  44. public final void addName()
  45. {
  46. _addName = true;
  47. }
  48. public final boolean isAddName()
  49. {
  50. return _addName;
  51. }
  52. void setListener(ConditionListener listener)
  53. {
  54. _listener = listener;
  55. notifyChanged();
  56. }
  57. final ConditionListener getListener()
  58. {
  59. return _listener;
  60. }
  61. public final boolean test(Env env)
  62. {
  63. boolean res = testImpl(env);
  64. if (_listener != null && res != _result)
  65. {
  66. _result = res;
  67. notifyChanged();
  68. }
  69. return res;
  70. }
  71. abstract boolean testImpl(Env env);
  72. public void notifyChanged()
  73. {
  74. if (_listener != null)
  75. _listener.notifyChanged();
  76. }
  77. }