Question Why do i get this

Cabbage

New member
Apr 5, 2025
3
0
1
error: cannot find symbol
commands.registrar().register(buildCommand);
^
symbol: variable buildCommand

Code: package com.cabbage.testplugin;

import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.plugin.java.JavaPlugin;

public final class Testplugin extends JavaPlugin {

@Override
public void onEnable() {
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
commands.registrar().register(buildCommand);
});
}

@Override
public void onDisable() {
// Plugin shutdown logic
}
}



Code 2:
package com.cabbage.testplugin;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;

public class coolcommand {


public static void command(){
LiteralCommandNode<CommandSourceStack> buildCommand = Commands.literal("testcmd")
.then(Commands.literal("argument_one"))
.then(Commands.literal("argument_two"))
.build();
}

}
 

stefvanschie

Moderator
Staff member
Dec 17, 2021
140
7
28
28
You can't access variables in a method from outside that method. What you can do is make the command method return a LiteralCommandNode<CommandSourceStack> and then call coolcommand.command() in your onEnable method.