From fb085c86234c6ec0eef45e54d06ec7bc19199f53 Mon Sep 17 00:00:00 2001
From: Rumen Nikiforov <unafraid89@gmail.com>
Date: Wed, 8 Feb 2012 21:59:09 +0000
Subject: [PATCH] BETA: AdminSiege handler typo fix and source format

---
 .../admincommandhandlers/AdminSiege.java      | 106 +++++++++---------
 1 file changed, 52 insertions(+), 54 deletions(-)

diff --git a/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminSiege.java b/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminSiege.java
index 180aa423f0..1ab6fdd82b 100644
--- a/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminSiege.java
+++ b/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminSiege.java
@@ -35,12 +35,8 @@ import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
 import com.l2jserver.util.StringUtil;
 
-
 /**
- * This class handles all siege commands:
- * Todo: change the class name, and neaten it up
- *
- *
+ * This class handles all siege commands: Todo: change the class name, and neaten it up
  */
 public class AdminSiege implements IAdminCommandHandler
 {
@@ -76,20 +72,27 @@ public class AdminSiege implements IAdminCommandHandler
 		// Get castle
 		Castle castle = null;
 		ClanHall clanhall = null;
-		if (st.hasMoreTokens()) {
-			if (command.startsWith("admin_clanhall")) {
+		if (st.hasMoreTokens())
+		{
+			if (command.startsWith("admin_clanhall"))
+			{
 				try
 				{
 					clanhall = ClanHallManager.getInstance().getClanHallById(Integer.parseInt(st.nextToken()));
 				}
-				catch (Exception e) {}
+				catch (Exception e)
+				{
+					// Who cares?
+				}
 			}
 			else
 				castle = CastleManager.getInstance().getCastle(st.nextToken());
 		}
 		if ((castle == null || castle.getCastleId() < 0) && clanhall == null)
+		{
 			// No castle specified
 			showCastleSelectPage(activeChar);
+		}
 		else
 		{
 			String val = "";
@@ -98,8 +101,8 @@ public class AdminSiege implements IAdminCommandHandler
 			
 			L2Object target = activeChar.getTarget();
 			L2PcInstance player = null;
-			if (target instanceof L2PcInstance)
-				player = (L2PcInstance) target;
+			if (target.isPlayer())
+				player = target.getActingPlayer();
 			
 			if (command.equalsIgnoreCase("admin_add_attacker"))
 			{
@@ -163,7 +166,9 @@ public class AdminSiege implements IAdminCommandHandler
 			{
 				if (st.hasMoreTokens())
 				{
-					Calendar newAdminSiegeDate = castle.getSiegeDate();
+					Calendar newAdminSiegeDate = Calendar.getInstance();
+					newAdminSiegeDate.setTimeInMillis(castle.getSiegeDate().getTimeInMillis());
+					
 					if (val.equalsIgnoreCase("day"))
 						newAdminSiegeDate.set(Calendar.DAY_OF_YEAR, Integer.parseInt(st.nextToken()));
 					else if (val.equalsIgnoreCase("hour"))
@@ -179,9 +184,10 @@ public class AdminSiege implements IAdminCommandHandler
 					{
 						castle.getSiegeDate().setTimeInMillis(newAdminSiegeDate.getTimeInMillis());
 						castle.getSiege().saveSiegeDate();
+						activeChar.sendMessage("Castle siege time for castle " + castle.getName() + " has been changed.");
 					}
 				}
-				showSiegeTimePage(activeChar,castle);
+				showSiegeTimePage(activeChar, castle);
 				return true;
 			}
 			else if (command.equalsIgnoreCase("admin_clanhallset"))
@@ -192,13 +198,13 @@ public class AdminSiege implements IAdminCommandHandler
 					activeChar.sendMessage("This ClanHall isn't free!");
 				else if (player.getClan().getHasHideout() == 0)
 				{
-					if(!clanhall.isSiegableHall())
+					if (!clanhall.isSiegableHall())
 					{
 						ClanHallManager.getInstance().setOwner(clanhall.getId(), player.getClan());
 						if (AuctionManager.getInstance().getAuction(clanhall.getId()) != null)
 							AuctionManager.getInstance().getAuction(clanhall.getId()).deleteAuctionFromDB();
 					}
-					else if(player.getClan() != null)
+					else if (player.getClan() != null)
 					{
 						clanhall.setOwner(player.getClan());
 						player.getClan().setHasHideout(clanhall.getId());
@@ -210,7 +216,7 @@ public class AdminSiege implements IAdminCommandHandler
 			else if (command.equalsIgnoreCase("admin_clanhalldel"))
 			{
 				int oldOwner = 0;
-				if(!clanhall.isSiegableHall())
+				if (!clanhall.isSiegableHall())
 				{
 					if (!ClanHallManager.getInstance().isFree(clanhall.getId()))
 					{
@@ -220,11 +226,11 @@ public class AdminSiege implements IAdminCommandHandler
 					else
 						activeChar.sendMessage("This ClanHall is already Free!");
 				}
-				else if((oldOwner = clanhall.getOwnerId()) > 0)
+				else if ((oldOwner = clanhall.getOwnerId()) > 0)
 				{
 					clanhall.free();
 					L2Clan clan = ClanTable.getInstance().getClan(oldOwner);
-					if(clan != null)
+					if (clan != null)
 					{
 						clan.setHasHideout(0);
 						clan.broadcastClanStatus();
@@ -255,10 +261,10 @@ public class AdminSiege implements IAdminCommandHandler
 			}
 			if (clanhall != null)
 			{
-				if(!clanhall.isSiegableHall())
+				if (!clanhall.isSiegableHall())
 					showClanHallPage(activeChar, clanhall);
 				else
-					showSiegableHallPage(activeChar, (SiegableHall)clanhall);
+					showSiegableHallPage(activeChar, (SiegableHall) clanhall);
 			}
 			else
 				showSiegePage(activeChar, castle.getName());
@@ -272,18 +278,16 @@ public class AdminSiege implements IAdminCommandHandler
 		NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
 		adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/castles.htm");
 		final StringBuilder cList = new StringBuilder(500);
-		for (Castle castle : CastleManager.getInstance().getCastles()) {
-			if (castle != null) {
+		for (Castle castle : CastleManager.getInstance().getCastles())
+		{
+			if (castle != null)
+			{
 				String name = castle.getName();
-				StringUtil.append(cList,
-						"<td fixwidth=90><a action=\"bypass -h admin_siege ",
-						name,
-						"\">",
-						name,
-				"</a></td>");
+				StringUtil.append(cList, "<td fixwidth=90><a action=\"bypass -h admin_siege ", name, "\">", name, "</a></td>");
 				i++;
 			}
-			if (i > 2) {
+			if (i > 2)
+			{
 				cList.append("</tr><tr>");
 				i = 0;
 			}
@@ -291,16 +295,14 @@ public class AdminSiege implements IAdminCommandHandler
 		adminReply.replace("%castles%", cList.toString());
 		cList.setLength(0);
 		i = 0;
-		for(SiegableHall hall : CHSiegeManager.getInstance().getConquerableHalls().values())
+		for (SiegableHall hall : CHSiegeManager.getInstance().getConquerableHalls().values())
 		{
-			if(hall != null)
+			if (hall != null)
 			{
-				StringUtil.append(cList, "<td fixwidth=90><a action=\"bypass -h admin_chsiege_siegablehall ",
-						String.valueOf(hall.getId()),
-						"\">", hall.getName(), "</a></td>");
+				StringUtil.append(cList, "<td fixwidth=90><a action=\"bypass -h admin_chsiege_siegablehall ", String.valueOf(hall.getId()), "\">", hall.getName(), "</a></td>");
 				i++;
 			}
-			if(i > 1)
+			if (i > 1)
 			{
 				cList.append("</tr><tr>");
 				i = 0;
@@ -309,17 +311,15 @@ public class AdminSiege implements IAdminCommandHandler
 		adminReply.replace("%siegableHalls%", cList.toString());
 		cList.setLength(0);
 		i = 0;
-		for (ClanHall clanhall : ClanHallManager.getInstance().getClanHalls().values()) {
-			if (clanhall != null) {
-				StringUtil.append(cList,
-						"<td fixwidth=134><a action=\"bypass -h admin_clanhall ",
-						String.valueOf(clanhall.getId()),
-						"\">",
-						clanhall.getName(),
-				"</a></td>");
+		for (ClanHall clanhall : ClanHallManager.getInstance().getClanHalls().values())
+		{
+			if (clanhall != null)
+			{
+				StringUtil.append(cList, "<td fixwidth=134><a action=\"bypass -h admin_clanhall ", String.valueOf(clanhall.getId()), "\">", clanhall.getName(), "</a></td>");
 				i++;
 			}
-			if (i > 1) {
+			if (i > 1)
+			{
 				cList.append("</tr><tr>");
 				i = 0;
 			}
@@ -327,17 +327,15 @@ public class AdminSiege implements IAdminCommandHandler
 		adminReply.replace("%clanhalls%", cList.toString());
 		cList.setLength(0);
 		i = 0;
-		for (ClanHall clanhall : ClanHallManager.getInstance().getFreeClanHalls().values()) {
-			if (clanhall != null) {
-				StringUtil.append(cList,
-						"<td fixwidth=134><a action=\"bypass -h admin_clanhall ",
-						String.valueOf(clanhall.getId()),
-						"\">",
-						clanhall.getName(),
-				"</a></td>");
+		for (ClanHall clanhall : ClanHallManager.getInstance().getFreeClanHalls().values())
+		{
+			if (clanhall != null)
+			{
+				StringUtil.append(cList, "<td fixwidth=134><a action=\"bypass -h admin_clanhall ", String.valueOf(clanhall.getId()), "\">", clanhall.getName(), "</a></td>");
 				i++;
 			}
-			if (i > 1) {
+			if (i > 1)
+			{
 				cList.append("</tr><tr>");
 				i = 0;
 			}
@@ -408,10 +406,10 @@ public class AdminSiege implements IAdminCommandHandler
 		msg.setFile(null, "data/html/admin/siegablehall.htm");
 		msg.replace("%clanhallId%", String.valueOf(hall.getId()));
 		msg.replace("%clanhallName%", hall.getName());
-		if(hall.getOwnerId() > 0)
+		if (hall.getOwnerId() > 0)
 		{
 			L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
-			if(owner != null)
+			if (owner != null)
 				msg.replace("%clanhallOwner%", owner.getName());
 			else
 				msg.replace("%clanhallOwner%", "No Owner");
-- 
GitLab