diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-12-25 16:02:30 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-12-25 16:02:30 +0100 |
commit | b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c (patch) | |
tree | e6b17ff17e749afb0042357e4922757e66eedfe3 /src/main/java/org/bukkit/map | |
parent | a345613cfaf533817ade333946461a2c31c3d400 (diff) | |
download | bukkit-b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c.tar bukkit-b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c.tar.gz bukkit-b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c.tar.lz bukkit-b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c.tar.xz bukkit-b9fca3c04d3561ffa1430724e5fb5ab8e024dd2c.zip |
Generic cleanup of warnings, whitespace and style.
Diffstat (limited to 'src/main/java/org/bukkit/map')
-rw-r--r-- | src/main/java/org/bukkit/map/MapCanvas.java | 28 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapCursor.java | 53 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapCursorCollection.java | 25 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapFont.java | 42 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapPalette.java | 32 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapRenderer.java | 18 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MapView.java | 67 | ||||
-rw-r--r-- | src/main/java/org/bukkit/map/MinecraftFont.java | 24 |
8 files changed, 174 insertions, 115 deletions
diff --git a/src/main/java/org/bukkit/map/MapCanvas.java b/src/main/java/org/bukkit/map/MapCanvas.java index 1681366a..f75e2093 100644 --- a/src/main/java/org/bukkit/map/MapCanvas.java +++ b/src/main/java/org/bukkit/map/MapCanvas.java @@ -7,69 +7,77 @@ import java.awt.Image; * specific {@link MapRenderer} and represents that renderer's layer on the map. */ public interface MapCanvas { - + /** * Get the map this canvas is attached to. + * * @return The MapView this canvas is attached to. */ public MapView getMapView(); - + /** * Get the cursor collection associated with this canvas. + * * @return The MapCursorCollection associated with this canvas. */ public MapCursorCollection getCursors(); - + /** * Set the cursor collection associated with this canvas. This does not * usually need to be called since a MapCursorCollection is already * provided. + * * @param cursors The MapCursorCollection to associate with this canvas. */ public void setCursors(MapCursorCollection cursors); - + /** * Draw a pixel to the canvas. + * * @param x The x coordinate, from 0 to 127. * @param y The y coordinate, from 0 to 127. * @param color The color. See {@link MapPalette}. */ public void setPixel(int x, int y, byte color); - + /** * Get a pixel from the canvas. + * * @param x The x coordinate, from 0 to 127. * @param y The y coordinate, from 0 to 127. * @return The color. See {@link MapPalette}. */ public byte getPixel(int x, int y); - + /** * Get a pixel from the layers below this canvas. - * @param x The x coordinate, from 0 to 127. + * + * @param x The x coordinate, from 0 to 127. * @param y The y coordinate, from 0 to 127. * @return The color. See {@link MapPalette}. */ public byte getBasePixel(int x, int y); - + /** * Draw an image to the map. The image will be clipped if necessary. + * * @param x The x coordinate of the image. * @param y The y coordinate of the image. * @param image The Image to draw. */ public void drawImage(int x, int y, Image image); - + /** * Render text to the map using fancy formatting. Newline (\n) characters * will move down one line and return to the original column, and the text * color can be changed using sequences such as "§12;", replacing 12 with * the palette index of the color (see {@link MapPalette}). + * * @param x The column to start rendering on. * @param y The row to start rendering on. * @param font The font to use. * @param text The formatted text to render. */ public void drawText(int x, int y, MapFont font, String text); - + } diff --git a/src/main/java/org/bukkit/map/MapCursor.java b/src/main/java/org/bukkit/map/MapCursor.java index 957db93b..6ef06597 100644 --- a/src/main/java/org/bukkit/map/MapCursor.java +++ b/src/main/java/org/bukkit/map/MapCursor.java @@ -4,13 +4,14 @@ package org.bukkit.map; * Represents a cursor on a map. */ public final class MapCursor { - + private byte x, y; private byte direction, type; private boolean visible; /** * Initialize the map cursor. + * * @param x The x coordinate, from -128 to 127. * @param y The y coordinate, from -128 to 127. * @param direction The facing of the cursor, from 0 to 15. @@ -24,73 +25,82 @@ public final class MapCursor { setRawType(type); this.visible = visible; } - + /** * Get the X position of this cursor. + * * @return The X coordinate. */ public byte getX() { return x; } - + /** * Get the Y position of this cursor. + * * @return The Y coordinate. */ public byte getY() { return y; } - + /** * Get the direction of this cursor. + * * @return The facing of the cursor, from 0 to 15. */ public byte getDirection() { return direction; } - + /** * Get the type of this cursor. + * * @return The type (color/style) of the map cursor. */ public Type getType() { return Type.byValue(type); } - + /** * Get the type of this cursor. + * * @return The type (color/style) of the map cursor. */ public byte getRawType() { return type; } - + /** * Get the visibility status of this cursor. + * * @return True if visible, false otherwise. */ public boolean isVisible() { return visible; } - + /** * Set the X position of this cursor. + * * @param x The X coordinate. */ public void setX(byte x) { this.x = x; } - + /** * Set the Y position of this cursor. + * * @param y The Y coordinate. */ public void setY(byte y) { this.y = y; } - + /** * Set the direction of this cursor. + * * @param direction The facing of the cursor, from 0 to 15. */ public void setDirection(byte direction) { @@ -99,17 +109,19 @@ public final class MapCursor { } this.direction = direction; } - + /** * Set the type of this cursor. + * * @param type The type (color/style) of the map cursor. */ public void setType(Type type) { setRawType(type.value); } - + /** * Set the type of this cursor. + * * @param type The type (color/style) of the map cursor. */ public void setRawType(byte type) { @@ -118,17 +130,18 @@ public final class MapCursor { } this.type = type; } - + /** * Set the visibility status of this cursor. + * * @param visible True if visible. */ public void setVisible(boolean visible) { this.visible = visible; } - + /** - * Represents the standard types of map cursors. More may be made available + * Represents the standard types of map cursors. More may be made available * by texture packs - the value is used by the client as an index in the * file './misc/mapicons.png' from minecraft.jar or from a texture pack. */ @@ -138,17 +151,17 @@ public final class MapCursor { RED_POINTER(2), BLUE_POINTER(3), WHITE_CROSS(4); - + private byte value; - + private Type(int value) { this.value = (byte) value; } - + public byte getValue() { return value; } - + public static Type byValue(byte value) { for (Type t : values()) { if (t.value == value) return t; @@ -156,5 +169,5 @@ public final class MapCursor { return null; } } - + } diff --git a/src/main/java/org/bukkit/map/MapCursorCollection.java b/src/main/java/org/bukkit/map/MapCursorCollection.java index ac5d3e30..1e234a14 100644 --- a/src/main/java/org/bukkit/map/MapCursorCollection.java +++ b/src/main/java/org/bukkit/map/MapCursorCollection.java @@ -8,37 +8,41 @@ import java.util.List; * MapCursorCollection is linked to a specific {@link MapRenderer}. */ public final class MapCursorCollection { - + private List<MapCursor> cursors = new ArrayList<MapCursor>(); - + /** * Get the amount of cursors in this collection. + * * @return The size of this collection. */ public int size() { return cursors.size(); } - + /** * Get a cursor from this collection. + * * @param index The index of the cursor. * @return The MapCursor. */ public MapCursor getCursor(int index) { return cursors.get(index); } - + /** * Remove a cursor from the collection. + * * @param cursor The MapCursor to remove. * @return Whether the cursor was removed successfully. */ public boolean removeCursor(MapCursor cursor) { return cursors.remove(cursor); } - + /** * Add a cursor to the collection. + * * @param cursor The MapCursor to add. * @return The MapCursor that was passed. */ @@ -46,9 +50,10 @@ public final class MapCursorCollection { cursors.add(cursor); return cursor; } - + /** * Add a cursor to the collection. + * * @param x The x coordinate, from -128 to 127. * @param y The y coordinate, from -128 to 127. * @param direction The facing of the cursor, from 0 to 15. @@ -57,9 +62,10 @@ public final class MapCursorCollection { public MapCursor addCursor(int x, int y, byte direction) { return addCursor(x, y, direction, (byte) 0, true); } - + /** * Add a cursor to the collection. + * * @param x The x coordinate, from -128 to 127. * @param y The y coordinate, from -128 to 127. * @param direction The facing of the cursor, from 0 to 15. @@ -69,9 +75,10 @@ public final class MapCursorCollection { public MapCursor addCursor(int x, int y, byte direction, byte type) { return addCursor(x, y, direction, type, true); } - + /** * Add a cursor to the collection. + * * @param x The x coordinate, from -128 to 127. * @param y The y coordinate, from -128 to 127. * @param direction The facing of the cursor, from 0 to 15. @@ -82,5 +89,5 @@ public final class MapCursorCollection { public MapCursor addCursor(int x, int y, byte direction, byte type, boolean visible) { return addCursor(new MapCursor((byte) x, (byte) y, direction, type, visible)); } - + } diff --git a/src/main/java/org/bukkit/map/MapFont.java b/src/main/java/org/bukkit/map/MapFont.java index 6d38d525..a6016ffc 100644 --- a/src/main/java/org/bukkit/map/MapFont.java +++ b/src/main/java/org/bukkit/map/MapFont.java @@ -6,13 +6,14 @@ import java.util.HashMap; * Represents a bitmap font drawable to a map. */ public class MapFont { - + private final HashMap<Character, CharacterSprite> chars = new HashMap<Character, CharacterSprite>(); private int height = 0; protected boolean malleable = true; - + /** * Set the sprite for a given character. + * * @param ch The character to set the sprite for. * @param sprite The CharacterSprite to set. * @throws IllegalStateException if this font is static. @@ -21,24 +22,26 @@ public class MapFont { if (!malleable) { throw new IllegalStateException("this font is not malleable"); } - + chars.put(ch, sprite); if (sprite.getHeight() > height) { height = sprite.getHeight(); } } - + /** * Get the sprite for a given character. + * * @param ch The character to get the sprite for. * @return The CharacterSprite associated with the character, or null if there is none. */ public CharacterSprite getChar(char ch) { return chars.get(ch); } - + /** * Get the width of the given text as it would be rendered using this font. + * * @param text The text. * @return The width in pixels. */ @@ -46,24 +49,26 @@ public class MapFont { if (!isValid(text)) { throw new IllegalArgumentException("text contains invalid characters"); } - + int result = 0; for (int i = 0; i < text.length(); ++i) { result += chars.get(text.charAt(i)).getWidth(); } return result; } - + /** * Get the height of this font. + * * @return The height of the font. */ public int getHeight() { return height; } - + /** * Check whether the given text is valid. + * * @param text The text. * @return True if the string contains only defined characters, false otherwise. */ @@ -75,28 +80,29 @@ public class MapFont { } return true; } - + /** * Represents the graphics for a single character in a MapFont. */ public static class CharacterSprite { - + private final int width; private final int height; private final boolean[] data; - + public CharacterSprite(int width, int height, boolean[] data) { this.width = width; this.height = height; this.data = data; - + if (data.length != width * height) { throw new IllegalArgumentException("size of data does not match dimensions"); } } - + /** * Get the value of a pixel of the character. + * * @param row The row, in the range [0,8). * @param col The column, in the range [0,8). * @return True if the pixel is solid, false if transparent. @@ -105,23 +111,25 @@ public class MapFont { if (row < 0 || col < 0 || row >= height || col >= width) return false; return data[row * width + col]; } - + /** * Get the width of the character sprite. + * * @return The width of the character. */ public int getWidth() { return width; } - + /** * Get the height of the character sprite. + * * @return The height of the character. */ public int getHeight() { return height; } - + } - + } diff --git a/src/main/java/org/bukkit/map/MapPalette.java b/src/main/java/org/bukkit/map/MapPalette.java index dcc254ea..b9935b7d 100644 --- a/src/main/java/org/bukkit/map/MapPalette.java +++ b/src/main/java/org/bukkit/map/MapPalette.java @@ -9,15 +9,14 @@ import java.awt.image.BufferedImage; * Represents the palette that map items use. */ public final class MapPalette { - + // Internal mechanisms - private MapPalette() {} - + private static Color c(int r, int g, int b) { return new Color(r, g, b); } - + private static double getDistance(Color c1, Color c2) { double rmean = (c1.getRed() + c2.getRed()) / 2.0; double r = c1.getRed() - c2.getRed(); @@ -28,7 +27,7 @@ public final class MapPalette { double weightB = 2 + (255 - rmean) / 256.0; return weightR * r * r + weightG * g * g + weightB * b * b; } - + private static final Color[] colors = { new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), @@ -46,9 +45,8 @@ public final class MapPalette { c(45,45,180), c(55,55,220), c(64,64,255), c(55,55,220), c(73,58,35), c(89,71,43), c(104,83,50), c(89,71,43) }; - + // Interface - /** * The base color ranges. Each entry corresponds to four colors of varying * shades with values entry to entry + 3. @@ -67,8 +65,10 @@ public final class MapPalette { public static final byte DARK_GRAY = 44; public static final byte BLUE = 48; public static final byte DARK_BROWN = 52; + /** * Resize an image to 128x128. + * * @param image The image to resize. * @return The resized image. */ @@ -82,6 +82,7 @@ public final class MapPalette { /** * Convert an Image to a byte[] using the palette. + * * @param image The image to convert. * @return A byte[] containing the pixels of the image. */ @@ -90,10 +91,10 @@ public final class MapPalette { Graphics2D graphics = temp.createGraphics(); graphics.drawImage(image, 0, 0, null); graphics.dispose(); - + int[] pixels = new int[temp.getWidth() * temp.getHeight()]; temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth()); - + byte[] result = new byte[temp.getWidth() * temp.getHeight()]; for (int i = 0; i < pixels.length; i++) { result[i] = matchColor(new Color(pixels[i])); @@ -103,6 +104,7 @@ public final class MapPalette { /** * Get the index of the closest matching color in the palette to the given color. + * * @param r The red component of the color. * @param b The blue component of the color. * @param g The green component of the color. @@ -111,18 +113,19 @@ public final class MapPalette { public static byte matchColor(int r, int g, int b) { return matchColor(new Color(r, g, b)); } - + /** * Get the index of the closest matching color in the palette to the given color. + * * @param color The Color to match. * @return The index in the palette. */ public static byte matchColor(Color color) { if (color.getAlpha() < 128) return 0; - + int index = 0; double best = -1; - + for (int i = 4; i < colors.length; i++) { double distance = getDistance(color, colors[i]); if (distance < best || best == -1) { @@ -133,9 +136,10 @@ public final class MapPalette { return (byte) index; } - + /** * Get the value of the given color in the palette. + * * @param index The index in the palette. * @return The Color of the palette entry. */ @@ -146,5 +150,5 @@ public final class MapPalette { return colors[index]; } } - + } diff --git a/src/main/java/org/bukkit/map/MapRenderer.java b/src/main/java/org/bukkit/map/MapRenderer.java index 2c1d00a6..342c9f8b 100644 --- a/src/main/java/org/bukkit/map/MapRenderer.java +++ b/src/main/java/org/bukkit/map/MapRenderer.java @@ -6,45 +6,49 @@ import org.bukkit.entity.Player; * Represents a renderer for a map. */ public abstract class MapRenderer { - + private boolean contextual; - + /** * Initialize the map renderer base to be non-contextual. See {@link #isContextual()}. */ public MapRenderer() { this(false); } - + /** * Initialize the map renderer base with the given contextual status. + * * @param contextual Whether the renderer is contextual. See {@link #isContextual()}. */ public MapRenderer(boolean contextual) { this.contextual = contextual; } - + /** * Get whether the renderer is contextual, i.e. has different canvases for * different players. + * * @return True if contextual, false otherwise. */ final public boolean isContextual() { return contextual; } - + /** * Initialize this MapRenderer for the given map. + * * @param map The MapView being initialized. */ public void initialize(MapView map) { } - + /** * Render to the given map. + * * @param map The MapView being rendered to. * @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); - + } diff --git a/src/main/java/org/bukkit/map/MapView.java b/src/main/java/org/bukkit/map/MapView.java index b0811f80..821afd69 100644 --- a/src/main/java/org/bukkit/map/MapView.java +++ b/src/main/java/org/bukkit/map/MapView.java @@ -7,7 +7,7 @@ import org.bukkit.World; * Represents a map item. */ public interface MapView { - + /** * An enum representing all possible scales a map can be set to. */ @@ -17,120 +17,135 @@ public interface MapView { NORMAL(2), FAR(3), FARTHEST(4); - + private byte value; - + private Scale(int value) { this.value = (byte) value; } - + /** * Get the scale given the raw value. + * * @param value The raw scale * @return The enum scale, or null for an invalid input */ public static Scale valueOf(byte value) { - switch(value) { - case 0: return CLOSEST; - case 1: return CLOSE; - case 2: return NORMAL; - case 3: return FAR; - case 4: return FARTHEST; - default: return null; + switch (value) { + case 0: return CLOSEST; + case 1: return CLOSE; + case 2: return NORMAL; + case 3: return FAR; + case 4: return FARTHEST; + default: return null; } } - + /** * Get the raw value of this scale level. + * * @return The scale value */ public byte getValue() { return value; } } - + /** * Get the ID of this map item. Corresponds to the damage value of a map * in an inventory. + * * @return The ID of the map. */ public short getId(); - + /** * Check whether this map is virtual. A map is virtual if its lowermost * MapRenderer is plugin-provided. + * * @return Whether the map is virtual. */ public boolean isVirtual(); - + /** * Get the scale of this map. + * * @return The scale of the map. */ public Scale getScale(); - + /** * Set the scale of this map. + * * @param scale The scale to set. */ public void setScale(Scale scale); - + /** * Get the center X position of this map. + * * @return The center X position. */ public int getCenterX(); - + /** * Get the center Z position of this map. + * * @return The center Z position. */ public int getCenterZ(); - + /** * Set the center X position of this map. + * * @param x The center X position. */ public void setCenterX(int x); - + /** * Set the center Z position of this map. + * * @param z The center Z position. */ public void setCenterZ(int z); - + /** * Get the world that this map is associated with. Primarily used by the * internal renderer, but may be used by external renderers. May return * null if the world the map is associated with is not loaded. + * * @return The World this map is associated with. */ public World getWorld(); - + /** * Set the world that this map is associated with. The world is used by * the internal renderer, and may also be used by external renderers. + * * @param world The World to associate this map with. */ public void setWorld(World world); - + /** * Get a list of MapRenderers currently in effect. + * * @return A List<MapRenderer> containing each map renderer. */ public List<MapRenderer> getRenderers(); - + /** * Add a renderer to this map. + * * @param renderer The MapRenderer to add. */ public void addRenderer(MapRenderer renderer); - + /** * Remove a renderer from this map. + * * @param renderer The MapRenderer to remove. * @return True if the renderer was successfully removed. */ public boolean removeRenderer(MapRenderer renderer); - + } diff --git a/src/main/java/org/bukkit/map/MinecraftFont.java b/src/main/java/org/bukkit/map/MinecraftFont.java index d84d5c2f..9ec8d10f 100644 --- a/src/main/java/org/bukkit/map/MinecraftFont.java +++ b/src/main/java/org/bukkit/map/MinecraftFont.java @@ -4,9 +4,9 @@ package org.bukkit.map; * Represents the built-in Minecraft font. */ public class MinecraftFont extends MapFont { - + private static final int spaceSize = 2; - + private static final String fontChars = " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + @@ -17,7 +17,7 @@ public class MinecraftFont extends MapFont { "\u00FF\u00D6\u00DC\u00F8\u00A3\u00D8\u00D7\u0191" + // ÿÖÜø£Ø׃ "\u00E1\u00ED\u00F3\u00FA\u00F1\u00D1\u00AA\u00BA" + // áíóúñѪº "\u00BF\u00AE\u00AC\u00BD\u00BC\u00A1\u00AB\u00BB"; // ¿®¬½¼¡«» - + private static final int[][] fontData = new int[][] { /* null */ {0,0,0,0,0,0,0,0}, /* 1 */ {126,129,165,129,189,153,129,126}, @@ -276,31 +276,31 @@ public class MinecraftFont extends MapFont { /* 254 */ {0,0,60,60,60,60,0,0}, /* 255 */ {0,0,0,0,0,0,0,0}, }; - + /** * A static non-malleable MinecraftFont. */ public static final MinecraftFont Font = new MinecraftFont(false); - + /** * Initialize a new MinecraftFont. */ public MinecraftFont() { this(true); } - + private MinecraftFont(boolean malleable) { for (int i = 1; i < fontData.length; ++i) { char ch = (char) i; if (i >= 32 && i < 32 + fontChars.length()) { ch = fontChars.charAt(i - 32); } - + if (ch == ' ') { setChar(ch, new CharacterSprite(spaceSize, 8, new boolean[spaceSize * 8])); continue; } - + int[] rows = fontData[i]; int width = 0; for (int r = 0; r < 8; ++r) { @@ -311,18 +311,18 @@ public class MinecraftFont extends MapFont { } } ++width; - + boolean[] data = new boolean[width * 8]; for (int r = 0; r < 8; ++r) { for (int c = 0; c < width; ++c) { data[r * width + c] = (rows[r] & (1 << c)) != 0; } } - + setChar(ch, new CharacterSprite(width, 8, data)); } - + this.malleable = malleable; } - + } |