Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 169 lines 3.9 kB view raw
1package org.bukkit.map; 2 3/** 4 * Represents a cursor on a map. 5 */ 6public final class MapCursor { 7 8 private byte x, y; 9 private byte direction, type; 10 private boolean visible; 11 12 /** 13 * Initialize the map cursor. 14 * 15 * @param x The x coordinate, from -128 to 127. 16 * @param y The y coordinate, from -128 to 127. 17 * @param direction The facing of the cursor, from 0 to 15. 18 * @param type The type (color/style) of the map cursor. 19 * @param visible Whether the cursor is visible by default. 20 */ 21 public MapCursor(byte x, byte y, byte direction, byte type, boolean visible) { 22 this.x = x; 23 this.y = y; 24 setDirection(direction); 25 setRawType(type); 26 this.visible = visible; 27 } 28 29 /** 30 * Get the X position of this cursor. 31 * 32 * @return The X coordinate. 33 */ 34 public byte getX() { 35 return x; 36 } 37 38 /** 39 * Get the Y position of this cursor. 40 * 41 * @return The Y coordinate. 42 */ 43 public byte getY() { 44 return y; 45 } 46 47 /** 48 * Get the direction of this cursor. 49 * 50 * @return The facing of the cursor, from 0 to 15. 51 */ 52 public byte getDirection() { 53 return direction; 54 } 55 56 /** 57 * Get the type of this cursor. 58 * 59 * @return The type (color/style) of the map cursor. 60 */ 61 public Type getType() { 62 return Type.byValue(type); 63 } 64 65 /** 66 * Get the type of this cursor. 67 * 68 * @return The type (color/style) of the map cursor. 69 */ 70 public byte getRawType() { 71 return type; 72 } 73 74 /** 75 * Get the visibility status of this cursor. 76 * 77 * @return True if visible, false otherwise. 78 */ 79 public boolean isVisible() { 80 return visible; 81 } 82 83 /** 84 * Set the X position of this cursor. 85 * 86 * @param x The X coordinate. 87 */ 88 public void setX(byte x) { 89 this.x = x; 90 } 91 92 /** 93 * Set the Y position of this cursor. 94 * 95 * @param y The Y coordinate. 96 */ 97 public void setY(byte y) { 98 this.y = y; 99 } 100 101 /** 102 * Set the direction of this cursor. 103 * 104 * @param direction The facing of the cursor, from 0 to 15. 105 */ 106 public void setDirection(byte direction) { 107 if (direction < 0 || direction > 15) { 108 throw new IllegalArgumentException("Direction must be in the range 0-15"); 109 } 110 this.direction = direction; 111 } 112 113 /** 114 * Set the type of this cursor. 115 * 116 * @param type The type (color/style) of the map cursor. 117 */ 118 public void setType(Type type) { 119 setRawType(type.value); 120 } 121 122 /** 123 * Set the type of this cursor. 124 * 125 * @param type The type (color/style) of the map cursor. 126 */ 127 public void setRawType(byte type) { 128 if (type < 0 || type > 15) { 129 throw new IllegalArgumentException("Type must be in the range 0-15"); 130 } 131 this.type = type; 132 } 133 134 /** 135 * Set the visibility status of this cursor. 136 * 137 * @param visible True if visible. 138 */ 139 public void setVisible(boolean visible) { 140 this.visible = visible; 141 } 142 143 /** 144 * Represents the standard types of map cursors. More may be made available 145 * by texture packs - the value is used by the client as an index in the 146 * file './misc/mapicons.png' from minecraft.jar or from a texture pack. 147 */ 148 public enum Type { 149 WHITE_POINTER(0), GREEN_POINTER(1), RED_POINTER(2), BLUE_POINTER(3), WHITE_CROSS(4); 150 151 private byte value; 152 153 private Type(int value) { 154 this.value = (byte) value; 155 } 156 157 public byte getValue() { 158 return value; 159 } 160 161 public static Type byValue(byte value) { 162 for (Type t : values()) { 163 if (t.value == value) return t; 164 } 165 return null; 166 } 167 } 168 169}