Making and calling new methods
Let's create a new method which will broadcast a message to the server. The following diagram labels various parts of a method in case you are not familiar with them:
Create a new method named broadcastToServer
. We will place it within our MyFirstBukkitPlugin
class under the
onEnable()
method. We only want to call this method from inside the MyFirstBukkitPlugin
class so the access modifier will be private
. If we want to call this method from other classes in our plugin we can remove the modifier or change it to public
. The method will not return anything and thus will have a return type of void
. Finally the method will have one parameter, a string named msg
. After creating this second method, your class will look similar to the following code:
public class MyFirstBukkitPlugin extends JavaPlugin { @Override public void onEnable() { } private void broadcastToServer(String msg) { } }
We will write the code within the body of our new method to accomplish...