Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into v3.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	buildSrc/src/main/kotlin/litecommands.java-conventions.gradle.kts
#	examples/bukkit/build.gradle.kts
#	examples/velocity/build.gradle.kts
#	litecommands-bukkit-adventure/README.md
#	litecommands-bukkit-adventure/src/main/java/dev/rollczi/litecommands/bukkit/adventure/LiteBukkitAdventureFactory.java
#	litecommands-bukkit/README.md
#	litecommands-bungee/README.md
#	litecommands-core/src/main/java/dev/rollczi/litecommands/argument/joiner/JoinerArgument.java
#	litecommands-core/src/main/java/dev/rollczi/litecommands/implementation/LiteFactory.java
#	litecommands-core/src/main/java/dev/rollczi/litecommands/suggestion/UniformSuggestionStack.java
#	litecommands-core/src/test/java/dev/rollczi/litecommands/suggestion/SuggestionStringTest.java
#	litecommands-minestom/README.md
#	litecommands-velocity/README.md
#	litecommands-velocity/src/main/java/dev/rollczi/litecommands/velocity/LiteVelocityFactory.java
  • Loading branch information
Rollczi committed Oct 7, 2023
2 parents 60ae93f + 52c2151 commit 1203cdc
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.rollczi.litecommands.bukkit.adventure;

import dev.rollczi.litecommands.argument.joiner.JoinerArgument;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import org.bukkit.command.CommandSender;

class KyoriComponentJoinerArgument extends JoinerArgument<CommandSender, Component> {

KyoriComponentJoinerArgument(ComponentSerializer<Component, ?, String> kyoriComponentSerializer) {
super(kyoriComponentSerializer::deserialize);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.rollczi.litecommands.bungee.tools;

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 java.util.List;
import java.util.stream.Collectors;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import panda.std.Option;
import panda.std.Result;

@ArgumentName("player")
public class BungeePlayerArgument<T> implements OneArgument<ProxiedPlayer> {

private final ProxyServer server;
private final T playerNotFoundMessage;

public BungeePlayerArgument(ProxyServer server, T playerNotFoundMessage) {
this.server = server;
this.playerNotFoundMessage = playerNotFoundMessage;
}

@Override
public Result<ProxiedPlayer, Object> parse(LiteInvocation invocation, String argument) {
return Option.of(this.server.getPlayer(argument)).toResult(playerNotFoundMessage);
}

@Override
public List<Suggestion> suggest(LiteInvocation invocation) {
return server.getPlayers().stream()
.map(ProxiedPlayer::getName)
.map(Suggestion::of)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.rollczi.litecommands.argument.joiner;

public class StringJoinerArgument<SENDER> extends JoinerArgument<SENDER, String> {

public StringJoinerArgument() {
super(String::valueOf);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.rollczi.litecommands.velocity;

import com.velocitypowered.api.command.CommandSource;
import dev.rollczi.litecommands.argument.joiner.JoinerArgument;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;

class KyoriComponentJoinerArgument extends JoinerArgument<CommandSource, Component> {

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

KyoriComponentJoinerArgument() {
super(MINI_MESSAGE::deserialize);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.rollczi.litecommands.velocity.tools;

import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
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 java.util.List;
import panda.std.Option;
import panda.std.Result;

@ArgumentName("player")
public class VelocityPlayerArgument<T> implements OneArgument<Player> {

private final ProxyServer server;
private final T playerNotFoundMessage;

public VelocityPlayerArgument(ProxyServer server, T playerNotFoundMessage) {
this.server = server;
this.playerNotFoundMessage = playerNotFoundMessage;
}

@Override
public Result<Player, Object> parse(LiteInvocation invocation, String argument) {
return Option.ofOptional(this.server.getPlayer(argument)).toResult(playerNotFoundMessage);
}

@Override
public List<Suggestion> suggest(LiteInvocation invocation) {
return server.getAllPlayers().stream()
.map(Player::getUsername)
.map(Suggestion::of)
.toList();
}
}

0 comments on commit 1203cdc

Please sign in to comment.