11package org .mcphackers .mcp .tools .injector ;
22
3- import java .util .ArrayList ;
4- import java .util .Collections ;
5- import java .util .HashMap ;
6- import java .util .Iterator ;
7- import java .util .List ;
8- import java .util .Map ;
3+ import java .io .InputStream ;
4+ import java .util .*;
95import java .util .Map .Entry ;
106
117import org .json .JSONArray ;
1511import org .mcphackers .rdi .util .IdentifyCall ;
1612import org .mcphackers .rdi .util .Pair ;
1713import org .objectweb .asm .Opcodes ;
18- import org .objectweb .asm .tree .AbstractInsnNode ;
19- import org .objectweb .asm .tree .FieldInsnNode ;
20- import org .objectweb .asm .tree .InsnList ;
21- import org .objectweb .asm .tree .InsnNode ;
22- import org .objectweb .asm .tree .IntInsnNode ;
23- import org .objectweb .asm .tree .LdcInsnNode ;
24- import org .objectweb .asm .tree .MethodInsnNode ;
25- import org .objectweb .asm .tree .MethodNode ;
14+ import org .objectweb .asm .tree .*;
2615
2716public final class GLConstants extends ClassVisitor {
2817
@@ -33,18 +22,14 @@ public final class GLConstants extends ClassVisitor {
3322 private static final char [] OPERATORS = {'|' , '&' , '^' };
3423
3524 static {
36- JSONObject json = JSONUtil .getJSON (GLConstants .class .getClassLoader ().getResourceAsStream ("gl_constants.json" ));
37- if (json != null ) {
38- CONSTANTS = getConstants (json .optJSONArray ("CONSTANTS" ));
39- CONSTANTS_KEYBOARD = JSONUtil .toMap (json .optJSONObject ("CONSTANTS_KEYBOARD" ));
40- PACKAGES = getPackages (CONSTANTS );
41- INIT = true ;
42- } else {
43- CONSTANTS = null ;
44- CONSTANTS_KEYBOARD = null ;
45- PACKAGES = null ;
46- INIT = false ;
47- }
25+ final Optional <InputStream > jsonStream = Optional
26+ .ofNullable (GLConstants .class .getClassLoader ().getResourceAsStream ("gl_constants.json" ));
27+
28+ final Optional <JSONObject > json = Optional .ofNullable (JSONUtil .getJSON (jsonStream .get ()));
29+ CONSTANTS = json .map (js -> getConstants (js .optJSONArray ("CONSTANTS" ))).orElse (null );
30+ CONSTANTS_KEYBOARD = json .map (js -> JSONUtil .toMap (js .optJSONObject ("CONSTANTS_KEYBOARD" ))).orElse (null );
31+ PACKAGES = json .map (js -> getPackages (CONSTANTS )).orElse (null );
32+ INIT = json .isPresent ();
4833 }
4934
5035 public GLConstants (ClassVisitor classVisitor ) {
0 commit comments