Skip to content

Commit

Permalink
Initial packet support, pushing basic types is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Feb 12, 2024
1 parent ca33762 commit 6b03bd8
Show file tree
Hide file tree
Showing 21 changed files with 1,516 additions and 49 deletions.
2 changes: 1 addition & 1 deletion nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
<org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapArrayInit>WRAP_ALWAYS</org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapArrayInit>
<org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapArrayInitItems>WRAP_ALWAYS</org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapArrayInitItems>
<org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapObjects>WRAP_ALWAYS</org-netbeans-modules-editor-indent.text.plain.CodeStyle.project.wrapObjects>
<netbeans.hint.jdkPlatform>JDK_16</netbeans.hint.jdkPlatform>
<netbeans.hint.jdkPlatform>JDK_17</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
34 changes: 32 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
<connection>scm:git:git://github.com/sk89q/commandhelper.git</connection>
<url>https://github.com/sk89q/commandhelper</url>
<developerConnection>scm:git:[email protected]:sk89q/commandhelper.git</developerConnection>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
Expand Down Expand Up @@ -162,6 +162,10 @@
<id>maven-central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>

</repositories>
<dependencies>
Expand Down Expand Up @@ -423,6 +427,18 @@
<artifactId>threetenbp</artifactId>
<version>${threetenbp-version}</version>
</dependency>
<!-- GPL-2.0 -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.2.0-SNAPSHOT</version>
</dependency>
<!-- Apache 2.0 -->
<dependency>
<groupId>net.fabricmc</groupId>
<artifactId>mapping-io</artifactId>
<version>0.5.1</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
Expand Down Expand Up @@ -580,6 +596,7 @@
<include>io.gsonfire:gson-fire:jar:*</include>
<include>com.squareup.okhttp:logging-interceptor:jar:*</include>
<include>com.microsoft.sqlserver:mssql-jdbc:jar:*</include>
<include>net.fabricmc:mapping-io:jar:*</include>
</includes>
</artifactSet>
<relocations>
Expand Down Expand Up @@ -703,6 +720,10 @@
<pattern>io.gsonfire</pattern>
<shadedPattern>com.laytonsmith.libs.io.gsonfire</shadedPattern>
</relocation>
<relocation>
<pattern>net.fabricmc</pattern>
<shadedPattern>com.laytonsmith.libs.net.fabricmc</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
Expand Down Expand Up @@ -938,6 +959,15 @@
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>net.fabricmc:mapping-io:jar:*</artifact>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -462,9 +464,8 @@ public static void throwUncheckedException(Throwable t) {
*
* @param className the fully qualified name of the desired class.
* @return the {@code Class} object for the class with the specified name.
* @throws LinkageError if the linkage fails
* @throws ExceptionInInitializerError if the initialization provoked by this method fails
* @throws ReflectionException if the class cannot be located
* @throws ReflectionException wraps a LinkageError if the linkage fails, ExceptionInInitializerError if the
* initialization provoked by this method fails, or ClassNotFoundException if the class is not found.
*/
public static Class forName(String className) {
try {
Expand Down Expand Up @@ -515,12 +516,11 @@ public static Class forName(String className) {
* @param loader class loader from which the class must be loaded
* @return class object representing the desired class
*
* @throws LinkageError if the linkage fails
* @throws ExceptionInInitializerError if the initialization provoked by this method fails
* @throws ReflectionException if the class cannot be located by the specified class loader
* @throws SecurityException if a security manager is present, and the {@code loader} is {@code null}, and the
* @throws ReflectionException wraps a LinkageError if the linkage fails, ExceptionInInitializerError if the
* initialization provoked by this method fails, SecurityException if a security manager is present,
* and the {@code loader} is {@code null}, and the
* caller's class loader is not {@code null}, and the caller does not have the
* {@link RuntimePermission}{@code ("getClassLoader")}
* {@link RuntimePermission}{@code ("getClassLoader")}, or ClassNotFoundException if the class is not found.
*
* @see java.lang.Class#forName(String, boolean, ClassLoader)
* @see java.lang.ClassLoader
Expand All @@ -533,4 +533,26 @@ public static Class forName(String name, boolean initialize, ClassLoader loader)
}
}

// Exceptions are expensive, so cache this.
private static Map<String, Boolean> classExistsMap = new HashMap<>();

/**
* Checks if a class exists, according to Class.forName(). This is cached.
* @param name The class name.
* @return True if the class exists.
*/
public static boolean classExists(String name) {
if(classExistsMap.containsKey(name)) {
return classExistsMap.get(name);
}
try {
Class.forName(name);
classExistsMap.put(name, Boolean.TRUE);
return true;
} catch(ClassNotFoundException ex) {
classExistsMap.put(name, Boolean.FALSE);
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
* Streams are hard sometimes. This class abstracts most of the functionality that is commonly used.
Expand Down Expand Up @@ -93,12 +92,14 @@ public static String GetString(InputStream in, String encoding) throws Unsupport
*/
public static byte[] GetBytes(InputStream in) throws IOException {
BufferedInputStream bis = new BufferedInputStream(in);
List<Byte> bytes = new ArrayList<>();
int i;
while((i = bis.read()) != -1) {
bytes.add(((byte) i));
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
int i;
byte[] buffer = new byte[8 * 1024];
while((i = bis.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
return out.toByteArray();
}
return ArrayUtils.unbox(bytes.toArray(new Byte[bytes.size()]));
}

/**
Expand Down
Loading

0 comments on commit 6b03bd8

Please sign in to comment.