Escape Room

Step 1
Welcome to the Escape Room!

In this project, we'll learn about all the different events that you can use in your Minecraft plugins. We will build a room that locks you in until you complete certain steps.

Before starting:

  • You should already have done the Drone lesson
  • We will be using code similar to the Capture the Flag mini game, so it helps if you have at least started it
Step 2
Make a room

First, we need a room. We can use one of the ScriptCraft built-in drone functions for this: cottage()

On your server, place a block on the ground and call the cottage() function.

You could also use a different drone function, like fort(), or build your own. Check out all the possibilities here.

Step 3
Get the Escape Room coordinates

In your game, press F3 to see the debug info. We need the coordinates for when you are right in front of the room, but not in it. Write them down somewhere so we can add them to our program.

Step 4
Create a location

We can save locations in ScriptCraft using the location() function. Add this code with your own coordinates for a place just in front of the Escape Room.

Step 5
Make an export function to teleport to the Escape Room

Using exports allows us to call the function in the game. When you use an export function, self will be whoever used it.

Check Your Work
Step 6
Test your new function

Move to somewhere away from your Escape Room, and call this new function to test that it teleports you back to the room.

Step 7
Who's in the room?

To figure out if a player is in the room, we're going to need to save two more locations, for opposite corners.

We will test if the player is in the room by checking if their X, Y, and Z coordinates are between the X, Y, and Z coordinates of these two corners.

Step 8
Find the bottom front corner

With your debug info on (F3), look at the floor block of the back corner. Instead of using the XYZ of your position, you can get the location of a block your are highlighting after "Looking at: ".

Step 9
Find the coordinates for the back right top corner
Step 10
Save the corners as locations

In your code, make an object called escapeRoom, and give it locations as properties for two corners.

Step 11
Is the player in the room?

To detect if the player is actually in the room, we are going to look at the X, Y, and Z coordinates.

If the player's X is less than the smaller X of the room, then we know they are not in it. If their X is greater than the larger X, we also know they can't be in it.

Step 12
Create a function, and add this code to check if the player's X is outside the boundaries

Make a new function called inEscapeRoom() and add this code to check if the player's X is less than the minimum X or greater than the maximum X

Step 13
Repeat this for Y and Z

For Y and Z:

  • make an array of the coordinates for both of the escape room's corners
  • sort the coordinates from smallest to largest
  • make an "if" statement for if the player's coordinate is less than the minimum
  • make an "if" statement for if the player's coordinate is more than the maximum
Step 14
Otherwise, return true

When any of these tests returns false, the program stops. If none of them do that, we can safely say the player is in the room!

Step 15
Test the Player Move event

We're going to make a new function, called onPlayerMove(), and have it called whenever the a player moves in Minecraft.

You can learn more about the Bukkit PlayerMoveEvent here

Check Your Work
Step 16
Deploy and test this on your server!

Save and deploy your code now, and go on to your server. Once you reload, you should see "A player moved" every single time you move in the game.

Step 17
Find the event's player

We can get the player involved in any player event by using event.player (as long as you have event as the input for the function).

Change "A player moved" inside your broadcast message to event.player

Check Your Work
Step 18
Figure out who is moving

Save, deploy, and reload on your server and move around again. You should now see a message with your own username.

Your name should be different!

Step 19
Test your inEscapeRoom() function

Now that we know we can access the event's player, it's time to test our inEscapeRoom() function. Use an if statement to broadcast a message only when a player is in the Escape Room.

Check Your Work
Step 20
Deploy your change and test if you are in the room

Save, deploy, and reload. When you move into the Escape Room, you should see the message saying that you are in the Escape Room.

Run around the outside as well to make sure it only works inside.

Step 21
Get the coordinates of the door

To seal the doorway, we're going to need the coordinates for it's location. In the game, turn on your debug info with F3 and look at the bottom block at the door. We'll make this into another location in our escapeRoom object.

Step 22
Add the door location to your escapeRoom object

We're going to add the location of the door as a property of the object, and another property that turns from false to true if we have sealed the room.

Step 23
Make an export function to seal the door

First, we're going to need to initialize a drone at the location. Add this function using the location you saved for the doorway.

Step 24
Make the drone build a box in the door way

Use the box() function to make the drone seal the door. Here we used iron bars for the material, but you can choose a different one if you like.

Step 25
How to choose different materials for the drone

Minecraft has data values that are a number assigned to each type of block. You can find a visual list of all of them here.

You can use these numbers instead of the blocks module to build with the drone.

For example:




Both produce one stone block.

If you want to find out what a block is called in ScriptCraft, the easiest way is to search the actual code for the blocks module

Check Your Work
Step 26
Test the sealDoor() function

On your server, use /js sealDoor(); to test your new export function.

Step 27
Make an unsealDoor() function

Now, see if you can make the unsealDoor() export function on your own! It should look very similar to seal doors.

Hint: blocks.air will have the drone place an empty air block

You could also try using the drone .door() command to put the door back there, instead of empty blocks!

Step 28
Add two more properties to the escapeRoom object

We're going to add two more boolean (true/false) properties to the escapeRoom object so we know when the puzzle has been started and when the player has finished it.

Step 29
Get this thing started!

Now, we're going to seal the doors as soon as the player enters the room. First, we check that we haven't already started it with !escapeRoom.started (which is the same as escapeRoom.started === false). Then we seal the doors and tell the player what's going on. Lastly, we change our started property, so we know that the game is afoot.

This broadcast message is pretty boring. You should make a different one that makes sense for you

Step 30
Make it possible to escape

We'll go ahead and add the code to release us once we've completed the room, even though we can't do that yet.

Step 31
Fix the unsealDoor() function

Right now, if we finished the Escape Room, our code would unseal the door over, and over, and over again. Every single time we moved.

To fix this, edit the unsealDoor() function so that it only unseals if the room is currently sealed.

ERROR ALERT: This should say escapeRoom.sealed = false

Step 32
Fix the sealDoor() function

Now, make the sealDoor() function only seal if the room is not currently sealed.

Remember that you can use the ! operator to mean "not" just like you did with !escapeRoom.started

Check Your Work
Step 33
Test out the trap

Reload your server and go into the Escape Room. The door should seal behind you.

Remember that you can still use /js unsealDoor() to get back out!

Step 34
Check out some events!

In your Minecraft server, try typing the following and pressing tab:

  • /js events.
  • /js events.player
  • /js events.playerBedLeave

There are 160 possible events for us to use!

Step 35
Test the playerBedLeave event
Step 36
Investigating Events

Whenever we want to use an event, we will follow these steps

  • Write a function to be called when the event happens
  • Put a broadcast message in that function so we know the function was called
  • Call that function when the event happens
Step 37
Escape the room

We're going to make our puzzle super easy at first. All you have to do is sleep in the bed to escape!

Step 38
Make it more complicated

Instead of just one simple step, we're going to have three, now. Add a steps property to your escape room, with these three steps inside of it.

Step 39
Make the "sleep" step completed

Instead of just finishing the room, mark the "sleep" step as true.

Step 40
Add a chest of clues

Place a chest in your Escape Room, and add the following items:

  • Book and Quill (We'll put our clues in this book)
  • Wooden Shovel
  • Potato
Step 41
Keep the player from digging their way out!

Now that we have introduced a shovel, we need to make sure that no one tries to dig their way out of the Escape Room.

This code will cancel any time anyone tries to break a block if the escape room is started.

Step 42
Burn, baby, burn!

The next event we are going to use in our Escape Room is the Furnace Burn Event.

We're going to need to know what the fuel was in the event, and we can see from the page that there is a method listed called getFuel().

Whenever you see getSomething() as a method name for Bukkit, you can almost always just use .something in JavaScript to return it.

This doesn't have to make perfect sense right now, but you can read more about it in the ScriptCraft documentation

Step 43
Make sure the event calls your function

Our first step with every event will be to make sure that it is calling our function by having it do nothing but give us a broadcast message.

Check Your Work
Step 44
Test out the Furnace Burn event

Save, deploy, and reload your server and throw some fuel and something to burn in the furnace. You should see a message like this:

Step 45
Find the fuel

Next, we will change our broadcast message to tell us what the fuel for the event was

Check Your Work
Step 46
Test the fuel burn event again

You should see a message with an item stack of the fuel you put in.

Step 47
Find out what to call the shovel

We need to know exactly what to call the wooden shovel in ScriptCraft, so that the step is only complete if the player uses the shovel.

Add .type to the message telling us the fuel used in the event.

Step 48
Find out what the type of fuel you want to use is called

Save, deploy, reload and throw the type of fuel you want to use into the furnace. Our broadcast message should tell you what it is called.

Step 49
Find the furnace

Great, now we can save this fuel type information as a variable called fuelType.

Next, we need to figure out how to determine if the event is happening in the Escape Room. We'll check if the furnace involved in the event is inside the room, since it is a block. event.furnace just returns undefined, but because this is a block event, we can try to get the furnace with event.block.

Check Your Work
Step 50
Test the furnace burn event again

Reload and put some new fuel in the furnace. The broadcast message should give you a block.

Step 51

Make a variable for the furnace, and use your two variables to make the conditions of completing the step. Once we know it works, we'll mark the step complete.

Step 52
Make an function to check if all the steps have been finished

Before we move on to the last step, we're going to make an export function to check all the steps for us. It will just give us back true or false, like a collision function.

Step 53
The "for . . . in" loop

To check if the room is finished, we are going to need to check each of the steps individually, using a loop. Since escapeRoom.steps is an object, we'll use a for . . . in loop.

The important thing to know at this point is that you can use .propertyKey or ["propertyKey"] to access an object's property. We have to use the second one.

// is the same thing as 
Step 54
Test out the for. . . in loop

Let's go ahead and test this out on our room. Add this loop to your export function. Then save, deploy, reload, and call /js checkRoomSteps() in your Minecraft server.

Check Your Work
Step 55
All the steps

We can see now that stepName got assigned to each of the keys of our steps object. First it was sleep, the next time through the loop it was cook, and finally it was eat.

Step 56
Tell us if all the steps are completed

Just like in our inEscapeRoom() function, whenever the function does the return it stops. So it will tell us the name of the first step that is false, and then stop checking.

If none of the steps are false, then it will get to return true, and we will know that all the steps have been completed.

We'll take out the broadcast message later.

Step 57
Check if the room is finished whenever the player moves

Now, we just need to call this function during the Player Move Event, and we should be able to free the player when all steps are complete.

Step 58
Complete the "eat" step on your own!

The last event you need to add is the Player Item Consume Event. See if you can figure the function on your own.

Remember to follow these steps:

  1. Make a function to be called whenever the Player Item Consume Event happens
  2. Check if the player is in the room.
  3. Broadcast the item's type, and eat a baked potato to find out what to call it.
  4. If the player is in the room, and eats a baked potato, make the "eat" step true
Step 59
Add some clues

The last step is to add some clues on how to escape! Open up your book and quill and add some clues about how to get out. You could write exactly this, or something completely different!

Escape Room Info


MVCode Clubs

Created By



Temple Dungeon

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach