new Maven module again + now generates javadoc

This commit is contained in:
Marc Baloup 2022-07-20 16:26:29 +02:00
parent d2ca501203
commit d4471f2845
83 changed files with 193 additions and 110 deletions

View File

@ -25,11 +25,13 @@ import fr.pandacube.lib.util.Log;
* as wrapper for the target {@link ServerSocket}.
* <br>
* This class provides a simple way to exchange data between client and server :
* <ul>
* <li>Maintained connection with the server</li>
* <li>Login with a password (send in the first packet)</li>
* <li>Binary packet id</li>
* <li>Binary data</li>
* <li>Input stream in a separate Thread</li>
* </ul>
*
*/
@Beta

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pandalib-parent</artifactId>
<groupId>fr.pandacube.lib</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pandalib-paper-reflect</artifactId>
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>fabricmc</id>
<url>https://maven.fabricmc.net/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-reflect</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Paper -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version}-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-mojangapi</artifactId>
<version>${paper.version}-SNAPSHOT</version>
</dependency>
<!-- Needed to read obfuscation mapping file. Already included in Paper -->
<dependency>
<groupId>net.fabricmc</groupId>
<artifactId>mapping-io</artifactId>
<version>0.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -337,14 +337,14 @@ public class NMSReflect {
* @param mojName the Mojang mapped name of the method.
* @param mojParametersType the list of parameters of the method.
* Each parameter type must be an instance of one of the following type:
* {@link Type}, {@link Class}, {@link ReflectClass} or {@link ClassMapping}.
* {@link NMSTypeWrapper}, {@link Class}, {@link ReflectClass} or {@link ClassMapping}.
* @throws IllegalArgumentException if one of the parameter has an invalid type
* @throws NullPointerException if one of the parameter is null, or if there is no mapping for the provided Mojang mapped method.
* @throws ClassNotFoundException if there is no runtime class to represent one of the provided parametersType.
* @throws NoSuchMethodException if there is no runtime method to represent the provided method.
*/
public ReflectMethod<?> mojMethod(String mojName, Object... mojParametersType) throws ClassNotFoundException, NoSuchMethodException {
MethodId mId = new MethodId(mojName, Type.toTypeList(Arrays.asList(mojParametersType)));
MethodId mId = new MethodId(mojName, NMSTypeWrapper.toTypeList(Arrays.asList(mojParametersType)));
MemberMapping<MethodId, ReflectMethod<?>> mm = methodsByMoj.get(mId);
Objects.requireNonNull(mm, "Unable to find the Mojang mapped method " + mId);
@ -396,8 +396,8 @@ public class NMSReflect {
/* package */ Type toType(boolean obf) {
return new Type(obf ? obfName : mojName, 0);
/* package */ NMSTypeWrapper toType(boolean obf) {
return new NMSTypeWrapper(obf ? obfName : mojName, 0);
}
@ -418,30 +418,30 @@ public class NMSReflect {
String classPackages = classToPrint.substring(0, Math.max(packageSep, 0));
String classHTML = (packageSep >= 0 ? (classPackages + ".") : "") + "<b class='cl'>" + classSimpleName + "</b>";
Type superClass = superClass(obf);
NMSTypeWrapper superClass = superClass(obf);
String superClassHTML = superClass == null ? "" : (" <span class='kw'>extends</span> " + superClass.toHTML(obf));
List<Type> superInterfaces = superInterfaces(obf);
List<NMSTypeWrapper> superInterfaces = superInterfaces(obf);
String superInterfacesHTML = superInterfaces.isEmpty() ? ""
: (" <span class='kw'>implements</span> " + superInterfaces.stream().map(t -> t.toHTML(obf)).collect(Collectors.joining(", ")));
return classHTML + superClassHTML + superInterfacesHTML;
}
private Type superClass(boolean obf) {
private NMSTypeWrapper superClass(boolean obf) {
Class<?> superClass = runtimeClass().getSuperclass();
if (superClass == null || superClass.equals(Object.class) || superClass.equals(Enum.class) || superClass.equals(Record.class))
return null;
ClassMapping cm = (IS_SERVER_OBFUSCATED ? CLASSES_BY_OBF : CLASSES_BY_MOJ).get(superClass.getName());
return (cm != null) ? cm.toType(obf) : Type.of(superClass);
return (cm != null) ? cm.toType(obf) : NMSTypeWrapper.of(superClass);
}
private List<Type> superInterfaces(boolean obf) {
private List<NMSTypeWrapper> superInterfaces(boolean obf) {
Class<?>[] interfaces = runtimeClass().getInterfaces();
List<Type> types = new ArrayList<>(interfaces.length);
List<NMSTypeWrapper> types = new ArrayList<>(interfaces.length);
for (Class<?> interfce : interfaces) {
ClassMapping cm = (IS_SERVER_OBFUSCATED ? CLASSES_BY_OBF : CLASSES_BY_MOJ).get(interfce.getName());
types.add((cm != null) ? cm.toType(obf) : Type.of(interfce));
types.add((cm != null) ? cm.toType(obf) : NMSTypeWrapper.of(interfce));
}
return types;
}
@ -451,12 +451,12 @@ public class NMSReflect {
String classObfSimpleName = obfName.substring(obfName.lastIndexOf('.') + 1);
String classMojSimpleName = mojName.substring(mojName.lastIndexOf('.') + 1);
for (Constructor<?> ct : runtimeClass().getDeclaredConstructors()) {
List<Type> obfParams = new ArrayList<>();
List<Type> mojParams = new ArrayList<>();
List<NMSTypeWrapper> obfParams = new ArrayList<>();
List<NMSTypeWrapper> mojParams = new ArrayList<>();
for (Class<?> param : ct.getParameterTypes()) {
ClassMapping cm = (IS_SERVER_OBFUSCATED ? CLASSES_BY_OBF : CLASSES_BY_MOJ).get(param.getName());
if (cm == null) {
Type t = Type.of(param);
NMSTypeWrapper t = NMSTypeWrapper.of(param);
obfParams.add(t);
mojParams.add(t);
}
@ -482,7 +482,7 @@ public class NMSReflect {
private record MethodId(String name, List<Type> parametersType) implements Comparable<MethodId> {
private record MethodId(String name, List<NMSTypeWrapper> parametersType) implements Comparable<MethodId> {
@Override
public int compareTo(MethodId o) {
int cmp = name.compareTo(o.name);
@ -502,7 +502,7 @@ public class NMSReflect {
}
public String toString() {
String paramsStr = parametersType.stream().map(Type::toString).collect(Collectors.joining(", "));
String paramsStr = parametersType.stream().map(NMSTypeWrapper::toString).collect(Collectors.joining(", "));
return name + "(" + paramsStr + ")";
}
@ -510,7 +510,7 @@ public class NMSReflect {
private record MemberDesc<I extends Comparable<I>>(I identifier, Type returnType) {
private record MemberDesc<I extends Comparable<I>>(I identifier, NMSTypeWrapper returnType) {
private String toHTML(boolean isObfClass, boolean isStatic, boolean isFinal) {
String identifierHTML = "";
if (identifier instanceof MethodId mId)
@ -533,14 +533,14 @@ public class NMSReflect {
if (r != '(')
throw new IllegalArgumentException("Invalid method description '" + desc + "'. Must start with '('.");
List<Type> paramsType = new ArrayList<>();
List<NMSTypeWrapper> paramsType = new ArrayList<>();
while (((char) descReader.read()) != ')') {
descReader.skip(-1);
paramsType.add(Type.parse(descReader));
paramsType.add(NMSTypeWrapper.parse(descReader));
}
Type retType = Type.parse(descReader);
NMSTypeWrapper retType = NMSTypeWrapper.parse(descReader);
return new MemberDesc<>(new MethodId(member.getName(namespace), Collections.unmodifiableList(paramsType)), retType);
} catch (IOException e) {
throw new RuntimeException("StringReader read error", e);
@ -551,7 +551,7 @@ public class NMSReflect {
private static MemberDesc<String> of(MappingTree.FieldMapping member, String namespace) {
StringReader descReader = new StringReader(member.getDesc(namespace));
return new MemberDesc<>(member.getName(namespace), Type.parse(descReader));
return new MemberDesc<>(member.getName(namespace), NMSTypeWrapper.parse(descReader));
}
}
@ -604,7 +604,7 @@ public class NMSReflect {
@Override
ReflectMethod<?> getReflectMember() throws ClassNotFoundException, NoSuchMethodException {
MethodId id = getReflectDesc().identifier;
return declaringClass.runtimeReflectClass.method(id.name, Type.toClassArray(id.parametersType));
return declaringClass.runtimeReflectClass.method(id.name, NMSTypeWrapper.toClassArray(id.parametersType));
}
};
}

View File

@ -9,18 +9,18 @@ import java.util.Objects;
import fr.pandacube.lib.reflect.Reflect.ReflectClass;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
public class Type implements Comparable<Type> {
/* package */ class NMSTypeWrapper implements Comparable<NMSTypeWrapper> {
private final String type;
private final int arrayDepth;
/* package */ Type(String type, int arrayDepth) {
/* package */ NMSTypeWrapper(String type, int arrayDepth) {
this.type = type;
this.arrayDepth = arrayDepth;
}
@Override
public boolean equals(Object obj) {
return obj instanceof Type ot && type.equals(ot.type) && arrayDepth == ot.arrayDepth;
return obj instanceof NMSTypeWrapper ot && type.equals(ot.type) && arrayDepth == ot.arrayDepth;
}
@Override
public int hashCode() {
@ -28,7 +28,7 @@ public class Type implements Comparable<Type> {
}
@Override
public int compareTo(Type o) {
public int compareTo(NMSTypeWrapper o) {
return toString().compareTo(o.toString());
}
@ -54,36 +54,36 @@ public class Type implements Comparable<Type> {
return cl;
}
public Type arrayType() {
return new Type(type, arrayDepth + 1);
public NMSTypeWrapper arrayType() {
return new NMSTypeWrapper(type, arrayDepth + 1);
}
/* package */ static Type of(Class<?> cl) {
/* package */ static NMSTypeWrapper of(Class<?> cl) {
int arrayDepth = 0;
while (cl.isArray()) {
cl = cl.getComponentType();
arrayDepth++;
}
return new Type(cl.getName(), arrayDepth);
return new NMSTypeWrapper(cl.getName(), arrayDepth);
}
public static Type of(ReflectClass<?> rc) {
public static NMSTypeWrapper of(ReflectClass<?> rc) {
return arrayOf(rc, 0);
}
public static Type arrayOf(ReflectClass<?> rc, int arrayDepth) {
return new Type(rc.get().getName(), arrayDepth);
public static NMSTypeWrapper arrayOf(ReflectClass<?> rc, int arrayDepth) {
return new NMSTypeWrapper(rc.get().getName(), arrayDepth);
}
public static Type mojOf(ClassMapping cm) {
public static NMSTypeWrapper mojOf(ClassMapping cm) {
return arrayMojOf(cm, 0);
}
public static Type arrayMojOf(ClassMapping cm, int arrayDepth) {
return new Type(cm.mojName, arrayDepth);
public static NMSTypeWrapper arrayMojOf(ClassMapping cm, int arrayDepth) {
return new NMSTypeWrapper(cm.mojName, arrayDepth);
}
/* package */ static Type toType(Object typeObj) {
/* package */ static NMSTypeWrapper toType(Object typeObj) {
Objects.requireNonNull(typeObj, "typeObj cannot be null");
if (typeObj instanceof Class<?> cl) {
return of(cl);
@ -94,7 +94,7 @@ public class Type implements Comparable<Type> {
else if (typeObj instanceof ReflectClass<?> rc) {
return of(rc);
}
else if (typeObj instanceof Type t) {
else if (typeObj instanceof NMSTypeWrapper t) {
return t;
}
else
@ -139,7 +139,7 @@ public class Type implements Comparable<Type> {
/* package */ static Type parse(StringReader desc) {
/* package */ static NMSTypeWrapper parse(StringReader desc) {
try {
int arrayDepth = 0;
char c;
@ -165,7 +165,7 @@ public class Type implements Comparable<Type> {
}
default -> "void";
};
return new Type(type, arrayDepth);
return new NMSTypeWrapper(type, arrayDepth);
} catch (IOException e) {
throw new RuntimeException("StringReader read error", e);
}
@ -174,12 +174,12 @@ public class Type implements Comparable<Type> {
/* package */ static List<Type> toTypeList(List<Object> paramsType) {
List<Type> types = new ArrayList<>(paramsType.size());
/* package */ static List<NMSTypeWrapper> toTypeList(List<Object> paramsType) {
List<NMSTypeWrapper> types = new ArrayList<>(paramsType.size());
for (int i = 0; i < paramsType.size(); i++) {
Object param = paramsType.get(i);
try {
types.add(Type.toType(param));
types.add(NMSTypeWrapper.toType(param));
} catch (NullPointerException|IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid parameterType at index " + i, e);
}
@ -187,7 +187,7 @@ public class Type implements Comparable<Type> {
return types;
}
/* package */ static Class<?>[] toClassArray(List<Type> types) throws ClassNotFoundException {
/* package */ static Class<?>[] toClassArray(List<NMSTypeWrapper> types) throws ClassNotFoundException {
Class<?>[] classes = new Class<?>[types.size()];
for (int i = 0; i < types.size(); i++) {
classes[i] = types.get(i).toClass();

View File

@ -0,0 +1,11 @@
package fr.pandacube.lib.paper.reflect;
import fr.pandacube.lib.paper.reflect.wrapper.WrapperRegistry;
public class PandalibPaperReflect {
public static void init() {
NMSReflect.init();
WrapperRegistry.init();
}
}

View File

@ -49,14 +49,6 @@
<artifactId>paper-mojangapi</artifactId>
<version>${paper.version}-SNAPSHOT</version>
</dependency>
<!-- Needed to read obfuscation mapping file. Already included in Paper -->
<dependency>
<groupId>net.fabricmc</groupId>
<artifactId>mapping-io</artifactId>
<version>0.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,5 @@
package fr.pandacube.lib.paper;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.WrapperRegistry;
import org.bukkit.plugin.Plugin;
public class PandaLibPaper {
@ -11,10 +9,6 @@ public class PandaLibPaper {
public static void init(Plugin plugin) {
PandaLibPaper.plugin = plugin;
NMSReflect.init();
WrapperRegistry.init();
}
public static Plugin getPlugin() {

View File

@ -1,7 +1,8 @@
package fr.pandacube.lib.paper.util;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.paper.PandaLibPaper;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
@ -12,8 +13,8 @@ import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.RegisteredListener;
import org.bukkit.scheduler.BukkitTask;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import fr.pandacube.lib.paper.PandaLibPaper;
import fr.pandacube.lib.reflect.Reflect;
public class BukkitEvent {

View File

@ -80,7 +80,8 @@ public class GeometryUtil {
* @param playerLocation the location of the player, generally provided by {@link Player#getLocation()}
* @param isSneaking if the player is sneaking. Generally {@link Player#isSneaking()}
* @return an array of 8 {@link Location}s with x, y, and z values filled (yaw and pitch are ignored).
* <pre>return[0] // top front left
* <pre>
* return[0] // top front left
* return[1] // top front right
* return[2] // bottom front left
* return[3] // bottom front right
@ -88,6 +89,7 @@ public class GeometryUtil {
* return[5] // top back right
* return[6] // bottom back left
* return[7] // bottom back right
* </pre>
*/
public static Location[] getPlayerHeadGeometry(Location playerLocation, boolean isSneaking) {
Location[] headAnglesPoints = new Location[8];
@ -255,11 +257,11 @@ public class GeometryUtil {
/**
* @param v the vector representing the direction. If v.getX() && v.getZ() are 0,
* @param v the vector representing the direction. If v.getX() and v.getZ() are 0,
* the yaw will be 0. This may have inconsistence if the vector is calculated
* from a {@link Location}'s yaw and pitch. In this case, prefer using
* {@link #DirectionalVector(Location)}. The {@link Vector} is
* normalized if necessary (does not modify provided {@link Vector}).
* normalized if necessary (does not modify the provided {@link Vector}).
*/
public DirectionalVector(Vector v) {
this(v.getX(), v.getY(), v.getZ());

View File

@ -46,55 +46,42 @@ import java.util.regex.Pattern;
* A cron expressions consists of 5 or 6 mandatory fields (seconds may be omitted) separated by space. <br>
* These are:
*
* <table cellspacing="8">
* <table>
* <caption>CRON fields</caption>
* <tr>
* <th align="left">Field</th>
* <th align="left">&nbsp;</th>
* <th align="left">Allowable values</th>
* <th align="left">&nbsp;</th>
* <th align="left">Special Characters</th>
* <th>Field</th>
* <th>Allowable values</th>
* <th>Special Characters</th>
* </tr>
* <tr>
* <td align="left"><code>Seconds (may be omitted)</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-59</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* <td><code>Seconds (may be omitted)</code></td>
* <td><code>0-59</code></td>
* <td><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Minutes</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-59</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* <td><code>Minutes</code></td>
* <td><code>0-59</code></td>
* <td><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Hours</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>0-23</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* <td><code>Hours</code></td>
* <td><code>0-23</code></td>
* <td><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Day of month</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1-31</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * ? / L W</code></td>
* <td><code>Day of month</code></td>
* <td><code>1-31</code></td>
* <td><code>, - * ? / L W</code></td>
* </tr>
* <tr>
* <td align="left"><code>Month</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1-12 or JAN-DEC (note: english abbreviations)</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * /</code></td>
* <td><code>Month</code></td>
* <td><code>1-12 or JAN-DEC (note: english abbreviations)</code></td>
* <td><code>, - * /</code></td>
* </tr>
* <tr>
* <td align="left"><code>Day of week</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>1-7 or MON-SUN (note: english abbreviations)</code></td>
* <td align="left">&nbsp;</th>
* <td align="left"><code>, - * ? / L #</code></td>
* <td><code>Day of week</code></td>
* <td><code>1-7 or MON-SUN (note: english abbreviations)</code></td>
* <td><code>, - * ? / L #</code></td>
* </tr>
* </table>
*

35
pom.xml
View File

@ -56,6 +56,7 @@
<module>pandalib-permissions</module>
<module>pandalib-reflect</module>
<module>pandalib-util</module>
<module>pandalib-paper-reflect</module>
</modules>
<dependencies>
@ -90,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.2.2</version>
<configuration>
<archive>
<manifestEntries>
@ -114,6 +115,38 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<tags>
<tag>
<name>apiNote</name>
<placement>a</placement>
<head>API Note:</head>
</tag>
<tag>
<name>implSpec</name>
<placement>a</placement>
<head>Implementation Requirements:</head>
</tag>
<tag>
<name>implNote</name>
<placement>a</placement>
<head>Implementation Note:</head>
</tag>
</tags>
</configuration>
</plugin>
</plugins>
</build>
</project>