AdminTvTEvent.java 2.9 KB

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