Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Improve documentation for developers #174

Open
AlexInCube opened this issue Dec 2, 2024 · 9 comments
Open

[ENHANCEMENT] Improve documentation for developers #174

AlexInCube opened this issue Dec 2, 2024 · 9 comments

Comments

@AlexInCube
Copy link

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

@mdxd44
Copy link
Member

mdxd44 commented Dec 2, 2024

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

@AlexInCube
Copy link
Author

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

@mdxd44
Copy link
Member

mdxd44 commented Dec 4, 2024

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

@AlexInCube
Copy link
Author

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
Copy link
Author

AlexInCube commented Dec 4, 2024

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());   
    }

@mdxd44
Copy link
Member

mdxd44 commented Dec 5, 2024

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"));
    }
  }
}

@AlexInCube
Copy link
Author

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();
        }
    }
}

@mdxd44
Copy link
Member

mdxd44 commented Dec 5, 2024

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

@AlexInCube
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants