Gets a constructor by its parameter types, accounts for cases where the given class might not be the exact same type as the parameter the method requires, but is a subclass. @param clazz The class to get the constructor in @param argTypes The class types for the constructor parameters @return Th
(Class<?> clazz, Class<?>[] argTypes)
| 132 | * @return The constructor in the class, or null if none was found |
| 133 | */ |
| 134 | public static Constructor getConstructor(Class<?> clazz, Class<?>[] argTypes) { |
| 135 | Constructor[] methods = clazz.getConstructors(); |
| 136 | methods: |
| 137 | for (Constructor method : methods) { |
| 138 | if (method.getParameterCount() != argTypes.length) { |
| 139 | continue; |
| 140 | } |
| 141 | Parameter[] params = method.getParameters(); |
| 142 | for (int i = 0; i < params.length; i++) { |
| 143 | if (!params[i].getType().isAssignableFrom(argTypes[i])) { |
| 144 | continue methods; |
| 145 | } |
| 146 | } |
| 147 | return method; |
| 148 | } |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Gets an NMS class (a class whose package is net.minecraft.server followed by the version package) |
no test coverage detected