@@ -140,10 +140,12 @@ public Object propertyCommand(Command.Parameters param) {
140
140
.setColor (Color .RED )
141
141
.setDescription ("Unknown property: `" + args [0 ] + "`" );
142
142
143
- if (args [1 ].equalsIgnoreCase ("#default#" ))
144
- args [1 ] = String .valueOf (propertySet .getDefaultValue ().getValue ());
143
+ Object setTo = extractValue (args [1 ]);
145
144
146
- value .setter ().toString (args [1 ]);
145
+ if (setTo .equals ("#default#" ))
146
+ setTo = String .valueOf (propertySet .getDefaultValue ().getValue ());
147
+
148
+ value .setter ().toObject (setTo );
147
149
148
150
return embedSupplier .get ()
149
151
.setDescription ("Changed property `" + args [0 ] + "` to new value: `" + value .asString () + "`" )
@@ -187,6 +189,27 @@ public void storeData() throws IOException {
187
189
stream .close ();
188
190
}
189
191
192
+ private Object extractValue (String val ) {
193
+ if (val .matches ("\\ d+" )) {
194
+ // is number without decimals
195
+ long longVal = Long .parseLong (val );
196
+
197
+ if (longVal <= Byte .MAX_VALUE ) return (byte ) longVal ;
198
+ else if (longVal <= Short .MAX_VALUE ) return (short ) longVal ;
199
+ else if (longVal <= Integer .MAX_VALUE ) return (int ) longVal ;
200
+ else return longVal ;
201
+ } else if (val .matches ("\\ d+\\ .\\ d+" )) {
202
+ // is number with decimals
203
+ return Double .parseDouble (val );
204
+ } else if (val .toLowerCase ().matches ("(true)|(false)" )) {
205
+ // is boolean
206
+ return Boolean .valueOf (val );
207
+ } else {
208
+ // is plain string
209
+ return val ;
210
+ }
211
+ }
212
+
190
213
private void readData () throws IOException {
191
214
int c = 0 ;
192
215
JsonNode node = new ObjectMapper ().readTree (new FileInputStream (propertiesFile ));
0 commit comments