|
| 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