API/Guide to making a Tool

Guide to making a tool

Step 1: The Tool class

The tool class contains all information about the tool and will perform the actions the tool should perform
The class must extend 'mcmount.trainjo.supertool.tool.Tool'.
The most important thing you need in the class is a public constructor which calls the protected Tool constructor. This constructor needs the tool's name, ToolAction class and id as parameters.
You can choose the name yourself or let it be given by the constructor of your class. It must be a string.
The id must be a unique one if we want to be sure the tool can be registered. The ToolLink class (mcmount.trainjo.supertool.ToolLink) provides us with a function which will found a unique id depending on the name. Use the function ToolLink.GetUniqueToolID(String name) to get your unique id and pass it to the constructor.
The GetUniqueToolID method keeps track of previous registered names as well, so if the tool has been registered before it will return the same id as before. Therefore always use this function and never save the tool id yourself.
The action method is the method that will be called when the tool is used by a player.
You can use the parameters (an event that triggered the tool action and a link to the plugin's main class) to perform the action.
Be aware that only one instance of the class will be called when this method is called!
The permission method should return the permission that is needed to use this tool.
If the method returns the right string, you can check whether a player has a permission with the hasPermission() method inherited.
The init method is a method that is called when a player selects your tool.
the method passes the player that selects the tool and the additional arguments entered by the player along.
The help() method should return a short string which gives a short description of the tool.
This help will be displayed in the in game list of tools.
now all is done for creating your Tool class

Step 2: Registering the tool

The tool is almost done, but you still have to register it.
Call the RegisterTool method of the ToolLink class and pass a new instance of the tool to it.
The RegisterTool method will returns true if the tool is regitered and you can use that to determine whether the register was succesfull
One last thing we have to do is complete the Tool method of the ToolAction class we made earlier.
The ToolLink class provides us with an easy way to get a tool reference from the name of the tool: The getTool(String name) method can be used to pass to retrieve the correct tool reference to be returned by the Tool() method.


Comments

Posts Quoted:
Reply
Clear All Quotes