Skip to content

Commit ef6b65c

Browse files
committed
Examples & Docs (WIP)
1 parent 0ac4740 commit ef6b65c

File tree

22 files changed

+439
-43
lines changed

22 files changed

+439
-43
lines changed

api/src/main/java/com/lunarclient/apollo/event/pingmarker/ApolloPlayerRequestPingEvent.java renamed to api/src/main/java/com/lunarclient/apollo/event/pingmarker/ApolloPlayerRequestMarkerEvent.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,44 @@
3636
import org.jetbrains.annotations.Nullable;
3737

3838
/**
39-
* Represents an event that is fired when the player requests a ping.
39+
* Represents an event that is fired when the player requests a ping marker.
4040
*
41-
* @since 1.1.3
41+
* @since 1.1.9
4242
*/
4343
@Getter
4444
@RequiredArgsConstructor
4545
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
46-
public final class ApolloPlayerRequestPingEvent implements EventCancellable {
46+
public final class ApolloPlayerRequestMarkerEvent implements EventCancellable {
4747

4848
/**
4949
* The player sending the ping request.
5050
*
5151
* @return the source player
52-
* @since 1.1.3
52+
* @since 1.1.9
5353
*/
5454
ApolloPlayer player;
5555

5656
/**
5757
* The {@link PingMarkerType} for this request.
5858
*
5959
* @return the ping marker type
60-
* @since 1.1.3
60+
* @since 1.1.9
6161
*/
6262
@Nullable PingMarkerType type;
6363

6464
/**
6565
* The source {@link ApolloLocation} for this request.
6666
*
6767
* @return the source location
68-
* @since 1.1.3
68+
* @since 1.1.9
6969
*/
7070
ApolloLocation source;
7171

7272
/**
7373
* The target {@link ApolloLocation} for this request.
7474
*
7575
* @return the target location
76-
* @since 1.1.3
76+
* @since 1.1.9
7777
*/
7878
ApolloLocation target;
7979

api/src/main/java/com/lunarclient/apollo/module/pingmarker/PingMarker.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/**
3636
* Represents a ping marker which can be shown on the client.
3737
*
38-
* @since 1.1.3
38+
* @since 1.1.9
3939
*/
4040
@Getter
4141
@Builder
@@ -45,47 +45,47 @@ public final class PingMarker {
4545
* Returns the marker {@link UUID}.
4646
*
4747
* @return the ping marker id
48-
* @since 1.1.3
48+
* @since 1.1.9
4949
*/
5050
UUID id;
5151

5252
/**
5353
* Returns the {@link PingMarkerType}.
5454
*
5555
* @return the ping marker type
56-
* @since 1.1.3
56+
* @since 1.1.9
5757
*/
5858
@Nullable PingMarkerType type;
5959

6060
/**
6161
* Returns the marker {@link ApolloLocation}.
6262
*
6363
* @return the ping marker location
64-
* @since 1.1.3
64+
* @since 1.1.9
6565
*/
6666
ApolloLocation location;
6767

6868
/**
6969
* Returns the marker {@link Color}.
7070
*
7171
* @return the ping marker color
72-
* @since 1.1.3
72+
* @since 1.1.9
7373
*/
7474
Color color;
7575

7676
/**
7777
* Returns the marker {@link Duration}.
7878
*
7979
* @return the ping marker duration
80-
* @since 1.1.3
80+
* @since 1.1.9
8181
*/
8282
Duration duration;
8383

8484
/**
8585
* Returns whether the marker should animate.
8686
*
8787
* @return the ping marker focus state
88-
* @since 1.1.3
88+
* @since 1.1.9
8989
*/
9090
boolean focus;
9191

@@ -96,7 +96,7 @@ public final class PingMarker {
9696
* for the most common use case, use {@link com.lunarclient.apollo.common.icon.ItemStackIcon}.</p>
9797
*
9898
* @return the ping marker icon
99-
* @since 1.1.3
99+
* @since 1.1.9
100100
*/
101101
Icon icon;
102102

api/src/main/java/com/lunarclient/apollo/module/pingmarker/PingMarkerModule.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Represents the ping marker module.
3434
*
35-
* @since 1.0.0
35+
* @since 1.1.9
3636
*/
3737
@ApiStatus.NonExtendable
3838
@ModuleDefinition(id = "ping_marker", name = "Ping Marker")
@@ -43,7 +43,7 @@ public abstract class PingMarkerModule extends ApolloModule {
4343
*
4444
* @param recipients the recipients that are receiving the packet
4545
* @param type the marker type
46-
* @since 1.1.3
46+
* @since 1.1.9
4747
*/
4848
public abstract void setMarkerType(Recipients recipients, PingMarkerType type);
4949

@@ -52,7 +52,7 @@ public abstract class PingMarkerModule extends ApolloModule {
5252
*
5353
* @param recipients the recipients that are receiving the packet
5454
* @param name the marker type name
55-
* @since 1.1.3
55+
* @since 1.1.9
5656
*/
5757
public abstract void removeMarkerType(Recipients recipients, String name);
5858

@@ -61,15 +61,15 @@ public abstract class PingMarkerModule extends ApolloModule {
6161
*
6262
* @param recipients the recipients that are receiving the packet
6363
* @param type the marker type
64-
* @since 1.1.3
64+
* @since 1.1.9
6565
*/
6666
public abstract void removeMarkerType(Recipients recipients, PingMarkerType type);
6767

6868
/**
6969
* Resets all {@link PingMarkerType}s for the {@link Recipients}.
7070
*
7171
* @param recipients the recipients that are receiving the packet
72-
* @since 1.1.3
72+
* @since 1.1.9
7373
*/
7474
public abstract void resetMarkerType(Recipients recipients);
7575

@@ -78,7 +78,7 @@ public abstract class PingMarkerModule extends ApolloModule {
7878
*
7979
* @param recipients the recipients that are receiving the packet
8080
* @param marker the marker
81-
* @since 1.1.3
81+
* @since 1.1.9
8282
*/
8383
public abstract void displayMarker(Recipients recipients, PingMarker marker);
8484

@@ -87,7 +87,7 @@ public abstract class PingMarkerModule extends ApolloModule {
8787
*
8888
* @param recipients the recipients that are receiving the packet
8989
* @param markerId the marker id
90-
* @since 1.1.3
90+
* @since 1.1.9
9191
*/
9292
public abstract void removeMarker(Recipients recipients, UUID markerId);
9393

@@ -96,15 +96,15 @@ public abstract class PingMarkerModule extends ApolloModule {
9696
*
9797
* @param recipients the recipients that are receiving the packet
9898
* @param marker the marker
99-
* @since 1.1.3
99+
* @since 1.1.9
100100
*/
101101
public abstract void removeMarker(Recipients recipients, PingMarker marker);
102102

103103
/**
104104
* Resets all {@link PingMarker}s for the {@link Recipients}.
105105
*
106106
* @param recipients the recipients that are receiving the packet
107-
* @since 1.1.3
107+
* @since 1.1.9
108108
*/
109109
public abstract void resetMarkers(Recipients recipients);
110110

api/src/main/java/com/lunarclient/apollo/module/pingmarker/PingMarkerType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Represents a ping marker type which can be shown on the client.
3232
*
33-
* @since 1.1.3
33+
* @since 1.1.9
3434
*/
3535
@Getter
3636
@Builder
@@ -40,7 +40,7 @@ public final class PingMarkerType {
4040
* Returns the ping marker type {@link String} name.
4141
*
4242
* @return the ping marker type name
43-
* @since 1.1.3
43+
* @since 1.1.9
4444
*/
4545
String name;
4646

@@ -51,7 +51,7 @@ public final class PingMarkerType {
5151
* for the most common use case, use {@link com.lunarclient.apollo.common.icon.ItemStackIcon}.</p>
5252
*
5353
* @return the ping marker icon
54-
* @since 1.1.3
54+
* @since 1.1.9
5555
*/
5656
Icon icon;
5757

api/src/main/java/com/lunarclient/apollo/recipients/Recipients.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static ForwardingRecipients ofEveryone() {
6464
*
6565
* @param player the apollo player
6666
* @return a {@code ForwardingRecipients} instance representing players in the world
67-
* @since 1.1.3
67+
* @since 1.1.9
6868
*/
6969
static ForwardingRecipients ofWorld(ApolloPlayer player) {
7070
return () -> player.getWorld().map(ApolloWorld::getPlayers).orElseGet(() -> Apollo.getPlayerManager().getPlayers());

bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/ApolloApiExamplePlatform.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.lunarclient.apollo.example.api.module.NametagApiExample;
4545
import com.lunarclient.apollo.example.api.module.NickHiderApiExample;
4646
import com.lunarclient.apollo.example.api.module.NotificationApiExample;
47+
import com.lunarclient.apollo.example.api.module.PingMarkerApiExample;
4748
import com.lunarclient.apollo.example.api.module.RichPresenceApiExample;
4849
import com.lunarclient.apollo.example.api.module.ServerRuleApiExample;
4950
import com.lunarclient.apollo.example.api.module.StaffModApiExample;
@@ -92,6 +93,7 @@ public void registerModuleExamples() {
9293
this.setNametagExample(new NametagApiExample());
9394
this.setNickHiderExample(new NickHiderApiExample());
9495
this.setNotificationExample(new NotificationApiExample());
96+
this.setPingMarkerExample(new PingMarkerApiExample());
9597
this.setRichPresenceExample(new RichPresenceApiExample());
9698
this.setServerRuleExample(new ServerRuleApiExample());
9799
this.setStaffModExample(new StaffModApiExample());

bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/listener/ApolloPlayerApiListener.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
import com.lunarclient.apollo.event.ApolloListener;
2727
import com.lunarclient.apollo.event.EventBus;
2828
import com.lunarclient.apollo.event.Listen;
29-
import com.lunarclient.apollo.event.pingmarker.ApolloPlayerRequestPingEvent;
3029
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
3130
import com.lunarclient.apollo.example.ApolloExamplePlugin;
3231
import com.lunarclient.apollo.example.api.module.TeamApiExample;
3332
import com.lunarclient.apollo.player.ApolloPlayer;
34-
import com.lunarclient.apollo.world.ApolloWorld;
3533
import org.bukkit.entity.Player;
3634

3735
public class ApolloPlayerApiListener implements ApolloListener {
@@ -65,12 +63,4 @@ private void onApolloRegister(ApolloRegisterPlayerEvent event) {
6563
this.example.getWaypointExample().displayWaypointExample(player);
6664
}
6765

68-
@Listen
69-
private void onPingMarker(ApolloPlayerRequestPingEvent event) {
70-
ApolloWorld world = event.getPlayer().getWorld().orElse(null);
71-
if (world == null) return;
72-
73-
this.plugin.getPingMarkerExample().displayMarkerExample(event.getType(), event.getTarget(), world.getPlayers());
74-
}
75-
7666
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.api.module;
25+
26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.BukkitApollo;
28+
import com.lunarclient.apollo.common.icon.SimpleResourceLocationIcon;
29+
import com.lunarclient.apollo.example.module.impl.PingMarkerExample;
30+
import com.lunarclient.apollo.module.pingmarker.PingMarker;
31+
import com.lunarclient.apollo.module.pingmarker.PingMarkerModule;
32+
import com.lunarclient.apollo.player.ApolloPlayer;
33+
import com.lunarclient.apollo.recipients.Recipients;
34+
import java.awt.Color;
35+
import java.time.Duration;
36+
import java.util.Optional;
37+
import java.util.UUID;
38+
import org.bukkit.Location;
39+
import org.bukkit.block.Block;
40+
import org.bukkit.entity.Player;
41+
42+
public class PingMarkerApiExample extends PingMarkerExample {
43+
44+
private final PingMarkerModule pingMarkerModule = Apollo.getModuleManager().getModule(PingMarkerModule.class);
45+
46+
@Override
47+
public void displayMarkerResourceExample(Player player) {
48+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(player.getUniqueId());
49+
50+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
51+
Location location = this.findTargetLocation(player);
52+
53+
if (location == null) {
54+
return;
55+
}
56+
57+
this.pingMarkerModule.displayMarker(Recipients.ofWorld(apolloPlayer), PingMarker.builder()
58+
.id(UUID.randomUUID())
59+
.type(null) // TODO: add another example with a specific type
60+
.location(BukkitApollo.toApolloLocation(location))
61+
.color(Color.WHITE)
62+
.icon(SimpleResourceLocationIcon.builder()
63+
.resourceLocation("lunar:icons/fluent-black-circle-icon.svg")
64+
.size(12)
65+
.build()
66+
)
67+
.duration(Duration.ofSeconds(5))
68+
.focus(true)
69+
.build());
70+
});
71+
72+
}
73+
74+
private Location findTargetLocation(Player player) {
75+
Block targetBlock = player.getTargetBlockExact(30);
76+
77+
if (targetBlock == null) {
78+
return null;
79+
}
80+
81+
return targetBlock.getLocation().add(0.5D, 0.5D, 0.5D);
82+
}
83+
84+
}

bukkit-example-api/src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ commands:
4343
description: "Nick Hider!"
4444
notification:
4545
description: "Notifications!"
46+
pingmarker:
47+
description: "Ping Marker!"
4648
richpresence:
4749
description: "Rich Presence!"
4850
saturation:

0 commit comments

Comments
 (0)