StringTokenizer st = new StringTokenizer(command, " ");
command = st.nextToken(); // Get actual command
// Get castle
Castle castle = null;
ClanHall clanhall = null;
if(command.startsWith("admin_clanhall"))
{
clanhall = ClanHallManager.getInstance().getClanHallById(Integer.parseInt(st.nextToken()));
}
else if(st.hasMoreTokens())
{
castle = CastleManager.getInstance().getCastle(st.nextToken());
}
// Get castle
String val = "";
if(st.hasMoreTokens())
{
val = st.nextToken();
}
if((castle == null || castle.getCastleId() < 0) && clanhall == null)
{
// No castle specified
showCastleSelectPage(activeChar);
}
else
{
L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if(target instanceof L2PcInstance)
{
player = (L2PcInstance) target;
}
if(command.equalsIgnoreCase("admin_add_attacker"))
{
if(player == null)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
}
else if(SiegeManager.getInstance().checkIsRegistered(player.getClan(), castle.getCastleId()))
{
activeChar.sendMessage("Clan is already registered!");
}
else
{
castle.getSiege().registerAttacker(player, true);
}
}
else if(command.equalsIgnoreCase("admin_add_defender"))
{
if(player == null)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
}
else
{
castle.getSiege().registerDefender(player, true);
}
}
else if(command.equalsIgnoreCase("admin_add_guard"))
{
try
{
int npcId = Integer.parseInt(val);
castle.getSiege().getSiegeGuardManager().addSiegeGuard(activeChar, npcId);
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
activeChar.sendMessage("Usage: //add_guard npcId");
}
}
else if(command.equalsIgnoreCase("admin_clear_siege_list"))
{
castle.getSiege().clearSiegeClan();
}
else if(command.equalsIgnoreCase("admin_endsiege"))
{
castle.getSiege().endSiege();
}
else if(command.equalsIgnoreCase("admin_list_siege_clans"))
{
castle.getSiege().listRegisterClan(activeChar);
return true;
}
else if(command.equalsIgnoreCase("admin_move_defenders"))
{
activeChar.sendPacket(SystemMessage.sendString("Not implemented yet."));
}
else if(command.equalsIgnoreCase("admin_setcastle"))
{
if(player == null || player.getClan() == null)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
}
else
{
castle.setOwner(player.getClan());
}
}
else if(command.equalsIgnoreCase("admin_removecastle"))
{
L2Clan clan = ClanTable.getInstance().getClan(castle.getOwnerId());
if(clan != null)
{
castle.removeOwner(clan);
}
else
{
activeChar.sendMessage("Unable to remove castle");
}
clan = null;
}
else if(command.equalsIgnoreCase("admin_clanhallset"))
{
if(player == null || player.getClan() == null)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
}
else if(!ClanHallManager.getInstance().isFree(clanhall.getId()))
{
activeChar.sendMessage("This ClanHall isn't free!");
}
else if(player.getClan().getHasHideout() == 0)
{
ClanHallManager.getInstance().setOwner(clanhall.getId(), player.getClan());
if(AuctionManager.getInstance().getAuction(clanhall.getId()) != null)
{
AuctionManager.getInstance().getAuction(clanhall.getId()).deleteAuctionFromDB();
}
}
else
{
activeChar.sendMessage("You have already a ClanHall!");
}
}
else if(command.equalsIgnoreCase("admin_clanhalldel"))
{
if(!ClanHallManager.getInstance().isFree(clanhall.getId()))
{
ClanHallManager.getInstance().setFree(clanhall.getId());
AuctionManager.getInstance().initNPC(clanhall.getId());
}
else
{
activeChar.sendMessage("This ClanHall is already Free!");
}
}
else if(command.equalsIgnoreCase("admin_clanhallopendoors"))
{
clanhall.openCloseDoors(true);
}
else if(command.equalsIgnoreCase("admin_clanhallclosedoors"))
{
clanhall.openCloseDoors(false);
}
else if(command.equalsIgnoreCase("admin_clanhallteleportself"))
{
L2ClanHallZone zone = clanhall.getZone();
if(zone != null)
{
activeChar.teleToLocation(zone.getSpawn(), true);
}