BlockAction.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2004-2014 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 java.util.List;
  22. import com.l2jserver.gameserver.datatables.BotReportTable;
  23. import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  24. import com.l2jserver.gameserver.model.StatsSet;
  25. import com.l2jserver.gameserver.model.conditions.Condition;
  26. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  27. import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  28. import com.l2jserver.gameserver.model.punishment.PunishmentTask;
  29. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  30. import com.l2jserver.gameserver.model.skills.BuffInfo;
  31. /**
  32. * Block Action effect implementation.
  33. * @author BiggBoss
  34. */
  35. public final class BlockAction extends AbstractEffect
  36. {
  37. private final List<Integer> _blockedActions;
  38. public BlockAction(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  39. {
  40. super(attachCond, applyCond, set, params);
  41. String[] rawActions = getParameters().getString("blockedActions").split(",");
  42. _blockedActions = new ArrayList<>(rawActions.length);
  43. for (String act : rawActions)
  44. {
  45. int id = -1;
  46. try
  47. {
  48. id = Integer.parseInt(act);
  49. _blockedActions.add(id);
  50. }
  51. catch (Exception e)
  52. {
  53. }
  54. }
  55. }
  56. @Override
  57. public boolean canStart(BuffInfo info)
  58. {
  59. return (info.getEffected() != null) && info.getEffected().isPlayer();
  60. }
  61. @Override
  62. public boolean checkCondition(Object id)
  63. {
  64. return !_blockedActions.contains(id);
  65. }
  66. @Override
  67. public void onExit(BuffInfo info)
  68. {
  69. if (_blockedActions.contains(BotReportTable.PARTY_ACTION_BLOCK_ID))
  70. {
  71. PunishmentManager.getInstance().stopPunishment(info.getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.PARTY_BAN);
  72. }
  73. if (_blockedActions.contains(BotReportTable.CHAT_BLOCK_ID))
  74. {
  75. PunishmentManager.getInstance().stopPunishment(info.getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN);
  76. }
  77. }
  78. @Override
  79. public void onStart(BuffInfo info)
  80. {
  81. if (_blockedActions.contains(BotReportTable.PARTY_ACTION_BLOCK_ID))
  82. {
  83. PunishmentManager.getInstance().startPunishment(new PunishmentTask(0, info.getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.PARTY_BAN, 0, "block action debuff", "system", true));
  84. }
  85. if (_blockedActions.contains(BotReportTable.CHAT_BLOCK_ID))
  86. {
  87. PunishmentManager.getInstance().startPunishment(new PunishmentTask(0, info.getEffected().getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.CHAT_BAN, 0, "block action debuff", "system", true));
  88. }
  89. }
  90. }