Hello would like help to leave the registration time every minute.
package net.sf.l2j.gameserver.model.entity.capturetheflag;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
*/publicclassCTFManager{protectedstatic final Logger _log =Logger.getLogger(CTFManager.class.getName());/** Task for event cycles<br> */privateCTFStartTask _task;/**
* New instance only by getInstance()<br>
*/publicCTFManager(){if(Config.CTF_EVENT_ENABLED){CTFEvent.init();this.scheduleEventStart();
_log.info("CTFEventEngine: Started.");}else{
_log.info("CTFEventEngine: Disabled.");}}/**
* Initialize new/Returns the one and only instance<br><br>
*
* @return CTFManager<br>
*/publicstaticCTFManager getInstance(){returnSingletonHolder._instance;}/**
* Starts CTFStartTask
*/publicvoid scheduleEventStart(){try{Calendar currentTime =Calendar.getInstance();Calendar nextStartTime = null;Calendar testStartTime = null;for(String timeOfDay :Config.CTF_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 =newCTFStartTask(nextStartTime.getTimeInMillis());ThreadPool.execute(_task);}}catch(Exception e){
_log.warning("CTFEventEngine[CTFManager.scheduleEventStart()]: Error figuring out a start time. Check CTFEventInterval in config file.");}}/**
* Method to start participation
*/publicvoid startReg(){if(!CTFEvent.startParticipation()){Broadcast.announceToOnlinePlayers("CTF Event: Event was cancelled.");
_log.warning("CTFEventEngine[CTFManager.run()]: Error spawning event npc for participation.");this.scheduleEventStart();}else{Broadcast.announceToOnlinePlayers("CTF Event: Registration opened for "+Config.CTF_EVENT_PARTICIPATION_TIME +" minute(s).",true);Broadcast.announceToOnlinePlayers("CTF Event: Joinable in "+Config.CTF_JOIN_LOCATION +".");if(Config.CTF_VOICED_COMMAND)Broadcast.announceToOnlinePlayers("CTF Event : Commands .ctfjoin .ctfleave .ctfinfo!");// schedule registration end
_task.setStartTime(System.currentTimeMillis()+60000L*Config.CTF_EVENT_PARTICIPATION_TIME);ThreadPool.execute(_task);}}/**
* Method to start the fight
*/publicvoid startEvent(){if(!CTFEvent.startFight()){Broadcast.announceToOnlinePlayers("CTF Event: Event cancelled due to lack of Participation.");
_log.info("CTFEventEngine[CTFManager.run()]: Lack of registration, abort event.");this.scheduleEventStart();}else{CTFEvent.sysMsgToAllParticipants("CTF Event: Teleporting participants to an arena in "+Config.CTF_EVENT_START_LEAVE_TELEPORT_DELAY +" second(s).");
_task.setStartTime(System.currentTimeMillis()+60000L*Config.CTF_EVENT_RUNNING_TIME);ThreadPool.execute(_task);}}/**
* Method to end the event and reward
*/publicvoid endEvent(){Broadcast.announceToOnlinePlayers(CTFEvent.calculateRewards());CTFEvent.sysMsgToAllParticipants("CTF Event: Teleporting back to the registration npc in "+Config.CTF_EVENT_START_LEAVE_TELEPORT_DELAY +" second(s).");CTFEvent.stopFight();this.scheduleEventStart();}publicvoid skipDelay(){if(_task.nextRun.cancel(false)){
_task.setStartTime(System.currentTimeMillis());ThreadPool.execute(_task);}}/**
* Class for CTF cycles
*/classCTFStartTask implements Runnable{privatelong _startTime;publicScheduledFuture<?> nextRun;publicCTFStartTask(long startTime){
_startTime = startTime;}publicvoid setStartTime(long startTime){
_startTime = startTime;}/**
* @see java.lang.Runnable#run()
*/@Overridepublicvoid 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;}elseif(delay >1800){
nextMsg = delay -1800;}elseif(delay >900){
nextMsg = delay -900;}elseif(delay >600){
nextMsg = delay -600;}elseif(delay >300){
nextMsg = delay -300;}elseif(delay >60){
nextMsg = delay -60;}elseif(delay >5){
nextMsg = delay -5;}elseif(delay >0){
nextMsg = delay;}else{// startif(CTFEvent.isInactive()){CTFManager.this.startReg();}elseif(CTFEvent.isParticipating()){CTFManager.this.startEvent();}else{CTFManager.this.endEvent();}}if(delay >0){
nextRun =ThreadPool.schedule(this, nextMsg *1000);}}privatevoid announce(long time){if(time >=3600&& time %3600==0){if(CTFEvent.isParticipating()){Broadcast.announceToOnlinePlayers("CTF Event: "+(time /60/60)+" hour(s) until registration is closed!");}elseif(CTFEvent.isStarted()){CTFEvent.sysMsgToAllParticipants("CTF Event: "+(time /60/60)+" hour(s) until event is finished!");}}elseif(time >=60){if(CTFEvent.isParticipating()){Broadcast.announceToOnlinePlayers("CTF Event: "+(time /60)+" minute(s) until registration is closed!");}elseif(CTFEvent.isStarted()){CTFEvent.sysMsgToAllParticipants("CTF Event: "+(time /60)+" minute(s) until the event is finished!");}}else{if(CTFEvent.isParticipating()){Broadcast.announceToOnlinePlayers("CTF Event: "+ time +" second(s) until registration is closed!");}elseif(CTFEvent.isStarted()){CTFEvent.sysMsgToAllParticipants("CTF Event: "+ time +" second(s) until the event is finished!");}}}}privatestaticclassSingletonHolder{protectedstatic final CTFManager _instance =newCTFManager();}}
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.
1. Optimize Packet Serialization
Look in ItemList.java or wherever the inventory packet is constructed.
Instead of building the packet with inefficient string concatenation or repeated allocations, use a preallocated buffer and avoid creating new objects for each item.
Mobius sources are Java-based, so profiling with something like VisualVM or YourKit can help see where most time is spent.
2. Avoid Sending the Full List Each Time
Modify the server to send only changed items (diff packets) when the inventory window opens.
Some newer forks implement this as “lazy loading” or paged inventory so the client only loads e.g. 100 items at a time.
3. Limit the Inventory Size Per Page
Instead of showing all 500 slots at once, split the inventory into pages/tabs (100 slots each).
When the user switches a tab, send only that page’s items.
This requires some client-side editing, but it’s the most user-friendly long-term fix.
4. Database & Cache Optimizations
Ensure your items table is indexed by owner_id to make the query for player items fast.
Cache item templates and static data so they are not reloaded every time the inventory is shown.
⚠️ Things to Keep in Mind
Increasing slots from 80 → 500 does not just change a number — it multiplies the workload for packet building and UI rendering.
You can’t fully avoid some extra cost with 500 items, but you can keep it under a few milliseconds if you optimize how and when the data is sent.
i think it's the auto sorting of the interface that sucks, check InventoryWnd script in interface.u, or completely disable the request item list packet when toggling the inventory window (also in InventoryWnd script or similar name)
Question
l2jkain
Hello would like help to leave the registration time every minute.
0 answers to this question
Recommended Posts
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.