001    package org.bukkit.map;
002    
003    /**
004     * Represents a cursor on a map.
005     */
006    public final class MapCursor {
007        private byte x, y;
008        private byte direction, type;
009        private boolean visible;
010    
011        /**
012         * Initialize the map cursor.
013         *
014         * @param x The x coordinate, from -128 to 127.
015         * @param y The y coordinate, from -128 to 127.
016         * @param direction The facing of the cursor, from 0 to 15.
017         * @param type The type (color/style) of the map cursor.
018         * @param visible Whether the cursor is visible by default.
019         * @deprecated Magic value
020         */
021        @Deprecated
022        public MapCursor(byte x, byte y, byte direction, byte type, boolean visible) {
023            this.x = x;
024            this.y = y;
025            setDirection(direction);
026            setRawType(type);
027            this.visible = visible;
028        }
029    
030        /**
031         * Get the X position of this cursor.
032         *
033         * @return The X coordinate.
034         */
035        public byte getX() {
036            return x;
037        }
038    
039        /**
040         * Get the Y position of this cursor.
041         *
042         * @return The Y coordinate.
043         */
044        public byte getY() {
045            return y;
046        }
047    
048        /**
049         * Get the direction of this cursor.
050         *
051         * @return The facing of the cursor, from 0 to 15.
052         */
053        public byte getDirection() {
054            return direction;
055        }
056    
057        /**
058         * Get the type of this cursor.
059         *
060         * @return The type (color/style) of the map cursor.
061         */
062        public Type getType() {
063            return Type.byValue(type);
064        }
065    
066        /**
067         * Get the type of this cursor.
068         *
069         * @return The type (color/style) of the map cursor.
070         * @deprecated Magic value
071         */
072        @Deprecated
073        public byte getRawType() {
074            return type;
075        }
076    
077        /**
078         * Get the visibility status of this cursor.
079         *
080         * @return True if visible, false otherwise.
081         */
082        public boolean isVisible() {
083            return visible;
084        }
085    
086        /**
087         * Set the X position of this cursor.
088         *
089         * @param x The X coordinate.
090         */
091        public void setX(byte x) {
092            this.x = x;
093        }
094    
095        /**
096         * Set the Y position of this cursor.
097         *
098         * @param y The Y coordinate.
099         */
100        public void setY(byte y) {
101            this.y = y;
102        }
103    
104        /**
105         * Set the direction of this cursor.
106         *
107         * @param direction The facing of the cursor, from 0 to 15.
108         */
109        public void setDirection(byte direction) {
110            if (direction < 0 || direction > 15) {
111                throw new IllegalArgumentException("Direction must be in the range 0-15");
112            }
113            this.direction = direction;
114        }
115    
116        /**
117         * Set the type of this cursor.
118         *
119         * @param type The type (color/style) of the map cursor.
120         */
121        public void setType(Type type) {
122            setRawType(type.value);
123        }
124    
125        /**
126         * Set the type of this cursor.
127         *
128         * @param type The type (color/style) of the map cursor.
129         * @deprecated Magic value
130         */
131        @Deprecated
132        public void setRawType(byte type) {
133            if (type < 0 || type > 15) {
134                throw new IllegalArgumentException("Type must be in the range 0-15");
135            }
136            this.type = type;
137        }
138    
139        /**
140         * Set the visibility status of this cursor.
141         *
142         * @param visible True if visible.
143         */
144        public void setVisible(boolean visible) {
145            this.visible = visible;
146        }
147    
148        /**
149         * Represents the standard types of map cursors. More may be made
150         * available by texture packs - the value is used by the client as an
151         * index in the file './misc/mapicons.png' from minecraft.jar or from a
152         * texture pack.
153         */
154        public enum Type {
155            WHITE_POINTER(0),
156            GREEN_POINTER(1),
157            RED_POINTER(2),
158            BLUE_POINTER(3),
159            WHITE_CROSS(4);
160    
161            private byte value;
162    
163            private Type(int value) {
164                this.value = (byte) value;
165            }
166    
167            /**
168             *
169             * @deprecated Magic value
170             */
171            @Deprecated
172            public byte getValue() {
173                return value;
174            }
175    
176            /**
177             *
178             * @deprecated Magic value
179             */
180            @Deprecated
181            public static Type byValue(byte value) {
182                for (Type t : values()) {
183                    if (t.value == value) return t;
184                }
185                return null;
186            }
187        }
188    
189    }