Merge remote-tracking branch 'upstream/dev/3.0.0'

This commit is contained in:
Lixfel
2024-12-06 11:14:27 +01:00
12 changed files with 140 additions and 11 deletions

View File

@ -253,7 +253,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
commandManager.metaBuilder(callbackCommand)
.plugin(VelocityVirtualPlugin.INSTANCE)
.build(),
velocityParentCommand
callbackCommand
);
final BrigadierCommand serverCommand = ServerCommand.create(this);
commandManager.register(

View File

@ -218,13 +218,14 @@ public class VelocityCommandManager implements CommandManager {
*
* @param source the source to execute the command for
* @param cmdLine the command to execute
* @param invocationInfo the invocation info
* @return the {@link CompletableFuture} of the event
*/
public CompletableFuture<CommandExecuteEvent> callCommandEvent(final CommandSource source,
final String cmdLine) {
final String cmdLine, final CommandExecuteEvent.InvocationInfo invocationInfo) {
Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(cmdLine, "cmdLine");
return eventManager.fire(new CommandExecuteEvent(source, cmdLine));
return eventManager.fire(new CommandExecuteEvent(source, cmdLine, invocationInfo));
}
private boolean executeImmediately0(final CommandSource source, final ParseResults<CommandSource> parsed) {
@ -266,7 +267,12 @@ public class VelocityCommandManager implements CommandManager {
Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(cmdLine, "cmdLine");
return callCommandEvent(source, cmdLine).thenComposeAsync(event -> {
CommandExecuteEvent.InvocationInfo invocationInfo = new CommandExecuteEvent.InvocationInfo(
CommandExecuteEvent.SignedState.UNSUPPORTED,
CommandExecuteEvent.Source.API
);
return callCommandEvent(source, cmdLine, invocationInfo).thenComposeAsync(event -> {
CommandExecuteEvent.CommandResult commandResult = event.getResult();
if (commandResult.isForwardToServer() || !commandResult.isAllowed()) {
return CompletableFuture.completedFuture(false);

View File

@ -38,6 +38,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_3;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_5;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_21;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_21_2;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_21_4;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_7_2;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
@ -359,7 +360,8 @@ public enum StateRegistry {
map(0x27, MINECRAFT_1_20_2, false),
map(0x28, MINECRAFT_1_20_3, false),
map(0x2B, MINECRAFT_1_20_5, false),
map(0x2D, MINECRAFT_1_21_2, false));
map(0x2D, MINECRAFT_1_21_2, false),
map(0x2F, MINECRAFT_1_21_4, false));
serverbound.register(
FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE,
map(0x0B, MINECRAFT_1_20_2, false),

View File

@ -193,6 +193,11 @@ public class UpsertPlayerInfoPacket implements MinecraftPacket {
info.listOrder = ProtocolUtils.readVarInt(buf);
}, (version, buf, info) -> { // write
ProtocolUtils.writeVarInt(buf, info.listOrder);
}),
UPDATE_HAT((version, buf, info) -> { // read
info.showHat = buf.readBoolean();
}, (version, buf, info) -> { // write
buf.writeBoolean(info.showHat);
});
private final Read read;
@ -223,6 +228,7 @@ public class UpsertPlayerInfoPacket implements MinecraftPacket {
private int gameMode;
@Nullable
private ComponentHolder displayName;
private boolean showHat;
private int listOrder;
@Nullable
private RemoteChatSession chatSession;
@ -256,6 +262,10 @@ public class UpsertPlayerInfoPacket implements MinecraftPacket {
return displayName;
}
public boolean isShowHat() {
return showHat;
}
public int getListOrder() {
return listOrder;
}
@ -285,6 +295,10 @@ public class UpsertPlayerInfoPacket implements MinecraftPacket {
this.displayName = displayName;
}
public void setShowHat(boolean showHat) {
this.showHat = showHat;
}
public void setListOrder(int listOrder) {
this.listOrder = listOrder;
}

View File

@ -56,8 +56,10 @@ public interface CommandHandler<T extends MinecraftPacket> {
default void queueCommandResult(VelocityServer server, ConnectedPlayer player,
BiFunction<CommandExecuteEvent, LastSeenMessages, CompletableFuture<MinecraftPacket>> futurePacketCreator,
String message, Instant timestamp, @Nullable LastSeenMessages lastSeenMessages) {
CompletableFuture<CommandExecuteEvent> eventFuture = server.getCommandManager().callCommandEvent(player, message);
String message, Instant timestamp, @Nullable LastSeenMessages lastSeenMessages,
CommandExecuteEvent.InvocationInfo invocationInfo) {
CompletableFuture<CommandExecuteEvent> eventFuture = server.getCommandManager().callCommandEvent(player, message,
invocationInfo);
player.getChatQueue().queuePacket(
newLastSeenMessages -> eventFuture
.thenComposeAsync(event -> futurePacketCreator.apply(event, newLastSeenMessages))

View File

@ -111,6 +111,6 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
}
return null;
});
}, packet.getCommand(), packet.getTimestamp(), null);
}, packet.getCommand(), packet.getTimestamp(), null, new CommandExecuteEvent.InvocationInfo(CommandExecuteEvent.SignedState.UNSUPPORTED, CommandExecuteEvent.Source.PLAYER));
}
}

View File

@ -62,6 +62,6 @@ public class LegacyCommandHandler implements CommandHandler<LegacyChatPacket> {
}
return null;
});
}, command, Instant.now(), null);
}, command, Instant.now(), null, new CommandExecuteEvent.InvocationInfo(CommandExecuteEvent.SignedState.UNSUPPORTED, CommandExecuteEvent.Source.PLAYER));
}
}

View File

@ -117,6 +117,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
}
return forwardCommand(fixedPacket, commandToRun);
});
}, packet.command, packet.timeStamp, packet.lastSeenMessages);
}, packet.command, packet.timeStamp, packet.lastSeenMessages,
new CommandExecuteEvent.InvocationInfo(packet.getEventSignedState(), CommandExecuteEvent.Source.PLAYER));
}
}

View File

@ -18,6 +18,7 @@
package com.velocitypowered.proxy.protocol.packet.chat.session;
import com.google.common.collect.Lists;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
@ -70,6 +71,10 @@ public class SessionPlayerCommandPacket implements MinecraftPacket {
return !argumentSignatures.isEmpty();
}
public CommandExecuteEvent.SignedState getEventSignedState() {
return !this.argumentSignatures.isEmpty() ? CommandExecuteEvent.SignedState.SIGNED_WITH_ARGS : CommandExecuteEvent.SignedState.SIGNED_WITHOUT_ARGS;
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);

View File

@ -17,6 +17,7 @@
package com.velocitypowered.proxy.protocol.packet.chat.session;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.LastSeenMessages;
@ -44,6 +45,11 @@ public class UnsignedPlayerCommandPacket extends SessionPlayerCommandPacket {
return false;
}
@Override
public CommandExecuteEvent.SignedState getEventSignedState() {
return CommandExecuteEvent.SignedState.UNSIGNED;
}
@Override
public String toString() {
return "UnsignedPlayerCommandPacket{" +