Skip to content

Commit

Permalink
Large updates to everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Swofty-Developments committed Jan 28, 2024
1 parent 8aa2870 commit 63a6d04
Show file tree
Hide file tree
Showing 32 changed files with 447 additions and 902 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<groupId>net.swofty</groupId>
<artifactId>swoftyworldmanager</artifactId>
<packaging>pom</packaging>
<version>3.1.1</version>
<version>4.0.0</version>
<modules>
<module>swoftyworldmanager-api</module>
<module>swoftyworldmanager-nms</module>
<module>swoftyworldmanager-plugin</module>
<module>swoftyworldmanager-importer</module>
<module>swoftyworldmanager-classmodifier</module>
</modules>

Expand Down
2 changes: 1 addition & 1 deletion swoftyworldmanager-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.1.1</version>
<version>4.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
128 changes: 128 additions & 0 deletions swoftyworldmanager-api/src/main/java/net/swofty/swm/api/ApiStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package net.swofty.swm.api;

import java.lang.annotation.*;

public final class ApiStatus {

/**
* Prohibited default constructor.
*/
private ApiStatus() {
throw new AssertionError("ApiStatus should not be instantiated");
}

/**
* <p>Indicates that a public API of the annotated element (class, method or field) is not in stable state yet. It may be renamed, changed or
* even removed in a future version. This annotation refers to API status only, it doesn't mean that the implementation has
* an 'experimental' quality.</p>
*
* <p>It's safe to use an element marked with this annotation if the usage is located in the same sources codebase as the declaration. However,
* if the declaration belongs to an external library such usages may lead to problems when the library will be updated to another version.</p>
*
* <p>If a package is marked with this annotation, all its containing classes are considered experimental.
* Subpackages of this package are not affected and should be marked independently.</p>
*
* <p>If a type is marked with this annotation, all its members are considered experimental, but its inheritors are not.</p>
*
* <p>If a method is marked with this annotation, overriding methods are not considered experimental.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE
})
public @interface Experimental {}

/**
* Indicates that the annotated element (class, method, field, etc) must not be considered as a public API. It's made visible to allow
* usages in other packages of the declaring library, but it must not be used outside of that library. Such elements
* may be renamed, changed or removed in future versions.
*
* <p>If a package is marked with this annotation, all its containing classes are considered internal.
* Subpackages of this package are not affected and should be marked independently.</p>
*
* <p>If a type is marked with this annotation, all its members are considered internal, but its inheritors are not.</p>
*
* <p>If a method is marked with this annotation, overriding methods are not considered internal.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE
})
public @interface Internal {}

/**
* <p>Indicates that a public API of the annotated element (class, method or field) is subject to removal in a future version.
* It's a stronger variant of {@link Deprecated} annotation.</p>
*
* <p>Since many tools aren't aware of this annotation it should be used as an addition to {@code @Deprecated} annotation
* or {@code @deprecated} Javadoc tag only.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE
})
public @interface ScheduledForRemoval {
/**
* Specifies in which version the API will be removed.
*/
String inVersion() default "";
}

/**
* <p>Indicates that the annotated element firstly appeared in the specified version of the library, so the code using that element
* won't be compatible with older versions of the library. This information may be used by IDEs and static analysis tools.
* This annotation can be used instead of '@since' Javadoc tag if it's needed to keep that information in *.class files or if you need
* to generate them automatically.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE
})
public @interface AvailableSince {
/**
* Specifies a version where the annotation API firstly appeared.
*/
String value();
}

