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

    • @Mobius I only asked you one question! All your previous versions are sh*t and the last version is the best ? Because this is what you said.
    • Close that LOLserver. And change name to L2Wipe&Money.
    • Open Beta January 17th & 21:00 UTC +2 Launch Date January 24th & 21:00 UTC +2 Click Here to Explore Vanilla Gracia Final Low-Rate Server. Join our Discord Community     Following the success of our Vanilla project, we decided to launch it again as Last PlayINERA’s Server! Core Settings *Vanilla will have Strict Botting & Client Limitation Rules and Chronicle Progression from Gracia Final to Gracia Epilogue to H5 in Long term! XP: x4 SP: x4 Adena: x2 Drop: x2 Spoil: x3 Manor: x0.4 (60% reduction) - Festive sweeper enabled! Seal Stones: x2 Herbs: x1 Safe Enchant: +3 Maximum Enchant: Retail Enchant Rate: Dynamic General Settings Auto-loot Can be toggled Buffs Adventurer Guide buffs are free, retail level limit removed. Buff Slots: 20 (+ 4) Summon buffs will remain on re-summoning & on death while Noblesse blessing is applied! (Olympiad excluded) Pet buffs will be saved on relog but not during summon/unsummon. Event Buffer [NEW] Event Buffer is enabled and will spawn randomly between 18:00 ~ 23:00 in Giran for 10 minutes, it will apply Farm Only buffs that are cancelled in PvP, Siege / Epic PvP zones & while in a chaotic state! Duration: 1-hour! Territory Wars every two weeks on Saturday. Castle sieges every two weeks on Sunday Class Transfer 1st Class Transfer: Available for purchase with either Adena or iCoin 2nd Class Transfer: Available for purchase with either Adena or iCoin 3rd Class Transfer: Quest or iCoin (the 3rd class transfer will become available for purchase with iCoin as soon as someone has entered the Hall of Fame for completing the 3rd class transfer quest for the class in question) Hellbound Hellbound Lv. 0-6: ATOD x1 Hellbound Lv. 7-12: ATOD x2 Tiat & Ekimus will become available at Stage 12 Hellbound can only be leveled up by killing monsters. No quests or raids are needed To open Hellbound, a party must kill Baylor in the Crystal Caverns The following items are now tradable: Ancient Tome of the Demon  Hidden First Page  Hidden Second Page  Demon Contract Fragment INERA Hub Library Clan Recruitment System Options Services Milestone Rewards Earn rewards for reaching various daily/one-time goals Client Limit: 1 (+1 with Standard Premium) Shift + Click Information on Monsters SP are required to learn new skills Offline shops Lasts for 15 days Olympiad Olympiad period: 1st and 15th day of the month (14th & Last day of month is the last day) 3 Vs. 3 match disabled Class-based matches will be held over the weekends One registration per HWID (PC) Minimum participants: 9 Party Matching System Earn bonuses for finding a group via the Party Matching system Vote Reward System World Chat No limits for first day! Available from level 20 Raid Bosses Epic Raid Boss zones will turn into a PvP zone while the Epic Raid Boss is alive ( + means Random) Server will start with all grand raids dead. Normal Raids: 12h (+6 hours random). Subclass raids, respawn 12h (+6 hours random). Noblesse Barakiel 12h (+6 hours random, PvP zone). Anakim & Lilith are static 24 hours respawn. Queen Ant: 24 hours (+2 hours random). Core: 40 hours (+2 hours random). Orfen: 32 hours (+2 hours random). Antharas Respawn: 8 Days. Randomly spawns at 19:00 ~ 21:00 Boosted to level 83 on Hellbound stage 7. Valakas Respawn: 10 Days. Randomly spawns at 19:00 ~ 21:00 Baium Respawn: 5 Days. Randomly spawns at 21:00 ~ 23:00 Boosted to level 83 on Hellbound stage 7. Frintezza Respawn: 2 Days. Randomly spawns at 21:00 ~ 23:00 Instanced Zaken Zaken (Day): Monday, Wednesday, Friday at 6:30. Zaken (Day): 9 players, LvL 55-65, 1hr max. Zaken (Night): Wednesday at 6:30 Zaken (Night): 18-45 players, LvL 55-65, 6hr max. Tiat: Saturday at 6:30, 18-36 players, 2 hrs max. Boosted to level 85. Ekimus: 24h at 6:30, 18-27 players, 1hr max. Tully’s Workshop (Darion & Tully): 24h +-1h. Tower of Naia (Beleth): 5 days, 18 min. & 36 max.
  • Topics

×
×
  • Create New...