Getting started

Initiate QuestLib

You should initiate QuestLib and register all quests before you start using your plugin. This step is very important.

Example

YourMainClass.java
@Override
public void onEnable() {

    QuestLib questLib = QuestLib.getInstance();

    // Register quests BEFORE initiating QuestLib.
    questLib.registerQuest("yourIdentifier", TheQuest.class);
    questLib.registerObjective("anotherIdentifier", YourObjective.class);
    
    YAML questStorage = new YAML(new File(this.getDataFolder() + "/data", "data.yml"));
    questLib.init(this, questStorage);

}

As you can see in the example, you can register your Quest class with registerQuest(String identifier, Class<? extends Quest> questClass) and your objectives with registerObjective(String identifier, Class<? extends QuestObjective> objectiveClass).

After this, QuestLib is initiated with init(JavaPlugin plugin, QuestStorage storage)

In the example, the storage used is the built in YAML storage of QuestLib. If you want other types of storage or use your own storage system, read Storage.

Create new quest

It's now time to create your quest. A quest can be created by extending the Quest class.

Example

You can now add several properties for your quest in the constructor. These aren't used by QuestLib, but can be used to your own wishes.

Method

Function

setName(String name)

Give the quest a name.

setDescription(String description)

Give the quest a description.

setStartMessage(String message)

Set the message sent when the quest is started.

This will be automatically color formatted.

setCompleteMessage(String message)

Set the message sent when the quest is completed.

This will be automatically color formatted.

setReward(Reward reward)

Set the reward given when the player completes the quest.

See the Reward section for more information.

Create new objective

Objectives are the best part of every quest, with objectives you'll be able to keep track of what a player does using the Spigot events you are already familiar with.

Example

In objectives, a empty constructor is NOT required since you instantiate the object yourself in the quest.

Just like quests, you can add several properties in your objective.

Method

Function

setName(String name)

Give the objective a name.

setDescription(String description)

Give the objective a description.

setStartMessage(String message)

Set the message sent when the objective is started.

This will be automatically color formatted.

setCompleteMessage(String message)

Set the message sent when the objective is completed.

This will be automatically color formatted.

setReward(Reward reward)

Set the reward given when the player completes the objective.

See the Reward section for more information.

Now register your objective in the quest with this.addObjective(QuestObjective objective)

Example

Storing data inside objectives

If you need to (temporarily) store data to keep track of the player's objective, you can do so by accessing QuestLib's setData() and getData() methods.

Data methods

Method

Description

getData(String key)

Returns an Object (cast to whatever you set it to)

getDataString(String key)

Returns a String

getDataNumber(String key)

Returns an Integer

setData(String key, Object value)

Set a key to a certain value

incrementData(String key, double incrementAmount)

Increment a number

Automatically inserts data if null

removeData(String key)

Remove data with key

All data stored using the methods above will be saved to the storage type you chose. Data will automatically be loaded again once the server restarts, reloads or something else happens.

Example

In the example, an event is created and uses some of the data methods to store its data. Of course, this data will be restored at every restart, reload of crash.

Last updated

Was this helpful?