/**
* <p>Indicates that the annotated API class, interface or method <strong>must not be extended, implemented or overridden</strong>.</p>
*
* <p>API class, interface or method may not be marked {@code final} because it is extended by classes of the declaring library
* but it is not supposed to be extended outside the library. Instances of classes and interfaces marked with this annotation
* may be cast to an internal implementing class in the library code, leading to {@code ClassCastException}
* if a different implementation is provided by a client.</p>
*
* <p>New abstract methods may be added to such classes and interfaces in new versions of the library breaking compatibility
* with a client's implementations.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.METHOD
})
public @interface NonExtendable { }

/**
* <p>Indicates that the annotated method is part of SPI (Service Provider Interface), which is intended to be
* <strong>only implemented or overridden</strong> but not called by clients of the declaring library.
* If a class or interface is marked with this annotation it means that all its methods can be only overridden.</p>
*
* <p>Although there is a standard mechanism of {@code protected} methods, it is not applicable to interface's methods.
* Also, API method may be made {@code public} to allow calls only from different parts of the declaring library but not outside it.</p>
*
* <p>Signatures of such methods may be changed in new versions of the library in the following steps. Firstly, a method with new signature
* is added to the library delegating to the old method by default. Secondly, all clients implement the new method and remove
* implementations of the old one. This leads to compatibility breakage with code that calls the methods directly.</p>
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.METHOD
})
public @interface OverrideOnly { }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.swofty.swm.api;

import jdk.jfr.Experimental;
import net.swofty.swm.api.exceptions.CorruptedWorldException;
import net.swofty.swm.api.exceptions.InvalidWorldException;
import net.swofty.swm.api.exceptions.NewerFormatException;
Expand All @@ -10,6 +11,7 @@
import net.swofty.swm.api.exceptions.WorldTooBigException;
import net.swofty.swm.api.loaders.SlimeLoader;
import net.swofty.swm.api.world.SlimeWorld;
import net.swofty.swm.api.world.SlimeWorldImporter;
import net.swofty.swm.api.world.data.ConfigManager;
import net.swofty.swm.api.world.properties.SlimePropertyMap;

Expand Down Expand Up @@ -133,4 +135,9 @@ void importWorld(File worldDir, String worldName, SlimeLoader loader) throws Wor
InvalidWorldException, WorldLoadedException, WorldTooBigException, IOException;

Map<String, SlimeWorld> getSlimeWorlds();


@ApiStatus.AvailableSince("4.0.0")
@ApiStatus.Internal
SlimeWorldImporter getWorldImporter();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.swofty.swm.api.utils;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class MathUtility {
public static int[] toIntArray(byte[] buf) {
ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN);
int[] ret = new int[buf.length / 4];

buffer.asIntBuffer().get(ret);

return ret;
}

public static boolean isEmpty(byte[] array) {
for (byte b : array) {
if (b != 0) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Source: https://github.com/Minikloon/CraftyWorld/blob/master/crafty-common/src/main/kotlin/world/crafty/common/utils/NibbleArray.kt
*/
@Getter
public class NibbleArray {

@Getter
private final byte[] backing;

public NibbleArray(int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface SlimeChunk {
*/
int getZ();

long getId();

/**
* Returns all the sections of the chunk.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.swofty.swm.api.world;

import net.swofty.swm.api.exceptions.InvalidWorldException;

import java.io.File;

public interface SlimeWorldImporter {
SlimeWorld readFromDirectory(File worldDir) throws InvalidWorldException;
}
2 changes: 1 addition & 1 deletion swoftyworldmanager-classmodifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.1.1</version>
<version>4.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

public interface CLSMBridge {

default Object getChunk(Object world, int x, int z) {
return null;
}

default boolean saveChunk(Object world, Object chunkAccess) {
return false;
}

// Array containing the normal world, the nether and the end
Object[] getDefaultWorlds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ public class ClassModifier {

private static CLSMBridge customLoader;

public static CompletableFuture getFutureChunk(Object world, int x, int z) {
if (customLoader == null) {
return null;
}

Object chunk = customLoader.getChunk(world, x, z);
return chunk != null ? CompletableFuture.supplyAsync(() -> Either.left(chunk)) : null;
}

public static boolean saveChunk(Object world, Object chunkAccess) {
return customLoader != null && customLoader.saveChunk(world, chunkAccess);
}

public static boolean isCustomWorld(Object world) {
return customLoader != null && customLoader.isCustomWorld(world);
}

public static boolean skipWorldAdd(Object world) {
return customLoader != null && customLoader.skipWorldAdd(world);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class NMSTransformer implements ClassFileTransformer {

private static Map<String, Change[]> changes = new HashMap<>();

/**
* Called when the agent is loaded.
* @param agentArgs Arguments passed to the agent
* @param instrumentation The instrumentation instance
*/
public static void premain(String agentArgs, Instrumentation instrumentation) {
instrumentation.addTransformer(new NMSTransformer());

Expand Down Expand Up @@ -198,11 +203,9 @@ public byte[] transform(ClassLoader classLoader, String className, Class<?> clas
@Getter
@RequiredArgsConstructor
private static class Change {

private final String methodName;
private final String[] params;
private final String content;
private final boolean optional;

}
}
Loading

0 comments on commit 63a6d04

Please sign in to comment.