mirror of
https://github.com/BlueMap-Minecraft/BlueMapAPI.git
synced 2025-01-29 19:21:33 +01:00
Add sorting option to Marker and MarkerSet
This commit is contained in:
parent
1d0d63f088
commit
bee8770fde
@ -44,11 +44,13 @@ public abstract class Marker {
|
||||
private final String type;
|
||||
private String label;
|
||||
private Vector3d position;
|
||||
private int sorting;
|
||||
|
||||
public Marker(String type, String label, Vector3d position) {
|
||||
this.type = Objects.requireNonNull(type, "type cannot be null");
|
||||
this.label = Objects.requireNonNull(label, "label cannot be null");
|
||||
this.position = Objects.requireNonNull(position, "position cannot be null");
|
||||
this.sorting = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,6 +109,28 @@ public void setPosition(double x, double y, double z) {
|
||||
setPosition(new Vector3d(x, y, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
|
||||
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @return This markers sorting-value
|
||||
*/
|
||||
public int getSorting() {
|
||||
return sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
|
||||
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @param sorting the new sorting-value for this marker
|
||||
*/
|
||||
public void setSorting(int sorting) {
|
||||
this.sorting = sorting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -131,6 +155,7 @@ public static abstract class Builder<T extends Marker, B extends Marker.Builder<
|
||||
|
||||
String label;
|
||||
Vector3d position;
|
||||
Integer sorting;
|
||||
|
||||
/**
|
||||
* Sets the label of the {@link Marker}.
|
||||
@ -164,6 +189,18 @@ public B position(double x, double y, double z) {
|
||||
return position(new Vector3d(x, y, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
|
||||
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @param sorting the new sorting-value for this marker
|
||||
*/
|
||||
public B sorting(Integer sorting) {
|
||||
this.sorting = sorting;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Marker} with the current builder-settings
|
||||
* @return The new {@link Marker}-instance
|
||||
@ -173,6 +210,7 @@ public B position(double x, double y, double z) {
|
||||
T build(T marker) {
|
||||
if (label != null) marker.setLabel(label);
|
||||
if (position != null) marker.setPosition(position);
|
||||
if (sorting != null) marker.setSorting(sorting);
|
||||
return marker;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ public class MarkerSet {
|
||||
|
||||
private String label;
|
||||
private boolean toggleable, defaultHidden;
|
||||
private int sorting;
|
||||
private final ConcurrentHashMap<String, Marker> markers;
|
||||
|
||||
/**
|
||||
@ -56,10 +57,7 @@ private MarkerSet() {
|
||||
* @see #setLabel(String)
|
||||
*/
|
||||
public MarkerSet(String label) {
|
||||
this.label = Objects.requireNonNull(label);
|
||||
this.toggleable = true;
|
||||
this.defaultHidden = false;
|
||||
this.markers = new ConcurrentHashMap<>();
|
||||
this(label, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +75,7 @@ public MarkerSet(String label, boolean toggleable, boolean defaultHidden) {
|
||||
this.label = Objects.requireNonNull(label);
|
||||
this.toggleable = toggleable;
|
||||
this.defaultHidden = defaultHidden;
|
||||
this.sorting = 0;
|
||||
this.markers = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@ -149,6 +148,28 @@ public void setDefaultHidden(boolean defaultHidden) {
|
||||
this.defaultHidden = defaultHidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sorting-value that will be used by the webapp to sort the marker-sets.<br>
|
||||
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @return This marker-sets sorting-value
|
||||
*/
|
||||
public int getSorting() {
|
||||
return sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
|
||||
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @param sorting the new sorting-value for this marker-set
|
||||
*/
|
||||
public void setSorting(int sorting) {
|
||||
this.sorting = sorting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a (modifiable) {@link Map} of all {@link Marker}s in this {@link MarkerSet}.
|
||||
* The keys of the map are the id's of the {@link Marker}s.
|
||||
@ -220,6 +241,7 @@ public static class Builder {
|
||||
|
||||
private String label;
|
||||
private Boolean toggleable, defaultHidden;
|
||||
Integer sorting;
|
||||
|
||||
/**
|
||||
* Sets the label of the {@link MarkerSet}.
|
||||
@ -262,6 +284,18 @@ public Builder defaultHidden(Boolean defaultHidden) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
|
||||
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
|
||||
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
|
||||
* This value defaults to 0.
|
||||
* @param sorting the new sorting-value for this marker-set
|
||||
*/
|
||||
public Builder sorting(Integer sorting) {
|
||||
this.sorting = sorting;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link MarkerSet} with the current builder-settings.<br>
|
||||
* The minimum required settings to build this marker-set are:
|
||||
@ -276,6 +310,7 @@ public MarkerSet build() {
|
||||
);
|
||||
if (toggleable != null) markerSet.setToggleable(toggleable);
|
||||
if (defaultHidden != null) markerSet.setDefaultHidden(defaultHidden);
|
||||
if (sorting != null) markerSet.setSorting(sorting);
|
||||
return markerSet;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user