ScriptCrafting A Quest In Minecraft

Below I will use the Bukkit API to implement a simple quest, including a quest-giving NPC, objective, and reward.

Spawn Quest Giving NPC

First we need to spawn the NPC who will offer the quest to players as well as give out the rewards. Creating an NPC with Bukkit looks like this:

The above will create a Villager NPC, which isn’t ideal because every time we right-click him he will show us his inventory, but it will work for this tutorial.

Track Quest Progress

So now that we have an NPC, we need to give it a memory so it can track each player’s respective quest progress. To save each player’s current quest progress we save the index of their state in a array where each key is the player’s ID (similar to what we did in the Wolfbot post).

Let’s also create a method which initializes another hash that maps quest state to a blurb of text we want the NPC to spit out when interacted with by a player:

As you can see from the code our quest involves a gang of skeletons who are running amok nearby. The quest is for the player to simply kill 10 and then return for their reward. Of course we are still missing the logic that will cause the Villager to spit out the text and drop the rewards if the quest objective is met:

Watch For Quest Completion

There are only two bits of code left to round out our quest logic. We need a command for the player to accept the quest and also a listener to watch for skeleton deaths–specifically deaths that were at the hands of our questing player:

The full code list can be found at the end of this post. Drop that code in your js-plugin directory and you can start questing:

  1. /jsp spawn_npc
  2. Right-click to move through the quest prompts.
  3. /jsp accept
  4. Go hunt down and slay 10 skeletons.
  5. Return to the NPC and claim your XP reward!
Skeleton Menace

Skeleton Menace

Next Steps

There are a number of improvements you can add to this ScriptCraft plugin; however, if you really want to put time into creating quests I would recommend checking out the Citizens plugin which is much more powerful and lets you script NPC interactions with YAML. There is also a helpful repository with script examples.

Here is our little quest plugin in its entirety:


2 thoughts on “ScriptCrafting A Quest In Minecraft

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s