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 ?!

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

    • hello everyone! I am wanting to save the files (Ini. - Data - ) of the EP5 Client: Salvation... But they generate the error "corrupt files"... I tried several versions of L2FileEditor without good results. I need help! Thank you!
    • Opening December 6th at 19:00 (GMT +3)! Open Beta Test from November 30th!   https://l2soe.com/   🌟 Introducing L2 Saga of Eternia: A Revolution in Lineage 2 High Five! 🌟   Dear Lineage 2 enthusiasts, Prepare to witness the future of private servers! L2 Saga of Eternia is not just another High Five project—it’s a game-changing experience designed to compete with the giants of the Lineage 2 private server scene. Built for the community, by the community, we’re here to raise the bar in quality, innovation, and longevity. What Sets Us Apart? 💎 No Wipes, Ever Say goodbye to the fear of losing your progress. Our server is built to last and will never close. Stability and consistency are our promises to you. ⚔️ Weekly New Content Our dedicated development team ensures fresh challenges, events, and updates every week. From custom quests to exclusive features, there will always be something exciting to explore. 💰 No Pay-to-Win Skill and strategy matter most here. Enjoy a balanced gameplay environment where your achievements come from effort, not your wallet. 🌍 A Massive Community With 2000+ players expected, join a vibrant and active community of like-minded adventurers ready to conquer the world of Aden. 🏆 Fair and Competitive Gameplay Our systems are designed to promote healthy competition while avoiding abusive mechanics and exploits. 🔧 Professional Development From advanced bug fixes to carefully curated content, we pride ourselves on smooth performance, no lag, and unparalleled server quality. Key Features Chronicle: High Five with unique interface Rate: Dynamic x10 rates Class Balance: Carefully fine-tuned for a fair experience PvP Focused: PvP Ranking & aura display effect for 3 Top PvPers every week Custom Events: Seasonal and permanent events to keep you engaged Additional Features:   Custom Endgame Content: Introduce unique dungeons, raids, or zones unavailable in other servers. Player-Driven Economy: Implement a strong market system and avoid overinflated drops or rewards. Epic Siege Battles: Announce special large-scale sieges and PvP events. Incentives for Streamers and Clans: Attract influencers and big clans to boost server publicity. Roadmap Transparency: Share a public roadmap of planned updates to build trust and excitemen   Here you can read all the features: https://l2soe.com/features   Video preview: Join the Revolution! This is your chance to be part of something legendary. L2 Saga of Eternia is not just a server; it’s a movement to redefine what Lineage 2 can be. Whether you’re a seasoned veteran or a newcomer to the world of Aden, we invite you to experience Lineage 2 at its finest.   Official Launch Date: December 6th 2024 Website: https://l2soe.com/ Facebook: https://www.facebook.com/l2soe Discord: https://discord.com/invite/l2eternia   Let’s build the ultimate Lineage 2 experience together. See you in-game! 🎮
    • That's like a tutorial on how to run l2 on MacOS Xd but good job for the investigation. 
    • small update: dc robe set sold   wts adena 1kk = 1.5$ 
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hood-services https://campsite.bio/utchihaamkt
  • Topics

×
×
  • Create New...