BanHandler.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.punishmenthandlers;
  20. import com.l2jserver.gameserver.LoginServerThread;
  21. import com.l2jserver.gameserver.handler.IPunishmentHandler;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.punishment.PunishmentTask;
  25. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  26. import com.l2jserver.gameserver.network.L2GameClient;
  27. /**
  28. * This class handles ban punishment.
  29. * @author UnAfraid
  30. */
  31. public class BanHandler implements IPunishmentHandler
  32. {
  33. @Override
  34. public void onStart(PunishmentTask task)
  35. {
  36. switch (task.getAffect())
  37. {
  38. case CHARACTER:
  39. {
  40. int objectId = Integer.parseInt(String.valueOf(task.getKey()));
  41. final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  42. if (player != null)
  43. {
  44. applyToPlayer(player);
  45. }
  46. break;
  47. }
  48. case ACCOUNT:
  49. {
  50. String account = String.valueOf(task.getKey());
  51. final L2GameClient client = LoginServerThread.getInstance().getClient(account);
  52. if (client != null)
  53. {
  54. final L2PcInstance player = client.getActiveChar();
  55. if (player != null)
  56. {
  57. applyToPlayer(player);
  58. }
  59. else
  60. {
  61. client.closeNow();
  62. }
  63. }
  64. break;
  65. }
  66. case IP:
  67. {
  68. String ip = String.valueOf(task.getKey());
  69. for (L2PcInstance player : L2World.getInstance().getPlayers())
  70. {
  71. if (player.getIPAddress().equals(ip))
  72. {
  73. applyToPlayer(player);
  74. }
  75. }
  76. break;
  77. }
  78. }
  79. }
  80. @Override
  81. public void onEnd(PunishmentTask task)
  82. {
  83. }
  84. /**
  85. * Applies all punishment effects from the player.
  86. * @param player
  87. */
  88. private static void applyToPlayer(L2PcInstance player)
  89. {
  90. player.logout();
  91. }
  92. @Override
  93. public PunishmentType getType()
  94. {
  95. return PunishmentType.BAN;
  96. }
  97. }