OlympiadObservation.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2004-2015 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.olympiad.Olympiad;
  27. import com.l2jserver.gameserver.model.olympiad.OlympiadGameManager;
  28. import com.l2jserver.gameserver.model.olympiad.OlympiadGameTask;
  29. import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMatchList;
  32. /**
  33. * @author DS
  34. */
  35. public class OlympiadObservation implements IBypassHandler
  36. {
  37. private static final String[] COMMANDS =
  38. {
  39. "watchmatch",
  40. "arenachange"
  41. };
  42. @Override
  43. public final boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  44. {
  45. try
  46. {
  47. final L2Npc olymanager = activeChar.getLastFolkNPC();
  48. if (command.startsWith(COMMANDS[0])) // list
  49. {
  50. if (!Olympiad.getInstance().inCompPeriod())
  51. {
  52. activeChar.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  53. return false;
  54. }
  55. activeChar.sendPacket(new ExOlympiadMatchList());
  56. }
  57. else
  58. {
  59. if ((olymanager == null) || !(olymanager instanceof L2OlympiadManagerInstance))
  60. {
  61. return false;
  62. }
  63. if (!activeChar.inObserverMode() && !activeChar.isInsideRadius(olymanager, 300, false, false))
  64. {
  65. return false;
  66. }
  67. if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
  68. {
  69. activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
  70. return false;
  71. }
  72. if (!Olympiad.getInstance().inCompPeriod())
  73. {
  74. activeChar.sendPacket(SystemMessageId.THE_OLYMPIAD_GAME_IS_NOT_CURRENTLY_IN_PROGRESS);
  75. return false;
  76. }
  77. if (activeChar.isOnEvent())
  78. {
  79. activeChar.sendMessage("You can not observe games while registered on an event");
  80. return false;
  81. }
  82. final int arenaId = Integer.parseInt(command.substring(12).trim());
  83. final OlympiadGameTask nextArena = OlympiadGameManager.getInstance().getOlympiadTask(arenaId);
  84. if (nextArena != null)
  85. {
  86. activeChar.enterOlympiadObserverMode(nextArena.getZone().getSpectatorSpawns().get(0), arenaId);
  87. activeChar.setInstanceId(OlympiadGameManager.getInstance().getOlympiadTask(arenaId).getZone().getInstanceId());
  88. }
  89. }
  90. return true;
  91. }
  92. catch (Exception e)
  93. {
  94. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  95. }
  96. return false;
  97. }
  98. @Override
  99. public final String[] getBypassList()
  100. {
  101. return COMMANDS;
  102. }
  103. }