Jump to content

Question

Posted (edited)

Hello I changed the tvt event manager tvt to announce every minute passes however the time gets a delay of 1:45 minutes to teleport the players and to go back to the village when it finishes someone help me?

 

code original :

 

 

 

 

 

 

 

 

 


/*
 * 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 net.sf.l2j.gameserver.model.entity.events.manager;

import java.util.Calendar;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;

import net.sf.l2j.Config;
import net.sf.l2j.commons.concurrent.ThreadPool;
import net.sf.l2j.gameserver.model.entity.events.TvTEvent;
import net.sf.l2j.gameserver.util.Broadcast;


/**
 * @author FBIagent
 */
public class TvTManager
{
    protected static final Logger _log = Logger.getLogger(TvTManager.class.getName());
    
    /** Task for event cycles<br> */
    private TvTStartTask _task;
    
    /**
     * New instance only by getInstance()<br>
     */
    public TvTManager()
    {
        if (Config.TVT_EVENT_ENABLED)
        {
            TvTEvent.init();
            
            this.scheduleEventStart();
            _log.info("TvTEventEngine: Started.");
        }
        else
        {
            _log.info("TvTEventEngine: Disabled.");
        }
    }
    
    /**
     * Initialize new/Returns the one and only instance<br><br>
     *
     * @return TvTManager<br>
     */
    public static TvTManager getInstance()
    {
        return SingletonHolder._instance;
    }
    
    /**
     * Starts TvTStartTask
     */
    public void scheduleEventStart()
    {
        try
        {
            Calendar currentTime = Calendar.getInstance();
            Calendar nextStartTime = null;
            Calendar testStartTime = null;
            for (String timeOfDay : Config.TVT_EVENT_INTERVAL)
            {
                // Creating a Calendar object from the specified interval value
                testStartTime = Calendar.getInstance();
                testStartTime.setLenient(true);
                String[] splitTimeOfDay = timeOfDay.split(":");
                testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
                testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
                // If the date is in the past, make it the next day (Example: Checking for "1:00", when the time is 23:57.)
                if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
                {
                    testStartTime.add(Calendar.DAY_OF_MONTH, 1);
                }
                // Check for the test date to be the minimum (smallest in the specified list)
                if (nextStartTime == null || testStartTime.getTimeInMillis() < nextStartTime.getTimeInMillis())
                {
                    nextStartTime = testStartTime;
                }
            }
            if (nextStartTime != null)
            {
                _task = new TvTStartTask(nextStartTime.getTimeInMillis());
                ThreadPool.execute(_task);
            }
        }
        catch (Exception e)
        {
            _log.warning("TvTEventEngine[TvTManager.scheduleEventStart()]: Error figuring out a start time. Check TvTEventInterval in config file.");
        }
    }
    
    /**
     * Method to start participation
     */
    public void startReg()
    {
        if (!TvTEvent.startParticipation())
        {
            Broadcast.announceToOnlinePlayers("TvT Event: Event was cancelled.");
            _log.warning("TvTEventEngine[TvTManager.run()]: Error spawning event npc for participation.");
            
            this.scheduleEventStart();
        }
        else
        {
            Broadcast.announceToOnlinePlayers("TvT Event: Registration opened for " + Config.TVT_EVENT_PARTICIPATION_TIME
                    + " minute(s). Type .tvtjoin or .tvtleave, .tvtinfo", true);
            
            // schedule registration end
            _task.setStartTime(System.currentTimeMillis() + 60000L * Config.TVT_EVENT_PARTICIPATION_TIME);
            ThreadPool.execute(_task);
        }
    }
    
    /**
     * Method to start the fight
     */
    public void startEvent()
    {
        if (!TvTEvent.startFight())
        {
            Broadcast.announceToOnlinePlayers("TvT Event: Event cancelled due to lack of Participation.");
            _log.info("TvTEventEngine[TvTManager.run()]: Lack of registration, abort event.");
            
            this.scheduleEventStart();
        }
        else
        {
            TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting participants to an arena in "
                    + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
            _task.setStartTime(System.currentTimeMillis() + 60000L * Config.TVT_EVENT_RUNNING_TIME);
            ThreadPool.execute(_task);
        }
    }
    
