Skip to content

Commit 2c42570

Browse files
committed
Server waypoints api
1 parent 76f7163 commit 2c42570

File tree

12 files changed

+467
-12
lines changed

12 files changed

+467
-12
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ classes
2222
eclipse
2323
run
2424
/.gradle-home/
25+
/neoforge/runs/junit/.mixin.out/class/net/minecraft/core/MappedRegistry.class
26+
/neoforge/runs/junit/.mixin.out/class/net/minecraft/world/level/block/entity/BlockEntityType.class
27+
/neoforge/runs/junit/.mixin.out/class/net/neoforged/neoforge/mixins/BlockEntityTypeAccessor.class
28+
/neoforge/runs/junit/.mixin.out/class/net/neoforged/neoforge/mixins/MappedRegistryAccessor.class
29+
/neoforge/runs/junit/config/fml.toml
30+
/neoforge/runs/junit/config/neoforge-common.toml
31+
/neoforge/runs/junit/logs/2024-06-07-1.log.gz
32+
/neoforge/runs/junit/logs/2024-06-13-1.log.gz
33+
/neoforge/runs/junit/logs/2024-06-24-1.log.gz
34+
/neoforge/runs/junit/logs/debug.log
35+
/neoforge/runs/junit/logs/debug-1.log.gz
36+
/neoforge/runs/junit/logs/debug-2.log.gz
37+
/neoforge/runs/junit/logs/debug-3.log.gz
38+
/neoforge/runs/junit/logs/latest.log
39+
/neoforge/runs/junit/junit_jvm_args.txt
40+
/neoforge/runs/junit/junit_test_args.txt
41+
/neoforge/runs/junit/test_args.txt

common/src/main/java/journeymap/api/v2/common/event/common/WaypointEvent.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ public WaypointEvent(Waypoint waypoint, Context context, ResourceKey<Level> dime
2424
this.context = context;
2525
}
2626

27+
/**
28+
* Server-side constructor. Use when firing from a server context.
29+
*/
30+
public WaypointEvent(Waypoint waypoint, Context context, ResourceKey<Level> dimension, Side side)
31+
{
32+
super(context.cancelable, side);
33+
this.dimension = dimension;
34+
this.waypoint = waypoint;
35+
this.context = context;
36+
}
37+
2738
/**
2839
* World dimension where event occurred.
2940
*/

common/src/main/java/journeymap/api/v2/common/waypoint/WaypointFactory.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ private static WaypointFactory getInstance()
2626
return INSTANCE;
2727
}
2828

29+
/**
30+
* Creates a Waypoint. On the client side this will be a ClientWaypoint; on the server side this
31+
* will be a plain WaypointImpl.
32+
*
33+
* @param modId - The modid of the mod creating the waypoint
34+
* @param pos - The BlockPos of the waypoint
35+
* @param name - The Optional Name of the waypoint. If null, it will use the coordinates as the name.
36+
* @param primaryDimension - The primary dimension identifier string.
37+
* @param persistent - should the waypoint persist between sessions?
38+
* True, JourneyMap will save this waypoint to disk and load every session it only needs to be sent once.
39+
* False, The waypoint will be flushed when the user changes dimensions and exits the game.
40+
* @return - The Waypoint with default values set.
41+
*/
42+
public static Waypoint createWaypoint(String modId, BlockPos pos, @Nullable String name, ResourceKey<Level> primaryDimension, boolean persistent)
43+
{
44+
return createWaypoint(modId, pos, name, primaryDimension.identifier().toString(), persistent);
45+
}
46+
47+
public static Waypoint createWaypoint(String modId, BlockPos pos, ResourceKey<Level> primaryDimension, boolean persistent)
48+
{
49+
return createWaypoint(modId, pos, primaryDimension.identifier().toString(), persistent);
50+
}
51+
52+
public static Waypoint createWaypoint(String modId, BlockPos pos, String primaryDimension, boolean persistent)
53+
{
54+
return createWaypoint(modId, pos, null, primaryDimension, persistent);
55+
}
56+
57+
public static Waypoint createWaypoint(String modId, BlockPos pos, @Nullable String name, String primaryDimension, boolean persistent)
58+
{
59+
return getInstance().store.createWaypoint(modId, pos, name, primaryDimension, persistent);
60+
}
61+
2962
/**
3063
* Creates a ClientWaypoint.
3164
*
@@ -38,22 +71,27 @@ private static WaypointFactory getInstance()
3871
* True, JourneyMap will save this waypoint to disk and load every session it only needs to be sent once.
3972
* False, The waypoint will be flushed when the user changes dimensions and exits the game.
4073
* @return - The Waypoint with default values set.
74+
* @deprecated Use {@link #createWaypoint(String, BlockPos, String, String, boolean)} instead.
4175
*/
76+
@Deprecated
4277
public static Waypoint createClientWaypoint(String modId, BlockPos pos, @Nullable String name, ResourceKey<Level> primaryDimension, boolean persistent)
4378
{
4479
return createClientWaypoint(modId, pos, name, primaryDimension.identifier().toString(), persistent);
4580
}
4681

