forked from GeyserMC/Geyser
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;
|
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.CommandNode;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
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.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareCommandsPacket;
|
||||||
import com.nukkitx.protocol.bedrock.data.CommandData;
|
import com.nukkitx.protocol.bedrock.data.CommandData;
|
||||||
import com.nukkitx.protocol.bedrock.data.CommandEnumData;
|
import com.nukkitx.protocol.bedrock.data.CommandEnumData;
|
||||||
|
@ -47,20 +44,14 @@ import java.util.*;
|
||||||
public class JavaServerDeclareCommandsTranslator extends PacketTranslator<ServerDeclareCommandsPacket> {
|
public class JavaServerDeclareCommandsTranslator extends PacketTranslator<ServerDeclareCommandsPacket> {
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) {
|
public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) {
|
||||||
List<CommandNode> rootNodes = new ArrayList<>();
|
|
||||||
List<CommandData> commandData = new ArrayList<>();
|
List<CommandData> commandData = new ArrayList<>();
|
||||||
Map<Integer, String> commands = new HashMap<>();
|
Map<Integer, String> commands = new HashMap<>();
|
||||||
Map<Integer, List<CommandNode>> commandArgs = new HashMap<>();
|
Map<Integer, List<CommandNode>> commandArgs = new HashMap<>();
|
||||||
|
|
||||||
// Find the root nodes
|
// Get the first node, it should be a root node
|
||||||
for (CommandNode node : packet.getNodes()) {
|
CommandNode rootNode = packet.getNodes()[packet.getFirstNodeIndex()];
|
||||||
if (node.getType() == CommandType.ROOT) {
|
|
||||||
rootNodes.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through the root nodes to get all commands
|
// Loop through the root nodes to get all commands
|
||||||
for (CommandNode rootNode : rootNodes) {
|
|
||||||
for (int nodeIndex : rootNode.getChildIndices()) {
|
for (int nodeIndex : rootNode.getChildIndices()) {
|
||||||
CommandNode node = packet.getNodes()[nodeIndex];
|
CommandNode node = packet.getNodes()[nodeIndex];
|
||||||
|
|
||||||
|
@ -78,7 +69,6 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
|
||||||
// Insert the command name into the list
|
// Insert the command name into the list
|
||||||
commands.put(nodeIndex, node.getName());
|
commands.put(nodeIndex, node.getName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// The command flags, not sure what these do apart from break things
|
// The command flags, not sure what these do apart from break things
|
||||||
List<CommandData.Flag> flags = new ArrayList<>();
|
List<CommandData.Flag> flags = new ArrayList<>();
|
||||||
|
@ -104,6 +94,8 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
|
||||||
availableCommandsPacket.getCommands().add(data);
|
availableCommandsPacket.getCommands().add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeyserConnector.getInstance().getLogger().debug("Sending command packet of " + commandData.size() + " commands");
|
||||||
|
|
||||||
// Finally, send the commands to the client
|
// Finally, send the commands to the client
|
||||||
session.getUpstream().sendPacket(availableCommandsPacket);
|
session.getUpstream().sendPacket(availableCommandsPacket);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue