Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P trunk_335
- Index: aCis_datapack/data/critannouncements.txt
- ===================================================================
- --- aCis_datapack/data/critannouncements.txt (revision 0)
- +++ aCis_datapack/data/critannouncements.txt (working copy)
- @@ -0,0 +1 @@
- +Welcome Project l2jacis interlude Pack !
- \ No newline at end of file
- Index: aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java
- ===================================================================
- --- aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java (revision 74)
- +++ aCis_gameserver/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAnnouncements.java (working copy)
- @@ -30,12 +30,16 @@
- private static final String[] ADMIN_COMMANDS =
- {
- "admin_list_announcements",
- + "admin_list_critannouncements",
- "admin_reload_announcements",
- "admin_announce_announcements",
- "admin_add_announcement",
- + "admin_add_critannouncement",
- "admin_del_announcement",
- "admin_announce",
- - "admin_announce_menu"
- + "admin_critannounce",
- + "admin_announce_menu",
- + "admin_critannounce_menu",
- };
- @Override
- @@ -45,6 +49,10 @@
- {
- Announcements.getInstance().listAnnouncements(activeChar);
- }
- + else if (command.equals("admin_list_critannouncements"))
- + {
- + Announcements.getInstance().listCritAnnouncements(activeChar);
- + }
- else if (command.equals("admin_reload_announcements"))
- {
- Announcements.getInstance().loadAnnouncements();
- @@ -52,9 +60,21 @@
- }
- else if (command.startsWith("admin_announce_menu"))
- {
- - Announcements.handleAnnounce(command, 20);
- + Announcements.handleAnnounce(command, 20, false);
- Announcements.getInstance().listAnnouncements(activeChar);
- }
- + else if (command.startsWith("admin_critannounce_menu"))
- + {
- + try
- + {
- + Announcements.getInstance();
- + Announcements.handleAnnounce(command.substring(24), 0, true);
- + }
- + catch (StringIndexOutOfBoundsException e)
- + {
- + }
- + AdminHelpPage.showHelpPage(activeChar, "critannounce.htm");
- + }
- else if (command.equals("admin_announce_announcements"))
- {
- Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
- @@ -66,7 +86,6 @@
- }
- else if (command.startsWith("admin_add_announcement"))
- {
- - // FIXME the player can send only 16 chars (if you try to send more it sends null), remove this function or not?
- if (!command.equals("admin_add_announcement"))
- {
- try
- @@ -80,6 +99,21 @@
- }// ignore errors
- }
- }
- + else if (command.startsWith("admin_add_critannouncement"))
- + {
- + if (!command.equals("admin_add_critannouncement"))
- + {
- + try
- + {
- + String val = command.substring(27);
- + Announcements.getInstance().addCritAnnouncement(val);
- + Announcements.getInstance().listCritAnnouncements(activeChar);
- + }
- + catch (StringIndexOutOfBoundsException e)
- + {
- + }
- + }
- + }
- else if (command.startsWith("admin_del_announcement"))
- {
- try
- @@ -92,12 +126,35 @@
- {
- }
- }
- + else if (command.startsWith("admin_del_critannouncement"))
- + {
- + try
- + {
- + final int val = Integer.parseInt(command.substring(27));
- + Announcements.getInstance().delCritAnnouncement(val);
- + Announcements.getInstance().listCritAnnouncements(activeChar);
- + }
- + catch (StringIndexOutOfBoundsException e)
- + {
- + }
- + }
- // Command is admin announce
- else if (command.startsWith("admin_announce"))
- {
- // Call method from another class
- - Announcements.handleAnnounce(command, 15);
- + Announcements.handleAnnounce(command, 15, false);
- }
- + else if (command.startsWith("admin_critannounce"))
- + {
- + try
- + {
- + Announcements.getInstance();
- + Announcements.handleAnnounce(command.substring(19), 0, true);
- + }
- + catch (StringIndexOutOfBoundsException e)
- + {
- + }
- + }
- return true;
- }
- Index: aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java
- ===================================================================
- --- aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java (revision 74)
- +++ aCis_gameserver/java/net/sf/l2j/gameserver/util/Broadcast.java (working copy)
- @@ -195,8 +195,19 @@
- }
- }
- - public static void announceToOnlinePlayers(String text)
- + public static void announceToOnlinePlayers(String text, boolean isCritical)
- {
- - toAllOnlinePlayers(new CreatureSay(0, Say2.ANNOUNCEMENT, "", text));
- + CreatureSay cs;
- +
- + if (isCritical)
- + {
- + cs = new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "", text);
- + }
- + else
- + {
- + cs = new CreatureSay(0, Say2.ANNOUNCEMENT, "", text);
- + }
- +
- + toAllOnlinePlayers(cs);
- }
- }
- \ No newline at end of file
- Index: aCis_datapack/data/xml/admin_commands_rights.xml
- ===================================================================
- --- aCis_datapack/data/xml/admin_commands_rights.xml (revision 74)
- +++ aCis_datapack/data/xml/admin_commands_rights.xml (working copy)
- @@ -14,14 +14,18 @@
- <aCar name="admin_reload" accessLevel="1" />
- <aCar name="admin_script_load" accessLevel="1" />
- - <!-- ANNOUNCEMENTS -->
- - <aCar name="admin_list_announcements" accessLevel="1" />
- - <aCar name="admin_reload_announcements" accessLevel="1" />
- - <aCar name="admin_announce_announcements" accessLevel="1" />
- - <aCar name="admin_add_announcement" accessLevel="1" />
- - <aCar name="admin_del_announcement" accessLevel="1" />
- - <aCar name="admin_announce" accessLevel="1" />
- - <aCar name="admin_announce_menu" accessLevel="1" />
- + <!-- ANNOUNCEMENTS -->
- + <aCar name="admin_list_announcements" accessLevel="2" />
- + <aCar name="admin_list_critannouncements" accessLevel="2" />
- + <aCar name="admin_reload_announcements" accessLevel="2" />
- + <aCar name="admin_announce_announcements" accessLevel="2" />
- + <aCar name="admin_add_announcement" accessLevel="2" />
- + <aCar name="admin_add_critannouncement" accessLevel="2" />
- + <aCar name="admin_del_announcement" accessLevel="2" />
- + <aCar name="admin_announce" accessLevel="4" />
- + <aCar name="admin_critannounce" accessLevel="4" />
- + <aCar name="admin_announce_menu" accessLevel="2" />
- + <aCar name="admin_critannounce_menu" accessLevel="2" />
- <!-- BAN -->
- <aCar name="admin_ban" accessLevel="1" />
- Index: aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java
- ===================================================================
- --- aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (revision 74)
- +++ aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/Say2.java (working copy)
- @@ -49,6 +49,7 @@
- public final static int PARTYROOM_COMMANDER = 15; // (Yellow)
- public final static int PARTYROOM_ALL = 16; // (Red)
- public final static int HERO_VOICE = 17;
- + public static final int CRITICAL_ANNOUNCE = 18;
- private final static String[] CHAT_NAMES =
- {
- @@ -69,7 +70,8 @@
- "PARTYMATCH_ROOM",
- "PARTYROOM_COMMANDER",
- "PARTYROOM_ALL",
- - "HERO_VOICE"
- + "HERO_VOICE",
- + "CRITICAL_ANNOUNCE"
- };
- private static final String[] WALKER_COMMAND_LIST =
- Index: aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java
- ===================================================================
- --- aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java (revision 74)
- +++ aCis_gameserver/java/net/sf/l2j/gameserver/Announcements.java (working copy)
- @@ -22,53 +22,58 @@
- import java.util.ArrayList;
- import java.util.List;
- import java.util.StringTokenizer;
- -import java.util.logging.Level;
- import java.util.logging.Logger;
- +import net.sf.l2j.gameserver.cache.HtmCache;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.network.clientpackets.Say2;
- import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.util.Broadcast;
- +import net.sf.l2j.util.StringUtil;
- public class Announcements
- {
- private static Logger _log = Logger.getLogger(Announcements.class.getName());
- - private static Announcements _instance;
- private final List<String> _announcements = new ArrayList<>();
- + private final List<String> _critAnnouncements = new ArrayList<>();
- - private Announcements()
- + protected Announcements()
- {
- loadAnnouncements();
- }
- public static Announcements getInstance()
- {
- - if (_instance == null)
- - _instance = new Announcements();
- -
- - return _instance;
- + return SingletonHolder._instance;
- }
- public void loadAnnouncements()
- {
- _announcements.clear();
- - File file = new File("./data/announcements.txt");
- - if (file.exists())
- - readFromDisk(file);
- - else
- - _log.config("The announcements file (normally located to 'data/announcements.txt') doesn't exist.");
- + _critAnnouncements.clear();
- +
- + readFromDisk("./data/announcements.txt", _announcements);
- + readFromDisk("./data/critannouncements.txt", _critAnnouncements);
- +
- + _log.info("Announcements: Loaded " + _announcements.size() + " announcements.");
- + _log.info("Announcements: Loaded " + _critAnnouncements.size() + " critical announcements.");
- }
- public void showAnnouncements(L2PcInstance activeChar)
- {
- - for (int i = 0; i < _announcements.size(); i++)
- + for (String _announcement : _announcements)
- {
- - CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, activeChar.getName(), _announcements.get(i));
- + CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, activeChar.getName(), _announcement);
- activeChar.sendPacket(cs);
- }
- + for (String _critAnnounce : _critAnnouncements)
- + {
- + CreatureSay cs = new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, activeChar.getName(), _critAnnounce);
- + activeChar.sendPacket(cs);
- + }
- }
- public void listAnnouncements(L2PcInstance activeChar)
- @@ -85,63 +90,135 @@
- activeChar.sendPacket(adminReply);
- }
- + public void listCritAnnouncements(L2PcInstance activeChar)
- + {
- + String content = HtmCache.getInstance().getHtmForce("data/html/admin/critannounce.htm");
- + NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
- + adminReply.setHtml(content);
- + final StringBuilder replyMSG = StringUtil.startAppend(500, "<br>");
- + for (int i = 0; i < _critAnnouncements.size(); i++)
- + {
- + 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>");
- + }
- + adminReply.replace("%critannounces%", replyMSG.toString());
- + activeChar.sendPacket(adminReply);
- + }
- +
- public void addAnnouncement(String text)
- {
- _announcements.add(text);
- - saveToDisk();
- + saveToDisk(false);
- }
- public void delAnnouncement(int line)
- {
- _announcements.remove(line);
- - saveToDisk();
- + saveToDisk(false);
- }
- - private void readFromDisk(File file)
- + public void addCritAnnouncement(String text)
- {
- - try (LineNumberReader lnr = new LineNumberReader(new FileReader(file)))
- + _critAnnouncements.add(text);
- + saveToDisk(true);
- + }
- +
- + public void delCritAnnouncement(int line)
- + {
- + _critAnnouncements.remove(line);
- + saveToDisk(true);
- + }
- +
- + private static void readFromDisk(String path, List<String> list)
- + {
- + File file = new File(path);
- +
- + if (file.exists())
- {
- - int i = 0;
- - String line = null;
- - while ((line = lnr.readLine()) != null)
- + LineNumberReader lnr = null;
- + try
- {
- - StringTokenizer st = new StringTokenizer(line, "\n\r");
- - if (st.hasMoreTokens())
- + String line = null;
- + lnr = new LineNumberReader(new FileReader(file));
- + while ((line = lnr.readLine()) != null)
- {
- - String announcement = st.nextToken();
- - _announcements.add(announcement);
- -
- - i++;
- + StringTokenizer st = new StringTokenizer(line, "\n\r");
- + if (st.hasMoreTokens())
- + {
- + String announcement = st.nextToken();
- + list.add(announcement);
- + }
- }
- }
- - _log.config("Announcements: Loaded " + i + " Announcements.");
- + catch (IOException e1)
- + {
- + _log.warning("Error reading announcements.");
- + }
- + finally
- + {
- + try
- + {
- + LineNumberReader _lnr = lnr;
- + _lnr.close();
- + }
- + catch (Exception e2)
- + {
- + }
- + }
- }
- - catch (IOException e1)
- + else
- {
- - _log.log(Level.SEVERE, "Error reading announcements", e1);
- + _log.warning(file.getAbsolutePath() + " doesn't exist");
- }
- }
- - private void saveToDisk()
- + private void saveToDisk(boolean isCritical)
- {
- - final File file = new File("data/announcements.txt");
- - try (FileWriter save = new FileWriter(file))
- + String path;
- + List<String> list;
- +
- + if (isCritical)
- {
- - for (int i = 0; i < _announcements.size(); i++)
- + path = "./data/critannouncements.txt";
- + list = _critAnnouncements;
- + }
- + else
- + {
- + path = "./data/announcements.txt";
- + list = _announcements;
- + }
- +
- + File file = new File(path);
- + FileWriter save = null;
- +
- + try
- + {
- + save = new FileWriter(file);
- + for (String announce : list)
- {
- - save.write(_announcements.get(i));
- + save.write(announce);
- save.write("\r\n");
- }
- }
- catch (IOException e)
- {
- - _log.warning("saving the announcements file has failed: " + e);
- + _log.warning("Saving to the announcements file has failed.");
- }
- + finally
- + {
- + try
- + {
- + FileWriter _save = save;
- + _save.close();
- + }
- + catch (Exception e)
- + {
- + }
- + }
- }
- public static void announceToAll(String text)
- {
- - Broadcast.announceToOnlinePlayers(text);
- + announceToAll(text, false);
- }
- public static void announceToAll(SystemMessage sm)
- @@ -149,16 +226,27 @@
- Broadcast.toAllOnlinePlayers(sm);
- }
- + public static void announceToAll(String text, boolean isCritical)
- + {
- + Broadcast.announceToOnlinePlayers(text, isCritical);
- + }
- +
- // Method for handling announcements from admin
- - public static void handleAnnounce(String command, int lengthToTrim)
- + public static void handleAnnounce(String command, int lengthToTrim, boolean isCritical)
- {
- try
- {
- // Announce string to everyone on server
- - announceToAll(command.substring(lengthToTrim));
- + String text = command.substring(lengthToTrim);
- + Announcements.announceToAll(text, isCritical);
- }
- catch (StringIndexOutOfBoundsException e)
- {
- }
- }
- +
- + private static class SingletonHolder
- + {
- + protected static final Announcements _instance = new Announcements();
- + }
- }
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement