Condition.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 net.sf.l2j.gameserver.skills.conditions;
  16. //import java.util.logging.Logger;
  17. import net.sf.l2j.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 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. void setListener(ConditionListener listener)
  37. {
  38. _listener = listener;
  39. notifyChanged();
  40. }
  41. final ConditionListener getListener()
  42. {
  43. return _listener;
  44. }
  45. public final boolean test(Env env)
  46. {
  47. boolean res = testImpl(env);
  48. if (_listener != null && res != _result)
  49. {
  50. _result = res;
  51. notifyChanged();
  52. }
  53. return res;
  54. }
  55. abstract boolean testImpl(Env env);
  56. public void notifyChanged()
  57. {
  58. if (_listener != null)
  59. _listener.notifyChanged();
  60. }
  61. }