Commit af46a2da7a4306f71c32496296819bdd16ce1dbd
1 parent
97e55cae
allow access to shared descriptor table in JSON event transformer definitions
Showing
3 changed files
with
49 additions
and
4 deletions
java/common/com/mumfrey/liteloader/core/runtime/Methods.java
1 | 1 | package com.mumfrey.liteloader.core.runtime; |
2 | 2 | |
3 | 3 | import java.io.File; |
4 | +import java.lang.reflect.Field; | |
5 | +import java.util.HashMap; | |
6 | +import java.util.Map; | |
4 | 7 | |
5 | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
6 | 9 | |
... | ... | @@ -44,4 +47,26 @@ public abstract class Methods |
44 | 47 | public static final MethodInfo endStartSection = new MethodInfo(Obf.Profiler, Obf.endStartSection, Void.TYPE, String.class); |
45 | 48 | |
46 | 49 | private Methods() {} |
50 | + | |
51 | + private static final Map<String, MethodInfo> methodMap = new HashMap<String, MethodInfo>(); | |
52 | + | |
53 | + static | |
54 | + { | |
55 | + try | |
56 | + { | |
57 | + for (Field fd : Methods.class.getFields()) | |
58 | + { | |
59 | + if (fd.getType().equals(MethodInfo.class)) | |
60 | + { | |
61 | + Methods.methodMap.put(fd.getName(), (MethodInfo)fd.get(null)); | |
62 | + } | |
63 | + } | |
64 | + } | |
65 | + catch (IllegalAccessException ex) {} | |
66 | + } | |
67 | + | |
68 | + public static MethodInfo getByName(String name) | |
69 | + { | |
70 | + return Methods.methodMap.get(name); | |
71 | + } | |
47 | 72 | } | ... | ... |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonInjection.java
... | ... | @@ -84,7 +84,14 @@ public class JsonInjection implements Serializable |
84 | 84 | |
85 | 85 | private MethodInfo parseMethod(JsonMethods methods) |
86 | 86 | { |
87 | - return methods.get(this.methodName); | |
87 | + try | |
88 | + { | |
89 | + return methods.get(this.methodName); | |
90 | + } | |
91 | + catch (NullPointerException ex) | |
92 | + { | |
93 | + throw new InvalidEventJsonException("'method' must not be null for injection"); | |
94 | + } | |
88 | 95 | } |
89 | 96 | |
90 | 97 | public InjectionPoint parseInjectionPoint(JsonMethods methods) |
... | ... | @@ -148,6 +155,11 @@ public class JsonInjection implements Serializable |
148 | 155 | } |
149 | 156 | } |
150 | 157 | |
158 | + if (this.target == null) | |
159 | + { | |
160 | + throw new InvalidEventJsonException("'target' is required for injection type " + this.type.name()); | |
161 | + } | |
162 | + | |
151 | 163 | return this.target; |
152 | 164 | } |
153 | 165 | ... | ... |
java/common/com/mumfrey/liteloader/transformers/event/json/JsonMethods.java
... | ... | @@ -4,6 +4,7 @@ import java.util.HashMap; |
4 | 4 | import java.util.List; |
5 | 5 | import java.util.Map; |
6 | 6 | |
7 | +import com.mumfrey.liteloader.core.runtime.Methods; | |
7 | 8 | import com.mumfrey.liteloader.transformers.event.MethodInfo; |
8 | 9 | |
9 | 10 | /** |
... | ... | @@ -69,10 +70,17 @@ public class JsonMethods |
69 | 70 | } |
70 | 71 | |
71 | 72 | MethodInfo method = this.methods.get(key); |
72 | - if (method == null) | |
73 | + if (method != null) | |
73 | 74 | { |
74 | - throw new InvalidEventJsonException("Could not locate method with token " + token); | |
75 | + return method; | |
75 | 76 | } |
76 | - return method; | |
77 | + | |
78 | + MethodInfo builtinMethod = Methods.getByName(key); | |
79 | + if (builtinMethod != null) | |
80 | + { | |
81 | + return builtinMethod; | |
82 | + } | |
83 | + | |
84 | + throw new InvalidEventJsonException("Could not locate method descriptor with token " + token); | |
77 | 85 | } |
78 | 86 | } |
79 | 87 | \ No newline at end of file | ... | ... |