Java Reference
In-Depth Information
Plugin: PlayerStuff
Let's play around with a Player a bit more.
We're going to install the PlayerStuff plugin and change some of the object
properties for players in the Minecraft world.
In the Player object, there are all kinds of interesting functions to get information
about a player, and to set those values as well. Here are a few we'll look at:
chat()
getWorld()
getDisplayName() (can set it too)
getExperience() (can set it too)
getHunger() (can set it too)
getHealth() (can set it too)
isSleeping()
getLocation()
We can send a message to a player, get some values, and more. Here's code
for a full plugin that demonstrates some of these features. It provides the
command "/whoami" . For more advanced plugins, this approach could be a
great way to debug in-game objects by displaying information about Minecraft
objects. When you're writing code and it's not working, printing out a couple
of values of different variables is a great way to find out what's going on.
Here's the code, which is in the plugin directory Desktop/code/PlayerStuff . The full
plugin has the necessary Canary.inf file and such:
PlayerStuff/src/playerstuff/PlayerStuff.java
package playerstuff;
import net.canarymod.plugin.Plugin;
import net.canarymod.logger.Logman;
import net.canarymod.Canary;
import net.canarymod.commandsys.*;
import net.canarymod.api.world.position.Location;
import net.canarymod.chat.MessageReceiver;
import net.canarymod.api.entity.living.humanoid.Player;
import com.pragprog.ahmine.ez.EZPlugin;
public class PlayerStuff extends EZPlugin {
@Command(aliases = { "whoami" },
description = "Displays information about the player." ,
permissions = { "" },
toolTip = "/whoami" )
 
 
Search WWH ::




Custom Search