diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 757fc714..44d69aae 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -176,8 +176,13 @@ public class UpstreamPacketHandler implements BedrockPacketHandler { public boolean handle(CommandRequestPacket packet) { connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); - ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand()); - session.getDownstream().getSession().send(chatPacket); + String command = packet.getCommand().replace("/", ""); + if (connector.getCommandMap().getCommands().containsKey(command)) { + connector.getCommandMap().runCommand(session, command); + } else { + ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand()); + session.getDownstream().getSession().send(chatPacket); + } return true; } @@ -408,18 +413,13 @@ public class UpstreamPacketHandler implements BedrockPacketHandler { public boolean handle(TextPacket packet) { connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); - if(packet.getMessage().charAt(0) == '.') { - + if (packet.getMessage().charAt(0) == '.') { ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage().replace(".", "/")); - session.getDownstream().getSession().send(chatPacket); - return true; - } ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage()); - session.getDownstream().getSession().send(chatPacket); return true; diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index d2d5b602..07a40f4f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -31,22 +31,21 @@ import com.github.steveice10.packetlib.event.session.ConnectedEvent; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; -import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.nukkitx.network.util.DisconnectReason; import com.nukkitx.protocol.PlayerSession; import com.nukkitx.protocol.bedrock.BedrockServerSession; +import com.nukkitx.protocol.bedrock.packet.TextPacket; import lombok.AllArgsConstructor; import lombok.Getter; -import org.geysermc.api.session.AuthData; +import org.geysermc.api.command.CommandSender; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.remote.RemoteJavaServer; import org.geysermc.connector.network.translators.Registry; -import sun.security.krb5.internal.AuthorizationData; import java.util.UUID; -public class GeyserSession implements PlayerSession { +public class GeyserSession implements PlayerSession, CommandSender { private GeyserConnector connector; @@ -128,12 +127,37 @@ public class GeyserSession implements PlayerSession { authenticationData = new AuthenticationData(name, uuid, xboxUUID); } + @Override + public String getName() { + return authenticationData.getName(); + } + + @Override + public void sendMessage(String message) { + TextPacket textPacket = new TextPacket(); + textPacket.setPlatformChatId(""); + textPacket.setSourceName(""); + textPacket.setXuid(""); + textPacket.setType(TextPacket.Type.CHAT); + textPacket.setNeedsTranslation(false); + textPacket.setMessage(message); + + upstream.sendPacket(textPacket); + } + + @Override + public void sendMessage(String[] messages) { + for (String message : messages) { + sendMessage(message); + } + } + @Getter @AllArgsConstructor - public class AuthenticationData implements AuthData { + public class AuthenticationData { private String name; - private UUID UUID; - private String XUID; + private UUID uuid; + private String xboxUUID; } } \ No newline at end of file