Tips on creating your very first plugin! - Historical

Applied By iRexiiOfficial: Feb 1, 2017 at 9:55 PM

Tips on creating your very first plugin!
Well,

Learning to code plugins is hard. This post should help you!

Well, your gonna wanna know the Spigot Javadocs.
https://hub.spigotmc.org/javadocs/bukkit

CODING
:

Well, you want to know some basics of the plugin development.

Here is some example code:
Please note that this code does nothing:
START OF CODE:
package example.example.example;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class Example extends JavaPlugin {

@Override
public void onEnable() {
Bukkit.getServer().getLogger().info("ExampleCode is now Enabled.");
}

@Override
public void onDisable() {
Bukkit.getServer().getLogger().info("ExampleCode is now Disabled.");
}

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

if (cmd.getName().equalsIgnoreCase("example") && sender instanceof Player) {

Player player = (Player) sender;

player.sendMessage(cmd.getName() + " You used a Example" + "!");

return true;

}

return false;
}

}
END OF CODE:

now lets decode this.

The "public boolean" is what controls commands, etc.

"@Override
public void onDisable() {
Bukkit.getServer().getLogger().info("ExampleCode is now Disabled.");"

This prints a message(ExampleCode is now Disabled.) when the plugin disables to the console.


PLUGIN.YML
ahhh. the plugin.yml. The plugin.yml is what tells the server the name, commands, and sometimes permissions, of your plugin. Here's a example:


name: Example

main: example.example.example
version: 1.0
commands:
example:
aliases: [examplecode]
description: It replies with a message!
usage: /<command>

Now Finally,
LICENSING:
Licensing allows your plugin to be protected from reproduction, etc.
If your plugin doesn't have a license, but the source code is available, you might as well say goodbye to your plugin. Here's a example.

Creator: publishes plugin with no license and gives source code
Person: Realizes the source code is public and there is no license
Person: Takes code and recreates plugin with license
Creator: forced to remove plugin

sender.sendMessage("THE END")

THE END