Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 76508c3

Browse files
committed
Documentation for NMSProxyProvider
1 parent 942d16f commit 76508c3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/me/theminecoder/minecraft/nmsproxy/proxy/NMSProxyProvider.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,25 @@ private void registerNMSClasses(Class<? extends NMSProxy> clazz) {
6565
proxyToNMSClassMap.put(clazz, nmsClass);
6666
}
6767

68+
/**
69+
* Generates a static only proxy to an NMS class
70+
*
71+
* @param clazz {@link NMSClass} annotated {@link NMSProxy} interface.
72+
* @return Generated Proxy
73+
*/
6874
public <T extends NMSProxy> T getStaticNMSObject(Class<T> clazz) {
6975
registerNMSClasses(clazz);
7076

7177
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new NMSProxyInvocationHandler(null, invocationMapper, this));
7278
}
7379

80+
/**
81+
* Generates a proxy to an NMS class instance
82+
*
83+
* @param clazz {@link NMSClass} annotated {@link NMSProxy} interface.
84+
* @param object Object to proxy
85+
* @return Generated Proxy
86+
*/
7487
public <T extends NMSProxy> T getNMSObject(Class<T> clazz, Object object) {
7588
registerNMSClasses(clazz);
7689

@@ -81,6 +94,13 @@ public <T extends NMSProxy> T getNMSObject(Class<T> clazz, Object object) {
8194
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new NMSProxyInvocationHandler(object, invocationMapper, this));
8295
}
8396

97+
/**
98+
* Constructs and returns a NMS object wrapped in a proxy.
99+
* @param clazz {@link NMSClass} annotated {@link NMSProxy} interface class
100+
* @param params Objects to pass to the constructor (NMSProxy instances will be converted to their actual objects for you)
101+
* @return The constructed NMS object wrapped in a proxy.
102+
* @throws ReflectiveOperationException
103+
*/
84104
public <T extends NMSProxy> T constructNMSObject(Class<T> clazz, Object... params) throws ReflectiveOperationException {
85105
registerNMSClasses(clazz);
86106

@@ -92,6 +112,17 @@ public <T extends NMSProxy> T constructNMSObject(Class<T> clazz, Object... param
92112
return getNMSObject(clazz, nmsObject);
93113
}
94114

115+
/**
116+
* Constructs and returns an object that is a subclass of another NMS class.
117+
*
118+
* Something of note here is that the class you use to define the subclass is not the same class you get back.
119+
* This is due to the use of a dynamic class generator to do the backend work with subclassing.
120+
*
121+
* @param clazz Class implementing another {@link NMSProxy} and {@link NMSSubclass}
122+
* @param params Objects to pass to the constructor of the final subclass
123+
* @return The constructed object (Note that this is not wrapped in a proxy)
124+
* @throws ReflectiveOperationException
125+
*/
95126
public <T extends NMSSubclass> T constructNMSSubclass(Class<T> clazz, Object... params) throws ReflectiveOperationException {
96127
if (clazz.getInterfaces().length == 0 || NMSProxy.class.isAssignableFrom(clazz.getInterfaces()[0])) {
97128
throw new IllegalArgumentException("Class does not implement a NMSProxy interface");

0 commit comments

Comments
 (0)