BlockAction.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.effecthandlers;
  20. import java.util.ArrayList;
  21. import com.l2jserver.gameserver.datatables.BotReportTable;
  22. import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  23. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  24. import com.l2jserver.gameserver.model.effects.L2Effect;
  25. import com.l2jserver.gameserver.model.effects.L2EffectType;
  26. import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  27. import com.l2jserver.gameserver.model.punishment.PunishmentTask;
  28. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  29. import com.l2jserver.gameserver.model.stats.Env;
  30. /**
  31. * @author BiggBoss
  32. */
  33. public final class BlockAction extends L2Effect
  34. {
  35. private final ArrayList<Integer> _blockedActions;
  36. /**
  37. * @param env
  38. * @param template
  39. */
  40. public BlockAction(Env env, EffectTemplate template)
  41. {
  42. super(env, template);
  43. String[] rawActions = template.getParameters().getString("blockedActions").split(",");
  44. _blockedActions = new ArrayList<>(rawActions.length);
  45. for (String act : rawActions)
  46. {
  47. int id = -1;
  48. try
  49. {
  50. id = Integer.parseInt(act);
  51. _blockedActions.add(id);
  52. }
  53. catch (Exception e)
  54. {
  55. }
  56. }
  57. }
  58. @Override
  59. public boolean onStart()
  60. {
  61. if ((getEffected() == null) || !getEffected().isPlayer())
  62. {
  63. return false;
  64. }
  65. if (_blockedActions.contains(BotReportTable.PARTY_ACTION_BLOCK_ID))
  66. {
  67. PunishmentManager.getInstance().startPunishment(new PunishmentTask(0, getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.PARTY_BAN, 0, "block action debuff", "system", true));
  68. }
  69. if (_blockedActions.contains(BotReportTable.CHAT_BLOCK_ID))
  70. {
  71. PunishmentManager.getInstance().startPunishment(new PunishmentTask(0, getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN, 0, "block action debuff", "system", true));
  72. }
  73. return true;
  74. }
  75. @Override
  76. public void onExit()
  77. {
  78. if (_blockedActions.contains(BotReportTable.PARTY_ACTION_BLOCK_ID))
  79. {
  80. PunishmentManager.getInstance().stopPunishment(getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.PARTY_BAN);
  81. }
  82. if (_blockedActions.contains(BotReportTable.CHAT_BLOCK_ID))
  83. {
  84. PunishmentManager.getInstance().stopPunishment(getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN);
  85. }
  86. }
  87. @Override
  88. public boolean checkCondition(Object id)
  89. {
  90. return !_blockedActions.contains(id);
  91. }
  92. @Override
  93. public L2EffectType getEffectType()
  94. {
  95. return L2EffectType.ACTION_BLOCK;
  96. }
  97. }