OlympiadObservation.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.bypasshandlers;
  20. import java.util.logging.Level;
  21. import com.l2jserver.gameserver.handler.IBypassHandler;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2OlympiadManagerInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.TvTEvent;
  27. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  28. import com.l2jserver.gameserver.model.olympiad.OlympiadGameManager;
  29. import com.l2jserver.gameserver.model.olympiad.OlympiadGameTask;
  30. import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMatchList;
  33. /**
  34. * @author DS
  35. */
  36. public class OlympiadObservation implements IBypassHandler
  37. {
  38. private static final String[] COMMANDS =
  39. {
  40. "watchmatch",
  41. "arenachange"
  42. };
  43. @Override
  44. public final boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  45. {
  46. try
  47. {
  48. final L2Npc olymanager = activeChar.getLastFolkNPC();
  49. if (command.startsWith(COMMANDS[0])) // list
  50. {
  51. activeChar.sendPacket(new ExOlympiadMatchList());
  52. }
  53. else
  54. {
  55. if ((olymanager == null) || !(olymanager instanceof L2OlympiadManagerInstance))
  56. {
  57. return false;
  58. }
  59. if (!activeChar.inObserverMode() && !activeChar.isInsideRadius(olymanager, 300, false, false))
  60. {
  61. return false;
  62. }
  63. if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
  64. {
  65. activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
  66. return false;
  67. }
  68. if (!Olympiad.getInstance().inCompPeriod())
  69. {
  70. activeChar.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  71. return false;
  72. }
  73. if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  74. {
  75. activeChar.sendMessage("You can not observe games while registered for TvT");
  76. return false;
  77. }
  78. final int arenaId = Integer.parseInt(command.substring(12).trim());
  79. final OlympiadGameTask nextArena = OlympiadGameManager.getInstance().getOlympiadTask(arenaId);
  80. if (nextArena != null)
  81. {
  82. activeChar.enterOlympiadObserverMode(nextArena.getZone().getSpawns().get(0), arenaId);
  83. activeChar.setInstanceId(OlympiadGameManager.getInstance().getOlympiadTask(arenaId).getZone().getInstanceId());
  84. }
  85. }
  86. return true;
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  91. }
  92. return false;
  93. }
  94. @Override
  95. public final String[] getBypassList()
  96. {
  97. return COMMANDS;
  98. }
  99. }