Skip to content

Commit 5137581

Browse files
committed
feat: code operation messages
1 parent b4ff043 commit 5137581

File tree

3 files changed

+87
-14
lines changed

3 files changed

+87
-14
lines changed

src/main/java/com/mcdiamondfire/proto/ModAPIMessages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public final class ModAPIMessages {
3838
// Server-bound.
3939

4040
// Plot.
41-
registerMessage(C2SGetTemplate.class, "c2s_get_template");
42-
registerMessage(C2SPlaceTemplate.class, "c2s_place_template");
41+
registerMessage(C2SCodeOperation.class, "c2s_code_operation");
42+
registerMessage(C2SMultiCodeOperations.class, "c2s_multi_code_operations");
4343

4444
// Player.
4545
registerMessage(C2SPlayerTeleport.class, "c2s_player_teleport");

src/main/proto/data_type.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ enum PlayerMode {
2424
VANISH = 5; // Mod vanish mode.
2525
IDLE = 6; // Spawn (idle) mode.
2626
}
27+
28+
// Represents a code template.
29+
message Template {
30+
oneof template {
31+
string json = 2; // The template JSON string.
32+
string data = 3; // The template code data.
33+
}
34+
}
35+
36+
// Represents a line starter type.
37+
enum LineStarterType {
38+
PLAYER_EVENT = 0; // A Player Event.
39+
ENTITY_EVENT = 1; // An Entity Event.
40+
FUNCTION = 2; // A Function.
41+
PROCESS = 3; // A Process.
42+
}

src/main/proto/serverbound_plot.proto

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,80 @@ import "data_type.proto";
44
option java_package = "com.mcdiamondfire.proto.messages.serverbound.player";
55
option java_multiple_files = true;
66

7-
// Requests the template at the given location,
7+
// Requests to get the template for the code block at the given location,
88
// requires the player to have developer permissions on the plot,
9-
// and the location being a valid code block position.
10-
// An S2CCodeTemplate packet will be sent as a response.
11-
message C2SGetTemplate {
12-
Location location = 1; // The location of the code block to get the template of.
9+
// and the location being a valid line starter.
10+
message GetByLocationOperation {
11+
Location location = 1; // The location of the code block to get the template for.
12+
}
13+
14+
// Requests to get the template for the code block with the given line starter type and action name,
15+
// requires the player to have developer permissions on the plot,
16+
// and that the code block exists.
17+
message GetByBlockOperation {
18+
LineStarterType type = 1; // The type of line starter of the code block to get the template for.
19+
string action = 2; // The sign action name of the code block to get the template for.
1320
}
1421

1522
// Requests to place a template at the given location,
1623
// requires the player to have developer permissions on the plot,
17-
// the location being a valid code block position,
24+
// the location being a valid line starter,
1825
// and that the template will not override any blocks nor exit the plot bounds.
19-
// An S2CPlaceTemplateResult packet will be sent as a response.
20-
message C2SPlaceTemplate {
21-
Location location = 1; // The location of the code block to place the template at.
22-
oneof template {
23-
string json = 2; // The template JSON string.
24-
string data = 3; // The template code data.
26+
message PlaceOperation {
27+
Location location = 1; // The location to place the template at.
28+
Template template = 2; // The template to place.
29+
}
30+
31+
// Requests to delete the code block at the given location,
32+
// requires the player to have developer permissions on the plot,
33+
// and the location being a valid line starter.
34+
message DeleteByLocationOperation {
35+
Location location = 1; // The location of the code block to delete.
36+
}
37+
38+
// Requests to delete the code block with the given line starter type and action name,
39+
// requires the player to have developer permissions on the plot,
40+
// and that the code block exists.
41+
message DeleteByBlockOperation {
42+
LineStarterType type = 1; // The type of line starter of the code block to delete.
43+
string action = 2; // The sign action name of the code block to delete.
44+
}
45+
46+
// Requests to replace the code block at the given location with the given template,
47+
// requires the player to have developer permissions on the plot,
48+
// the location being a valid line starter,
49+
// and that the template will not override any blocks nor exit the plot bounds (except for the blocks being replaced).
50+
message ReplaceByLocationOperation {
51+
Location location = 1; // The location of the code block to replace.
52+
Template template = 2; // The template to replace the code block with.
53+
}
54+
55+
// Requests to replace the code block with the given line starter type and action name with the given template,
56+
// requires the player to have developer permissions on the plot,
57+
// and that the code block exists,
58+
// and that the template will not override any blocks nor exit the plot bounds (except for the blocks being replaced).
59+
message ReplaceByBlockOperation {
60+
LineStarterType type = 1; // The type of line starter of the code block to replace.
61+
string action = 2; // The sign action name of the code block to replace.
62+
Template template = 3; // The template to replace the code block with.
63+
}
64+
65+
// Requests a code operation.
66+
// An S2CCodeOperationResult packet will be sent as a response, the relevant field will be set depending on the operation requested.
67+
message C2SCodeOperation {
68+
oneof operation {
69+
GetByLocationOperation get_by_location = 1; // The operation to get the template for the code block at the given location.
70+
GetByBlockOperation get_by_block = 2; // The operation to get the template for the code block with the given line starter type and action name.
71+
PlaceOperation place = 3; // The operation to place a template at the given location.
72+
DeleteByLocationOperation delete_by_location = 4; // The operation to delete the code block at the given location.
73+
DeleteByBlockOperation delete_by_block = 5; // The operation to delete the code block with the given line starter type and action name.
74+
ReplaceByLocationOperation replace_by_location = 6; // The operation to replace the code block at the given location with the given template.
75+
ReplaceByBlockOperation replace_by_block = 7; // The operation to replace the code block with the given line starter type and action name with the given template.
2576
}
2677
}
78+
79+
// Requests multiple code operations in one packet.
80+
// An S2CMultiCodeOperationResult packet will be sent as a response, containing the results of all operations requested.
81+
message C2SMultiCodeOperations {
82+
repeated C2SCodeOperation operations = 1; // The operations to perform.
83+
}

0 commit comments

Comments
 (0)