mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fixed crashing bug when using more than 1 root node
This commit is contained in:
parent
b0d39c587f
commit
549fe1d479
1 changed files with 16 additions and 24 deletions
|
@ -25,11 +25,8 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.java;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandNode;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareCommandsPacket;
|
||||
import com.nukkitx.protocol.bedrock.data.CommandData;
|
||||
import com.nukkitx.protocol.bedrock.data.CommandEnumData;
|
||||
|
@ -47,20 +44,14 @@ import java.util.*;
|
|||
public class JavaServerDeclareCommandsTranslator extends PacketTranslator<ServerDeclareCommandsPacket> {
|
||||
@Override
|
||||
public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) {
|
||||
List<CommandNode> rootNodes = new ArrayList<>();
|
||||
List<CommandData> commandData = new ArrayList<>();
|
||||
Map<Integer, String> commands = new HashMap<>();
|
||||
Map<Integer, List<CommandNode>> commandArgs = new HashMap<>();
|
||||
|
||||
// Find the root nodes
|
||||
for (CommandNode node : packet.getNodes()) {
|
||||
if (node.getType() == CommandType.ROOT) {
|
||||
rootNodes.add(node);
|
||||
}
|
||||
}
|
||||
// Get the first node, it should be a root node
|
||||
CommandNode rootNode = packet.getNodes()[packet.getFirstNodeIndex()];
|
||||
|
||||
// Loop through the root nodes to get all commands
|
||||
for (CommandNode rootNode : rootNodes) {
|
||||
for (int nodeIndex : rootNode.getChildIndices()) {
|
||||
CommandNode node = packet.getNodes()[nodeIndex];
|
||||
|
||||
|
@ -78,7 +69,6 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
|
|||
// Insert the command name into the list
|
||||
commands.put(nodeIndex, node.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// The command flags, not sure what these do apart from break things
|
||||
List<CommandData.Flag> flags = new ArrayList<>();
|
||||
|
@ -104,6 +94,8 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
|
|||
availableCommandsPacket.getCommands().add(data);
|
||||
}
|
||||
|
||||
GeyserConnector.getInstance().getLogger().debug("Sending command packet of " + commandData.size() + " commands");
|
||||
|
||||
// Finally, send the commands to the client
|
||||
session.getUpstream().sendPacket(availableCommandsPacket);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue