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 * <p>
30 * This class does not depend on JAnsi, so it is safe to use even in
31 * environments where JAnsi is not available (e.g. PaperSpigot).
32 * </p>
33 *
34 * @author Ronald Jack Jenkins Jr.
35 */
36 public enum ColorMarker implements Marker {
37
38 AQUA(ChatColor.AQUA), BLACK(ChatColor.BLACK), BLUE(ChatColor.BLUE),
39 DARK_AQUA(ChatColor.DARK_AQUA), DARK_BLUE(ChatColor.DARK_BLUE),
40 DARK_GRAY(ChatColor.DARK_GRAY), DARK_GREEN(ChatColor.DARK_GREEN),
41 DARK_PURPLE(ChatColor.DARK_PURPLE), DARK_RED(ChatColor.DARK_RED),
42 GOLD(ChatColor.GOLD), GRAY(ChatColor.GRAY), GREEN(ChatColor.GREEN),
43 LIGHT_PURPLE(ChatColor.LIGHT_PURPLE), NONE(ChatColor.RESET),
44 RED(ChatColor.RED), WHITE(ChatColor.WHITE), YELLOW(ChatColor.YELLOW);
45
46 private final ChatColor value;
47
48 private ColorMarker(final ChatColor value) {
49 this.value = value;
50 }
51
52 /**
53 * Not supported.
54 *
55 * @param reference
56 * unused.
57 * @throws UnsupportedOperationException
58 * always.
59 */
60 @Override
61 public void add(final Marker reference) {
62 throw new UnsupportedOperationException();
63 }
64
65 /*
66 * Marker API
67 */
68
69 /**
70 * These markers never have references.
71 *
72 * @return false.
73 */
74 @Override
75 public boolean contains(final Marker other) {
76 return false;
77 }
78
79 /**
80 * These markers never have references.
81 *
82 * @return false.
83 */
84 @Override
85 public boolean contains(final String name) {
86 return false;
87 }
88
89 /**
90 * Returns the enum name of this marker.
91 *
92 * @return never null.
93 */
94 @Override
95 public String getName() {
96 return this.name();
97 }
98
99 /**
100 * Returns the Bukkit color object associated with this marker.
101 *
102 * @return never null.
103 */
104 public ChatColor getValue() {
105 return this.value;
106 }
107
108 /**
109 * These markers never have references.
110 *
111 * @return false.
112 */
113 @Override
114 @SuppressWarnings({ "all", "deprecation" })
115 public boolean hasChildren() {
116 return false;
117 }
118
119 /**
120 * These markers never have references.
121 *
122 * @return false.
123 */
124 @Override
125 public boolean hasReferences() {
126 return false;
127 }
128
129 /**
130 * These markers never have references.
131 *
132 * @return false.
133 */
134 @Override
135 public Iterator<Marker> iterator() {
136 return Collections.emptyIterator();
137 }
138
139 /**
140 * Not supported.
141 *
142 * @param reference
143 * unused.
144 * @throws UnsupportedOperationException
145 * always.
146 */
147 @Override
148 public boolean remove(final Marker reference) {
149 throw new UnsupportedOperationException();
150 }
151
152 }