Condition.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 java.util.logging.Logger;
  17. import com.l2jserver.gameserver.skills.Env;
  18. /**
  19. * @author mkizub
  20. *
  21. */
  22. public abstract class Condition implements ConditionListener
  23. {
  24. //private static final Logger _log = Logger.getLogger(Condition.class.getName());
  25. private ConditionListener _listener;
  26. private String _msg;
  27. private int _msgId;
  28. private boolean _addName = false;
  29. private boolean _result;
  30. public final void setMessage(String msg)
  31. {
  32. _msg = msg;
  33. }
  34. public final String getMessage()
  35. {
  36. return _msg;
  37. }
  38. public final void setMessageId(int msgId)
  39. {
  40. _msgId = msgId;
  41. }
  42. public final int getMessageId()
  43. {
  44. return _msgId;
  45. }
  46. public final void addName()
  47. {
  48. _addName = true;
  49. }
  50. public final boolean isAddName()
  51. {
  52. return _addName;
  53. }
  54. void setListener(ConditionListener listener)
  55. {
  56. _listener = listener;
  57. notifyChanged();
  58. }
  59. final ConditionListener getListener()
  60. {
  61. return _listener;
  62. }
  63. public final boolean test(Env env)
  64. {
  65. boolean res = testImpl(env);
  66. if (_listener != null && res != _result)
  67. {
  68. _result = res;
  69. notifyChanged();
  70. }
  71. return res;
  72. }
  73. abstract boolean testImpl(Env env);
  74. public void notifyChanged()
  75. {
  76. if (_listener != null)
  77. _listener.notifyChanged();
  78. }
  79. }