    /**
     * Method to end the event and reward
     */
    public void endEvent()
    {
        Broadcast.announceToOnlinePlayers(TvTEvent.calculateRewards());
        TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting back to the registration npc in "
                + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
        TvTEvent.stopFight();
        
        this.scheduleEventStart();
    }
    
    public void skipDelay()
    {
        if (_task.nextRun.cancel(false))
        {
            _task.setStartTime(System.currentTimeMillis());
            ThreadPool.execute(_task);
        }
    }
    
    /**
     * Class for TvT cycles
     */
    class TvTStartTask implements Runnable
    {
        private long _startTime;
        public ScheduledFuture<?> nextRun;
        
        public TvTStartTask(long startTime)
        {
            _startTime = startTime;
        }
        
        public void setStartTime(long startTime)
        {
            _startTime = startTime;
        }
        
        /**
         * @see java.lang.Runnable#run()
         */
        @Override
        public void run()
        {
            int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0);
            
            if (delay > 0)
            {
                this.announce(delay);
            }
            
            int nextMsg = 0;
            if (delay > 3600)
            {
                nextMsg = delay - 3600;
            }
            else if (delay > 1800)
            {
                nextMsg = delay - 1800;
            }
            else if (delay > 900)
            {
                nextMsg = delay - 900;
            }
            else if (delay > 600)
            {
                nextMsg = delay - 600;
            }
            else if (delay > 300)
            {
                nextMsg = delay - 300;
            }
            else if (delay > 60)
            {
                nextMsg = delay - 60;
            }
            else if (delay > 5)
            {
                nextMsg = delay - 5;
            }
            else if (delay > 0)
            {
                nextMsg = delay;
            }
            else
            {
                // start
                if (TvTEvent.isInactive())
                {
                    TvTManager.this.startReg();
                }
                else if (TvTEvent.isParticipating())
                {
                    TvTManager.this.startEvent();
                }
                else
                {
                    TvTManager.this.endEvent();
                }
            }
            
            if (delay > 0)
            {
                nextRun = ThreadPool.schedule(this, nextMsg * 1000);
            }
        }
        
        private void announce(long time)
        {
            if (time >= 3600 && time % 3600 == 0)
            {
                if (TvTEvent.isParticipating())
                {
                    Broadcast.announceToOnlinePlayers("TvT Event: " + (time / 60 / 60) + " hour(s) until registration is closed!");
                }
                else if (TvTEvent.isStarted())
                {
                    TvTEvent.sysMsgToAllParticipants("TvT Event: " + (time / 60 / 60) + " hour(s) until event is finished!");
                }
            }
            else if (time >= 60)
            {
                if (TvTEvent.isParticipating())
                {
                    Broadcast.announceToOnlinePlayers("TvT Event: " + (time / 60) + " minute(s) until registration is closed!");
                }
                else if (TvTEvent.isStarted())
                {
                    TvTEvent.sysMsgToAllParticipants("TvT Event: " + (time / 60) + " minute(s) until the event is finished!");
                }
            }
            else
            {
                if (TvTEvent.isParticipating())
                {
                    Broadcast.announceToOnlinePlayers("TvT Event: " + time + " second(s) until registration is closed!");
                }
                else if (TvTEvent.isStarted())
                {
                    TvTEvent.sysMsgToAllParticipants("TvT Event: " + time + " second(s) until the event is finished!");
                }
            }
        }
    }

    private static class SingletonHolder
    {
        protected static final TvTManager _instance = new TvTManager();
    }
}

 

 

Code modified



 

