Jump to content

Recommended Posts

Posted

Hello people!

 

I know that Ass4s1n has already made a guide for Task Managers, but I want to explain it even more because at his share there were complains..

So allow me to show you!

I will make a simple code and explain every step.

 

 

You can skip that Step.

We always start with the GNU License (No reason actually, but its cool xD).

/*
* 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/>.
*/

 

Now lets define the package.

As we are working on Tasks, the package has to be this:

package com.l2jserver.gameserver.taskmanager.tasks;

 

If you're using Interlude or other projects than L2JServer, you just need to fic those:

com.l2jserver

 

with

 

net.sf.l2j

 

Etcetera..

 

Now we have two options:

1) We can first add the imports that we will use, if we are sure about what we will make

2) We can start writing the code and leave the imports for later, to be added as quickfixes.

 

I personally prefer to start writing the code immediately, so in case I need to add something extra, I will not have to worry!

 

The only imports that you will need for sure are those:

import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;

 

Let's continue.

 

You can skip that Step.

Now let's add the author's name (your name if you are the creator) just to be respected by the ones that will use the code, or simply to keep your credits.

So, we will make something like:

 

/**
* 
* @author YourNameHere
*/

 

In my case, for example, it will be like:

/**
* 
* @author SoFaKi
*/

 


 

OK, now we will start with the main thingy! The code.

 

Let's start as we always start:

public class TaskNameHere extends Task
{

 

It's a public class (you have to replace the TaskNameHere with you class's name) which extends the Task class.

 

Now let's talk about the Logger, since we may need it for catching exceptions below (we will :D).

 

So write something like

private static final Logger _log = Logger.getLogger(TaskNameHere.class.getName());

 

But now, you will have to import it either manually, or by the quickfix.

So the import you have to add below is that:

import java.util.logging.Logger;

 

NOTE! L2JServer is using the random java logger, however other projects like L2jFree have advanced their commons one, so it will be kinda different at its use. Don't worry, the difference is not big!!

 

OK, after this we will need to add one more code:

public static final String NAME = "your_string";

 

This string defines something like.. The use of the code.

For example, at the TaskSevenSignsUpdate.java class, that String is this:

 

public static final String NAME = "seven_signs_update";

 

I hope you can understand everything until now :)

 

Let's continue now, by setting the name.

What do I mean? Check out:

 

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#getName()
 */
@Override
public String getName()
{
	return NAME;
}

 

Here, we see the Task class (where we will register that task later) and return THIS task's name.

The NAME is the one we defined above as a string (public static final String NAME = "your_string";).

 

Add this, as the next step:

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
 */
@Override
public void onTimeElapsed(ExecutedTask task)
{
	try
	{	
		//your action
	}
	catch (Exception e)
	{
		_log.warning("Error X : " + e);
	}
}

 

Here is the MAIN part, imo.

At this part, we define which will be the use of the task - important, don't you agree?

 

The public void "onTimeElapsed" defines the use of the code, after the proper time (we will set it below) has passed, and it's time to use the code. And in this, we set the use.

 

The use of the task is at the "try".

Here you will set your own stuff.

And I have set it to catch an exception, in case something goes wrong..

 

Note that you can make it normally, without setting any tries, or so, but it depends on what you want to do. For example, the TaskOlympiadSave class, is setting the task's use like that:

if (Olympiad.getInstance().inCompPeriod())
	{
		Olympiad.getInstance().saveOlympiadStatus();
		_log.info("Olympiad System: Data updated.");
	}

 

I suppose you can understand me.

 

And we are almost done.

Now, we must define how much time will be needed to execute the task.

We will define it in this way:

 

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#initializate()
 */
@Override
public void initializate()
{
	super.initializate();
	TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "60000", "60000", "");
}

 

As you can see, we use the NAME (we set it above) and the TaskType set as sheduled task.

Take care of the time though: Those numbers aren't minutes, but miliseconds!

What does that mean? For example, 1 minute is 60000 miliseconds! So be careful: Don't use too small values but also don't use too high ones! First calculate them!

 

And this is how we end the class!

Our task is now ready (considering that you have set a use for the task)!

Let's see how did the code become:

/*
* 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.taskmanager.tasks;

import java.util.logging.Logger;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;

/**
* 
* @author YourNameHere
*/

public class TaskNameHere extends Task
{
private static final Logger _log = Logger.getLogger(TaskNameHere.class.getName());
public static final String NAME = "your_string";

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#getName()
 */
@Override
public String getName()
{
	return NAME;
}

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
 */
@Override
public void onTimeElapsed(ExecutedTask task)
{
	try
	{	
		//your action
	}
	catch (Exception e)
	{
		_log.warning("Error X : " + e);
	}
}

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#initializate()
 */
@Override
public void initializate()
{
	super.initializate();
	TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "60000", "60000", "");
}
}

 

Yes, this is the code :)

Now, let's finish by registering the task.

If you have previously worked with Handlers, you may understand what we are going to talk about.

 

Let's go to the file TaskManager.java to set the task which will be initializated.

Let me explain just a few things about the TaskManager class, before continuing.

In this class, the tasks are getting imported into the global_tasks sql file, to be executed from there properly. It is auto, that's why you don't have to touch anything. This is the main use and that's why it's called "Manager".

 

Anyway, let's now find that line:

private void initializate()

 

Below, you just have to set the task to be initializated.

So, under that:

registerTask(new TaskShutdown());

 

Add that line:

registerTask(new TaskNameHere());

 

Don't forget to import your task's class!!

And ofc don't forget to replace the "TaskNameHere" with your class's name.

 

 


 

 

That's all with the guide!!

I explained it as well as I good, so that newbies can understand it!

I know that I didn't give a professional explanation, since I am not a professional, but I hope that people can understand it :)

 

