22
33import net .countercraft .movecraft .craft .Craft ;
44import net .countercraft .movecraft .util .MathUtils ;
5+ import org .bukkit .NamespacedKey ;
56import org .jetbrains .annotations .NotNull ;
67
8+ import java .util .HashSet ;
9+
710public class TrackedLocation {
811 private MovecraftLocation offSet ;
912 private final Craft craft ;
@@ -20,6 +23,21 @@ public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location
2023 offSet = location .subtract (midPoint );
2124 }
2225
26+ /**
27+ * Creates a new TrackedLocation instance which tracks a location about a craft's midpoint.
28+ * @param craft The craft that's that tied to the location.
29+ * @param location The absolute position to track. This location will be stored as a relative
30+ * location to the craft's central hitbox.
31+ * @param key The namespaced key that references a set of tracked locations stored within the craft.
32+ */
33+ public TrackedLocation (@ NotNull Craft craft , @ NotNull MovecraftLocation location , @ NotNull NamespacedKey key ) {
34+ this (craft , location );
35+ if (craft .getTrackedLocations ().get (key ) == null ) {
36+ craft .getTrackedLocations ().put (key , new HashSet <>());
37+ }
38+ craft .getTrackedLocations ().get (key ).add (this );
39+ }
40+
2341 /**
2442 * Rotates the stored location.
2543 * @param rotation A clockwise or counter-clockwise direction to rotate.
@@ -44,4 +62,12 @@ public MovecraftLocation getAbsoluteLocation() {
4462 public MovecraftLocation getOffSet () {
4563 return offSet ;
4664 }
65+
66+ /**
67+ * Gets the craft associated with the tracked location.
68+ * @return Returns the craft.
69+ */
70+ public Craft getCraft () {
71+ return craft ;
72+ }
4773}
0 commit comments