MCPcopy Create free account
hub / github.com/boxbeam/RedLib / getConstructor

Method getConstructor

src/redempt/redlib/nms/NMSHelper.java:134–150  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 3

getInstanceMethod · 0.95
registerAllMethod · 0.80
registerAllMethod · 0.80

Calls 1

getTypeMethod · 0.45

Tested by

no test coverage detected