mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -04:00
player health, food and saturation, support for incoming plugin messages
This commit is contained in:
parent
b9b20b1318
commit
e29e8e3752
@ -4,6 +4,9 @@ import java.util.UUID;
|
||||
|
||||
public class Player {
|
||||
Account acc;
|
||||
float health;
|
||||
short food;
|
||||
float saturation;
|
||||
|
||||
public Player(Account acc) {
|
||||
this.acc = acc;
|
||||
@ -21,4 +24,24 @@ public class Player {
|
||||
public Account getAccount() {
|
||||
return this.acc;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public short getFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
public void setFood(short food) {
|
||||
this.food = food;
|
||||
}
|
||||
|
||||
public void setSaturation(float saturation) {
|
||||
this.saturation = saturation;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
public class PacketPluginMessageReceived implements ClientboundPacket {
|
||||
String channel;
|
||||
byte[] data;
|
||||
|
||||
|
||||
@Override
|
||||
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||
switch (v) {
|
||||
case VERSION_1_7_10:
|
||||
channel = buffer.readString();
|
||||
data = buffer.readBytes(buffer.readShort()); // first read length, then the data
|
||||
break;
|
||||
}
|
||||
log();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Plugin message received in channel %s with %s bytes of data", channel, data.length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketHandler h) {
|
||||
h.handle(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
public class PacketUpdateHealth implements ClientboundPacket {
|
||||
float health;
|
||||
short food;
|
||||
float saturation;
|
||||
|
||||
|
||||
@Override
|
||||
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||
switch (v) {
|
||||
case VERSION_1_7_10:
|
||||
health = buffer.readFloat();
|
||||
food = buffer.readShort();
|
||||
saturation = buffer.readFloat();
|
||||
break;
|
||||
}
|
||||
log();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Health update. Now at %s hearts and %s food level and %s saturation", health, food, saturation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketHandler h) {
|
||||
h.handle(this);
|
||||
}
|
||||
|
||||
public short getFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
}
|
@ -69,4 +69,13 @@ public class PacketHandler {
|
||||
public void handle(PlayChunkBulk pkg) {
|
||||
//ToDo
|
||||
}
|
||||
|
||||
public void handle(PacketUpdateHealth pkg) {
|
||||
connection.getPlayer().setFood(pkg.getFood());
|
||||
connection.getPlayer().setHealth(pkg.getHealth());
|
||||
connection.getPlayer().setSaturation(pkg.getSaturation());
|
||||
}
|
||||
|
||||
public void handle(PacketPluginMessageReceived pkg) {
|
||||
}
|
||||
}
|
||||
|
@ -39,5 +39,7 @@ public interface Protocol {
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_TIME_UPDATE, PacketTimeUpdate.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_KEEP_ALIVE, PacketKeepAlive.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, PlayChunkBulk.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_HEALTH, PacketUpdateHealth.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_PLUGIN_MESSAGE, PacketUpdateHealth.class);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user