AdminCHSiege.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. *
  3. */
  4. package handlers.admincommandhandlers;
  5. import java.util.Calendar;
  6. import com.l2jserver.Config;
  7. import com.l2jserver.gameserver.datatables.ClanTable;
  8. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  9. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  10. import com.l2jserver.gameserver.model.L2Clan;
  11. import com.l2jserver.gameserver.model.L2Object;
  12. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  13. import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
  14. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  15. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  16. import com.l2jserver.gameserver.network.serverpackets.SiegeInfo;
  17. /**
  18. * @author BiggBoss
  19. */
  20. public final class AdminCHSiege implements IAdminCommandHandler
  21. {
  22. private static final String[] COMMANDS =
  23. {
  24. "admin_chsiege_siegablehall",
  25. "admin_chsiege_startSiege",
  26. "admin_chsiege_endsSiege",
  27. "admin_chsiege_setSiegeDate",
  28. "admin_chsiege_addAttacker",
  29. "admin_chsiege_removeAttacker",
  30. "admin_chsiege_clearAttackers",
  31. "admin_chsiege_listAttackers"
  32. };
  33. @Override
  34. public String[] getAdminCommandList()
  35. {
  36. return COMMANDS;
  37. }
  38. @Override
  39. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. final String[] split = command.split(" ");
  42. SiegableHall hall = null;
  43. if(Config.ALT_DEV_NO_QUESTS)
  44. activeChar.sendMessage("AltDevNoQuests = true; Clan Hall Sieges are disabled!");
  45. else if(split.length < 2)
  46. activeChar.sendMessage("You have to specify the hall id at least");
  47. else if((hall = getHall(split[1], activeChar)) == null)
  48. activeChar.sendMessage("Couldnt find he desired siegable hall ("+split[1]+")");
  49. else if(split[0].equals(COMMANDS[1]))
  50. {
  51. if(hall.isInSiege())
  52. activeChar.sendMessage("The requested clan hall is alredy in siege!");
  53. else
  54. {
  55. L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
  56. if(owner != null)
  57. {
  58. hall.free();
  59. owner.setHasHideout(0);
  60. hall.addAttacker(owner);
  61. }
  62. hall.getSiege().startSiege();
  63. }
  64. }
  65. else if(split[0].equals(COMMANDS[2]))
  66. {
  67. if(!hall.isInSiege())
  68. activeChar.sendMessage("The requested clan hall isnt in siege!");
  69. else
  70. hall.getSiege().endSiege();
  71. }
  72. else if(split[0].equals(COMMANDS[3]))
  73. {
  74. if(!hall.isRegistering())
  75. activeChar.sendMessage("Cannot change siege date while hall is in siege");
  76. else if(split.length < 3)
  77. activeChar.sendMessage("The date format is incorrect. Try again.");
  78. else
  79. {
  80. String[] rawDate = split[2].split(";");
  81. if(rawDate.length < 2)
  82. activeChar.sendMessage("You have to specify this format DD-MM-YYYY;HH:MM");
  83. else
  84. {
  85. String[] day = rawDate[0].split("-");
  86. String[] hour = rawDate[1].split(":");
  87. if(day.length < 3 || hour.length < 2)
  88. activeChar.sendMessage("Incomplete day, hour or both!");
  89. else
  90. {
  91. int d = parseInt(day[0]);
  92. int month = parseInt(day[1]) - 1;
  93. int year = parseInt(day[2]);
  94. int h = parseInt(hour[0]);
  95. int min = parseInt(hour[1]);
  96. if((month == 2 && d > 28) || d > 31 || d <= 0
  97. || month <= 0 || month > 12
  98. || year < Calendar.getInstance().get(Calendar.YEAR))
  99. activeChar.sendMessage("Wrong day/month/year gave!");
  100. else if(h <= 0 || h > 24
  101. || min < 0 || min >= 60)
  102. activeChar.sendMessage("Wrong hour/minutes gave!");
  103. else
  104. {
  105. Calendar c = Calendar.getInstance();
  106. c.set(Calendar.YEAR, year);
  107. c.set(Calendar.MONTH, month);
  108. c.set(Calendar.DAY_OF_MONTH, d);
  109. c.set(Calendar.HOUR_OF_DAY, h);
  110. c.set(Calendar.MINUTE, min);
  111. c.set(Calendar.SECOND, 0);
  112. if(c.getTimeInMillis() > System.currentTimeMillis())
  113. {
  114. activeChar.sendMessage(hall.getName()+" siege: "+c.getTime().toString());
  115. hall.setNextSiegeDate(c.getTimeInMillis());
  116. hall.getSiege().updateSiege();
  117. hall.updateDb();
  118. }
  119. else
  120. activeChar.sendMessage("The given time is in the past!");
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else if(split[0].equals(COMMANDS[4]))
  127. {
  128. if(hall.isInSiege())
  129. {
  130. activeChar.sendMessage("The clan hall is in siege, cannot add attackers now.");
  131. return false;
  132. }
  133. L2Clan attacker = null;
  134. if(split.length < 3)
  135. {
  136. L2Object rawTarget = activeChar.getTarget();
  137. L2PcInstance target = null;
  138. if(rawTarget == null)
  139. activeChar.sendMessage("You must target a clan member of the attacker!");
  140. else if(!(rawTarget instanceof L2PcInstance))
  141. activeChar.sendMessage("You must target a player with clan!");
  142. else if((target = (L2PcInstance)rawTarget).getClan() == null)
  143. activeChar.sendMessage("Your target does not have any clan!");
  144. else if(hall.getSiege().checkIsAttacker(target.getClan()))
  145. activeChar.sendMessage("Your target's clan is alredy participating!");
  146. else
  147. attacker = target.getClan();
  148. }
  149. else
  150. {
  151. L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
  152. if(rawClan == null)
  153. activeChar.sendMessage("The given clan does not exist!");
  154. else if(hall.getSiege().checkIsAttacker(rawClan))
  155. activeChar.sendMessage("The given clan is alredy participating!");
  156. else
  157. attacker = rawClan;
  158. }
  159. if(attacker != null)
  160. hall.addAttacker(attacker);
  161. }
  162. else if(split[0].equals(COMMANDS[5]))
  163. {
  164. if(hall.isInSiege())
  165. {
  166. activeChar.sendMessage("The clan hall is in siege, cannot remove attackers now.");
  167. return false;
  168. }
  169. if(split.length < 3)
  170. {
  171. L2Object rawTarget = activeChar.getTarget();
  172. L2PcInstance target = null;
  173. if(rawTarget == null)
  174. activeChar.sendMessage("You must target a clan member of the attacker!");
  175. else if(!(rawTarget instanceof L2PcInstance))
  176. activeChar.sendMessage("You must target a player with clan!");
  177. else if((target = (L2PcInstance)rawTarget).getClan() == null)
  178. activeChar.sendMessage("Your target does not have any clan!");
  179. else if(!hall.getSiege().checkIsAttacker(target.getClan()))
  180. activeChar.sendMessage("Your target's clan is not participating!");
  181. else
  182. hall.removeAttacker(target.getClan());
  183. }
  184. else
  185. {
  186. L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
  187. if(rawClan == null)
  188. activeChar.sendMessage("The given clan does not exist!");
  189. else if(!hall.getSiege().checkIsAttacker(rawClan))
  190. activeChar.sendMessage("The given clan is not participating!");
  191. else
  192. hall.removeAttacker(rawClan);
  193. }
  194. }
  195. else if(split[0].equals(COMMANDS[6]))
  196. {
  197. if(hall.isInSiege())
  198. activeChar.sendMessage("The requested hall is in siege right now, cannot clear attacker list!");
  199. else
  200. {
  201. ClanHallSiegeEngine siegable = hall.getSiege();
  202. siegable.getAttackers().clear();
  203. }
  204. }
  205. else if(split[0].equals(COMMANDS[7]))
  206. activeChar.sendPacket(new SiegeInfo(hall));
  207. sendSiegableHallPage(activeChar, split[1], hall);
  208. return false;
  209. }
  210. private SiegableHall getHall(String id, L2PcInstance gm)
  211. {
  212. int ch = parseInt(id);
  213. if(ch == 0)
  214. {
  215. gm.sendMessage("Wrong clan hall id, unparseable id!");
  216. return null;
  217. }
  218. SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(ch);
  219. if(hall == null)
  220. gm.sendMessage("Couldnt find the clan hall.");
  221. return hall;
  222. }
  223. private int parseInt(String st)
  224. {
  225. int val = 0;
  226. try
  227. {
  228. val = Integer.parseInt(st);
  229. }
  230. catch(NumberFormatException e)
  231. {
  232. e.printStackTrace();
  233. }
  234. return val;
  235. }
  236. private void sendSiegableHallPage(L2PcInstance activeChar, String hallId, SiegableHall hall)
  237. {
  238. NpcHtmlMessage msg = new NpcHtmlMessage(5);
  239. msg.setFile(null, "data/html/admin/siegablehall.htm");
  240. msg.replace("%clanhallId%", hallId);
  241. msg.replace("%clanhallName%", hall.getName());
  242. if(hall.getOwnerId() > 0)
  243. {
  244. L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
  245. if(owner != null)
  246. msg.replace("%clanhallOwner%", owner.getName());
  247. else
  248. msg.replace("%clanhallOwner%", "No Owner");
  249. }
  250. else
  251. msg.replace("%clanhallOwner%", "No Owner");
  252. activeChar.sendPacket(msg);
  253. }
  254. }