82+
@Deprecated
4783
public static Waypoint createClientWaypoint(String modId, BlockPos pos, ResourceKey<Level> primaryDimension, boolean persistent)
4884
{
4985
return createClientWaypoint(modId, pos, primaryDimension.identifier().toString(), persistent);
5086
}
5187

88+
@Deprecated
5289
public static Waypoint createClientWaypoint(String modId, BlockPos pos, String primaryDimension, boolean persistent)
5390
{
5491
return createClientWaypoint(modId, pos, null, primaryDimension, persistent);
5592
}
5693

94+
@Deprecated
5795
public static Waypoint createClientWaypoint(String modId, BlockPos pos, @Nullable String name, String primaryDimension, boolean persistent)
5896
{
5997
return getInstance().store.createClientWaypoint(modId, pos, name, primaryDimension, persistent);
@@ -78,6 +116,9 @@ public static WaypointGroup createWaypointGroup(String modId, String name)
78116
@ApiStatus.Internal
79117
public interface WaypointStore
80118
{
119+
Waypoint createWaypoint(String modId, BlockPos pos, @Nullable String name, String primaryDimension, boolean persistent);
120+
121+
@Deprecated
81122
Waypoint createClientWaypoint(String modId, BlockPos pos, @Nullable String name, String primaryDimension, boolean persistent);
82123

83124
Waypoint fromWaypointJsonString(String waypoint);

common/src/main/java/journeymap/api/v2/server/IServerAPI.java

Lines changed: 153 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,186 @@
22

33
import journeymap.api.v2.common.CommonAPI;
44
import journeymap.api.v2.common.waypoint.Waypoint;
5+
import journeymap.api.v2.common.waypoint.WaypointGroup;
56
import net.minecraft.server.level.ServerPlayer;
67

78
import java.util.List;
89
import java.util.UUID;
910

1011
/**
11-
* Currently unused, just a placeholder. Please do not code any of this as it will likely change.
12+
* Server-side JourneyMap API for reading and manipulating waypoints.
1213
*/
13-
@Deprecated
1414
public interface IServerAPI extends CommonAPI
1515
{
16+
// ---- Player waypoint getters ----
17+
1618
/**
17-
* Gets all the waypoints stored for the target Server Player.
19+
* Gets all waypoints stored for the given server player.
1820
*
19-
* @param player - the Player
20-
* @return - the waypoints.
21+
* @param player the server player
22+
* @return the player's waypoints
2123
*/
2224
List<Waypoint> getWaypoints(ServerPlayer player);
2325

2426
/**
25-
* Gets all the waypoints stored for the target Server Player.
27+
* Gets all waypoints stored for the player with the given UUID.
2628
*
27-
* @param id - the player uuid
28-
* @return - the waypoints.
29+
* @param playerUUID the player UUID
30+
* @return the player's waypoints
2931
*/
30-
List<Waypoint> getWaypoints(UUID id);
32+
List<Waypoint> getWaypoints(UUID playerUUID);
3133

3234
/**
33-
* Gets All waypoints stored on the server for all players and all common/global waypoints.
35+
* Gets all waypoints stored on the server for all players and all global waypoints.
3436
*
3537
* @return all waypoints
3638
*/
3739
List<Waypoint> getWaypoints();
3840

41+
/**
42+
* Gets the waypoint with the given GUID for the specified player.
43+
*
44+
* @param playerUUID the player UUID
45+
* @param guid the waypoint GUID
46+
* @return the waypoint, or null if not found
47+
*/
48+
Waypoint getWaypoint(UUID playerUUID, String guid);
49+
50+
/**
51+
* Gets all waypoint groups for the specified player.
52+
*
53+
* @param playerUUID the player UUID
54+
* @return the player's waypoint groups
55+
*/
56+
List<WaypointGroup> getAllGroups(UUID playerUUID);
57+
58+
/**
59+
* Gets the waypoint group with the given GUID for the specified player.
60+
*
61+
* @param playerUUID the player UUID
62+
* @param guid the group GUID
63+
* @return the group, or null if not found
64+
*/
65+
WaypointGroup getGroup(UUID playerUUID, String guid);
66+
67+
// ---- Player waypoint mutations ----
68+
69+
/**
70+
* Adds or updates a waypoint for the specified player.
71+
* Fires {@link journeymap.api.v2.common.event.common.WaypointEvent} (CREATE or UPDATE, cancellable).
72+
*
73+
* @param playerUUID the player UUID
74+
* @param waypoint the waypoint to add or update
75+
*/
76+
void addPlayerWaypoint(UUID playerUUID, Waypoint waypoint);
77+
78+
/**
79+
* Deletes the waypoint with the given GUID for the specified player.
80+
* Fires {@link journeymap.api.v2.common.event.common.WaypointEvent} (DELETED).
81+
*
82+
* @param playerUUID the player UUID
83+
* @param guid the waypoint GUID to delete
84+
*/
85+
void deletePlayerWaypoint(UUID playerUUID, String guid);
86+
87+
/**
88+
* Adds or updates a waypoint group for the specified player.
89+
*
90+
* @param playerUUID the player UUID
91+
* @param group the group to add or update
92+
*/
93+
void addPlayerGroup(UUID playerUUID, WaypointGroup group);
94+
95+
/**
96+
* Deletes the waypoint group with the given GUID for the specified player.
97+
*
98+
* @param playerUUID the player UUID
99+
* @param guid the group GUID to delete
100+
* @param deleteWaypoints if true, also deletes all waypoints belonging to the group
101+
*/
102+
void deletePlayerGroup(UUID playerUUID, String guid, boolean deleteWaypoints);
103+
104+
// ---- Global waypoint getters ----
105+
39106
/**
40107
* Gets all waypoints that are not tied to specific players.
41-
* These waypoints are created for every player when they log in.
108+
* These waypoints are visible to every player when they log in.
42109
*
43-
* @return
110+
* @return all global waypoints
44111
*/
45112
List<Waypoint> getGlobalWaypoints();
113+
114+
/**
115+
* Gets the global waypoint with the given GUID.
116+
*
117+
* @param guid the waypoint GUID
118+
* @return the waypoint, or null if not found
119+
*/
120+
Waypoint getGlobalWaypoint(String guid);
121+
122+
/**
123+
* Gets all global waypoint groups.
124+
*
125+
* @return all global waypoint groups
126+
*/
127+
List<WaypointGroup> getAllGlobalGroups();
128+
129+
/**
130+
* Gets the global waypoint group with the given GUID.
131+
*
132+
* @param guid the group GUID
133+
* @return the group, or null if not found
134+
*/
135+
WaypointGroup getGlobalGroup(String guid);
136+
137+
// ---- Global waypoint mutations ----
138+
139+
/**
140+
* Adds or updates a global waypoint.
141+
* Fires {@link journeymap.api.v2.server.event.server.GlobalWaypointEvent} (CREATE or UPDATE, cancellable).
142+
*
143+
* @param waypoint the waypoint to add or update
144+
*/
145+
void addGlobalWaypoint(Waypoint waypoint);
146+
147+
/**
148+
* Deletes the global waypoint with the given GUID.
149+
* Fires {@link journeymap.api.v2.server.event.server.GlobalWaypointEvent} (DELETED).
150+
*
151+
* @param guid the waypoint GUID to delete
152+
*/
153+
void deleteGlobalWaypoint(String guid);
154+
155+
/**
156+
* Adds or updates a global waypoint group.
157+
* Fires {@link journeymap.api.v2.server.event.server.GlobalWaypointGroupEvent} (CREATE or UPDATE, cancellable).
158+
*
159+
* @param group the group to add or update
160+
*/
161+
void addGlobalGroup(WaypointGroup group);
162+
163+
/**
164+
* Deletes the global waypoint group with the given GUID.
165+
* Fires {@link journeymap.api.v2.server.event.server.GlobalWaypointGroupEvent} (DELETED).
166+
*
167+
* @param guid the group GUID to delete
168+
* @param deleteWaypoints if true, also deletes all waypoints belonging to the group
169+
*/
170+
void deleteGlobalGroup(String guid, boolean deleteWaypoints);
171+
172+
// ---- Share hook ----
173+
174+
/**
175+
* Programmatically share a waypoint with one or more players.
176+
* Fires {@link journeymap.api.v2.server.event.ServerEventRegistry#WAYPOINT_SHARE_SUBMIT_EVENT} (cancellable)
177+
* before storing pending entries.
178+
*
179+
* @param waypoint the waypoint to share
180+
* @param fromUUID UUID of the player or system initiating the share
181+
* @param fromName display name shown to recipients
182+
* @param targetIds specific recipients; ignored if allKnownUsers is true
183+
* @param allKnownUsers if true, shares with all players in PlayerData
184+
*/
185+
void shareWaypoint(Waypoint waypoint, UUID fromUUID, String fromName,
186+
List<UUID> targetIds, boolean allKnownUsers);
46187
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
11
package journeymap.api.v2.server.event;
22

3+
import journeymap.api.v2.common.event.impl.Event;
4+
import journeymap.api.v2.common.event.impl.EventFactory;
5+
import journeymap.api.v2.server.event.server.GlobalWaypointEvent;
6+
import journeymap.api.v2.server.event.server.GlobalWaypointGroupEvent;
7+
import journeymap.api.v2.server.event.server.WaypointPendingActionEvent;
8+
import journeymap.api.v2.server.event.server.WaypointPendingReceivedEvent;
9+
import journeymap.api.v2.server.event.server.WaypointShareSubmitEvent;
10+
311
/**
412
* Server only events will be here.
513
*/
614
public class ServerEventRegistry
715
{
16+
/**
17+
* Fired on the server when a player (or addon via IServerAPI) submits a waypoint share.
18+
* Cancellable: cancel to block the entire share (nothing stored, no notifications sent).
19+
*/
20+
public static final Event<WaypointShareSubmitEvent> WAYPOINT_SHARE_SUBMIT_EVENT =
21+
EventFactory.create(WaypointShareSubmitEvent.class);
22+
23+
/**
24+
* Fired once per recipient before a pending waypoint entry is stored.
25+
* Cancellable: cancel to skip this specific recipient; other recipients are unaffected.
26+
*/
27+
public static final Event<WaypointPendingReceivedEvent> WAYPOINT_PENDING_RECEIVED_EVENT =
28+
EventFactory.create(WaypointPendingReceivedEvent.class);
29+
30+
/**
31+
* Fired when a recipient accepts or declines a pending waypoint.
32+
* Cancellable: cancel to block the action (waypoint stays in pending).
33+
*/
34+
public static final Event<WaypointPendingActionEvent> WAYPOINT_PENDING_ACTION_EVENT =
35+
EventFactory.create(WaypointPendingActionEvent.class);
36+
37+
/**
38+
* Fired for global waypoint CRUD. CREATE and UPDATE are cancellable.
39+
*/
40+
public static final Event<GlobalWaypointEvent> GLOBAL_WAYPOINT_EVENT =
41+
EventFactory.create(GlobalWaypointEvent.class);
42+
43+
/**
44+
* Fired for global waypoint group CRUD. CREATE and UPDATE are cancellable.
45+
*/
46+
public static final Event<GlobalWaypointGroupEvent> GLOBAL_WAYPOINT_GROUP_EVENT =
47+
EventFactory.create(GlobalWaypointGroupEvent.class);
848
}

0 commit comments

Comments
 (0)