13
0
geforkt von Mirrors/Velocity

Allow plugins to mutate available commands sent to the client.

This is the first unstable API being introduced and is primarily to get feedback on the system.
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-05-28 07:14:49 -04:00
Ursprung 305949487e
Commit cb99b184ed
3 geänderte Dateien mit 44 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -26,6 +26,7 @@ dependencies {
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile 'com.google.inject:guice:4.2.2'
compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
compile 'com.mojang:brigadier:1.0.17'
compile "org.spongepowered:configurate-hocon:${configurateVersion}"
compile "org.spongepowered:configurate-yaml:${configurateVersion}"

Datei anzeigen

@ -0,0 +1,37 @@
package com.velocitypowered.api.event.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.mojang.brigadier.tree.RootCommandNode;
import com.velocitypowered.api.annotations.UnstableApi;
import com.velocitypowered.api.proxy.Player;
/**
* Allows plugins to modify the packet indicating commands available on the server to a
* Minecraft 1.13+ client.
*/
@UnstableApi
public class PlayerAvailableCommandsEvent {
private final Player player;
private final RootCommandNode<?> rootNode;
/**
* Constructs an available commands event.
* @param player the targeted player
* @param rootNode the Brigadier root node
*/
public PlayerAvailableCommandsEvent(Player player,
RootCommandNode<?> rootNode) {
this.player = checkNotNull(player, "player");
this.rootNode = checkNotNull(rootNode, "rootNode");
}
public Player getPlayer() {
return player;
}
public RootCommandNode<?> getRootNode() {
return rootNode;
}
}

Datei anzeigen

@ -7,6 +7,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.proxy.VelocityServer;
@ -175,7 +176,11 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
.build();
commands.getRootNode().addChild(root);
}
return false;
server.getEventManager().fire(
new PlayerAvailableCommandsEvent(serverConn.getPlayer(), commands.getRootNode()))
.thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop());
return true;
}
@Override