3131import com .lunarclient .apollo .player .ApolloPlayer ;
3232import com .lunarclient .apollo .recipients .Recipients ;
3333import com .lunarclient .apollo .waypoint .v1 .DisplayWaypointMessage ;
34+ import com .lunarclient .apollo .waypoint .v1 .HideWaypointMessage ;
3435import com .lunarclient .apollo .waypoint .v1 .RemoveWaypointMessage ;
3536import com .lunarclient .apollo .waypoint .v1 .ResetWaypointsMessage ;
37+ import com .lunarclient .apollo .waypoint .v1 .ShowWaypointMessage ;
3638import java .awt .Color ;
3739import java .lang .reflect .Type ;
3840import java .util .Arrays ;
4345import org .spongepowered .configurate .serialize .SerializationException ;
4446import org .spongepowered .configurate .serialize .TypeSerializer ;
4547
48+ import static com .lunarclient .apollo .util .Ranges .checkRange ;
49+
4650/**
4751 * Provides the waypoints module.
4852 *
@@ -87,6 +91,24 @@ public void resetWaypoints(@NonNull Recipients recipients) {
8791 recipients .forEach (player -> ((AbstractApolloPlayer ) player ).sendPacket (message ));
8892 }
8993
94+ @ Override
95+ public void showWaypoint (@ NonNull Recipients recipients , @ NonNull String waypointName ) {
96+ ShowWaypointMessage message = ShowWaypointMessage .newBuilder ()
97+ .setName (waypointName )
98+ .build ();
99+
100+ recipients .forEach (player -> ((AbstractApolloPlayer ) player ).sendPacket (message ));
101+ }
102+
103+ @ Override
104+ public void hideWaypoint (@ NonNull Recipients recipients , @ NonNull String waypointName ) {
105+ HideWaypointMessage message = HideWaypointMessage .newBuilder ()
106+ .setName (waypointName )
107+ .build ();
108+
109+ recipients .forEach (player -> ((AbstractApolloPlayer ) player ).sendPacket (message ));
110+ }
111+
90112 private void onPlayerRegister (ApolloRegisterPlayerEvent event ) {
91113 ApolloPlayer player = event .getPlayer ();
92114 List <Waypoint > waypoints = this .getOptions ().get (player , WaypointModule .DEFAULT_WAYPOINTS );
@@ -99,31 +121,74 @@ private void onPlayerRegister(ApolloRegisterPlayerEvent event) {
99121 }
100122
101123 private DisplayWaypointMessage toProtobuf (Waypoint waypoint ) {
102- return DisplayWaypointMessage .newBuilder ()
124+ DisplayWaypointMessage . Builder builder = DisplayWaypointMessage .newBuilder ()
103125 .setName (waypoint .getName ())
104126 .setLocation (NetworkTypes .toProtobuf (waypoint .getLocation ()))
105127 .setColor (NetworkTypes .toProtobuf (waypoint .getColor ()))
106128 .setPreventRemoval (waypoint .isPreventRemoval ())
107129 .setHidden (waypoint .isHidden ())
130+ .setShowBeam (waypoint .isShowBeam ())
131+ .setHighlightBlock (waypoint .isHighlightBlock ());
132+
133+ float highlightBlockLineWidth = waypoint .getHighlightBlockLineWidth ();
134+ if (highlightBlockLineWidth != 0.0F ) {
135+ builder .setHighlightBlockLineWidth (checkRange (highlightBlockLineWidth , 1.5F , 7.5F , "Waypoint#highlightBlockLineWidth" ));
136+ }
137+
138+ WaypointTextStyle style = waypoint .getTextStyle ();
139+ if (style != null ) {
140+ builder .setStyle (this .toProtobuf (style ));
141+ }
142+
143+ return builder .build ();
144+ }
145+
146+ private com .lunarclient .apollo .waypoint .v1 .WaypointTextStyle toProtobuf (WaypointTextStyle style ) {
147+ return com .lunarclient .apollo .waypoint .v1 .WaypointTextStyle .newBuilder ()
148+ .setShowText (style .isShowText ())
149+ .setOnlyShowTextWhenLookingNear (style .isOnlyShowTextWhenLookingNear ())
150+ .setShowIcons (style .isShowIcons ())
151+ .setTextIconScale (checkRange (style .getTextIconScale (), 0.1F , 3.0F , "WaypointTextStyle#textIconScale" ))
152+ .setLabelScale (checkRange (style .getLabelScale (), 0.1F , 2.0F , "WaypointTextStyle#labelScale" ))
153+ .setBoxPadding (checkRange (style .getBoxPadding (), 1.0F , 8.0F , "WaypointTextStyle#boxPadding" ))
154+ .setBoxBorders (style .isBoxBorders ())
155+ .setTextShadow (style .isTextShadow ())
156+ .setShowDistance (style .isShowDistance ())
108157 .build ();
109158 }
110159
111160 private static final class WaypointSerializer implements TypeSerializer <Waypoint > {
112161 @ Override
113162 public Waypoint deserialize (Type type , ConfigurationNode node ) throws SerializationException {
114- return Waypoint .builder ()
163+ Waypoint . WaypointBuilder builder = Waypoint .builder ()
115164 .name (this .virtualNode (node , "name" ).getString ())
116165 .location (ApolloBlockLocation .builder ()
117166 .world (this .virtualNode (node , "location" , "world" ).getString ())
118167 .x (this .virtualNode (node , "location" , "x" ).getInt ())
119168 .y (this .virtualNode (node , "location" , "y" ).getInt ())
120169 .z (this .virtualNode (node , "location" , "z" ).getInt ())
121- .build ()
122- )
123- .color (Color .decode (this .virtualNode (node , "color" ).getString ("#FFFFFF" )))
124- .preventRemoval (this .virtualNode (node , "prevent-removal" ).getBoolean ())
125- .hidden (this .virtualNode (node , "hidden" ).getBoolean ())
126- .build ();
170+ .build ())
171+ .color (Color .decode (node .node ("color" ).getString ("#FFFFFF" )))
172+ .preventRemoval (node .node ("prevent-removal" ).getBoolean ())
173+ .hidden (node .node ("hidden" ).getBoolean ());
174+
175+ if (node .hasChild ("show-beam" )) {
176+ builder .showBeam (node .node ("show-beam" ).getBoolean (true ));
177+ }
178+
179+ if (node .hasChild ("highlight-block" )) {
180+ builder .highlightBlock (node .node ("highlight-block" ).getBoolean (true ));
181+ }
182+
183+ if (node .hasChild ("highlight-block-line-width" )) {
184+ builder .highlightBlockLineWidth ((float ) node .node ("highlight-block-line-width" ).getDouble (4.0D ));
185+ }
186+
187+ if (node .hasChild ("style" )) {
188+ builder .textStyle (this .readStyle (node .node ("style" )));
189+ }
190+
191+ return builder .build ();
127192 }
128193
129194 @ Override
@@ -141,6 +206,66 @@ public void serialize(Type type, @Nullable Waypoint waypoint, ConfigurationNode
141206 node .node ("color" ).set (String .format ("#%06X" , (0xFFFFFF & waypoint .getColor ().getRGB ())));
142207 node .node ("prevent-removal" ).set (waypoint .isPreventRemoval ());
143208 node .node ("hidden" ).set (waypoint .isHidden ());
209+ node .node ("show-beam" ).set (waypoint .isShowBeam ());
210+ node .node ("highlight-block" ).set (waypoint .isHighlightBlock ());
211+ node .node ("highlight-block-line-width" ).set (waypoint .getHighlightBlockLineWidth ());
212+
213+ if (waypoint .getTextStyle () != null ) {
214+ this .writeStyle (node .node ("style" ), waypoint .getTextStyle ());
215+ }
216+ }
217+
218+ private WaypointTextStyle readStyle (ConfigurationNode node ) {
219+ WaypointTextStyle .WaypointTextStyleBuilder builder = WaypointTextStyle .builder ();
220+ if (node .hasChild ("show-text" )) {
221+ builder .showText (node .node ("show-text" ).getBoolean (true ));
222+ }
223+
224+ if (node .hasChild ("only-show-text-when-looking-near" )) {
225+ builder .onlyShowTextWhenLookingNear (node .node ("only-show-text-when-looking-near" ).getBoolean (false ));
226+ }
227+
228+ if (node .hasChild ("show-icons" )) {
229+ builder .showIcons (node .node ("show-icons" ).getBoolean (false ));
230+ }
231+
232+ if (node .hasChild ("text-icon-scale" )) {
233+ builder .textIconScale (node .node ("text-icon-scale" ).getFloat (1.5F ));
234+ }
235+
236+ if (node .hasChild ("label-scale" )) {
237+ builder .labelScale (node .node ("label-scale" ).getFloat (1.0F ));
238+ }
239+
240+ if (node .hasChild ("box-padding" )) {
241+ builder .boxPadding (node .node ("box-padding" ).getFloat (4.0F ));
242+ }
243+
244+ if (node .hasChild ("box-borders" )) {
245+ builder .boxBorders (node .node ("box-borders" ).getBoolean (true ));
246+ }
247+
248+ if (node .hasChild ("text-shadow" )) {
249+ builder .textShadow (node .node ("text-shadow" ).getBoolean (false ));
250+ }
251+
252+ if (node .hasChild ("show-distance" )) {
253+ builder .showDistance (node .node ("show-distance" ).getBoolean (true ));
254+ }
255+
256+ return builder .build ();
257+ }
258+
259+ private void writeStyle (ConfigurationNode node , WaypointTextStyle style ) throws SerializationException {
260+ node .node ("show-text" ).set (style .isShowText ());
261+ node .node ("only-show-text-when-looking-near" ).set (style .isOnlyShowTextWhenLookingNear ());
262+ node .node ("show-icons" ).set (style .isShowIcons ());
263+ node .node ("text-icon-scale" ).set (style .getTextIconScale ());
264+ node .node ("label-scale" ).set (style .getLabelScale ());
265+ node .node ("box-padding" ).set (style .getBoxPadding ());
266+ node .node ("box-borders" ).set (style .isBoxBorders ());
267+ node .node ("text-shadow" ).set (style .isTextShadow ());
268+ node .node ("show-distance" ).set (style .isShowDistance ());
144269 }
145270
146271 private ConfigurationNode virtualNode (ConfigurationNode source , Object ... path ) throws SerializationException {
0 commit comments