AdminTvTEvent.java 2.9 KB

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