AdminTvTEvent.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2004-2015 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.admincommandhandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.TvTEvent;
  25. import com.l2jserver.gameserver.model.entity.TvTEventTeleporter;
  26. import com.l2jserver.gameserver.model.entity.TvTManager;
  27. /**
  28. * @author HorridoJoho
  29. */
  30. public class AdminTvTEvent implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_tvt_add",
  35. "admin_tvt_remove",
  36. "admin_tvt_advance"
  37. };
  38. @Override
  39. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. if (command.equals("admin_tvt_add"))
  42. {
  43. L2Object target = activeChar.getTarget();
  44. if (!(target instanceof L2PcInstance))
  45. {
  46. activeChar.sendMessage("You should select a player!");
  47. return true;
  48. }
  49. add(activeChar, (L2PcInstance) target);
  50. }
  51. else if (command.equals("admin_tvt_remove"))
  52. {
  53. L2Object target = activeChar.getTarget();
  54. if (!(target instanceof L2PcInstance))
  55. {
  56. activeChar.sendMessage("You should select a player!");
  57. return true;
  58. }
  59. remove(activeChar, (L2PcInstance) target);
  60. }
  61. else if (command.equals("admin_tvt_advance"))
  62. {
  63. TvTManager.getInstance().skipDelay();
  64. }
  65. return true;
  66. }
  67. @Override
  68. public String[] getAdminCommandList()
  69. {
  70. return ADMIN_COMMANDS;
  71. }
  72. private void add(L2PcInstance activeChar, L2PcInstance playerInstance)
  73. {
  74. if (playerInstance.isOnEvent())
  75. {
  76. activeChar.sendMessage("Player already participated in the event!");
  77. return;
  78. }
  79. if (!TvTEvent.addParticipant(playerInstance))
  80. {
  81. activeChar.sendMessage("Player instance could not be added, it seems to be null!");
  82. return;
  83. }
  84. if (TvTEvent.isStarted())
  85. {
  86. new TvTEventTeleporter(playerInstance, TvTEvent.getParticipantTeamCoordinates(playerInstance.getObjectId()), true, false);
  87. }
  88. }
  89. private void remove(L2PcInstance activeChar, L2PcInstance playerInstance)
  90. {
  91. if (!TvTEvent.removeParticipant(playerInstance.getObjectId()))
  92. {
  93. activeChar.sendMessage("Player is not part of the event!");
  94. return;
  95. }
  96. new TvTEventTeleporter(playerInstance, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES, true, true);
  97. }
  98. }