SPIGOT-2540: Add nullability annotations to entire Bukkit API

By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
Bukkit/Spigot
2019-03-13 17:42:57 +11:00
parent e069a80fd8
commit 416c865476
565 changed files with 5372 additions and 2008 deletions

View File

@@ -1,5 +1,7 @@
package org.bukkit.map;
import org.jetbrains.annotations.NotNull;
import java.awt.Image;
/**
@@ -14,6 +16,7 @@ public interface MapCanvas {
*
* @return The MapView this canvas is attached to.
*/
@NotNull
public MapView getMapView();
/**
@@ -21,6 +24,7 @@ public interface MapCanvas {
*
* @return The MapCursorCollection associated with this canvas.
*/
@NotNull
public MapCursorCollection getCursors();
/**
@@ -30,7 +34,7 @@ public interface MapCanvas {
*
* @param cursors The MapCursorCollection to associate with this canvas.
*/
public void setCursors(MapCursorCollection cursors);
public void setCursors(@NotNull MapCursorCollection cursors);
/**
* Draw a pixel to the canvas.
@@ -66,7 +70,7 @@ public interface MapCanvas {
* @param y The y coordinate of the image.
* @param image The Image to draw.
*/
public void drawImage(int x, int y, Image image);
public void drawImage(int x, int y, @NotNull Image image);
/**
* Render text to the map using fancy formatting. Newline (\n) characters
@@ -79,6 +83,6 @@ public interface MapCanvas {
* @param font The font to use.
* @param text The formatted text to render.
*/
public void drawText(int x, int y, MapFont font, String text);
public void drawText(int x, int y, @NotNull MapFont font, @NotNull String text);
}

View File

