Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Warning.java
1 package org.bukkit;
2 
3 import java.lang.annotation.ElementType;
4 import java.lang.annotation.Retention;
5 import java.lang.annotation.RetentionPolicy;
6 import java.lang.annotation.Target;
7 import java.util.Map;
8 
9 import com.google.common.collect.ImmutableMap;
10 
11 /**
12  * This designates the warning state for a specific item.
13  * <p>
14  * When the server settings dictate 'default' warnings, warnings are printed
15  * if the {@link #value()} is true.
16  */
17 @Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
18 @Retention(RetentionPolicy.RUNTIME)
19 public @interface Warning {
20 
21  /**
22  * This represents the states that server verbose for warnings may be.
23  */
24  public enum WarningState {
25 
26  /**
27  * Indicates all warnings should be printed for deprecated items.
28  */
29  ON,
30  /**
31  * Indicates no warnings should be printed for deprecated items.
32  */
33  OFF,
34  /**
35  * Indicates each warning would default to the configured {@link
36  * Warning} annotation, or always if annotation not found.
37  */
39 
40  private static final Map<String, WarningState> values = ImmutableMap.<String,WarningState>builder()
41  .put("off", OFF)
42  .put("false", OFF)
43  .put("f", OFF)
44  .put("no", OFF)
45  .put("n", OFF)
46  .put("on", ON)
47  .put("true", ON)
48  .put("t", ON)
49  .put("yes", ON)
50  .put("y", ON)
51  .put("", DEFAULT)
52  .put("d", DEFAULT)
53  .put("default", DEFAULT)
54  .build();
55 
56  /**
57  * This method checks the provided warning should be printed for this
58  * state
59  *
60  * @param warning The warning annotation added to a deprecated item
61  * @return <ul>
62  * <li>ON is always True
63  * <li>OFF is always false
64  * <li>DEFAULT is false if and only if annotation is not null and
65  * specifies false for {@link Warning#value()}, true otherwise.
66  * </ul>
67  */
68  public boolean printFor(Warning warning) {
69  if (this == DEFAULT) {
70  return warning == null || warning.value();
71  }
72  return this == ON;
73  }
74 
75  /**
76  * This method returns the corresponding warning state for the given
77  * string value.
78  *
79  * @param value The string value to check
80  * @return {@link #DEFAULT} if not found, or the respective
81  * WarningState
82  */
83  public static WarningState value(final String value) {
84  if (value == null) {
85  return DEFAULT;
86  }
87  WarningState state = values.get(value.toLowerCase());
88  if (state == null) {
89  return DEFAULT;
90  }
91  return state;
92  }
93  }
94 
95  /**
96  * This sets if the deprecation warnings when registering events gets
97  * printed when the setting is in the default state.
98  *
99  * @return false normally, or true to encourage warning printout
100  */
101  boolean value() default false;
102 
103  /**
104  * This can provide detailed information on why the event is deprecated.
105  *
106  * @return The reason an event is deprecated
107  */
108  String reason() default "";
109 }
boolean printFor(Warning warning)
Definition: Warning.java:68
static WarningState value(final String value)
Definition: Warning.java:83
boolean value() default false