View Javadoc
1   /*
2    * Copyright (C) 2016 Ronald Jack Jenkins Jr.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package info.ronjenkins.slf4bukkit;
18  
19  import java.util.Collections;
20  import java.util.Iterator;
21  
22  import org.bukkit.ChatColor;
23  import org.slf4j.Marker;
24  
25  /**
26   * SLF4J markers that map to a subset of {@link ChatColor}s. These markers never
27   * contain any references (other markers).
28   *
29   * @author Ronald Jack Jenkins Jr.
30   */
31  public enum ColorMarker implements Marker {
32  
33    AQUA(ChatColor.AQUA), BLACK(ChatColor.BLACK), BLUE(ChatColor.BLUE),
34    DARK_AQUA(ChatColor.DARK_AQUA), DARK_BLUE(ChatColor.DARK_BLUE),
35    DARK_GRAY(ChatColor.DARK_GRAY), DARK_GREEN(ChatColor.DARK_GREEN),
36    DARK_PURPLE(ChatColor.DARK_PURPLE), DARK_RED(ChatColor.DARK_RED),
37    GOLD(ChatColor.GOLD), GRAY(ChatColor.GRAY), GREEN(ChatColor.GREEN),
38    LIGHT_PURPLE(ChatColor.LIGHT_PURPLE), NONE(ChatColor.RESET),
39    RED(ChatColor.RED), WHITE(ChatColor.WHITE), YELLOW(ChatColor.YELLOW);
40  
41    private final ChatColor value;
42  
43    private ColorMarker(final ChatColor value) {
44      this.value = value;
45    }
46  
47    /**
48     * Not supported.
49     *
50     * @param reference
51     *          unused.
52     * @throws UnsupportedOperationException
53     *           always.
54     */
55    @Override
56    public void add(final Marker reference) {
57      throw new UnsupportedOperationException();
58    }
59  
60    /*
61     * Marker API
62     */
63  
64    /**
65     * These markers never have references.
66     *
67     * @return false.
68     */
69    @Override
70    public boolean contains(final Marker other) {
71      // TODO Auto-generated method stub
72      return false;
73    }
74  
75    /**
76     * These markers never have references.
77     *
78     * @return false.
79     */
80    @Override
81    public boolean contains(final String name) {
82      return false;
83    }
84  
85    /**
86     * Returns the enum name of this marker.
87     *
88     * @return never null.
89     */
90    @Override
91    public String getName() {
92      return this.name();
93    }
94  
95    /**
96     * Returns the Bukkit color object associated with this marker.
97     *
98     * @return never null.
99     */
100   public ChatColor getValue() {
101     return this.value;
102   }
103 
104   /**
105    * These markers never have references.
106    *
107    * @return false.
108    */
109   @Override
110   @SuppressWarnings({ "all", "deprecation" })
111   public boolean hasChildren() {
112     return false;
113   }
114 
115   /**
116    * These markers never have references.
117    *
118    * @return false.
119    */
120   @Override
121   public boolean hasReferences() {
122     // TODO Auto-generated method stub
123     return false;
124   }
125 
126   /**
127    * These markers never have references.
128    *
129    * @return false.
130    */
131   @Override
132   public Iterator<Marker> iterator() {
133     return Collections.emptyIterator();
134   }
135 
136   /**
137    * Not supported.
138    *
139    * @param reference
140    *          unused.
141    * @throws UnsupportedOperationException
142    *           always.
143    */
144   @Override
145   public boolean remove(final Marker reference) {
146     throw new UnsupportedOperationException();
147   }
148 
149 }