LimboAPI icon indicating copy to clipboard operation
LimboAPI copied to clipboard

[ENHANCEMENT] Improve documentation for developers

Open AlexInCube opened this issue 1 year ago • 9 comments

Describe the feature you'd like to have implemented I would like to see methods described in the code or documentation, and a primitive example of how to create virtual worlds.

Is your feature request related to an existing problem? Please describe. Without documentation, you have to sit and research the LimboAuth plugin for a very long time to try to understand how to work with LimboAPI. But in LimboAuth there is a lot of code and it is without comments, you have to sit with a debugger to understand something in it.

Additional context All we have from the code samples are three lines from README.md

AlexInCube avatar Dec 02 '24 16:12 AlexInCube

Actually, i made one, but it was a long time ago, and i only shared it on discord limboexample_test.zip

I will later create a separate submodule or repository with a similar project that includes an example of how to use most of the provided API

mdxd44 avatar Dec 02 '24 23:12 mdxd44

I have error: java.lang.NullPointerException: Cannot read field "REDUCED_DEBUG_INFO" because "net.elytrium.limboapi.Settings.IMP.MAIN" is null

AlexInCube avatar Dec 03 '24 17:12 AlexInCube

I have error: java.lang.NullPointerException: Cannot read field "REDUCED_DEBUG_INFO" because "net.elytrium.limboapi.Settings.IMP.MAIN" is null

The error you provided doesn't provide much information, please share the full error log

mdxd44 avatar Dec 04 '24 00:12 mdxd44

I have error: java.lang.NullPointerException: Cannot read field "REDUCED_DEBUG_INFO" because "net.elytrium.limboapi.Settings.IMP.MAIN" is null

The error you provided doesn't provide much information, please share the full error log

I am resolve this issue by adding dependencies field to @Plugin

dependencies = {
      @Dependency(id = "limboapi")
}

AlexInCube avatar Dec 04 '24 02:12 AlexInCube

I don't understand yet how to properly register commands in LimboApi. From Velocity documentation, I am register command using Brigadier. https://docs.papermc.io/velocity/dev/command-api#brigadiercommand

When i join to Velocity Minecraft server, i have autocomplete for /register command. But command dont executes, also i give myself "register.permission" using plugin LuckPerms (LuckPerms installed on proxy-server).

Register Command class:

public class RegisterCommand implements SimpleCommand {
    @Override
    public void execute(final Invocation invocation) {
        CommandSource source = invocation.source();
        // Get the arguments after the command alias
        String[] args = invocation.arguments();

        source.sendMessage(Component.text("Hello World!", NamedTextColor.AQUA));
    }

    // This method allows you to control who can execute the command.
    // If the executor does not have the required permission,
    // the execution of the command and the control of its autocompletion
    // will be sent directly to the server on which the sender is located
    @Override
    public boolean hasPermission(final Invocation invocation) {
        return invocation.source().hasPermission("register.permission");
    }

    // Here you can offer argument suggestions in the same way as the previous method,
    // but asynchronously.
    // It is recommended to use this method instead of the previous one,
    // especially in cases where you make a more extensive logic to provide the suggestions
    @Override
    public CompletableFuture<List<String>> suggestAsync(final Invocation invocation) {
        return CompletableFuture.completedFuture(List.of());
    }
}

In main plugin class, event onProxyInitialization

CommandManager commandManager = proxyServer.getCommandManager();
        CommandMeta commandMeta = commandManager.metaBuilder("register")
                .plugin(this)
                .build();

        commandManager.register(commandMeta, new RegisterCommand());

Creating limbo world:

public void reload(){
        VirtualWorld world = this.limboFactory.createVirtualWorld(
                Dimension.OVERWORLD,
                17, 32, 15,
                0F, 0F
        );

        this.virtualServer = this.limboFactory.createLimbo(world)
                .setGameMode(GameMode.SURVIVAL)
                .registerCommand(this.server.getCommandManager().getCommandMeta("register"), new RegisterCommand());   
    }

AlexInCube avatar Dec 04 '24 21:12 AlexInCube

Currently, command registration exists solely to inform the client that your command exists. The actual processing needs to be moved to the LimboSessionHandler#onChat(String) method

Example:

this.virtualServer.registerCommand(this.server.getCommandManager().metaBuilder("mycmd").build());
@Override
public void onChat(String message) {
  if (message.startsWith("/")) {
    String[] args = message.split(" ");
    if ("/mycmd".equals(args[0])) {
      this.player.sendMessage(Component.text("kool"));
    }
  }
}

mdxd44 avatar Dec 05 '24 02:12 mdxd44

I'm trying to figure out how to disconnect or join players to the server. In my researching, i write this code, it works, but something seems wrong to me. That .disconnect() function do not disconnect, but connect player to a Paper server.

public class LimboCustomSessionHandler implements LimboSessionHandler {
    private final Player proxyPlayer;
    @MonotonicNonNull
    private LimboPlayer limboPlayer;

    private static final Serializer serializer = new Serializer(Objects.requireNonNull(Serializers.LEGACY_AMPERSAND.getSerializer()));
    private static final Component loginWrongPasswordKick = serializer.deserialize("**** you");

    public LimboCustomSessionHandler(Player proxyPlayer){
        this.proxyPlayer = proxyPlayer;
    }

    @Override
    public void onSpawn(Limbo server, LimboPlayer player) {
        player.disableFalling();
        this.limboPlayer = player;
    }

    @Override
    public void onChat(String chat) {
        // This code disconnects you from the server completely
        if (chat.equals("go back i wan't to be monke")) {
            this.proxyPlayer.disconnect(loginWrongPasswordKick);
        }

        // This code connects you to a Paper server
        if (chat.equals("login")) {
            this.limboPlayer.disconnect();
        }
    }
}

AlexInCube avatar Dec 05 '24 22:12 AlexInCube

LimboPlayer#disconnect disconnects the player from the current limbo, while Player#disconnect disconnects the player from the proxy

mdxd44 avatar Dec 05 '24 23:12 mdxd44

LimboPlayer#disconnect disconnects the player from the current limbo, while Player#disconnect disconnects the player from the proxy

Well, if everything is OK, then I'll keep using this code.

AlexInCube avatar Dec 06 '24 00:12 AlexInCube