# Home

## Contents

Welcome to the **QuestLib** wiki, please choose a subject below or in the sidebar to continue.

* [Getting started](https://questlib.themelvin.nl/docs/guide/installation)
* [Storage](https://questlib.themelvin.nl/docs/guide/storage)
* [Rewards](https://questlib.themelvin.nl/docs/guide/reward)

## Features

* Built-in YAML or MySQL storage.
* Custom reward types.
* Multiple custom objectives.
* Easily configurable.
* Customisable to your own wishes.
* Extensive API.

## Usage

To use QuestLib, either:

* Put it in the `plugins` folder of your server, add it to your dependencies in your `plugin.yml` (e.g. `depend: [QuestLib]`) and add it to the dependencies in your IDE.
* Put it inside your plugin jar, and initiate the library.

You can download the latest version on the [Releases page](https://github.com/MinusKube/SmartInvs/releases) on Github.

You can also use a build system:

### Gradle

{% code title="build.gradle" %}

```groovy
repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile 'com.github.TheMelvinNL:QuestLib:<version>'
}
```

{% endcode %}

### Maven

{% code title="pom.xml" %}

```markup
<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
  <groupId>com.github.TheMelvinNL</groupId>
  <artifactId>QuestLib</artifactId>
  <version>version-number</version>
</dependency>
```

{% endcode %}

## Example

#### Quest

{% code title="BreakQuest.java" %}

```java
public class BreakQuest extends Quest {

    public BreakQuest() {

        this.setName("Break Quest");
        this.setDescription("Break different kind of blocks");

        this.setStartMessage("&bQuest started: " + this.getName());
        this.setCompleteMessage("&bQuest finished: " + this.getName());

        this.setReward(new MultiReward(new ItemReward(new ItemStack(Material.EMERALD, 2)), new ItemReward((new ItemStack(Material.IRON_INGOT, 10)))));

        this.addObjective(new CobblestoneObjective());

    }

}
```

{% endcode %}

#### Objective

{% code title="CobblestoneObjective.java" %}

```java
public class CobblestoneObjective extends QuestObjective {

    public CobblestoneObjective() {

        this.setName("Cobblestone objective");
        this.setDescription("Break 5 cobblestone blocks.");
        this.setReward(new ItemReward(new ItemStack(Material.DIAMOND, 1), "&6You received &e1x Diamond &6as a reward."));

        this.setStartMessage("&b" + this.getName() + ": " + this.getDescription());
        this.setCompleteMessage("&aYou finished this objective.");

    }

    @EventHandler
    public void blockBreak(BlockBreakEvent event) {

        // This check is neccessary, as QuestLib is not able to recognise events.
        if(!this.isFrom(event.getPlayer())) return;

        if(event.getBlock().getType() != Material.COBBLESTONE) {
            return;
        }

        this.incrementData("count", 1);

        if(this.getDataNumber("count") >= 5) {
            this.complete();
        }

    }

}
```

{% endcode %}

As you can see, with QuestLib you're able to easily create new objectives and register them in your quest. QuestLib also saves all the data you provide using `setData()` or `incrementData()` (for integers).

If you want more examples, have a look at the [Example repository](https://github.com/TheMelvinNL/QuestLib-Example).
