Skip to content

Commit

Permalink
Add telemetry events missed in 1.13 and 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeMortal committed Dec 22, 2019
1 parent f9705b6 commit ee72557
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Packets with this annotation will be sent in plain text over the network
*
* @see com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface NoEncryption {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nukkitx.protocol.bedrock.data.event;

import lombok.Value;

@Value
public class EntityDefinitionTriggerEventData implements EventData {
private final String id;

@Override
public EventDataType getType() {
return EventDataType.ENTITY_DEFINITION_TRIGGER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ public enum EventDataType {
PET_DIED,
CAULDRON_BLOCK_USED,
COMPOSTER_BLOCK_USED,
BELL_BLOCK_USED
BELL_BLOCK_USED,
ENTITY_DEFINITION_TRIGGER, // 18
RAID_UPDATE, // 19
MOVEMENT, // 20
MOVEMENT_THRESHOLD, // 21
EXTRACT_HONEY // 22
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nukkitx.protocol.bedrock.data.event;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ExtractHoneyEventData implements EventData {
public static final ExtractHoneyEventData INSTANCE = new ExtractHoneyEventData();

@Override
public EventDataType getType() {
return EventDataType.EXTRACT_HONEY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nukkitx.protocol.bedrock.data.event;

import com.nukkitx.math.vector.Vector2f;
import com.nukkitx.math.vector.Vector3f;
import lombok.Value;

@Value
public class MovementEventData implements EventData {
private final int movementType;
private final Vector2f rotation; // Guess
private final Vector3f position; // Guess

@Override
public EventDataType getType() {
return EventDataType.MOVEMENT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nukkitx.protocol.bedrock.data.event;

import lombok.Value;

@Value
public class MovementThresholdEventData implements EventData {
private final float unknown0;
private final float unknown1;
private final float playerMovementScoreThreshold;
private final float playerMovementDistanceThreshold;
private final int playerMovementDurationThreshold;

@Override
public EventDataType getType() {
return EventDataType.MOVEMENT_THRESHOLD;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nukkitx.protocol.bedrock.data.event;

import lombok.Value;

@Value
public class RaidUpdateEventData implements EventData {
private final int currentWave;
private final int totalWaves;
private final boolean unknown0; // Hero of the village?

@Override
public EventDataType getType() {
return EventDataType.RAID_UPDATE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nukkitx.protocol.bedrock.v388.serializer;

import com.nukkitx.math.vector.Vector2f;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.network.VarInts;
import com.nukkitx.network.util.Preconditions;
import com.nukkitx.protocol.bedrock.data.event.*;
Expand Down Expand Up @@ -80,6 +82,9 @@ public void serialize(ByteBuf buffer, EventPacket packet) {
BedrockUtils.writeString(buffer, agentCommandEventData.getDataKey());
BedrockUtils.writeString(buffer, agentCommandEventData.getOutput());
break;
case AGENT_CREATED:
// No extra data
break;
case PATTERN_REMOVED:
PatternRemovedEventData patternRemovedEventData = (PatternRemovedEventData) eventData;
VarInts.writeInt(buffer, patternRemovedEventData.getItemId());
Expand Down Expand Up @@ -130,8 +135,28 @@ public void serialize(ByteBuf buffer, EventPacket packet) {
case BELL_BLOCK_USED:
VarInts.writeInt(buffer, ((BellBlockUsedEventData) eventData).getUnknown0());
break;
case AGENT_CREATED:
// No extra data
case ENTITY_DEFINITION_TRIGGER:
BedrockUtils.writeString(buffer, ((EntityDefinitionTriggerEventData) eventData).getId());
break;
case RAID_UPDATE:
RaidUpdateEventData raidUpdateEventData = (RaidUpdateEventData) eventData;
VarInts.writeInt(buffer, raidUpdateEventData.getCurrentWave());
VarInts.writeInt(buffer, raidUpdateEventData.getTotalWaves());
buffer.writeBoolean(raidUpdateEventData.isUnknown0());
break;
case MOVEMENT:
MovementEventData movementEventData = (MovementEventData) eventData;
buffer.writeByte(movementEventData.getMovementType());
BedrockUtils.writeVector2f(buffer, movementEventData.getRotation());
BedrockUtils.writeVector3f(buffer, movementEventData.getPosition());
break;
case MOVEMENT_THRESHOLD:
MovementThresholdEventData movementThresholdEventData = (MovementThresholdEventData) eventData;
buffer.writeFloatLE(movementThresholdEventData.getUnknown0());
buffer.writeFloatLE(movementThresholdEventData.getUnknown1());
buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementScoreThreshold());
buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementDistanceThreshold());
VarInts.writeInt(buffer, movementThresholdEventData.getPlayerMovementDurationThreshold());
break;
}
}
Expand Down Expand Up @@ -256,6 +281,31 @@ public void deserialize(ByteBuf buffer, EventPacket packet) {
case BELL_BLOCK_USED:
data = new BellBlockUsedEventData(VarInts.readInt(buffer));
break;
case ENTITY_DEFINITION_TRIGGER:
String id = BedrockUtils.readString(buffer);
data = new EntityDefinitionTriggerEventData(id);
break;
case RAID_UPDATE:
int currentWave = VarInts.readInt(buffer);
int totalWaves = VarInts.readInt(buffer);
unknownBool = buffer.readBoolean();
data = new RaidUpdateEventData(currentWave, totalWaves, unknownBool);
break;
case MOVEMENT:
int movementType = buffer.readUnsignedByte();
Vector2f rotation = BedrockUtils.readVector2f(buffer);
Vector3f position = BedrockUtils.readVector3f(buffer);
data = new MovementEventData(movementType, rotation, position);
break;
case MOVEMENT_THRESHOLD:
float unknownFloat0 = buffer.readFloatLE();
float unknownFloat1 = buffer.readFloatLE();
float playerMovementScoreThreshold = buffer.readFloatLE();
float playerMovementDistanceThreshold = buffer.readFloatLE();
int playerMovementDurationThreshold = VarInts.readInt(buffer);
data = new MovementThresholdEventData(unknownFloat0, unknownFloat1, playerMovementScoreThreshold,
playerMovementDistanceThreshold, playerMovementDurationThreshold);
break;
default:
throw new IllegalArgumentException("Unknown EventDataType");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.packet.*;
import com.nukkitx.protocol.bedrock.v388.serializer.*;
import com.nukkitx.protocol.bedrock.v389.serializer.EventSerializer_v389;
import lombok.experimental.UtilityClass;

@UtilityClass
Expand Down Expand Up @@ -74,7 +75,7 @@ public class Bedrock_v389 {
.registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v388.INSTANCE, 62)
.registerPacket(PlayerListPacket.class, PlayerListSerializer_v388.INSTANCE, 63)
.registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v388.INSTANCE, 64)
.registerPacket(EventPacket.class, EventSerializer_v388.INSTANCE, 65)
.registerPacket(EventPacket.class, EventSerializer_v389.INSTANCE, 65)
.registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v388.INSTANCE, 66)
.registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v388.INSTANCE, 67)
.registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v388.INSTANCE, 68)
Expand Down
Loading

0 comments on commit ee72557

Please sign in to comment.