OlympiadObservation.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.bypasshandlers;
  16. import java.util.logging.Level;
  17. import com.l2jserver.gameserver.handler.IBypassHandler;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2OlympiadManagerInstance;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.entity.TvTEvent;
  23. import com.l2jserver.gameserver.model.olympiad.OlympiadGameManager;
  24. import com.l2jserver.gameserver.model.olympiad.OlympiadGameTask;
  25. import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMatchList;
  28. /**
  29. * @author DS
  30. */
  31. public class OlympiadObservation implements IBypassHandler
  32. {
  33. private static final String[] COMMANDS =
  34. {
  35. "watchmatch",
  36. "arenachange"
  37. };
  38. @Override
  39. public final boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  40. {
  41. try
  42. {
  43. final L2Npc olymanager = activeChar.getLastFolkNPC();
  44. if (command.startsWith(COMMANDS[0])) // list
  45. {
  46. activeChar.sendPacket(new ExOlympiadMatchList());
  47. }
  48. else
  49. {
  50. if (olymanager == null || !(olymanager instanceof L2OlympiadManagerInstance))
  51. return false;
  52. if (!activeChar.inObserverMode() && !activeChar.isInsideRadius(olymanager, 300, false, false))
  53. return false;
  54. if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
  55. {
  56. activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
  57. return false;
  58. }
  59. if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  60. {
  61. activeChar.sendMessage("You can not observe games while registered for TvT");
  62. return false;
  63. }
  64. final int arenaId = Integer.parseInt(command.substring(12).trim());
  65. final OlympiadGameTask nextArena = OlympiadGameManager.getInstance().getOlympiadTask(arenaId);
  66. if (nextArena != null)
  67. {
  68. activeChar.enterOlympiadObserverMode(nextArena.getZone().getSpawns().get(0), arenaId);
  69. activeChar.setInstanceId(OlympiadGameManager.getInstance().getOlympiadTask(arenaId).getZone().getInstanceId());
  70. }
  71. }
  72. return true;
  73. }
  74. catch (Exception e)
  75. {
  76. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  77. }
  78. return false;
  79. }
  80. @Override
  81. public final String[] getBypassList()
  82. {
  83. return COMMANDS;
  84. }
  85. }