wip: PacketSender (use this to interact with the server)

This commit is contained in:
Bixilon 2020-07-03 14:02:16 +02:00
parent 17656a82bc
commit 598925ba5b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 52 additions and 5 deletions

View File

@ -23,7 +23,6 @@ import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.packets.serverbound.handshaking.PacketHandshake;
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketLoginStart;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketChatMessage;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusPing;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusRequest;
import de.bixilon.minosoft.protocol.protocol.*;
@ -35,6 +34,7 @@ public class Connection {
final int port;
final Network network;
final PacketHandler handler;
final PacketSender sender;
final ArrayList<ClientboundPacket> handlingQueue;
PluginChannelHandler pluginChannelHandler;
Thread handleThread;
@ -49,6 +49,7 @@ public class Connection {
network = new Network(this);
handlingQueue = new ArrayList<>();
handler = new PacketHandler(this);
sender = new PacketSender(this);
}
/**
@ -188,10 +189,6 @@ public class Connection {
handleThread.start();
}
public void sendChatMessage(String message) {
sendPacket(new PacketChatMessage(message));
}
public PluginChannelHandler getPluginChannelHandler() {
return pluginChannelHandler;
}
@ -220,4 +217,8 @@ public class Connection {
public boolean isConnected() {
return network.isConnected();
}
public PacketSender getSender() {
return sender;
}
}

View File

@ -0,0 +1,46 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketChatMessage;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketHeldItemChangeSending;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerAbilitiesSending;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketSpectate;
import java.util.UUID;
public class PacketSender {
final Connection connection;
public PacketSender(Connection connection) {
this.connection = connection;
}
public void setFlyStatus(boolean flying) {
connection.sendPacket(new PacketPlayerAbilitiesSending(flying));
}
public void sendChatMessage(String message) {
connection.sendPacket(new PacketChatMessage(message));
}
public void spectateEntity(UUID entityUUID) {
connection.sendPacket(new PacketSpectate(entityUUID));
}
public void setSlot(int slotId) {
connection.sendPacket(new PacketHeldItemChangeSending(slotId));
}
}