@@ -1,5 +1,8 @@
package org.bukkit.map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a cursor on a map.
*/
@@ -33,7 +36,7 @@ public final class MapCursor {
* @param type The type (color/style) of the map cursor.
* @param visible Whether the cursor is visible by default.
*/
public MapCursor(byte x, byte y, byte direction, Type type, boolean visible) {
public MapCursor(byte x, byte y, byte direction, @NotNull Type type, boolean visible) {
this(x, y, direction, type, visible, null);
}
@@ -49,7 +52,7 @@ public final class MapCursor {
* @deprecated Magic value
*/
@Deprecated
public MapCursor(byte x, byte y, byte direction, byte type, boolean visible, String caption) {
public MapCursor(byte x, byte y, byte direction, byte type, boolean visible, @Nullable String caption) {
this.x = x;
this.y = y;
setDirection(direction);
@@ -68,7 +71,7 @@ public final class MapCursor {
* @param visible Whether the cursor is visible by default.
* @param caption cursor caption
*/
public MapCursor(byte x, byte y, byte direction, Type type, boolean visible, String caption) {
public MapCursor(byte x, byte y, byte direction, @NotNull Type type, boolean visible, @Nullable String caption) {
this.x = x;
this.y = y;
setDirection(direction);
@@ -109,7 +112,9 @@ public final class MapCursor {
*
* @return The type (color/style) of the map cursor.
*/
@NotNull
public Type getType() {
// It should be impossible to set type to something without appropriate Type, so this shouldn't return null
return Type.byValue(type);
}
@@ -168,7 +173,7 @@ public final class MapCursor {
*
* @param type The type (color/style) of the map cursor.
*/
public void setType(Type type) {
public void setType(@NotNull Type type) {
setRawType(type.value);
}
@@ -200,6 +205,7 @@ public final class MapCursor {
*
* @return caption
*/
@Nullable
public String getCaption() {
return caption;
}
@@ -209,7 +215,7 @@ public final class MapCursor {
*
* @param caption new caption
*/
public void setCaption(String caption) {
public void setCaption(@Nullable String caption) {
this.caption = caption;
}
@@ -271,6 +277,7 @@ public final class MapCursor {
* @deprecated Magic value
*/
@Deprecated
@Nullable
public static Type byValue(byte value) {
for (Type t : values()) {
if (t.value == value) return t;

View File

@@ -1,5 +1,8 @@
package org.bukkit.map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -25,6 +28,7 @@ public final class MapCursorCollection {
* @param index The index of the cursor.
* @return The MapCursor.
*/
@NotNull
public MapCursor getCursor(int index) {
return cursors.get(index);
}
@@ -35,7 +39,7 @@ public final class MapCursorCollection {
* @param cursor The MapCursor to remove.
* @return Whether the cursor was removed successfully.
*/
public boolean removeCursor(MapCursor cursor) {
public boolean removeCursor(@NotNull MapCursor cursor) {
return cursors.remove(cursor);
}
@@ -45,7 +49,8 @@ public final class MapCursorCollection {
* @param cursor The MapCursor to add.
* @return The MapCursor that was passed.
*/
public MapCursor addCursor(MapCursor cursor) {
@NotNull
public MapCursor addCursor(@NotNull MapCursor cursor) {
cursors.add(cursor);
return cursor;
}
@@ -58,6 +63,7 @@ public final class MapCursorCollection {
* @param direction The facing of the cursor, from 0 to 15.
* @return The newly added MapCursor.
*/
@NotNull
public MapCursor addCursor(int x, int y, byte direction) {
return addCursor(x, y, direction, (byte) 0, true);
}
@@ -73,6 +79,7 @@ public final class MapCursorCollection {
* @deprecated Magic value
*/
@Deprecated
@NotNull
public MapCursor addCursor(int x, int y, byte direction, byte type) {
return addCursor(x, y, direction, type, true);
}
@@ -89,6 +96,7 @@ public final class MapCursorCollection {
* @deprecated Magic value
*/
@Deprecated
@NotNull
public MapCursor addCursor(int x, int y, byte direction, byte type, boolean visible) {
return addCursor(new MapCursor((byte) x, (byte) y, direction, type, visible));
}
@@ -106,7 +114,8 @@ public final class MapCursorCollection {
* @deprecated Magic value
*/
@Deprecated
public MapCursor addCursor(int x, int y, byte direction, byte type, boolean visible, String caption) {
@NotNull
public MapCursor addCursor(int x, int y, byte direction, byte type, boolean visible, @Nullable String caption) {
return addCursor(new MapCursor((byte) x, (byte) y, direction, type, visible, caption));
}
}

View File

@@ -2,6 +2,8 @@ package org.bukkit.map;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a bitmap font drawable to a map.
@@ -19,7 +21,7 @@ public class MapFont {
* @param sprite The CharacterSprite to set.
* @throws IllegalStateException if this font is static.
*/
public void setChar(char ch, CharacterSprite sprite) {
public void setChar(char ch, @NotNull CharacterSprite sprite) {
if (!malleable) {
throw new IllegalStateException("this font is not malleable");
}
@@ -37,6 +39,7 @@ public class MapFont {
* @return The CharacterSprite associated with the character, or null if
* there is none.
*/
@Nullable
public CharacterSprite getChar(char ch) {
return chars.get(ch);
}
@@ -48,7 +51,7 @@ public class MapFont {
* @param text The text.
* @return The width in pixels.
*/
public int getWidth(String text) {
public int getWidth(@NotNull String text) {
if (!isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
@@ -84,7 +87,7 @@ public class MapFont {
* @return True if the string contains only defined characters, false
* otherwise.
*/
public boolean isValid(String text) {
public boolean isValid(@NotNull String text) {
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == ChatColor.COLOR_CHAR || ch == '\n') continue;
@@ -102,7 +105,7 @@ public class MapFont {
private final int height;
private final boolean[] data;
public CharacterSprite(int width, int height, boolean[] data) {
public CharacterSprite(int width, int height, @NotNull boolean[] data) {
this.width = width;
this.height = height;
this.data = data;

View File

@@ -1,5 +1,8 @@
package org.bukkit.map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
@@ -15,11 +18,12 @@ public final class MapPalette {
// Internal mechanisms
private MapPalette() {}
@NotNull
private static Color c(int r, int g, int b) {
return new Color(r, g, b);
}
private static double getDistance(Color c1, Color c2) {
private static double getDistance(@NotNull Color c1, @NotNull Color c2) {
double rmean = (c1.getRed() + c2.getRed()) / 2.0;
double r = c1.getRed() - c2.getRed();
double g = c1.getGreen() - c2.getGreen();
@@ -30,6 +34,7 @@ public final class MapPalette {
return weightR * r * r + weightG * g * g + weightB * b * b;
}
@NotNull
static final Color[] colors = {
c(0, 0, 0), c(0, 0, 0), c(0, 0, 0), c(0, 0, 0),
c(89, 125, 39), c(109, 153, 48), c(127, 178, 56), c(67, 94, 29),
@@ -163,7 +168,8 @@ public final class MapPalette {
* @param image The image to resize.
* @return The resized image.
*/
public static BufferedImage resizeImage(Image image) {
@NotNull
public static BufferedImage resizeImage(@Nullable Image image) {
BufferedImage result = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = result.createGraphics();
graphics.drawImage(image, 0, 0, 128, 128, null);
@@ -179,7 +185,8 @@ public final class MapPalette {
* @deprecated Magic value
*/
@Deprecated
public static byte[] imageToBytes(Image image) {
@NotNull
public static byte[] imageToBytes(@NotNull Image image) {
BufferedImage temp = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = temp.createGraphics();
graphics.drawImage(image, 0, 0, null);
@@ -219,7 +226,7 @@ public final class MapPalette {
* @deprecated Magic value
*/
@Deprecated
public static byte matchColor(Color color) {
public static byte matchColor(@NotNull Color color) {
if (color.getAlpha() < 128) return 0;
int index = 0;
@@ -245,6 +252,7 @@ public final class MapPalette {
* @deprecated Magic value
*/
@Deprecated
@NotNull
public static Color getColor(byte index) {
if ((index > -49 && index < 0) || index > 127) {
throw new IndexOutOfBoundsException();

View File

@@ -1,6 +1,7 @@
package org.bukkit.map;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
/**
* Represents a renderer for a map.
@@ -42,7 +43,7 @@ public abstract class MapRenderer {
*
* @param map The MapView being initialized.
*/
public void initialize(MapView map) {}
public void initialize(@NotNull MapView map) {}
/**
* Render to the given map.
@@ -51,6 +52,6 @@ public abstract class MapRenderer {
* @param canvas The canvas to use for rendering.
* @param player The player who triggered the rendering.
*/
abstract public void render(MapView map, MapCanvas canvas, Player player);
abstract public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player);
}

View File

@@ -3,6 +3,8 @@ package org.bukkit.map;
import java.util.List;
import org.bukkit.World;
import org.bukkit.inventory.meta.MapMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a map item.
@@ -33,6 +35,7 @@ public interface MapView {
* @deprecated Magic value
*/
@Deprecated
@Nullable
public static Scale valueOf(byte value) {
switch (value) {
case 0: return CLOSEST;
@@ -76,6 +79,7 @@ public interface MapView {
*
* @return The scale of the map.
*/
@NotNull
public Scale getScale();
/**
@@ -83,7 +87,7 @@ public interface MapView {
*
* @param scale The scale to set.
*/
public void setScale(Scale scale);
public void setScale(@NotNull Scale scale);
/**
* Get the center X position of this map.
@@ -120,6 +124,7 @@ public interface MapView {
*
* @return The World this map is associated with.
*/
@Nullable
public World getWorld();
/**
@@ -128,13 +133,14 @@ public interface MapView {
*
* @param world The World to associate this map with.
*/
public void setWorld(World world);
public void setWorld(@NotNull World world);
/**
* Get a list of MapRenderers currently in effect.
*
* @return A {@code List<MapRenderer>} containing each map renderer.
*/
@NotNull
public List<MapRenderer> getRenderers();
/**
@@ -142,7 +148,7 @@ public interface MapView {
*
* @param renderer The MapRenderer to add.
*/
public void addRenderer(MapRenderer renderer);
public void addRenderer(@NotNull MapRenderer renderer);
/**
* Remove a renderer from this map.
@@ -150,7 +156,7 @@ public interface MapView {
* @param renderer The MapRenderer to remove.
* @return True if the renderer was successfully removed.
*/
public boolean removeRenderer(MapRenderer renderer);
public boolean removeRenderer(@Nullable MapRenderer renderer);
/**
* Whether the map will show a smaller position cursor (true), or no

View File

@@ -1,5 +1,7 @@
package org.bukkit.map;
import org.jetbrains.annotations.NotNull;
/**
* Represents the built-in Minecraft font.
*/
@@ -280,6 +282,7 @@ public class MinecraftFont extends MapFont {
/**
* A static non-malleable MinecraftFont.
*/
@NotNull
public static final MinecraftFont Font = new MinecraftFont(false);
/**