Jump to content

Recommended Posts

  • 3 weeks later...
  • 3 weeks later...
Posted
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver;

import java.io.*;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.script.DateRange;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.StringUtil;

import javolution.util.FastList;

/**
* This class ...
* @author HoangNhan L2JVN http://vietcheaters.com
* UTF-8 Announcement  
*/
public class Announcements
{
        private static Logger _log = Logger.getLogger(Announcements.class.getName());
        
        private List<String> _announcements = new FastList<String>();
        private List<List<Object>> _eventAnnouncements = new FastList<List<Object>>();
        
        private Announcements()
        {
                loadAnnouncements();
        }
        
        public static Announcements getInstance()
        {
                return SingletonHolder._instance;
        }
        
        public void loadAnnouncements()
        {
                _announcements.clear();
                File file = new File(Config.DATAPACK_ROOT, "data/announcements.txt");
                if (file.exists())
                {
                        readFromDisk(file);
                }
                else
                {
                        _log.warning("data/announcements.txt doesn't exist");
                }
        }
        
        public void showAnnouncements(L2PcInstance activeChar)
        {
                for (int i = 0; i < _announcements.size(); i  )
                {
                        CreatureSay cs = new CreatureSay(0, Say2.ANNOUNCEMENT, activeChar.getName(), _announcements.get(i));
                        activeChar.sendPacket(cs);
                }
                
                for (int i = 0; i < _eventAnnouncements.size(); i  )
                {
                        List<Object> entry = _eventAnnouncements.get(i);
                        
                        DateRange validDateRange = (DateRange) entry.get(0);
                        String[] msg = (String[]) entry.get(1);
                        Date currentDate = new Date();
                        
                        if (!validDateRange.isValid() || validDateRange.isWithinRange(currentDate))
                        {
                                SystemMessage sm = new SystemMessage(SystemMessageId.S1);
                                for (int j = 0; j < msg.length; j  )
                                {
                                        sm.addString(msg[j]);
                                }
                                activeChar.sendPacket(sm);
                        }
                        
                }
        }
        
        public void addEventAnnouncement(DateRange validDateRange, String[] msg)
        {
                List<Object> entry = new FastList<Object>();
                entry.add(validDateRange);
                entry.add(msg);
                _eventAnnouncements.add(entry);
        }
        
