AdminTvTEvent.java 3.1 KB

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