Allow connected sessions to run Geyser commands

This commit is contained in:
RednedEpic 2019-07-21 19:52:20 -05:00
parent 58819ea9ce
commit ccb52007fc
2 changed files with 36 additions and 10 deletions

View file

@ -176,8 +176,13 @@ public class UpstreamPacketHandler implements BedrockPacketHandler {
public boolean handle(CommandRequestPacket packet) { public boolean handle(CommandRequestPacket packet) {
connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName());
String command = packet.getCommand().replace("/", "");
if (connector.getCommandMap().getCommands().containsKey(command)) {
connector.getCommandMap().runCommand(session, command);
} else {
ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand()); ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand());
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);
}
return true; return true;
} }
@ -408,18 +413,13 @@ public class UpstreamPacketHandler implements BedrockPacketHandler {
public boolean handle(TextPacket packet) { public boolean handle(TextPacket packet) {
connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); 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(".", "/")); ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage().replace(".", "/"));
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);
return true; return true;
} }
ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage()); ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage());
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);
return true; return true;

View file

@ -31,20 +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.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import com.nukkitx.network.util.DisconnectReason; import com.nukkitx.network.util.DisconnectReason;
import com.nukkitx.protocol.PlayerSession; import com.nukkitx.protocol.PlayerSession;
import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.packet.TextPacket;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.api.command.CommandSender;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.remote.RemoteJavaServer; import org.geysermc.connector.network.remote.RemoteJavaServer;
import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.Registry;
import java.util.UUID; import java.util.UUID;
public class GeyserSession implements PlayerSession { public class GeyserSession implements PlayerSession, CommandSender {
private GeyserConnector connector; private GeyserConnector connector;
@ -126,6 +127,31 @@ public class GeyserSession implements PlayerSession {
authenticationData = new AuthenticationData(name, uuid, xboxUUID); 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 @Getter
@AllArgsConstructor @AllArgsConstructor
public class AuthenticationData { public class AuthenticationData {