API Tutorial

This is a tutorial page on how to use the Player Control GUI in your plugin. This will get your GUI going in a few (Not so easy) steps. Sorry if I use big words, just go with me. ;)


----------------------------------------
In order to start using this, you're going to want to add my plugin as a library, just like you would with the bukkit jar. I won't do a tutorial on this part.

Next, at the top of your plugin, you want to type in:

PlayerControlsGUI mgui;

After that, you want to import me.redstonefreak589.pcg.Main.PlayerControlsGUI.

Now in your onEnable() you want to type the following:

mgui = (PlayerControlsGUI) getServer().getPluginManager().getPlugin("Player Controls GUI");
if (mgui == null) {
	getLogger().severe("PlayerControlsGUI isn't found! Disabling plugin.");
	Bukkit.getPluginManager().disablePlugin(this);
}

This is a safeguard so that your plugin doesn't enable, and it doesn't flood your console with errors. Sorry if this is an inefficient way of doing this.


----------------------------------------
Now you want to create a way to enable your GUI, whether it be by item click, or command, that's up to you. In the body of your method, you want to create a new menu object by typing in the following:

NewMenu = MenuAPI.createMenu("Menu Title", 1);

The number is the number of rows. Each row has 9 slots, and the first slot is slot 0. If you have 1 row, it will be slots 0-8. If you have 2, it will be slots 0-17, and so on.
Now comes the confusing part. :)


----------------------------------------
Now you are going to want to create items. To do this, you can either just give a name, a name and item type, and a name, item, and number. I prefer name and item type. Let's do that. Let's go ahead and create an item that says "You clicked the item" when you click it, and then closes the menu! It will be an apple in the 1st slot.
This is a lot of code, so bear with me.

MenuItem  a = new MenuItem("Item Name", new MaterialData(Material.APPLE)) {
	@Override
	public void onClick(Player player) {
		player.sendMessage("You clicked the item!");
		NewMenu.closeMenu(player);
	}
};

We had to instantiate the MenuItem. That's why the "{}" with the onClick method are there. In that onClick, you can have anything you want! You could have sheep shoot into the sky for all I care! :D


----------------------------------------
Remember how I said it would be in the 1st slot? We are going to do that now! All you need to do is add the menu item like so:

NewMenu.addMenuItem(a, 0);

"a" is the name of the item we created earlier, and 0 is the 1st slot. Remember, the 1st slot is slot 0, and if you have 1 row, the last slot is 8. Keep that in mind. ;)


----------------------------------------
Now all you want to do is show the menu to the player. So just do:

NewMenu.openMenu((Player) sender);

I made my menu activate on a command, but if you made it activate on a item click, then you want to do event.getPlayer(), or however you want to get the player. It has to be a player though, not the name of one. If you type something like "Steve" in there, it will say it's a String not a Player.


----------------------------------------
There you have it! You have created your first menu! There is lot's more to do in this API, so download the JavaDocs and read up on them! :D


Comments

Posts Quoted:
Reply
Clear All Quotes