Custom Quest API

Alert: This information is intended for developers. Learn how to use Java first!

Add to your project

For a quick start, a module template project is available on Github here.

If you're using Maven or another project management tool, add the latest version of Quests through the CodeMC service.

<repository>
  <id>codemc-repo</id>
  <url>https://repo.codemc.io/repository/maven-public/</url>
</repository>

Unless designing a cross-platform project, you'll want to define the core artifact.

<dependency>
  <groupId>me.pikamug.quests</groupId>
  <artifactId>quests-core</artifactId>
  <version>VERSION</version>
</dependency>

Learn the interface

Quests provides a simple API to create custom requirements, rewards, and objectives. To begin, make sure you are compiling against version 4.0.0 or above. Once you've finished following this guide, use the Quests/modules folder as the destination for your finished and compiled jar. If distributing your module, make sure to inform the end user of the correct folder location.

The following examples assume you are creating a project for Bukkit-based software.

Requirements API

Building a Quests Requirement is very simple. To get started, create a Java class that extends the CustomRequirement class. After that, check out this example of a Custom Requirement where the player must have a particular name in order to take the Quest:

In the constructor of your class, you may use any of the following methods:

Method
Description

setName

Sets the name of the Custom Objective.

setAuthor

Sets the author of the Custom Objective (you!).

setItem

Set an item which might appear in overlay plugins like QuestsGUI.

setDisplay

Sets how the requirement is displayed when failed.

addStringPrompt

Adds a new editor prompt with the specified title, description, and default value for your Custom Objective. Quest editors may input a string which is up to you to parse.

Inside #testRequirement is where you perform your logic to determine whether the player passes the requirement, returning true if they do, and false if they do not.

The data Map contains the data that the person who created the Quest gave to it. In this example, the data Map contains the two values for 'Name' and 'Case-Sensitive'. Also, note that while the values are of type Object, they were cast to type String internally. You must perform manual type-conversion if you want to obtain integers, booleans, et al.

Rewards API

Building a Quests Reward is very simple. To get started, create a Java class that extends the CustomReward class. After that, check out this example of a Custom Reward where a player gets a GUI Inventory that pops up containing iron, gold and diamonds:

In the constructor of your class, you may use any of the following methods:

Method
Description

setName

Sets the name of the Custom Objective.

setAuthor

Sets the author of the Custom Objective (you!).

setItem

Set an item which might appear in overlay plugins like QuestsGUI.

setDisplay

Sets the reward name (text that will appear when the player completes the Quest) of the Custom Reward.

addStringPrompt

Adds a new editor prompt with the specified title, description, and default value for your Custom Objective. Quest editors may input a string which is up to you to parse.

Inside #giveReward is where you perform your logic to give the player whatever it is your Custom Reward gives. The data Map contains the data that the person who created the Quest gave to it. In this example, the data Map contains four values: One for the title of the GUI, and three for the amount of iron/gold/diamonds. Also, note that while the values are of type Object, they were cast to type String internally. You must perform manual type-conversion if you want to obtain integers, booleans, et al.

Objectives API

Building a Quests Objective is a bit more complicated than Requirements or Rewards. To get started, create a Java class that extends the CustomObjective class. If you want to catch one of Bukkit's Events, you'll need to implement the Listener class (Quests will take care of registering it for you). After that, check out these examples of a Custom Objective:

In the constructor of your class, you may use any of the following methods:

Method
Description

setName

Sets the name of the Custom Objective.

setAuthor

Sets the author of the Custom Objective (you!).

setItem

Set an item which might appear in overlay plugins like QuestsGUI.

setShowCount

Sets whether the quest editor may set the count (number of times player must repeat task). Default is "true". This will apply to all prompts added with #addStringPrompt unless disabled.

setCountPrompt

Sets the prompt description for the user to enter the count for the objective. Default is "Enter number".

setDisplay

Sets how the objective is displayed in /quests list and the Quest Journal. For placeholders, use %count% to get the value of #setShowCount, and #addStringPrompt titles for user input (such as %Item Name% in the second example). Default is "Progress: %count%".

addStringPrompt

Adds a new editor prompt with the specified title, description, and default value for your Custom Objective. Quest editors may input a string which is up to you to parse.

Inside your EventHandlers (if applicable), determine whether the player has completed part or all of the objective, and then use #incrementObjective to advance the player. The first and the second argument of #incrementObjective should always be the player and 'this' respectively. The third argument is how much to increment the objective by, while the last is the quest for which to apply the increment to. Even if your objective does not have a count, you must still use #incrementObjective - use an increment of 1 to signal that the objective has been completed.

The Map<String, Object> contains the data that the quest editor provided. In this example, the data keys are the item names, whereas the values are the user's input for your prompt (which can be null). Also, note that while the values are of type Object, they were cast to type String internally. You must perform manual type-conversion if you want to obtain integers, booleans, et al.

Last updated

Was this helpful?