Sumesh Sumesh - 1 year ago 151
Java Question

Splitting Code into Different Classes [Bukkit/Spigot]

So I created this small plugin and I want to know how to move the code from inside onCommand to another class and call/execute that class inside onCommand.
Please Help. Thanks

public class SkinStandoff extends JavaPlugin {
Block bEnd;
Location End;
Block ZeroBlock;
Location Zero;
Location ZeroEnd;

public void onEnable(){

public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
if (cmd.getName().equalsIgnoreCase("build") && sender instanceof Player) {
Player player = (Player) sender;
Location start;
int Count;
Count = 1;

start = player.getLocation();
End = start.add(3, -1, 3);
Zero = getEnd().add(1,0,0);

bEnd = End.getBlock();
do {
Zero= Zero.add(1,0,0);
ZeroBlock = Zero.getBlock();
} while (Count != 10);
return true;
return false;

public Location getEnd(){
return End;
public Location getZeroEnd(Location ZeroEnd){
ZeroEnd = this.Zero.add(10,0,0);
return ZeroEnd;

Answer Source

you can create new Class Commands and there will be:

public class Commands implements CommandExecutor {

    private MainClass plugin;

    public Commands(MainClass core) {
        this.plugin = core;

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
your commands here
return true;

And in your MainClass you have to set CommandExecutor:

getCommand("command").setExecutor(new Commands(this));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download