Skip to content

Commit 1a89393

Browse files
authored
Addition/waypoints (#2)
* add waypoints integration * 2025
1 parent 5063ace commit 1a89393

File tree

8 files changed

+836
-2
lines changed

8 files changed

+836
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ subprojects {
5252

5353
dependencies {
5454
compileOnly("org.jetbrains:annotations:22.0.0")
55-
compileOnly("net.labymod.serverapi:core:0.1.13")
55+
compileOnly("net.labymod.serverapi:core:1.0.6")
5656
compileOnly("com.google.auto.service:auto-service:1.1.1")
5757
annotationProcessor("com.google.auto.service:auto-service:1.1.1")
5858
}

settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
rootProject.name = "labymod4-server-api-integrations"
22

33
include(":voicechat")
4-
include(":betterperspective")
4+
include(":betterperspective")
5+
include(":waypoints")
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.integration.waypoints;
26+
27+
import com.google.auto.service.AutoService;
28+
import net.labymod.serverapi.api.packet.Direction;
29+
import net.labymod.serverapi.core.AbstractLabyModPlayer;
30+
import net.labymod.serverapi.core.AbstractLabyModProtocolService;
31+
import net.labymod.serverapi.core.AddonProtocol;
32+
import net.labymod.serverapi.core.integration.LabyModIntegrationPlayer;
33+
import net.labymod.serverapi.core.integration.LabyModProtocolIntegration;
34+
import net.labymod.serverapi.integration.waypoints.packets.WaypointDimensionPacket;
35+
import net.labymod.serverapi.integration.waypoints.packets.WaypointPacket;
36+
import net.labymod.serverapi.integration.waypoints.packets.WaypointRemovePacket;
37+
import org.jetbrains.annotations.NotNull;
38+
39+
@AutoService(LabyModProtocolIntegration.class)
40+
public class WaypointsIntegration implements LabyModProtocolIntegration {
41+
42+
private AbstractLabyModProtocolService protocolService;
43+
private AddonProtocol addonProtocol;
44+
45+
@Override
46+
public void initialize(AbstractLabyModProtocolService protocolService) {
47+
if (this.protocolService != null) {
48+
throw new IllegalStateException("WaypointsIntegration is already initialized");
49+
}
50+
51+
this.protocolService = protocolService;
52+
53+
this.addonProtocol = new AddonProtocol(protocolService, "waypoints");
54+
this.addonProtocol.registerPacket(0, WaypointPacket.class, Direction.CLIENTBOUND);
55+
this.addonProtocol.registerPacket(1, WaypointRemovePacket.class, Direction.CLIENTBOUND);
56+
this.addonProtocol.registerPacket(2, WaypointDimensionPacket.class, Direction.CLIENTBOUND);
57+
58+
protocolService.registry().registerProtocol(this.addonProtocol);
59+
}
60+
61+
@Override
62+
public LabyModIntegrationPlayer createIntegrationPlayer(AbstractLabyModPlayer<?> labyModPlayer) {
63+
return new WaypointsPlayer(this.addonProtocol, labyModPlayer.getUniqueId());
64+
}
65+
66+
public @NotNull AddonProtocol waypointsProtocol() {
67+
if (this.addonProtocol == null) {
68+
throw new IllegalStateException("WaypointsIntegration is not initialized yet");
69+
}
70+
71+
return this.addonProtocol;
72+
}
73+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 LabyMedia GmbH
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+
25+
package net.labymod.serverapi.integration.waypoints;
26+
27+
import net.labymod.serverapi.core.AddonProtocol;
28+
import net.labymod.serverapi.core.integration.LabyModIntegrationPlayer;
29+
import net.labymod.serverapi.integration.waypoints.model.ServerWaypoint;
30+
import net.labymod.serverapi.integration.waypoints.packets.WaypointDimensionPacket;
31+
import net.labymod.serverapi.integration.waypoints.packets.WaypointPacket;
32+
import net.labymod.serverapi.integration.waypoints.packets.WaypointRemovePacket;
33+
import org.jetbrains.annotations.NotNull;
34+
import org.jetbrains.annotations.Nullable;
35+
36+
import java.util.List;
37+
import java.util.UUID;
38+
39+
public class WaypointsPlayer implements LabyModIntegrationPlayer {
40+
41+
private final AddonProtocol addonProtocol;
42+
private final UUID uniqueId;
43+
44+
protected WaypointsPlayer(AddonProtocol addonProtocol, UUID uniqueId) {
45+
this.addonProtocol = addonProtocol;
46+
this.uniqueId = uniqueId;
47+
}
48+
49+
/**
50+
* Update the current dimension of the player until the specified condition is met.
51+
*
52+
* @param dimension the dimension to use (if null, the current vanilla dimension is used)
53+
* @param until the condition until the dimension is used
54+
*/
55+
public void setDimension(
56+
@Nullable String dimension,
57+
@NotNull WaypointDimensionPacket.Until until
58+
) {
59+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointDimensionPacket(dimension, until));
60+
}
61+
62+
/**
63+
* Sets the dimension of the player to the provided dimension until the dimension is updated by
64+
* vanilla.
65+
*
66+
* @param dimension the dimension to use (if null, the current vanilla dimension is used)
67+
*/
68+
public void setDimension(@Nullable String dimension) {
69+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointDimensionPacket(dimension));
70+
}
71+
72+
/**
73+
* Resets the dimension of the player to the current dimension the player is on.
74+
*/
75+
public void resetDimension() {
76+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointDimensionPacket(null));
77+
}
78+
79+
/**
80+
* Add or update a single waypoint for the player.
81+
*
82+
* @param waypoint The waypoint to add or update
83+
*/
84+
public void sendWaypoint(ServerWaypoint waypoint) {
85+
this.sendWaypoints(waypoint);
86+
}
87+
88+
/**
89+
* Add or update multiple waypoints for the player.
90+
*
91+
* @param waypoints The waypoints to add or update
92+
*/
93+
public void sendWaypoints(ServerWaypoint... waypoints) {
94+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointPacket(waypoints));
95+
}
96+
97+
/**
98+
* Add or update multiple waypoints for the player.
99+
*
100+
* @param waypoints The waypoints to add or update
101+
*/
102+
public void sendWaypoints(List<ServerWaypoint> waypoints) {
103+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointPacket(waypoints));
104+
}
105+
106+
/**
107+
* Remove the waypoint with the provided waypoint id.
108+
*
109+
* @param waypointId The id of the waypoint to remove
110+
*/
111+
public void removeWaypoint(String waypointId) {
112+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointRemovePacket(waypointId));
113+
}
114+
115+
/**
116+
* Remove the provided waypoint.
117+
*
118+
* @param waypoint The waypoint to remove
119+
*/
120+
public void removeWaypoint(ServerWaypoint waypoint) {
121+
this.addonProtocol.sendPacket(this.uniqueId, new WaypointRemovePacket(waypoint));
122+
}
123+
124+
@Override
125+
public String toString() {
126+
return "WaypointsPlayer{" +
127+
"uniqueId=" + this.uniqueId +
128+
'}';
129+
}
130+
}

0 commit comments

Comments
 (0)