123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.admincommandhandlers;
- import java.util.Calendar;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.data.sql.impl.ClanTable;
- import com.l2jserver.gameserver.handler.IAdminCommandHandler;
- import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
- import com.l2jserver.gameserver.model.L2Clan;
- import com.l2jserver.gameserver.model.L2Object;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
- import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
- import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- import com.l2jserver.gameserver.network.serverpackets.SiegeInfo;
- /**
- * @author BiggBoss
- */
- public final class AdminCHSiege implements IAdminCommandHandler
- {
- private static final String[] COMMANDS =
- {
- "admin_chsiege_siegablehall",
- "admin_chsiege_startSiege",
- "admin_chsiege_endsSiege",
- "admin_chsiege_setSiegeDate",
- "admin_chsiege_addAttacker",
- "admin_chsiege_removeAttacker",
- "admin_chsiege_clearAttackers",
- "admin_chsiege_listAttackers",
- "admin_chsiege_forwardSiege"
- };
-
- @Override
- public String[] getAdminCommandList()
- {
- return COMMANDS;
- }
-
- @Override
- public boolean useAdminCommand(String command, L2PcInstance activeChar)
- {
- final String[] split = command.split(" ");
- SiegableHall hall = null;
- if (Config.ALT_DEV_NO_QUESTS)
- {
- activeChar.sendMessage("AltDevNoQuests = true; Clan Hall Sieges are disabled!");
- return false;
- }
- if (split.length < 2)
- {
- activeChar.sendMessage("You have to specify the hall id at least");
- return false;
- }
- if ((hall = getHall(split[1], activeChar)) == null)
- {
- activeChar.sendMessage("Couldnt find he desired siegable hall (" + split[1] + ")");
- return false;
- }
- if (hall.getSiege() == null)
- {
- activeChar.sendMessage("The given hall dont have any attached siege!");
- return false;
- }
-
- if (split[0].equals(COMMANDS[1]))
- {
- if (hall.isInSiege())
- {
- activeChar.sendMessage("The requested clan hall is alredy in siege!");
- }
- else
- {
- L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
- if (owner != null)
- {
- hall.free();
- owner.setHideoutId(0);
- hall.addAttacker(owner);
- }
- hall.getSiege().startSiege();
- }
- }
- else if (split[0].equals(COMMANDS[2]))
- {
- if (!hall.isInSiege())
- {
- activeChar.sendMessage("The requested clan hall isnt in siege!");
- }
- else
- {
- hall.getSiege().endSiege();
- }
- }
- else if (split[0].equals(COMMANDS[3]))
- {
- if (!hall.isRegistering())
- {
- activeChar.sendMessage("Cannot change siege date while hall is in siege");
- }
- else if (split.length < 3)
- {
- activeChar.sendMessage("The date format is incorrect. Try again.");
- }
- else
- {
- String[] rawDate = split[2].split(";");
- if (rawDate.length < 2)
- {
- activeChar.sendMessage("You have to specify this format DD-MM-YYYY;HH:MM");
- }
- else
- {
- String[] day = rawDate[0].split("-");
- String[] hour = rawDate[1].split(":");
- if ((day.length < 3) || (hour.length < 2))
- {
- activeChar.sendMessage("Incomplete day, hour or both!");
- }
- else
- {
- int d = parseInt(day[0]);
- int month = parseInt(day[1]) - 1;
- int year = parseInt(day[2]);
- int h = parseInt(hour[0]);
- int min = parseInt(hour[1]);
- if (((month == 2) && (d > 28)) || (d > 31) || (d <= 0) || (month <= 0) || (month > 12) || (year < Calendar.getInstance().get(Calendar.YEAR)))
- {
- activeChar.sendMessage("Wrong day/month/year gave!");
- }
- else if ((h <= 0) || (h > 24) || (min < 0) || (min >= 60))
- {
- activeChar.sendMessage("Wrong hour/minutes gave!");
- }
- else
- {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.YEAR, year);
- c.set(Calendar.MONTH, month);
- c.set(Calendar.DAY_OF_MONTH, d);
- c.set(Calendar.HOUR_OF_DAY, h);
- c.set(Calendar.MINUTE, min);
- c.set(Calendar.SECOND, 0);
-
- if (c.getTimeInMillis() > System.currentTimeMillis())
- {
- activeChar.sendMessage(hall.getName() + " siege: " + c.getTime().toString());
- hall.setNextSiegeDate(c.getTimeInMillis());
- hall.getSiege().updateSiege();
- hall.updateDb();
- }
- else
- {
- activeChar.sendMessage("The given time is in the past!");
- }
- }
- }
-
- }
- }
- }
- else if (split[0].equals(COMMANDS[4]))
- {
- if (hall.isInSiege())
- {
- activeChar.sendMessage("The clan hall is in siege, cannot add attackers now.");
- return false;
- }
-
- L2Clan attacker = null;
- if (split.length < 3)
- {
- L2Object rawTarget = activeChar.getTarget();
- L2PcInstance target = null;
- if (rawTarget == null)
- {
- activeChar.sendMessage("You must target a clan member of the attacker!");
- }
- else if (!(rawTarget instanceof L2PcInstance))
- {
- activeChar.sendMessage("You must target a player with clan!");
- }
- else if ((target = (L2PcInstance) rawTarget).getClan() == null)
- {
- activeChar.sendMessage("Your target does not have any clan!");
- }
- else if (hall.getSiege().checkIsAttacker(target.getClan()))
- {
- activeChar.sendMessage("Your target's clan is alredy participating!");
- }
- else
- {
- attacker = target.getClan();
- }
- }
- else
- {
- L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
- if (rawClan == null)
- {
- activeChar.sendMessage("The given clan does not exist!");
- }
- else if (hall.getSiege().checkIsAttacker(rawClan))
- {
- activeChar.sendMessage("The given clan is alredy participating!");
- }
- else
- {
- attacker = rawClan;
- }
- }
-
- if (attacker != null)
- {
- hall.addAttacker(attacker);
- }
- }
- else if (split[0].equals(COMMANDS[5]))
- {
- if (hall.isInSiege())
- {
- activeChar.sendMessage("The clan hall is in siege, cannot remove attackers now.");
- return false;
- }
-
- if (split.length < 3)
- {
- L2Object rawTarget = activeChar.getTarget();
- L2PcInstance target = null;
- if (rawTarget == null)
- {
- activeChar.sendMessage("You must target a clan member of the attacker!");
- }
- else if (!(rawTarget instanceof L2PcInstance))
- {
- activeChar.sendMessage("You must target a player with clan!");
- }
- else if ((target = (L2PcInstance) rawTarget).getClan() == null)
- {
- activeChar.sendMessage("Your target does not have any clan!");
- }
- else if (!hall.getSiege().checkIsAttacker(target.getClan()))
- {
- activeChar.sendMessage("Your target's clan is not participating!");
- }
- else
- {
- hall.removeAttacker(target.getClan());
- }
- }
- else
- {
- L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
- if (rawClan == null)
- {
- activeChar.sendMessage("The given clan does not exist!");
- }
- else if (!hall.getSiege().checkIsAttacker(rawClan))
- {
- activeChar.sendMessage("The given clan is not participating!");
- }
- else
- {
- hall.removeAttacker(rawClan);
- }
- }
- }
- else if (split[0].equals(COMMANDS[6]))
- {
- if (hall.isInSiege())
- {
- activeChar.sendMessage("The requested hall is in siege right now, cannot clear attacker list!");
- }
- else
- {
- hall.getSiege().getAttackers().clear();
- }
- }
- else if (split[0].equals(COMMANDS[7]))
- {
- activeChar.sendPacket(new SiegeInfo(hall));
- }
- else if (split[0].equals(COMMANDS[8]))
- {
- ClanHallSiegeEngine siegable = hall.getSiege();
- siegable.cancelSiegeTask();
- switch (hall.getSiegeStatus())
- {
- case REGISTERING:
- siegable.prepareOwner();
- break;
- case WAITING_BATTLE:
- siegable.startSiege();
- break;
- case RUNNING:
- siegable.endSiege();
- break;
- }
- }
-
- sendSiegableHallPage(activeChar, split[1], hall);
- return false;
- }
-
- private SiegableHall getHall(String id, L2PcInstance gm)
- {
- int ch = parseInt(id);
- if (ch == 0)
- {
- gm.sendMessage("Wrong clan hall id, unparseable id!");
- return null;
- }
-
- SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(ch);
-
- if (hall == null)
- {
- gm.sendMessage("Couldnt find the clan hall.");
- }
-
- return hall;
- }
-
- private int parseInt(String st)
- {
- int val = 0;
- try
- {
- val = Integer.parseInt(st);
- }
- catch (NumberFormatException e)
- {
- e.printStackTrace();
- }
- return val;
- }
-
- private void sendSiegableHallPage(L2PcInstance activeChar, String hallId, SiegableHall hall)
- {
- final NpcHtmlMessage msg = new NpcHtmlMessage();
- msg.setFile(null, "data/html/admin/siegablehall.htm");
- msg.replace("%clanhallId%", hallId);
- msg.replace("%clanhallName%", hall.getName());
- if (hall.getOwnerId() > 0)
- {
- L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
- if (owner != null)
- {
- msg.replace("%clanhallOwner%", owner.getName());
- }
- else
- {
- msg.replace("%clanhallOwner%", "No Owner");
- }
- }
- else
- {
- msg.replace("%clanhallOwner%", "No Owner");
- }
- activeChar.sendPacket(msg);
- }
- }
|