/*  * 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 net.sf.l2j.gameserver.model.entity.engine.tvt; import java.util.Calendar; import java.util.concurrent.ScheduledFuture; import java.util.logging.Logger; import net.sf.l2j.Config; import net.sf.l2j.commons.concurrent.ThreadPool; import net.sf.l2j.gameserver.util.Broadcast; /**  * @author FBIagent  */ public class TvTManager {     protected static final Logger _log = Logger.getLogger(TvTManager.class.getName());          /** Task for event cycles<br> */     private TvTStartTask _task;          /**      * New instance only by getInstance()<br>      */     public TvTManager()     {         if (Config.TVT_EVENT_ENABLED)         {             TvTEvent.init();                          this.scheduleEventStart();             _log.info("TvTEventEngine: Started.");         }         else             _log.info("TvTEventEngine: Disabled.");     }          /**      * Initialize new/Returns the one and only instance<br><br>      *      * @return TvTManager<br>      */     public static TvTManager getInstance()     {         return SingletonHolder._instance;     }          /**      * Starts TvTStartTask      */     public void scheduleEventStart()     {         try         {             Calendar currentTime = Calendar.getInstance();             Calendar nextStartTime = null;             Calendar testStartTime = null;             for (String timeOfDay : Config.TVT_EVENT_INTERVAL)             {                 // Creating a Calendar object from the specified interval value                 testStartTime = Calendar.getInstance();                 testStartTime.setLenient(true);                 String[] splitTimeOfDay = timeOfDay.split(":");                 testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));                 testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));                                  // If the date is in the past, make it the next day (Example: Checking for "1:00", when the time is 23:57.)                 if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())                     testStartTime.add(Calendar.DAY_OF_MONTH, 1);                                  // Check for the test date to be the minimum (smallest in the specified list)                 if (nextStartTime == null || testStartTime.getTimeInMillis() < nextStartTime.getTimeInMillis())                     nextStartTime = testStartTime;             }             if (nextStartTime != null)             {                 _task = new TvTStartTask(nextStartTime.getTimeInMillis());                 ThreadPool.execute(_task);             }         }         catch (Exception e)         {             _log.warning("TvTEventEngine[TvTManager.scheduleEventStart()]: Error figuring out a start time. Check TvTEventInterval in config file.");         }     }          /**      * Method to start participation      */     public void startReg()     {         if (!TvTEvent.startParticipation())         {             Broadcast.announceToOnlinePlayers("TvT Event: Event was cancelled.");             _log.warning("TvTEventEngine[TvTManager.run()]: Error spawning event npc for participation.");                          this.scheduleEventStart();         }         else         {             Broadcast.announceToOnlinePlayers("TvT Event: Registration opened for " + Config.TVT_EVENT_PARTICIPATION_TIME                 + " minute(s). Type .tvtjoin or .tvtleave, .tvtinfo", true);                          // schedule registration end             _task.setStartTime(System.currentTimeMillis() + 60000L * Config.TVT_EVENT_PARTICIPATION_TIME);             ThreadPool.execute(_task);         }     }          /**      * Method to start the fight      */     public void startEvent()     {         if (!TvTEvent.startFight())         {             Broadcast.announceToOnlinePlayers("TvT Event: Event cancelled due to lack of Participation.");             _log.info("TvTEventEngine[TvTManager.run()]: Lack of registration, abort event.");                          this.scheduleEventStart();         }         else         {             TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting participants to an arena in "                 + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");             _task.setStartTime(System.currentTimeMillis() + 60000L * Config.TVT_EVENT_RUNNING_TIME);             ThreadPool.execute(_task);         }     }          /**      * Method to end the event and reward      */     public void endEvent()     {         Broadcast.announceToOnlinePlayers(TvTEvent.calculateRewards());         TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting back to the registration npc in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");         TvTEvent.stopFight();                  this.scheduleEventStart();     }          public void skipDelay()     {         if (_task.nextRun.cancel(false))         {             _task.setStartTime(System.currentTimeMillis());             ThreadPool.execute(_task);         }     }          /**      * Class for TvT cycles      */     class TvTStartTask implements Runnable     {         private long _startTime;         public ScheduledFuture<?> nextRun;                  public TvTStartTask(long startTime)         {             _startTime = startTime;         }                  public void setStartTime(long startTime)         {             _startTime = startTime;         }                  /**          * @see java.lang.Runnable#run()          */         @Override         public void run()         {             int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0);                          if (delay > 0)                 this.announce(delay);                          int nextMsg = 0;             if (delay > 3600)                 nextMsg = delay - 3600;             else if (delay > 1800)                 nextMsg = delay - 1800;             else if (delay > 900)                 nextMsg = delay - 900;             else if (delay > 600)                 nextMsg = delay - 600;             else if (delay > 300)                 nextMsg = delay - 300;             else if (delay > 60)                 nextMsg = delay - 60;             else if (delay > 5)                 nextMsg = delay - 5;             else if (delay > 0)                 nextMsg = delay;             else             {                 // start                 if (TvTEvent.isInactive())                     TvTManager.this.startReg();                 else if (TvTEvent.isParticipating())                     TvTManager.this.startEvent();                 else                     TvTManager.this.endEvent();             }                          if (delay > 0)                 nextRun = ThreadPool.schedule(this, nextMsg * 1000);         }                  private void announce(int seconds)         {             while (seconds > 1)             {                 seconds--; // here because we don't want to see two time announce at the same time                                  if (TvTEvent.isParticipating() || TvTEvent.isStarted())                 {                     switch (seconds)                     {                         case 3600: // 1 hour left                                                          if (TvTEvent.isParticipating())                                 Broadcast.announceToOnlinePlayers("TVT: " + seconds / 60 / 60 + " hour(s) umtil registration is closed!", true);                             else if (TvTEvent.isStarted())                                 TvTEvent.sysMsgToAllParticipants("TVT: " + seconds / 60 / 60 + " hour(s) until event is finished!");                                                          break;                         case 1800: // 30 minutes left                         case 900: // 15 minutes left                         case 600: // 10 minutes left                         case 300: // 5 minutes left                         case 240: // 4 minutes left                         case 180: // 3 minutes left                         case 120: // 2 minutes left                         case 60: // 1 minute left                                                          if (TvTEvent.isParticipating())                                 Broadcast.announceToOnlinePlayers("TVT: " + seconds / 60 + " minute(s) until registration is closed!", true);                             else if (TvTEvent.isStarted())                                 TvTEvent.sysMsgToAllParticipants("TVT: " + seconds / 60 + " minute(s) until the event is finished!");                                                          break;                         case 30: // 30 seconds left                         case 15: // 15 seconds left                          case 10: // 10 seconds left                         case 5: // 5 seconds left                                                     case 4: // 4 seconds left                          case 3: // 3 seconds left                          case 2: // 2 seconds left                          case 1: // 1 seconds left                                                          if (TvTEvent.isParticipating())                                 Broadcast.announceToOnlinePlayers("TVT: " + seconds + " second(s) until registration is closed!", true);                             else if (TvTEvent.isStarted())                                 TvTEvent.sysMsgToAllParticipants("TVT: " + seconds + " second(s) until the event is finished!");                                                          break;                     }                 }                 TvTEvent.waiter(1);             }         }     }          private static class SingletonHolder     {         protected static final TvTManager _instance = new TvTManager();     } }

Edited by l2jkain

1 answer to this question

Recommended Posts

Guest
This topic is now closed to further replies.


  • Posts

    • Offtopic, personal attacks, probably too old to use that much memes and what's YOUR actual contribution to L2J, in order I laugh aswell ?   The main poster quotes my pack so I answer accordingly, while you advertise L2JFrozen in both of your posts - discontinued since 2011, with none taking back the open source lead while anyone could.   If you're somewhat affiliated to hopzone, you probably packed way more money than me. Packs don't make any type of money (barely 100e/month) and if you would follow me, you would know there are ways to handle it or even getting paid.   Hope I was short enough, 🧂🤡.
    • Hi guys, this is a CMS im sharing for lineage 2 servers, im tired of the crap i see on new release servers. Dont let me start on the IA developed ones lmao.   📋 Description Free and open source template to create landing pages for Lineage 2 private servers. Designed with a dark fantasy theme and modern animations. ✨ Current Features This FREE version includes: Complete Landing Page - Professional design ready to use Multi-language Support - Spanish, English, Portuguese Dark Fantasy Theme - With animated UI elements Server Information - Rates, features, and rules Olympiad Ranking - Rankings display Download Section - For game client Skins and Animations Gallery Streaming Widget - Twitch/Kick integration Fully Customizable - Via configuration files ❌ Not Included in Free Version ❌ User Registration System ❌ Online Players Counter ❌ Donation Panel 💎 Premium Integrations IntegrationPrice Registration System $50 USD Online Players Counter $50 USD Donation Panel $50 USD   📧 Contact: https://gh0tstudio.com 🛠️ Tech Stack Technology    Version    Description React              19.2.0       UI Library TypeScript       5.8.2        Static typing Vite                 6.2.0         Build tool TailwindCSS   CDNCSS    Framework Lucide React   0.554.0         Icons i18next           23.16.0       Internationalization react-i18next   15.1.0        React bindings for i18n All documentation provided for AI AGENTS to make changes on the ui texts and so on. u can have a look on the cms fully working with donation panel, online count and register via: https://crmlineage2.vercel.app/ https://github.com/6h0T/CRM-LINEAGE2-FREE If u are in the lookings to develop a unique website for ur projects, u can dm me or contact me throw my socials on my profile. all code has encrypted references so any type of rebranding, copying or selling without authorization will result in take downs
    • Hello dude, i can help u out, i reached to u via DM, my studio is https://gh0tstudio.com i have worked with almost 40 brands on developing Private Lineage and Mu online servers, dashboard for vote pages and more. I sent u some examples too
    • L2 TARTARUS - HTML DESIGN       L2 KOMBAT - ANIMATED BORDER   L2 SERENITY - ANIMATED LOGO   L2 ARCANE - COMMUNITY BOARD     L2 AMERIKA - ADVERTISING BANNER   L2 ZERON - ADVERTISING BANNER  
    • SOCNET — 生日快乐! 感谢您一直陪伴我们! 为期一周的礼物、奖励和折扣盛宴! 今天我们庆祝SOCNET项目的生日——而礼物属于您! 我们为所有服务准备了超强优惠: ⭐ SOCNET STORE — 商店 (网站/Telegram) 1. 优惠码BIRTHDAY — 20%折扣 可用于购买任何商品! 2. 大额购买礼品 在任意商品上消费$200,即可任选一件价值不超过$10的商品——免费赠送! 3. 在我们商店主题帖中发表评论可获赠余额 "Happy Birthday, SOCNET. My username/email is":BHW、BFD、voided、nulled 和 patched 论坛。 ➡ 1个论坛 = $1余额! 通过下方提供的联系方式将帖子截图发送给客服,附上您的登录名/邮箱,即可领取奖励。 ⭐ SOCNET SMM 面板 1. 充值 = 奖励 充值$100并获得+$5余额。 充值后请在面板内创建工单。 2. 在我们的 SMM 面板主题帖中发表评论可获赠余额 "Happy Birthday, SOCNET. My username/email is":BHW、BFD、voided、nulled 和 patched 论坛。 ➡ 1个论坛 = $1余额! 通过下方提供的联系方式将帖子截图发送给客服,附上您的登录名/邮箱,即可领取奖励。 ⭐SOCNET STARS — Telegram Stars/Premium 购买机器人 1. 大额购买 = 巨额奖励 单笔购买>1000 Stars,即可获赠+100 Stars! 购买后请联系支持。 2. 在我们 Stars 购买机器人的主题帖中发表评论可获赠余额 "Happy Birthday, SOCNET. My username/email is":BHW、BFD、voided、nulled 和 patched 论坛。 发表评论: ➡ 1个论坛 = +50 Stars余额! 通过下方提供的联系方式将帖子截图发送给客服,附上您的登录名/邮箱,即可领取奖励。 ⭐SOCNET SMS 虚拟号码服务 1. 充值赠送奖励 充值$50即可获赠+$10。 充值后只需联系支持即可。 2. 在我们的 SMS 服务主题帖中发表评论可获赠余额 "Happy Birthday, SOCNET. My username/email is":BHW、BFD、voided、nulled 和 patched 论坛。 ➡ 1个论坛 = $1余额! 通过下方提供的联系方式将帖子截图发送给客服,附上您的登录名/邮箱,即可领取奖励。 让我们一起庆祝吧! 活动有效期为2025年12月02日至12月07日(含)。 不要错过——这是全年最优惠的条件! 新闻: ➡ Telegram 频道: https://t.me/accsforyou_shop ➡ WhatsApp 频道: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord 服务器: https://discord.gg/y9AStFFsrh 联系方式 & 支持: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock