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.
First, we need a room. We can use one of the ScriptCraft built-in drone functions for this:
On your server, place a block on the ground and call the
You could also use a different drone function, like
fort(), or build your own. Check out all the possibilities here.
For Y and Z:
We're going to make a new function, called
onPlayerMove(), and have it called whenever the a player moves in Minecraft.
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.
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
Now, see if you can make the
unsealDoor() export function on your own! It should look very similar to seal doors.
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!
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
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
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!
In your Minecraft server, try typing the following and pressing tab:
There are 160 possible events for us to use!
Whenever we want to use an event, we will follow these steps
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
Whenever you see
getSomething() as a method name for Bukkit, you can almost always just use
This doesn't have to make perfect sense right now, but you can read more about it in the ScriptCraft documentation
Great, now we can save this fuel type information as a variable called
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
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"] to access an object's property. We have to use the second one.
escapeRoom.steps.sleep // is the same thing as escapeRoom.steps["sleep"]
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.
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: