mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-08-05 16:49:39 +00:00
Make MapCursor#type not depends on deprecated values
This commit is contained in:
parent
befcf86d22
commit
e2160a1865
1 changed files with 14 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.bukkit.map;
|
package org.bukkit.map;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import org.bukkit.Keyed;
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -10,9 +11,10 @@ import org.jetbrains.annotations.Nullable;
|
||||||
*/
|
*/
|
||||||
public final class MapCursor {
|
public final class MapCursor {
|
||||||
private byte x, y;
|
private byte x, y;
|
||||||
private byte direction, type;
|
private byte direction;
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
private String caption;
|
private String caption;
|
||||||
|
private Type type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the map cursor.
|
* Initialize the map cursor.
|
||||||
|
@ -51,7 +53,7 @@ public final class MapCursor {
|
||||||
* @param type The type (color/style) of the map cursor.
|
* @param type The type (color/style) of the map cursor.
|
||||||
* @param visible Whether the cursor is visible by default.
|
* @param visible Whether the cursor is visible by default.
|
||||||
* @param caption cursor caption
|
* @param caption cursor caption
|
||||||
* @deprecated Magic value
|
* @deprecated Magic value, use {@link #MapCursor(byte, byte, byte, Type, boolean, String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public MapCursor(byte x, byte y, byte direction, byte type, boolean visible, @Nullable String caption) {
|
public MapCursor(byte x, byte y, byte direction, byte type, boolean visible, @Nullable String caption) {
|
||||||
|
@ -77,7 +79,7 @@ public final class MapCursor {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
setDirection(direction);
|
setDirection(direction);
|
||||||
setType(type);
|
this.type = type;
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
this.caption = caption;
|
this.caption = caption;
|
||||||
}
|
}
|
||||||
|
@ -116,8 +118,7 @@ public final class MapCursor {
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
// It should be impossible to set type to something without appropriate Type, so this shouldn't return null
|
return type;
|
||||||
return Type.byValue(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +129,7 @@ public final class MapCursor {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public byte getRawType() {
|
public byte getRawType() {
|
||||||
return type;
|
return type.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,9 +165,7 @@ public final class MapCursor {
|
||||||
* @param direction The facing of the cursor, from 0 to 15.
|
* @param direction The facing of the cursor, from 0 to 15.
|
||||||
*/
|
*/
|
||||||
public void setDirection(byte direction) {
|
public void setDirection(byte direction) {
|
||||||
if (direction < 0 || direction > 15) {
|
Preconditions.checkArgument(direction >= 0 && direction <= 15, "direction must be between 0 and 15 but is %s", direction);
|
||||||
throw new IllegalArgumentException("Direction must be in the range 0-15");
|
|
||||||
}
|
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +175,7 @@ public final class MapCursor {
|
||||||
* @param type The type (color/style) of the map cursor.
|
* @param type The type (color/style) of the map cursor.
|
||||||
*/
|
*/
|
||||||
public void setType(@NotNull Type type) {
|
public void setType(@NotNull Type type) {
|
||||||
setRawType(type.value);
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,10 +186,9 @@ public final class MapCursor {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setRawType(byte type) {
|
public void setRawType(byte type) {
|
||||||
if (type < 0 || type > 34) {
|
Type enumType = Type.byValue(type);
|
||||||
throw new IllegalArgumentException("Type must be in the range 0-34");
|
Preconditions.checkArgument(enumType != null, "Unknown type by id %s", type);
|
||||||
}
|
this.type = enumType;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -265,10 +263,10 @@ public final class MapCursor {
|
||||||
TRIAL_CHAMBERS(34, "trial_chambers")
|
TRIAL_CHAMBERS(34, "trial_chambers")
|
||||||
;
|
;
|
||||||
|
|
||||||
private byte value;
|
private final byte value;
|
||||||
private final NamespacedKey key;
|
private final NamespacedKey key;
|
||||||
|
|
||||||
private Type(int value, String key) {
|
Type(int value, String key) {
|
||||||
this.value = (byte) value;
|
this.value = (byte) value;
|
||||||
this.key = NamespacedKey.minecraft(key);
|
this.key = NamespacedKey.minecraft(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue