Class CoordAdapter
java.lang.Object
com.fren_gor.ultimateAdvancementAPI.util.CoordAdapter
The
CoordAdapter
class adds support for advancement negative coordinates.
Note that the x-axis points to the right (as usual), whereas the y-axis points downward.
An example usage is shown below:
// Keys of the advancements to create var advKey1 = new AdvancementKey(myPlugin, "first_advancement"); var advKey2 = new AdvancementKey(myPlugin, "second_advancement"); var advKey3 = new AdvancementKey(myPlugin, "third_advancement"); // Create the CoordAdapter instance CoordAdapter adapter = CoordAdapter.builder() .add(advKey1, 0, 0) // Will become (0, 1) .add(advKey2, 1, -1) // Will become (1, 0) .add(advKey3, 1, 1) // Will become (1, 2) .build(); // Create the AdvancementDisplays var advDisplay1 = new AdvancementDisplay.Builder(Material.GRASS_BLOCK, "Title1").coords(adapter, advKey1).build(); var advDisplay2 = new AdvancementDisplay.Builder(Material.GRASS_BLOCK, "Title2").coords(adapter, advKey2).build(); var advDisplay3 = new AdvancementDisplay.Builder(Material.GRASS_BLOCK, "Title3").coords(adapter, advKey3).build(); // Create the advancements var adv1 = new RootAdvancement(myTab, advKey1.getKey(), advDisplay1, "textures/block/stone.png"); var adv2 = new BaseAdvancement(advKey2.getKey(), advDisplay2, adv1); var adv3 = new BaseAdvancement(advKey3.getKey(), advDisplay3, adv1, 5);
- Since:
- 2.1.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Record which represents a coordinate in a Cartesian plane where the x-axis points to the right (as usual) and the y-axis points downward.static final class
A builder forCoordAdapter
s. -
Constructor Summary
ConstructorDescriptionCoordAdapter
(@NotNull Map<AdvancementKey, CoordAdapter.Coord> advancementCoords) Creates a newCoordAdapter
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Creates a newCoordAdapter.CoordAdapterBuilder
.float
getOriginalX
(float x) Converts back the provided x coordinate to the original one.float
getOriginalX
(@NotNull AdvancementDisplay display) Converts back the providedAdvancementDisplay
's x coordinate to the original one.float
Converts back the providedAdvancementKey
's x coordinate to the original one passed to thisCoordAdapter
.getOriginalXAndY
(float x, float y) Converts back the provided x and y coordinates to the original ones.getOriginalXAndY
(@NotNull AdvancementDisplay display) Converts back the providedAdvancementDisplay
's x and y coordinates to the original ones.Converts back the providedAdvancementKey
's x and y coordinates to the original ones passed to thisCoordAdapter
.Converts back the provided x and y coordinates to the original ones.float
getOriginalY
(float y) Converts back the provided y coordinate to the original one.float
getOriginalY
(@NotNull AdvancementDisplay display) Converts back the providedAdvancementDisplay
's y coordinate to the original one.float
Converts back the providedAdvancementKey
's y coordinate to the original one passed to thisCoordAdapter
.float
getX
(@NotNull AdvancementKey key) Gets the converted x coordinate to be used in aAdvancementDisplay
.Gets the converted x and y coordinates to be used in aAdvancementDisplay
.float
getY
(@NotNull AdvancementKey key) Gets the converted y coordinate to be used in aAdvancementDisplay
.
-
Constructor Details
-
CoordAdapter
Creates a newCoordAdapter
.- Parameters:
advancementCoords
- The map of everyAdvancementKey
with its position. Negative values are accepted.- Throws:
NullPointerException
- IfadvancementCoords
or any of its values arenull
.- See Also:
-
-
Method Details
-
getX
Gets the converted x coordinate to be used in aAdvancementDisplay
.- Parameters:
key
- TheAdvancementKey
of the coordinate.- Returns:
- The converted x coordinate to be used in a
AdvancementDisplay
. - Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getY
Gets the converted y coordinate to be used in aAdvancementDisplay
.- Parameters:
key
- TheAdvancementKey
of the coordinate.- Returns:
- The converted y coordinate to be used in a
AdvancementDisplay
. - Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getXAndY
@NotNull public @NotNull CoordAdapter.Coord getXAndY(@NotNull @NotNull AdvancementKey key) throws IllegalArgumentException Gets the converted x and y coordinates to be used in aAdvancementDisplay
.- Parameters:
key
- TheAdvancementKey
of the coordinates.- Returns:
- The converted x and y coordinates to be used in a
AdvancementDisplay
. - Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getOriginalX
Converts back the providedAdvancementDisplay
's x coordinate to the original one.- Parameters:
display
- TheAdvancementDisplay
.- Returns:
- The original x coordinate.
-
getOriginalX
Converts back the providedAdvancementKey
's x coordinate to the original one passed to thisCoordAdapter
.- Parameters:
key
- TheAdvancementKey
of the coordinate.- Returns:
- The original x coordinate.
- Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getOriginalX
public float getOriginalX(float x) Converts back the provided x coordinate to the original one.- Parameters:
x
- The coordinate to convert back.- Returns:
- The original x coordinate.
- Throws:
IllegalArgumentException
- If the provided x coordinate is NaN or infinite.
-
getOriginalY
Converts back the providedAdvancementDisplay
's y coordinate to the original one.- Parameters:
display
- TheAdvancementDisplay
.- Returns:
- The original y coordinate.
-
getOriginalY
Converts back the providedAdvancementKey
's y coordinate to the original one passed to thisCoordAdapter
.- Parameters:
key
- TheAdvancementKey
of the coordinate.- Returns:
- The original y coordinate.
- Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getOriginalY
public float getOriginalY(float y) Converts back the provided y coordinate to the original one.- Parameters:
y
- The coordinate to convert back.- Returns:
- The original y coordinate.
- Throws:
IllegalArgumentException
- If the provided y coordinate is NaN or infinite.
-
getOriginalXAndY
@NotNull public @NotNull CoordAdapter.Coord getOriginalXAndY(@NotNull @NotNull AdvancementDisplay display) Converts back the providedAdvancementDisplay
's x and y coordinates to the original ones.- Parameters:
display
- TheAdvancementDisplay
.- Returns:
- The original x and y coordinates.
-
getOriginalXAndY
@NotNull public @NotNull CoordAdapter.Coord getOriginalXAndY(@NotNull @NotNull AdvancementKey key) throws IllegalArgumentException Converts back the providedAdvancementKey
's x and y coordinates to the original ones passed to thisCoordAdapter
.- Parameters:
key
- TheAdvancementKey
of the coordinates.- Returns:
- The original x and y coordinates.
- Throws:
IllegalArgumentException
- If the providedAdvancementKey
is not present in the adapter.
-
getOriginalXAndY
@NotNull public @NotNull CoordAdapter.Coord getOriginalXAndY(@NotNull @NotNull CoordAdapter.Coord coord) Converts back the provided x and y coordinates to the original ones.- Parameters:
coord
- The coordinates to convert back.- Returns:
- The original x and y coordinates.
-
getOriginalXAndY
Converts back the provided x and y coordinates to the original ones.- Parameters:
x
- The x coordinate to convert back.y
- The y coordinate to convert back.- Returns:
- The original x and y coordinates.
- Throws:
IllegalArgumentException
- If the provided x or y coordinates are NaN or infinite.
-
builder
@NotNull @Contract(pure=true, value="-> new") public static @NotNull CoordAdapter.CoordAdapterBuilder builder()Creates a newCoordAdapter.CoordAdapterBuilder
.- Returns:
- A new
CoordAdapter.CoordAdapterBuilder
.
-