AdminTvTEvent.java 3.0 KB

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