Let me give you the class of a Task that I made, just to give a nice example.

/*
* 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.taskmanager.tasks;

import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;

/**
* 
* @author Sofia
*/

public class TaskFactionOnline extends Task
{
private static final Logger _log = Logger.getLogger(TaskFactionOnline.class.getName());
public static final String NAME = "your_string";

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#getName()
 */
@Override
public String getName()
{
	return NAME;
}

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
 */
@Override
public void onTimeElapsed(ExecutedTask task)
{
	try
	{	
		Announcements.getInstance().announceToAll(Config.FACTION_TEAM1_NAME + " " + L2World.getInstance().getAllTeam1PlayersCount() + " || " + Config.FACTION_TEAM2_NAME + " " + L2World.getInstance().getAllTeam2PlayersCount() + " || " + Config.FACTION_TEAM3_NAME + " " + L2World.getInstance().getAllTeam3PlayersCount());
	}
	catch (Exception e)
	{
		_log.warning("Faction Engine: There was an error while trying to execute the TaskFactionOnline Task. Please fix it! " + e);
	}
}

/**
 * 
 * @see com.l2jserver.gameserver.taskmanager.Task#initializate()
 */
@Override
public void initializate()
{
	super.initializate();
	TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "60000", "60000", "");
}
}

 

What we see here?

This is a code related to this Faction Engine!!

What happens? Well, an announcement appears every time the task is executed, which shows the online ammount of Neutral, Devs and Cheaters Factions!

And ofc it needs a registeration, as every task.

 

Note that here we used extra imports, because of the different use!

To be more exact:

import com.l2jserver.Config;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.model.L2World;

 

 


 

 

That's all ppl!

Thanks for reading my guide!!

See you soon!!

 

Credits: SoFaKi aka Kokkinoula

Thanks to Ass4s1n for the inspiration!!

Posted

WoW Sofi!

You are sharing awesome things last days!

Sonthis is why i will give you a little reward!

+1karma from me...for all your good works!

Keep it like this please!

 

You are not allowed to give a karma reward, for a competition topic >_>

She will get rewarded in the end, if she deserves it!

Posted

WoW Sofi!

You are sharing awesome things last days!

Sonthis is why i will give you a little reward!

+1karma from me...for all your good works!

Keep it like this please!

You are not allowed to get karma for your share. You will be rewarded in the end, if you win. (NOTE: If somebody rewards you with karma, please report it in order for us to fix it.)

 

Since it's for competision i have to smite her

Posted

[OFFTOPIC]

Did any1 who comment the guide of Setekh read it all :s???

you ment sofaki ?!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Παίρνουμε μια δόση ντοπαμίνης και ξανά γυρνάμε στις ρουτίνες μας!
    • Σαγαπω απλά έκλαψα !🤣🤣
    • https://t.me/l2fungame   You can find updates on our project in our Telegram channel.  
    • L2 Pearl — Fresh Interlude Lineage 2 Server L2 Pearl is a fresh Interlude Lineage 2 server focused on fair progression, competitive PvP and long-term gameplay. Every player starts from zero, with a clean economy, balanced progression and a strong focus on active community and clan gameplay. Server Timeline Account Creation: 29 September 2026 Open Beta: 2 October 2026 Grand Opening: 9 October 2026 First Seal Validation: 23 October 2026 First Mammon Appearance: 23 October 2026 First Olympiad Match: 23 October 2026 Mammon A-Grade Services: 24–25 October 2026 First Castle Siege: 25 October 2026 Open Beta progress will be wiped before the official launch. Main Features Interlude Chronicle with Classic GUI XP / SP x5 Adena x3 General Drop x2 Spoil x3 Key Materials and Recipes x2 Quest Item Drop x2 Maximum Level 80 Up to 3 Subclasses Offline Shops Full Geodata with Pathnodes Events available from Level 20 One box per PC Two boxes with VIP .menu System The .menu command gives players quick access to useful quality-of-life features: Block unwanted buffs Block system messages Delevel your character Set up and manage an offline shop Enable automatic HP potions Enable automatic CP potions Configure personal gameplay preferences The system is designed to make everyday gameplay easier while keeping the classic Interlude experience intact. Events and Rewards Events are available from Level 20 and include: Team vs Team Capture the Flag Deathmatch Special Live Events Players will receive full buffs during events, allowing everyone to focus on teamwork and PvP. By participating in events, players can earn Glittering Medals and exchange them for event-related rewards. Rates and Economy XP / SP: x5 Adena: x3 General Drop: x2 Spoil: x3 Key Materials and Recipes: x2 Quest Item Drop: x2 Equipment: x1 Quest Rewards: x1 Raid and Epic Drops: x1 Equipment and major rewards remain at x1 to preserve their value and keep farming, crafting, trading and party play meaningful. Enchant and Progression Safe Enchant: +3 Maximum Weapon Enchant: +16 Maximum Armor Enchant: +10 Normal Scroll Success Rate: 55% Blessed Scroll Success Rate: 65% 1st and 2nd Class Changes: Free 3rd Class Change: Quest or donation Nobless: Quest or donation Barakiel required for the Nobless quest PvP and Endgame Content Olympiad Seven Signs Mammon Services Castle Sieges Weekly Sieges Team vs Team Capture the Flag Deathmatch Special Live Events Fair Play No Pay-to-Win shop Dedicated anti-cheat protection Active GM support Clean economy from launch Progression based on effort, teamwork and skill L2 Pearl is built for players who want a fresh start, meaningful progression and a competitive environment where clans and individuals can build their own reputation. Create your account from 29 September, invite your friends and prepare your clan. The gates of L2 Pearl open on 9 October 2026.   Website: www.l2pearl.com
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..