MCPcopy Create free account
hub / github.com/DGVPSH/SlackOpen / read

Method read

src/main/java/cc/slack/features/config/Config.java:84–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82 FileUtil.writeJsonToFile(jsonObject, new File(directory, name + ".json").getAbsolutePath());
83 }
84 public void read() {
85 JsonObject config = FileUtil.readJsonFromFile(
86 new File(directory, name + ".json"
87 ).getAbsolutePath());
88 configManager.currentConfig = name;
89 for (Map.Entry<String, JsonElement> entry : config.entrySet()) {
90 Slack.getInstance().getModuleManager().getModules().forEach(module -> {
91 if (entry.getKey().equalsIgnoreCase(module.getName())) {
92 JsonObject json = (JsonObject) entry.getValue();
93
94 module.setToggle(json.get("state").getAsBoolean());
95 module.setKey(json.get("bind").getAsInt());
96 try {
97 module.render = json.get("render").getAsBoolean();
98 } catch (Exception e) {
99 module.render = true;
100 }
101
102 JsonObject values = json.get("values").getAsJsonObject();
103 for (Map.Entry<String, JsonElement> value : values.entrySet()) {
104 if (module.getValueByName(value.getKey()) != null) {
105 try {
106 Value v = module.getValueByName(value.getKey());
107
108 if (v instanceof BooleanValue)
109 ((BooleanValue) v).setValue(value.getValue().getAsBoolean());
110
111 if (v instanceof ModeValue)
112 ((ModeValue) v).setIndex(value.getValue().getAsInt());
113
114 if (v instanceof NumberValue) {
115 if (((NumberValue) v).getMinimum() instanceof Integer)
116 v.setValue(value.getValue().getAsInt());
117 if (((NumberValue) v).getMinimum() instanceof Float)
118 v.setValue(value.getValue().getAsFloat());
119 if (((NumberValue) v).getMinimum() instanceof Double)
120 v.setValue(value.getValue().getAsDouble());
121 if (((NumberValue) v).getMinimum() instanceof Long)
122 try {
123 v.setValue(value.getValue().getAsLong());
124 } catch (Exception e){
125 v.setValue((int) value.getValue().getAsLong());
126 }
127 }
128
129 if (v instanceof ColorValue) {
130 v.setValue(new Color(value.getValue().getAsInt()));
131 }
132
133 if (v instanceof StringValue) {
134 v.setValue(value.getValue().getAsString());
135 }
136
137 if (v instanceof SubCatagory) {
138 v.setValue(value.getValue().getAsBoolean());
139 }
140
141 } catch (Exception e) {

Callers 2

initMethod · 0.45
loadConfigMethod · 0.45

Calls 14

readJsonFromFileMethod · 0.95
setValueMethod · 0.95
entrySetMethod · 0.80
getModulesMethod · 0.80
setToggleMethod · 0.80
getNameMethod · 0.65
getValueMethod · 0.65
getMethod · 0.65
getAsLongMethod · 0.65
getInstanceMethod · 0.45
getKeyMethod · 0.45
getValueByNameMethod · 0.45

Tested by

no test coverage detected