|
7 | 7 |
|
8 | 8 | import org.bukkit.configuration.ConfigurationSection; |
9 | 9 |
|
| 10 | +import mineverse.Aust1n46.chat.ClickAction; |
10 | 11 | import mineverse.Aust1n46.chat.MineverseChat; |
| 12 | +import mineverse.Aust1n46.chat.utilities.Format; |
11 | 13 |
|
12 | 14 | public class JsonFormat { |
13 | | - private static MineverseChat plugin = MineverseChat.getInstance(); |
14 | | - private static HashMap<String, JsonFormat> jsonFormats; |
| 15 | + private static MineverseChat plugin = MineverseChat.getInstance(); |
| 16 | + private static HashMap<String, JsonFormat> jsonFormats; |
15 | 17 |
|
16 | | - private List<JsonAttribute> jsonAttributes; |
17 | | - private int priority; |
18 | | - private String name; |
| 18 | + private List<JsonAttribute> jsonAttributes; |
| 19 | + private int priority; |
| 20 | + private String name; |
19 | 21 |
|
20 | | - public JsonFormat(String name, int priority, List<JsonAttribute> jsonAttributes) { |
21 | | - this.name = name; |
22 | | - this.priority = priority; |
23 | | - this.jsonAttributes = jsonAttributes; |
24 | | - } |
| 22 | + public JsonFormat(String name, int priority, List<JsonAttribute> jsonAttributes) { |
| 23 | + this.name = name; |
| 24 | + this.priority = priority; |
| 25 | + this.jsonAttributes = jsonAttributes; |
| 26 | + } |
25 | 27 |
|
26 | | - public static void initialize() { |
27 | | - jsonFormats = new HashMap<String, JsonFormat>(); |
28 | | - ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting"); |
29 | | - for (String jsonFormat : jsonFormatSection.getKeys(false)) { |
30 | | - int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0); |
31 | | - List<JsonAttribute> jsonAttributes = new ArrayList<>(); |
32 | | - ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes"); |
33 | | - if (jsonAttributeSection != null) { |
34 | | - for (String attribute : jsonAttributeSection.getKeys(false)) { |
35 | | - List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text"); |
36 | | - String clickAction = jsonAttributeSection.getString(attribute + ".click_action", ""); |
37 | | - String clickText = jsonAttributeSection.getString(attribute + ".click_text", ""); |
38 | | - jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText)); |
39 | | - } |
40 | | - } |
41 | | - jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes)); |
42 | | - } |
43 | | - } |
| 28 | + public static void initialize() { |
| 29 | + jsonFormats = new HashMap<String, JsonFormat>(); |
| 30 | + ConfigurationSection jsonFormatSection = plugin.getConfig().getConfigurationSection("jsonformatting"); |
| 31 | + for (String jsonFormat : jsonFormatSection.getKeys(false)) { |
| 32 | + int priority = jsonFormatSection.getInt(jsonFormat + ".priority", 0); |
| 33 | + List<JsonAttribute> jsonAttributes = new ArrayList<>(); |
| 34 | + ConfigurationSection jsonAttributeSection = jsonFormatSection.getConfigurationSection(jsonFormat + ".json_attributes"); |
| 35 | + if (jsonAttributeSection != null) { |
| 36 | + for (String attribute : jsonAttributeSection.getKeys(false)) { |
| 37 | + List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text"); |
| 38 | + String clickActionText = jsonAttributeSection.getString(attribute + ".click_action", "none"); |
| 39 | + try { |
| 40 | + ClickAction clickAction = ClickAction.valueOf(clickActionText.toUpperCase()); |
| 41 | + String clickText = jsonAttributeSection.getString(attribute + ".click_text", ""); |
| 42 | + jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText)); |
| 43 | + } catch (IllegalArgumentException | NullPointerException exception) { |
| 44 | + plugin.getServer().getConsoleSender() |
| 45 | + .sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&c - Illegal click_action: " + clickActionText + " in jsonFormat: " + jsonFormat)); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes)); |
| 50 | + } |
| 51 | + } |
44 | 52 |
|
45 | | - public static Collection<JsonFormat> getJsonFormats() { |
46 | | - return jsonFormats.values(); |
47 | | - } |
| 53 | + public static Collection<JsonFormat> getJsonFormats() { |
| 54 | + return jsonFormats.values(); |
| 55 | + } |
48 | 56 |
|
49 | | - public static JsonFormat getJsonFormat(String name) { |
50 | | - return jsonFormats.get(name.toLowerCase()); |
51 | | - } |
| 57 | + public static JsonFormat getJsonFormat(String name) { |
| 58 | + return jsonFormats.get(name.toLowerCase()); |
| 59 | + } |
52 | 60 |
|
53 | | - public String getName() { |
54 | | - return name; |
55 | | - } |
| 61 | + public String getName() { |
| 62 | + return name; |
| 63 | + } |
56 | 64 |
|
57 | | - public int getPriority() { |
58 | | - return priority; |
59 | | - } |
60 | | - |
61 | | - public List<JsonAttribute> getJsonAttributes() { |
62 | | - return jsonAttributes; |
63 | | - } |
| 65 | + public int getPriority() { |
| 66 | + return priority; |
| 67 | + } |
| 68 | + |
| 69 | + public List<JsonAttribute> getJsonAttributes() { |
| 70 | + return jsonAttributes; |
| 71 | + } |
64 | 72 | } |
0 commit comments