Java Reference
In-Depth Information
Let's walk through the code and see what's going on. We start off getting the
player object me , and then the fun begins. Using the me object, we get the
player's name and then send that as a message back to that player.
Then just for fun we'll make it rain (or snow) on the player by setting raining
to true , and set the rainy time to 5 seconds with setRainTime(100) . 2 There are 20
server ticks per second, so 100 server ticks will be about 5 seconds.
Next we'll get the experience points for the next level and the food level, and
send those as a message back to the player. You can play around in this
world for a while, and run "/whoami" to see if your food and experience have
changed any.
It's just that simple: me is an object of type Player , and we can get values for
various player values and send commands to me to do playerlike things.
That's what objects are for.
Try This Yourself
In the screenshot, you'll notice I also printed out a line that says whether or
not you are sleeping. Add a local boolean variable in PlayerStuff and set it to a
true or false depending on whether the player is sleeping or not, and then create
an appropriate message to display either way.
Build the plugin with build.sh and try it out.
You can see how I did it in code/MyPlayerStuff/src/myplayerstuff/MyPlayerStuff.java .
Next Up
In this chapter you've seen how to use Java objects: how to import a Java
package and class, how to use new to create objects, and how to change
properties of objects that will affect the game. We'll need all of that for the
following chapters.
In the next chapter we'll take a closer look at how plugins are wired into
Minecraft, how to add commands, and how to find things in the Minecraft
world.
2.
You could make it stop by setting raining to false instead.
 
 
 
Search WWH ::




Custom Search