Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Share
    avatar
    jamaica

    Posts : 135
    Join date : 2013-02-24
    Age : 28
    Location : Romania

    Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  jamaica on 18th August 2013, 12:29

    Code:
    Index: data/autoannouncement.txt
    ===================================================================
    --- data/autoannouncement.txt   (revision 0)
    +++ data/autoannouncement.txt   (revision 0)
    @@ -0,0 +1,4 @@
    +First autoannounce.
    +Second autoannounce.
    +Third autoannounce.
    +Fourth autoannounce.
    \ No newline at end of file
    Index: java/config/General.properties
    ===================================================================
    --- java/config/General.properties   (revision 2909)
    +++ java/config/General.properties   (working copy)
    @@ -135,7 +135,12 @@
     # Default: False
     RestartOnDeadlock = False
     
    +# Auto Aannounce Cycle Time
    +# interval is in Minutes.
    +# Default: 20
    +AutoAannounceCycleTime = 20
     
    +
     # ---------------------------------------------------------------------------
     # Optimization
     # ---------------------------------------------------------------------------
    Index: java/net/sf/l2j/Config.java
    ===================================================================
    --- java/net/sf/l2j/Config.java   (revision 2909)
    +++ java/net/sf/l2j/Config.java   (working copy)
    @@ -352,6 +352,7 @@
        public static boolean DEADLOCK_DETECTOR;
        public static int DEADLOCK_CHECK_INTERVAL;
        public static boolean RESTART_ON_DEADLOCK;
    +   public static int AUTO_ANNOUNCE_TIME;
        public static int FLOODPROTECTOR_INITIALSIZE;
        public static boolean ALLOW_DISCARDITEM;
        public static int AUTODESTROY_ITEM_AFTER;
    @@ -1319,6 +1320,7 @@
                    DEADLOCK_DETECTOR = Boolean.parseBoolean(General.getProperty("DeadLockDetector", "False"));
                    DEADLOCK_CHECK_INTERVAL = Integer.parseInt(General.getProperty("DeadLockCheckInterval", "20"));
                    RESTART_ON_DEADLOCK = Boolean.parseBoolean(General.getProperty("RestartOnDeadlock", "False"));
    +               AUTO_ANNOUNCE_TIME = Integer.parseInt(General.getProperty("AutoAannounceCycleTime", "20"));
                    FLOODPROTECTOR_INITIALSIZE = Integer.parseInt(General.getProperty("FloodProtectorInitialSize", "50"));
                    ALLOW_DISCARDITEM = Boolean.parseBoolean(General.getProperty("AllowDiscardItem", "True"));
                    AUTODESTROY_ITEM_AFTER = Integer.parseInt(General.getProperty("AutoDestroyDroppedItemAfter", "0"));
    Index: java/net/sf/l2j/gameserver/taskmanager/AutoAnnounceTaskManager.java
    ===================================================================
    --- java/net/sf/l2j/gameserver/taskmanager/AutoAnnounceTaskManager.java   (revision 2909)
    +++ java/net/sf/l2j/gameserver/taskmanager/AutoAnnounceTaskManager.java   (working copy)
    @@ -12,27 +12,30 @@
      */
     package net.sf.l2j.gameserver.taskmanager;
     
    -import java.sql.PreparedStatement;
    -import java.sql.ResultSet;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.io.LineNumberReader;
     import java.util.List;
    +import java.util.StringTokenizer;
     import java.util.logging.Level;
     import java.util.logging.Logger;
     
     import javolution.util.FastList;
    -import net.sf.l2j.L2DatabaseFactory;
    +import net.sf.l2j.Config;
     import net.sf.l2j.gameserver.ThreadPoolManager;
     import net.sf.l2j.gameserver.util.Broadcast;
     
     /**
      *
    - * @author nBd
    + * @author L2JGAME m121752332 2009/04/12 rewrite
      */
     public class AutoAnnounceTaskManager
     {
        protected static final Logger _log = Logger.getLogger(AutoAnnounceTaskManager.class.getName());
    -   
        private static AutoAnnounceTaskManager _instance;
    -   protected List<AutoAnnouncement> _announces = new FastList<AutoAnnouncement>();
    +    protected List<String> _AutoAnnouncement = new FastList<String>();
    +    protected int _AutoAnnouncementSize = 0;
        
        public static AutoAnnounceTaskManager getInstance()
        {
    @@ -41,85 +44,93 @@
           
           return _instance;
        }
    -   
    +   
        public AutoAnnounceTaskManager()
        {
    -      restore();
    +      loadAutoAnnouncement();
        }
        
    -   public void restore()
    +   class AnnouncTask implements Runnable
        {
    -      if (!_announces.isEmpty())
    -      {
    -         for (AutoAnnouncement a : _announces)
    -            a.stopAnnounce();
    -         
    -         _announces.clear();
    -      }
    -      
    -      java.sql.Connection conn = null;
    -      int count = 0;
    -      try
    -      {
    -         conn = L2DatabaseFactory.getInstance().getConnection();
    -         PreparedStatement statement = conn.prepareStatement("SELECT id, initial, delay, cycle, memo FROM auto_announcements");
    -         ResultSet data = statement.executeQuery();
    -         while(data.next())
    +      public void run()
    +      {      
    +         try
              {
    -            int id = data.getInt("id");
    -            long initial = data.getLong("initial");
    -            long delay = data.getLong("delay");
    -            int repeat = data.getInt("cycle");
    -            String memo = data.getString("memo");
    -            String[] text = memo.split("/n");
    -            ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(id, delay, repeat, text), initial);
    -            count++;
    +            showAutoAnnouncement(_AutoAnnouncement.get(_AutoAnnouncementSize));//AutoAnnounce announce
    +            _AutoAnnouncementSize++;
    +            if( _AutoAnnouncementSize >= _AutoAnnouncement.size()) //Return to first AutoAnnounce
    +               _AutoAnnouncementSize = 0;
              }
    +         catch (Exception e)
    +         {
    +            _log.log(Level.WARNING, "", e);
    +         }
           }
    -      catch (Exception e)
    +   }
    +   
    +   public void doAutoAnnouncement()
    +   {
    +      AnnouncTask rs = new AnnouncTask();//Create thread
    +      ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(rs, 60000, Config.AUTO_ANNOUNCE_TIME * 60000);
    +   }
    +   
    +   public void loadAutoAnnouncement()//Load AutoAnnouncement file
    +   {
    +      _AutoAnnouncement.clear();
    +      File file = new File(Config.DATAPACK_ROOT, "data/autoannouncement.txt");
    +      if (file.exists())
           {
    -         _log.log(Level.SEVERE, "AutoAnnoucements: Fail to load announcements data.", e);
    +         readFromDiskmulti(file);
    +         doAutoAnnouncement();//If so, load the file that is the beginning of the operation of the auto announcement thread
           }
    -      _log.log(Level.SEVERE, "AutoAnnoucements: Load "+count+" Auto Annoucement Data.");
    +      else
    +      {
    +         _log.config("AutoAnnoucements: data/autoannouncement.txt doesn't exist");
    +      }
        }
        
    -   private class AutoAnnouncement implements Runnable
    +   public void showAutoAnnouncement(String str)
        {
    -      private int _id;
    -      private long _delay;
    -      private int _repeat = -1;
    -      private String[] _memo;
    -      private boolean _stopped = false;
    -      
    -      public AutoAnnouncement(int id, long delay, int repeat, String[] memo)
    +      Broadcast.announceToOnlinePlayers(str);
    +      System.out.println("AutoAnnounce: "+str);
    +   }
    +
    +   private void readFromDiskmulti(File file)
    +   {
    +      LineNumberReader lnr = null;
    +      try
           {
    -         _id = id;
    -         _delay = delay;
    -         _repeat = repeat;
    -         _memo = memo;
    -         if (!_announces.contains(this))
    -            _announces.add(this);
    +         int i=0;
    +         String line = null;
    +         lnr = new LineNumberReader(new FileReader(file));
    +         while ( (line = lnr.readLine()) != null)
    +         {
    +            StringTokenizer st = new StringTokenizer(line,"\n\r");
    +            if (st.hasMoreTokens())
    +            {   
    +               String announcement = st.nextToken();
    +               _AutoAnnouncement.add(announcement);
    +               _log.warning("AutoAnnounce: " + announcement);
    +               i++;
    +            }
    +         }
    +         
    +         _log.config("AutoAnnoucements: Loaded " + i + " Auto Annoucement Data.");
           }
    -      
    -      public void stopAnnounce()
    +      catch (IOException e1)
           {
    -         _stopped = true;
    +         _log.log(Level.SEVERE, "AutoAnnoucements: Fail to load announcements data.", e1);
           }
    -      
    -      public void run()
    +      finally
           {
    -         for (String text : _memo)
    +         try
              {
    -            announce(text);
    +            lnr.close();
              }
    -         if (!_stopped && _repeat > 0)
    -            ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(_id, _delay, _repeat--, _memo), _delay);
    +         catch (Exception e2)
    +         {
    +            // nothing
    +         }
           }
        }
    -   
    -   public void announce(String text)
    -   {
    -      Broadcast.announceToOnlinePlayers(text);
    -      _log.warning("AutoAnnounce: " + text);
    -   }
     }
    \ No newline at end of file

    DnR
    Admin
    Admin

    Posts : 985
    Join date : 2012-12-03

    Re: Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  DnR on 19th August 2013, 17:34

    They will. It's an important feature for private servers.
    But this code is buggy, with limited functions. L2J has shared something more advanced.
    avatar
    jamaica

    Posts : 135
    Join date : 2013-02-24
    Age : 28
    Location : Romania

    Re: Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  jamaica on 19th August 2013, 20:38

    i`m not a pro in java code , everything i know is what ive learn by my self Very Happy so im tring to stand this project how much i can

    DnR
    Admin
    Admin

    Posts : 985
    Join date : 2012-12-03

    Re: Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  DnR on 19th August 2013, 21:38

    jamaica wrote:i`m not a pro in java code , everything i know is what ive learn by my self :Dso im tring to stand this project how much i can
    I never had the intention of offending you. I just explained why this code would not be commited.
    I knew how to fix it, but still you wouldn't be able to add delay for each announcement seperately (which is a limitation), due to the way it's written.
    Yet, your suggestion is really precious to me.

    Auto Announcement system added. Thanks a lot. Smile
    avatar
    jamaica

    Posts : 135
    Join date : 2013-02-24
    Age : 28
    Location : Romania

    Re: Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  jamaica on 20th August 2013, 10:04

    hey i didnt get offended chill out :d im just explainin` Razz together we will do a good project and in time maybe u will commit some other custom mods seted false by default like pvp color manager protection against pk between levels , some minor stuffs who can help community somehow...anyways...ty for givin attention and taking care svn, u rule ^.^

    Sponsored content

    Re: Usefull thing for retail server AutoAnnounces (hope is going to be commited)

    Post  Sponsored content


      Current date/time is 23rd July 2017, 11:43