Skip to content

Commit e026ff2

Browse files
authored
Merge pull request #1 from ForestTechMC/release/1.0.2
Release/1.0.2
2 parents 18b72d0 + 869f0dc commit e026ff2

File tree

9 files changed

+150
-5
lines changed

9 files changed

+150
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
![badge](https://img.shields.io/github/last-commit/ForestTechMC/ForestCommandAPI)
77
![badge](https://img.shields.io/github/actions/workflow/status/ForestTechMC/ForestCommandAPI/release.yml)
88
![badge](https://img.shields.io/codefactor/grade/github/foresttechmc/forestcommandapi)
9-
![badge](https://img.shields.io/badge/platform-PaperMC-lightgrey)
9+
![badge](https://img.shields.io/badge/platform-PaperMC%20%7C%20Velocity-lightgrey)
1010
[![badge](https://img.shields.io/discord/896466173166747650?label=discord)](https://discord.gg/2PpdrfxhD4)
1111
[![badge](https://img.shields.io/github/license/ForestTechMC/ForestRedisAPI)](https://github.com/ForestTechMC/ForestCommandAPI/blob/master/LICENSE.txt)
1212

@@ -30,7 +30,7 @@ This API works as library - it does not require to install any file to the serve
3030

3131
First, you need to setup the dependency on the ForestCommandAPI.
3232
Replace **VERSION** with the version of the release.
33-
Replace **PLATFORM** with the name of the supported platforms (currently "paper", in the future "velocity", "spigot" and "bungeecord" will follow).
33+
Replace **PLATFORM** with the name of the supported platforms (currently "paper" and "velocity", in the future "spigot" and "bungeecord" will follow).
3434

3535
<details>
3636
<summary>Maven</summary>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ compileJava.options.encoding = "UTF-8"
77
compileTestJava.options.encoding = "UTF-8"
88

99
allprojects {
10-
version = '1.0.1'
10+
version = '1.0.2-SNAPSHOT'
1111
group = 'cz.foresttech'
1212

1313
repositories {

settings.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
rootProject.name = 'ForestCommandAPI'
22
include 'paper'
33
include 'shared'
4-
include 'paper'
5-
include 'shared'
4+
include 'velocity'
65

velocity/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repositories {
2+
maven {
3+
url "https://repo.papermc.io/repository/maven-public/"
4+
}
5+
}
6+
7+
dependencies {
8+
compileOnly "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT"
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cz.foresttech.commandapi.velocity;
2+
3+
import com.velocitypowered.api.command.CommandManager;
4+
import com.velocitypowered.api.command.CommandMeta;
5+
import com.velocitypowered.api.proxy.Player;
6+
import com.velocitypowered.api.proxy.ProxyServer;
7+
import cz.foresttech.commandapi.shared.AbstractCommandAPI;
8+
import cz.foresttech.commandapi.velocity.argument.PlayerArgumentProcessor;
9+
10+
public class CommandAPI extends AbstractCommandAPI<CommandSenderWrapper> {
11+
12+
private static ProxyServer proxyServer;
13+
private final ProxyServerProvider proxyServerProvider;
14+
15+
public CommandAPI(ProxyServerProvider proxyServerProvider) {
16+
this.proxyServerProvider = proxyServerProvider;
17+
proxyServer = proxyServerProvider.getProxyServer();
18+
}
19+
20+
@Override
21+
protected void setup() {
22+
registerArgumentTypeProcessor(Player.class, new PlayerArgumentProcessor());
23+
}
24+
25+
@Override
26+
protected boolean registerToPlatform(String cmdName) {
27+
CommandManager commandManager = proxyServerProvider.getProxyServer().getCommandManager();
28+
CommandMeta commandMeta = commandManager.metaBuilder(cmdName)
29+
.plugin(this)
30+
.build();
31+
32+
VelocityCommandHandler velocityCommandHandler = new VelocityCommandHandler(cmdName.toLowerCase(), this);
33+
commandManager.register(commandMeta, velocityCommandHandler);
34+
return true;
35+
}
36+
37+
public static ProxyServer getProxyServer() {
38+
return proxyServer;
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cz.foresttech.commandapi.velocity;
2+
3+
import com.velocitypowered.api.command.CommandSource;
4+
import cz.foresttech.commandapi.shared.AbstractCommandSenderWrapper;
5+
6+
public class CommandSenderWrapper extends AbstractCommandSenderWrapper<CommandSource> {
7+
8+
public CommandSenderWrapper(CommandSource sender) {
9+
super(sender);
10+
}
11+
12+
@Override
13+
public void sendMessage(String message) {
14+
sender.sendRichMessage(message);
15+
}
16+
17+
@Override
18+
public void sendMessageColored(String message) {
19+
sender.sendRichMessage(message);
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cz.foresttech.commandapi.velocity;
2+
3+
import com.velocitypowered.api.proxy.ProxyServer;
4+
5+
public interface ProxyServerProvider {
6+
7+
ProxyServer getProxyServer();
8+
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cz.foresttech.commandapi.velocity;
2+
3+
import com.velocitypowered.api.command.CommandSource;
4+
import com.velocitypowered.api.command.SimpleCommand;
5+
6+
import java.util.List;
7+
8+
public class VelocityCommandHandler implements SimpleCommand {
9+
10+
private final String commandName;
11+
private final CommandAPI commandAPI;
12+
13+
public VelocityCommandHandler(String commandName, CommandAPI commandAPI) {
14+
this.commandName = commandName;
15+
this.commandAPI = commandAPI;
16+
}
17+
18+
@Override
19+
public void execute(Invocation invocation) {
20+
CommandSource commandSender = invocation.source();
21+
String[] args = invocation.arguments();
22+
commandAPI.onCommand(new CommandSenderWrapper(commandSender), commandName, args);
23+
}
24+
25+
@Override
26+
public List<String> suggest(Invocation invocation) {
27+
CommandSource commandSender = invocation.source();
28+
String[] args = invocation.arguments();
29+
return commandAPI.tabComplete(new CommandSenderWrapper(commandSender), commandName, args);
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cz.foresttech.commandapi.velocity.argument;
2+
3+
import com.velocitypowered.api.proxy.Player;
4+
import cz.foresttech.commandapi.shared.AbstractCommandSenderWrapper;
5+
import cz.foresttech.commandapi.shared.processor.ArgumentTypeProcessor;
6+
import cz.foresttech.commandapi.velocity.CommandAPI;
7+
8+
import java.util.List;
9+
import java.util.UUID;
10+
11+
public class PlayerArgumentProcessor implements ArgumentTypeProcessor<Player> {
12+
13+
@Override
14+
public <S extends AbstractCommandSenderWrapper<?>> Player get(S commandSender, String argument) {
15+
Player player = CommandAPI.getProxyServer().getPlayer(argument).orElse(null);
16+
if (player == null) {
17+
try {
18+
UUID uuid = UUID.fromString(argument);
19+
player = CommandAPI.getProxyServer().getPlayer(uuid).orElse(null);
20+
} catch (IllegalArgumentException ignored) {
21+
}
22+
}
23+
return player;
24+
}
25+
26+
@Override
27+
public <S extends AbstractCommandSenderWrapper<?>> List<String> tabComplete(S commandSender, String argument) {
28+
String inLowerCase = argument.toLowerCase();
29+
CommandAPI.getProxyServer().getAllPlayers();
30+
return CommandAPI.getProxyServer().getAllPlayers().stream()
31+
.map(Player::getUsername)
32+
.filter(name -> name.toLowerCase().startsWith(inLowerCase))
33+
.toList();
34+
}
35+
36+
}

0 commit comments

Comments
 (0)