        public void listAnnouncements(L2PcInstance activeChar)
        {
                String content = HtmCache.getInstance().getHtmForce(activeChar.getHtmlPrefix(), "data/html/admin/announce.htm");
                NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
                adminReply.setHtml(content);
                final StringBuilder replyMSG = StringUtil.startAppend(500, "<br>");
                for (int i = 0; i < _announcements.size(); i  )
                {
                        StringUtil.append(replyMSG, "<table width=260><tr><td width=220>", _announcements.get(i), "</td><td width=40>"
                                          "<button value="Delete" action="bypass -h admin_del_announcement ", String.valueOf(i), "" width=60 height=20 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df"></td></tr></table>");
                }
                adminReply.replace("%announces%", replyMSG.toString());
                activeChar.sendPacket(adminReply);
        }
        
        public void addAnnouncement(String text)
        {
                _announcements.add(text);
                saveToDisk();
        }
        
        public void delAnnouncement(int line)
        {
                _announcements.remove(line);
                saveToDisk();
        }
        
        private void readFromDisk(File file)
        {
                BufferedReader lnr = null;
                try
                {
                        int i = 0;
                        String line = null;
                        lnr =  new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF8"));
                        while ((line = lnr.readLine()) != null)
                        {
                                StringTokenizer st = new StringTokenizer(line, "nr");
                                if (st.hasMoreTokens())
                                {
                                        String announcement = st.nextToken();
                                        _announcements.add(announcement);
                                        
                                        i  ;
                                }
                        }
                        
                        if (Config.DEBUG)
                                _log.info("Announcements: Loaded "   i   " Announcements.");
                }
                catch (IOException e1)
                {
                        _log.log(Level.SEVERE, "Error reading announcements: ", e1);
                }
                finally
                {
                        try
                        {
                                lnr.close();
                        }
                        catch (Exception e2)
                        {
                                // nothing
                        }
                }
        }
        
        private void saveToDisk()
        {
                File file = new File("data/announcements.txt");
                BufferedWriter save = null;
                
                try
                {
                        save = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF8"));
                        for (int i = 0; i < _announcements.size(); i  )
                        {
                                save.write(_announcements.get(i));
                                save.write("rn");
                        }
                }
                catch (IOException e)
                {
                        _log.log(Level.SEVERE, "Saving to the announcements file has failed: ", e);
                }
                finally
                {
                        try
                        {
                                save.close();
                        }
                        catch (Exception e)
                        {
                        }
                }
        }
        
        public void announceToAll(String text)
        {
                Broadcast.announceToOnlinePlayers(text);
        }
        
        public void announceToAll(SystemMessage sm)
        {
                Broadcast.toAllOnlinePlayers(sm);
        }
        
        public void announceToInstance(SystemMessage sm, int instanceId)
        {
                Broadcast.toPlayersInInstance(sm, instanceId);
        }
        
        // Method for handling announcements from admin
        public void handleAnnounce(String command, int lengthToTrim)
        {
                try
                {
                        // Announce string to everyone on server
                        String text = command.substring(lengthToTrim);
                        SingletonHolder._instance.announceToAll(text);
                }
                
                // No body cares!
                catch (StringIndexOutOfBoundsException e)
                {
                        // empty message.. ignore
                }
        }
        
        @SuppressWarnings("synthetic-access")
        private static class SingletonHolder
        {
                protected static final Announcements _instance = new Announcements();
        }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Lineage 2 Interlude L2OFF Server Based on H5 Files   Are you looking to start your own Lineage 2 server? This is your chance! I’m selling a 100% functional server based on Official L2OFF H5 files, adapted to the Interlude version. Main Features: Based on official L2OFF H5 files, perfectly configured for Interlude. Includes the full source code, allowing you to fully customize the server to fit your needs. Fully working events, such as: TvT (Team vs. Team) CTF (Capture the Flag) Tons of custom content added, keeping the balance and original essence of the game. Why choose this project? The server is fully functional and optimized, ready to launch. You can test the server before purchasing, with access to a GM character to explore all features. Comes with everything you need to make your project a success, both technically and in terms of content. Interested? Feel free to contact me! If you need more information or would like to schedule a test, I’m happy to answer any questions.   Auto Create Accounts Client Test Server: DOWNLOAD   Price: 600 usd Source price: send pm. Discord: Guytis#6760 Skype: gustavoorellano@hotmail.com  
    • Website: https://l2aurum.com/  Discord: https://discord.gg/l2aurum   Hello Everyone,  finally, the moment has arrived: I'm launching my own server, L2Aurum!   L2Aurum x300 Closed Beta Test - Start: 17.02.2025  [20:00 GMT+2] Grand Opening 21.02.2025 [20:00 GMT+2]     Experience Rates: x300 Skill Points Rates: x300 Adena Drop: x300 Premium Accounts: x2 Drop Rates: x1 Spoil Rates: x1 Quest Rates: x1 Only one account per player, no dualboxing allowed. Everything is earned through gameplay, no pay-to-win mechanics. No server wipes—your progress is permanent. Fair play is a priority, with no room for corruption. All players are treated equally, no special favors.     Buffs slots: 26+4, all buffs in NPC and Scheme System. Custom Armors: Aurum Apella Armor Custom Weapons: Aurum Weapon Custom Accessories: +300 P.Def & M.Def Tattoos: Mage & Fighter & Custom Shirts Custom Jewels: New Grand Bosses Auto Farm is FREE for everyone. Status Noblesse: Barakiel. Player Spawn Protection: 10 seconds. Geodata e Panthodes: ENABLED. All Commands are visible in .menu. System 2 Bishop Per Party: ENABLED. Boss Protect - Anti-Zerg: ENABLED.     Siege Duration: 2 hours (120 minutes). Siege Period: Every 7 days. Castle Reward: 100E Per Castle. Available Castles: Rune Aden Giran Giran Siege: Every Friday 20:00 GMT +2. Aden Siege: Every Saturday 20:00 GMT +2. Rune Siege: Every Sunday 20:00 GMT +2. Main Clan: 40 Members max. Royal Clan: 12 Members max. Knight Clan: 7 Members max. Alliance: You can have only 1.     Epic Boss Valakas: Monday 22:30 (GMT+2) Zaken: Tuesday | Thursday 22:30 (GMT+2) Queen Ant: Monday | Wednesday 22:30 (GMT+2) Baium: Friday 22:30 (GMT+2) Antharas: Saturday 22:30 (GMT+2) Orfen: Tuesday | Thursday | Saturday 18:30 (GMT+2) Core: Monday | Wednesday | Friday | Sunday 18:30 (GMT+2)   Raid Boss  Flame Of Splendor Barakiel Last Hit: Every Day Respawn 3-4 hours Ember: Every Day Respawn 3-4 hours Lilith: Every Day Respawn 3-4 hours Anakim: Every Day Respawn 3-4 hours Queen Shyeed: Every Day Respawn 3-4 hours Golkonda: Every Day Respawn 3-4 hours Shuriel: Every Day Respawn 3-4 hours Varka's Hero Shadith: Every Day Respawn 3-4 hours Ketra's Hero Hekaton: Every Day Respawn 3-4 hours Varka's Mos: Every Day Respawn 3-4 hours Chief Horus: Every Day Respawn 3-4 hours Ketra's Tayer: Every Day Respawn 3-4 hours Chief Brakki: Every Day Respawn 3-4 hours Sailren: Every Day Respawn 02:00   🥳🥳🥳🥳 I would like to chat personally with all of you over on our Discord and discuss any suggestions or feedback you might have.      Website: https://l2aurum.com/  Discord: https://discord.gg/l2aurum
  • Topics

×
×
  • Create New...