Skip to content

Commit 378cf80

Browse files
committed
Improved documentation
1 parent 8184e93 commit 378cf80

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

src/main/java/com/rayzr522/jsonmessage/JSONMessage.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,19 +795,31 @@ public static Object createTitleTimesPacket(int fadeIn, int stay, int fadeOut) {
795795

796796
}
797797

798-
public static Object componentText(String msg) {
798+
/**
799+
* Creates a ChatComponentText from plain text
800+
*
801+
* @param message The text to convert to a chat component
802+
* @return The chat component
803+
*/
804+
public static Object componentText(String message) {
799805
if (!SETUP) {
800806
throw new IllegalStateException("ReflectionHelper is not set up!");
801807
}
802808
try {
803-
return chatComponentText.newInstance(msg);
809+
return chatComponentText.newInstance(message);
804810
} catch (Exception e) {
805811
e.printStackTrace();
806812
return null;
807813
}
808814

809815
}
810816

817+
/**
818+
* Attempts to convert a String representing a JSON message into a usable object
819+
*
820+
* @param json The JSON to attempt to parse
821+
* @return The object representing the text in JSON form, or <code>null</code> if something went wrong converting the String to JSON data
822+
*/
811823
public static Object fromJson(String json) {
812824
if (!SETUP) {
813825
throw new IllegalStateException("ReflectionHelper is not set up!");
@@ -825,18 +837,39 @@ public static Object fromJson(String json) {
825837

826838
}
827839

840+
/**
841+
* Returns a class with the given package and name. This method replaces <code>{nms}</code> with <code>net.minecraft.server.[version]</code> and <code>{obc}</code> with <code>org.bukkit.craft.[version]</code>
842+
* <br>
843+
* <br>
844+
* Example:
845+
*
846+
* <pre>
847+
* Class<?> entityPlayer = ReflectionHelper.getClass("{nms}.EntityPlayer");
848+
* </pre>
849+
*
850+
* @param path The path to the {@link Class}
851+
* @return The class
852+
* @throws ClassNotFoundException If the class was not found
853+
*/
828854
public static Class<?> getClass(String path) throws ClassNotFoundException {
829855
if (!SETUP) {
830856
throw new IllegalStateException("ReflectionHelper is not set up!");
831857
}
832858
return Class.forName(path.replace("{nms}", "net.minecraft.server." + version).replace("{obc}", "org.bukkit.craftbukkit." + version));
833859
}
834860

835-
public static void set(String field, Object o, Object v) {
861+
/**
862+
* Sets a field with the given name on an object to the value specified
863+
*
864+
* @param field The name of the field to change
865+
* @param obj The object to change the field of
866+
* @param value The new value to set
867+
*/
868+
public static void set(String field, Object obj, Object value) {
836869
try {
837-
Field f = o.getClass().getDeclaredField(field);
870+
Field f = obj.getClass().getDeclaredField(field);
838871
f.setAccessible(true);
839-
f.set(o, v);
872+
f.set(obj, value);
840873
} catch (Exception e) {
841874
e.printStackTrace();
842875
}

0 commit comments

Comments
 (0)