Advertisement
WallisTeer

[aCis] CritAnnounce

Jan 1st, 2015
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.76 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P trunk_335
  3. Index: aCis_datapack/data/critannouncements.txt
  4. ===================================================================
  5. --- aCis_datapack/data/critannouncements.txt (revision 0)
  6. +++ aCis_datapack/data/critannouncements.txt (working copy)
  7. @@ -0,0 +1 @@
  8. +Welcome Project l2jacis interlude Pack !
  9. \ No newline at end of file
  10. Index: aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java
  11. ===================================================================
  12. --- aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java (revision 74)
  13. +++ aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java (working copy)
  14. @@ -30,12 +30,16 @@
  15. private static final String[] ADMIN_COMMANDS =
  16. {
  17. "admin_list_announcements",
  18. + "admin_list_critannouncements",
  19. "admin_reload_announcements",
  20. "admin_announce_announcements",
  21. "admin_add_announcement",
  22. + "admin_add_critannouncement",
  23. "admin_del_announcement",
  24. "admin_announce",
  25. - "admin_announce_menu"
  26. + "admin_critannounce",
  27. + "admin_announce_menu",
  28. + "admin_critannounce_menu",
  29. };
  30.  
  31. @Override
  32. @@ -45,6 +49,10 @@
  33. {
  34. Announcements.getInstance().listAnnouncements(activeChar);
  35. }
  36. + else if (command.equals("admin_list_critannouncements"))
  37. + {
  38. + Announcements.getInstance().listCritAnnouncements(activeChar);
  39. + }
  40. else if (command.equals("admin_reload_announcements"))
  41. {
  42. Announcements.getInstance().loadAnnouncements();
  43. @@ -52,9 +60,21 @@
  44. }
  45. else if (command.startsWith("admin_announce_menu"))
  46. {
  47. - Announcements.handleAnnounce(command, 20);
  48. + Announcements.handleAnnounce(command, 20, false);
  49. Announcements.getInstance().listAnnouncements(activeChar);
  50. }
  51. + else if (command.startsWith("admin_critannounce_menu"))
  52. + {
  53. + try
  54. + {
  55. + Announcements.getInstance();
  56. + Announcements.handleAnnounce(command.substring(24), 0, true);
  57. + }
  58. + catch (StringIndexOutOfBoundsException e)
  59. + {
  60. + }
  61. + AdminHelpPage.showHelpPage(activeChar, "critannounce.htm");
  62. + }
  63. else if (command.equals("admin_announce_announcements"))
  64. {
  65. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  66. @@ -66,7 +86,6 @@
  67. }
  68. else if (command.startsWith("admin_add_announcement"))
  69. {
  70. - // FIXME the player can send only 16 chars (if you try to send more it sends null), remove this function or not?
  71. if (!command.equals("admin_add_announcement"))
  72. {
  73. try
  74. @@ -80,6 +99,21 @@
  75. }// ignore errors
  76. }
  77. }
  78. + else if (command.startsWith("admin_add_critannouncement"))
  79. + {
  80. + if (!command.equals("admin_add_critannouncement"))
  81. + {
  82. + try
  83. + {
  84. + String val = command.substring(27);
  85. + Announcements.getInstance().addCritAnnouncement(val);
  86. + Announcements.getInstance().listCritAnnouncements(activeChar);
  87. + }
  88. + catch (StringIndexOutOfBoundsException e)
  89. + {
  90. + }
  91. + }
  92. + }
  93. else if (command.startsWith("admin_del_announcement"))
  94. {
  95. try
  96. @@ -92,12 +126,35 @@
  97. {
  98. }
  99. }
  100. + else if (command.startsWith("admin_del_critannouncement"))
  101. + {
  102. + try
  103. + {
  104. + final int val = Integer.parseInt(command.substring(27));
  105. + Announcements.getInstance().delCritAnnouncement(val);
  106. + Announcements.getInstance().listCritAnnouncements(activeChar);
  107. + }
  108. + catch (StringIndexOutOfBoundsException e)
  109. + {
  110. + }
  111. + }
  112. // Command is admin announce
  113. else if (command.startsWith("admin_announce"))
  114. {
  115. // Call method from another class
  116. - Announcements.handleAnnounce(command, 15);
  117. + Announcements.handleAnnounce(command, 15, false);
  118. }
  119. + else if (command.startsWith("admin_critannounce"))
  120. + {
  121. + try
  122. + {
  123. + Announcements.getInstance();
  124. + Announcements.handleAnnounce(command.substring(19), 0, true);
  125. + }
  126. + catch (StringIndexOutOfBoundsException e)
  127. + {
  128. + }
  129. + }
  130. return true;
  131. }
  132.  
  133. Index: aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java
  134. ===================================================================
  135. --- aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java (revision 74)
  136. +++ aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java (working copy)
  137. @@ -195,8 +195,19 @@
  138. }
  139. }
  140.  
  141. - public static void announceToOnlinePlayers(String text)
  142. + public static void announceToOnlinePlayers(String text, boolean isCritical)
  143. {
  144. - toAllOnlinePlayers(new CreatureSay(0, Say2.ANNOUNCEMENT, "", text));
  145. + CreatureSay cs;
  146. +
  147. + if (isCritical)
  148. + {
  149. + cs = new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "", text);
  150. + }
  151. + else
  152. + {
  153. + cs = new CreatureSay(0, Say2.ANNOUNCEMENT, "", text);
  154. + }
  155. +
  156. + toAllOnlinePlayers(cs);
  157. }
  158. }
  159. \ No newline at end of file
  160. Index: aCis_datapack/data/xml/admin_commands_rights.xml
  161. ===================================================================
  162. --- aCis_datapack/data/xml/admin_commands_rights.xml (revision 74)
  163. +++ aCis_datapack/data/xml/admin_commands_rights.xml (working copy)
  164. @@ -14,14 +14,18 @@
  165. <aCar name="admin_reload" accessLevel="1" />
  166. <aCar name="admin_script_load" accessLevel="1" />
  167.  
  168. - <!-- ANNOUNCEMENTS -->
  169. - <aCar name="admin_list_announcements" accessLevel="1" />
  170. - <aCar name="admin_reload_announcements" accessLevel="1" />
  171. - <aCar name="admin_announce_announcements" accessLevel="1" />
  172. - <aCar name="admin_add_announcement" accessLevel="1" />
  173. - <aCar name="admin_del_announcement" accessLevel="1" />
  174. - <aCar name="admin_announce" accessLevel="1" />
  175. - <aCar name="admin_announce_menu" accessLevel="1" />
  176. + <!-- ANNOUNCEMENTS -->
  177. + <aCar name="admin_list_announcements" accessLevel="2" />
  178. + <aCar name="admin_list_critannouncements" accessLevel="2" />
  179. + <aCar name="admin_reload_announcements" accessLevel="2" />
  180. + <aCar name="admin_announce_announcements" accessLevel="2" />
  181. + <aCar name="admin_add_announcement" accessLevel="2" />
  182. + <aCar name="admin_add_critannouncement" accessLevel="2" />
  183. + <aCar name="admin_del_announcement" accessLevel="2" />
  184. + <aCar name="admin_announce" accessLevel="4" />
  185. + <aCar name="admin_critannounce" accessLevel="4" />
  186. + <aCar name="admin_announce_menu" accessLevel="2" />
  187. + <aCar name="admin_critannounce_menu" accessLevel="2" />
  188.  
  189. <!-- BAN -->
  190. <aCar name="admin_ban" accessLevel="1" />
  191. Index: aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java
  192. ===================================================================
  193. --- aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (revision 74)
  194. +++ aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (working copy)
  195. @@ -49,6 +49,7 @@
  196. public final static int PARTYROOM_COMMANDER = 15; // (Yellow)
  197. public final static int PARTYROOM_ALL = 16; // (Red)
  198. public final static int HERO_VOICE = 17;
  199. + public static final int CRITICAL_ANNOUNCE = 18;
  200.  
  201. private final static String[] CHAT_NAMES =
  202. {
  203. @@ -69,7 +70,8 @@
  204. "PARTYMATCH_ROOM",
  205. "PARTYROOM_COMMANDER",
  206. "PARTYROOM_ALL",
  207. - "HERO_VOICE"
  208. + "HERO_VOICE",
  209. + "CRITICAL_ANNOUNCE"
  210. };
  211.  
  212. private static final String[] WALKER_COMMAND_LIST =
  213. Index: aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java
  214. ===================================================================
  215. --- aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java (revision 74)
  216. +++ aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java (working copy)
  217. @@ -22,53 +22,58 @@
  218. import java.util.ArrayList;
  219. import java.util.List;
  220. import java.util.StringTokenizer;
  221. -import java.util.logging.Level;
  222. import java.util.logging.Logger;
  223.  
  224. +import net.sf.l2j.gameserver.cache.HtmCache;
  225. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  226. import net.sf.l2j.gameserver.network.clientpackets.Say2;
  227. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  228. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  229. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  230. import net.sf.l2j.gameserver.util.Broadcast;
  231. +import net.sf.l2j.util.StringUtil;
  232.  
  233. public class Announcements
  234. {
  235. private static Logger _log = Logger.getLogger(Announcements.class.getName());
  236.  
  237. - private static Announcements _instance;
  238. private final List<String> _announcements = new ArrayList<>();
  239. + private final List<String> _critAnnouncements = new ArrayList<>();
  240.  
  241. - private Announcements()
  242. + protected Announcements()
  243. {
  244. loadAnnouncements();
  245. }
  246.  
  247. public static Announcements getInstance()
  248. {
  249. - if (_instance == null)
  250. - _instance = new Announcements();
  251. -
  252. - return _instance;
  253. + return SingletonHolder._instance;
  254. }
  255.  
  256. public void loadAnnouncements()
  257. {
  258. _announcements.clear();
  259. - File file = new File("./data/announcements.txt");
  260. - if (file.exists())
  261. - readFromDisk(file);
  262. - else
  263. - _log.config("The announcements file (normally located to 'data/announcements.txt') doesn't exist.");
  264. + _critAnnouncements.clear();
  265. +
  266. + readFromDisk("./data/announcements.txt", _announcements);
  267. + readFromDisk("./data/critannouncements.txt", _critAnnouncements);
  268. +
  269. + _log.info("Announcements: Loaded " + _announcements.size() + " announcements.");
  270. + _log.info("Announcements: Loaded " + _critAnnouncements.size() + " critical announcements.");
  271. }
  272.  
  273. public void showAnnouncements(L2PcInstance activeChar)
  274. {
  275. - for (int i = 0; i < _announcements.size(); i++)
  276. + for (String _announcement : _announcements)
  277. {
  278. - CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, activeChar.getName(), _announcements.get(i));
  279. + CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, activeChar.getName(), _announcement);
  280. activeChar.sendPacket(cs);
  281. }
  282. + for (String _critAnnounce : _critAnnouncements)
  283. + {
  284. + CreatureSay cs = new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, activeChar.getName(), _critAnnounce);
  285. + activeChar.sendPacket(cs);
  286. + }
  287. }
  288.  
  289. public void listAnnouncements(L2PcInstance activeChar)
  290. @@ -85,63 +90,135 @@
  291. activeChar.sendPacket(adminReply);
  292. }
  293.  
  294. + public void listCritAnnouncements(L2PcInstance activeChar)
  295. + {
  296. + String content = HtmCache.getInstance().getHtmForce("data/html/admin/critannounce.htm");
  297. + NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  298. + adminReply.setHtml(content);
  299. + final StringBuilder replyMSG = StringUtil.startAppend(500, "<br>");
  300. + for (int i = 0; i < _critAnnouncements.size(); i++)
  301. + {
  302. + StringUtil.append(replyMSG, "<table width=260><tr><td width=220>", _critAnnouncements.get(i), "</td><td width=40>" + "<button value=\"Delete\" action=\"bypass -h admin_del_critannouncement ", String.valueOf(i), "\" width=60 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table>");
  303. + }
  304. + adminReply.replace("%critannounces%", replyMSG.toString());
  305. + activeChar.sendPacket(adminReply);
  306. + }
  307. +
  308. public void addAnnouncement(String text)
  309. {
  310. _announcements.add(text);
  311. - saveToDisk();
  312. + saveToDisk(false);
  313. }
  314.  
  315. public void delAnnouncement(int line)
  316. {
  317. _announcements.remove(line);
  318. - saveToDisk();
  319. + saveToDisk(false);
  320. }
  321.  
  322. - private void readFromDisk(File file)
  323. + public void addCritAnnouncement(String text)
  324. {
  325. - try (LineNumberReader lnr = new LineNumberReader(new FileReader(file)))
  326. + _critAnnouncements.add(text);
  327. + saveToDisk(true);
  328. + }
  329. +
  330. + public void delCritAnnouncement(int line)
  331. + {
  332. + _critAnnouncements.remove(line);
  333. + saveToDisk(true);
  334. + }
  335. +
  336. + private static void readFromDisk(String path, List<String> list)
  337. + {
  338. + File file = new File(path);
  339. +
  340. + if (file.exists())
  341. {
  342. - int i = 0;
  343. - String line = null;
  344. - while ((line = lnr.readLine()) != null)
  345. + LineNumberReader lnr = null;
  346. + try
  347. {
  348. - StringTokenizer st = new StringTokenizer(line, "\n\r");
  349. - if (st.hasMoreTokens())
  350. + String line = null;
  351. + lnr = new LineNumberReader(new FileReader(file));
  352. + while ((line = lnr.readLine()) != null)
  353. {
  354. - String announcement = st.nextToken();
  355. - _announcements.add(announcement);
  356. -
  357. - i++;
  358. + StringTokenizer st = new StringTokenizer(line, "\n\r");
  359. + if (st.hasMoreTokens())
  360. + {
  361. + String announcement = st.nextToken();
  362. + list.add(announcement);
  363. + }
  364. }
  365. }
  366. - _log.config("Announcements: Loaded " + i + " Announcements.");
  367. + catch (IOException e1)
  368. + {
  369. + _log.warning("Error reading announcements.");
  370. + }
  371. + finally
  372. + {
  373. + try
  374. + {
  375. + LineNumberReader _lnr = lnr;
  376. + _lnr.close();
  377. + }
  378. + catch (Exception e2)
  379. + {
  380. + }
  381. + }
  382. }
  383. - catch (IOException e1)
  384. + else
  385. {
  386. - _log.log(Level.SEVERE, "Error reading announcements", e1);
  387. + _log.warning(file.getAbsolutePath() + " doesn't exist");
  388. }
  389. }
  390.  
  391. - private void saveToDisk()
  392. + private void saveToDisk(boolean isCritical)
  393. {
  394. - final File file = new File("data/announcements.txt");
  395. - try (FileWriter save = new FileWriter(file))
  396. + String path;
  397. + List<String> list;
  398. +
  399. + if (isCritical)
  400. {
  401. - for (int i = 0; i < _announcements.size(); i++)
  402. + path = "./data/critannouncements.txt";
  403. + list = _critAnnouncements;
  404. + }
  405. + else
  406. + {
  407. + path = "./data/announcements.txt";
  408. + list = _announcements;
  409. + }
  410. +
  411. + File file = new File(path);
  412. + FileWriter save = null;
  413. +
  414. + try
  415. + {
  416. + save = new FileWriter(file);
  417. + for (String announce : list)
  418. {
  419. - save.write(_announcements.get(i));
  420. + save.write(announce);
  421. save.write("\r\n");
  422. }
  423. }
  424. catch (IOException e)
  425. {
  426. - _log.warning("saving the announcements file has failed: " + e);
  427. + _log.warning("Saving to the announcements file has failed.");
  428. }
  429. + finally
  430. + {
  431. + try
  432. + {
  433. + FileWriter _save = save;
  434. + _save.close();
  435. + }
  436. + catch (Exception e)
  437. + {
  438. + }
  439. + }
  440. }
  441.  
  442. public static void announceToAll(String text)
  443. {
  444. - Broadcast.announceToOnlinePlayers(text);
  445. + announceToAll(text, false);
  446. }
  447.  
  448. public static void announceToAll(SystemMessage sm)
  449. @@ -149,16 +226,27 @@
  450. Broadcast.toAllOnlinePlayers(sm);
  451. }
  452.  
  453. + public static void announceToAll(String text, boolean isCritical)
  454. + {
  455. + Broadcast.announceToOnlinePlayers(text, isCritical);
  456. + }
  457. +
  458. // Method for handling announcements from admin
  459. - public static void handleAnnounce(String command, int lengthToTrim)
  460. + public static void handleAnnounce(String command, int lengthToTrim, boolean isCritical)
  461. {
  462. try
  463. {
  464. // Announce string to everyone on server
  465. - announceToAll(command.substring(lengthToTrim));
  466. + String text = command.substring(lengthToTrim);
  467. + Announcements.announceToAll(text, isCritical);
  468. }
  469. catch (StringIndexOutOfBoundsException e)
  470. {
  471. }
  472. }
  473. +
  474. + private static class SingletonHolder
  475. + {
  476. + protected static final Announcements _instance = new Announcements();
  477. + }
  478. }
  479. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement