Skip to content

Commit

Permalink
Better adventure support for velocity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Jul 7, 2022
1 parent 956918a commit 9f79b7c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
8 changes: 0 additions & 8 deletions build.gradle.kts
Expand Up @@ -54,14 +54,6 @@ subprojects {
}
}
maven {
name = "eternalcode-repository"
url = uri("https://repo.eternalcode.pl/releases")
credentials {
username = properties["lucky_user_litecommands"] as String
password = properties["lucky_pass_litecommands"] as String
}
}
maven {
name = "mine-repository"
url = uri("https://repository.minecodes.pl/releases")
Expand Down
Expand Up @@ -11,7 +11,7 @@
@ArgumentName("text")
class KyoriColoredComponentArgument implements OneArgument<Component> {

private final static MiniMessage MINI_MESSAGE = MiniMessage.builder()
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder()
.postProcessor(new LegacyProcessor())
.build();

Expand Down
@@ -0,0 +1,16 @@
package dev.rollczi.litecommands.velocity;

import com.velocitypowered.api.command.CommandSource;
import dev.rollczi.litecommands.command.Invocation;
import dev.rollczi.litecommands.contextual.Contextual;
import net.kyori.adventure.audience.Audience;
import panda.std.Result;

class KyoriAudienceContextual implements Contextual<CommandSource, Audience> {

@Override
public Result<Audience, Object> extract(CommandSource commandSender, Invocation<CommandSource> invocation) {
return Result.ok(commandSender);
}

}
@@ -0,0 +1,28 @@
package dev.rollczi.litecommands.velocity;

import dev.rollczi.litecommands.argument.ArgumentName;
import dev.rollczi.litecommands.argument.simple.OneArgument;
import dev.rollczi.litecommands.command.LiteInvocation;
import dev.rollczi.litecommands.suggestion.Suggestion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import panda.std.Result;

@ArgumentName("text")
class KyoriColoredComponentArgument implements OneArgument<Component> {

private static final MiniMessage MINI_MESSAGE = MiniMessage.builder()
.postProcessor(new LegacyProcessor())
.build();

@Override
public Result<Component, ?> parse(LiteInvocation invocation, String argument) {
return Result.ok(MINI_MESSAGE.deserialize(argument));
}

@Override
public boolean validate(LiteInvocation invocation, Suggestion suggestion) {
return true;
}

}
@@ -0,0 +1,23 @@
package dev.rollczi.litecommands.velocity;

import dev.rollczi.litecommands.argument.ArgumentName;
import dev.rollczi.litecommands.argument.simple.OneArgument;
import dev.rollczi.litecommands.command.LiteInvocation;
import dev.rollczi.litecommands.suggestion.Suggestion;
import net.kyori.adventure.text.Component;
import panda.std.Result;

@ArgumentName("text")
class KyoriComponentArgument implements OneArgument<Component> {

@Override
public Result<Component, ?> parse(LiteInvocation invocation, String argument) {
return Result.ok(Component.text(argument));
}

@Override
public boolean validate(LiteInvocation invocation, Suggestion suggestion) {
return true;
}

}
Expand Up @@ -5,6 +5,7 @@
import com.velocitypowered.api.proxy.ProxyServer;
import dev.rollczi.litecommands.LiteCommandsBuilder;
import dev.rollczi.litecommands.implementation.LiteFactory;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import panda.std.Option;
import panda.std.Result;
Expand All @@ -19,6 +20,11 @@ private LiteVelocityFactory() {
public static LiteCommandsBuilder<CommandSource> builder(ProxyServer proxy) {
return LiteFactory.builder(CommandSource.class)
.typeBind(ProxyServer.class, () -> proxy)

.argument(Component.class, new KyoriComponentArgument())
.argument(Component.class, "color", new KyoriColoredComponentArgument())

.contextualBind(Audience.class, new KyoriAudienceContextual())
.contextualBind(CommandSource.class, (commandSource, invocation) -> Result.ok(commandSource))

.resultHandler(String.class, new StringHandler())
Expand Down

0 comments on commit 9f79b7c

Please sign in to comment.