diff --git a/.github/workflows/build-maven.yml b/.github/workflows/build-maven.yml index a9775ef..7745ca3 100644 --- a/.github/workflows/build-maven.yml +++ b/.github/workflows/build-maven.yml @@ -11,17 +11,27 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 server-id: github settings-path: ${{ github.workspace }} - - name: Build Spigot dependencies + - name: Download Server dependencies run: | - chmod +x "${{ github.workspace }}/scripts/build-spigot.sh" - ${{ github.workspace }}/scripts/build-spigot.sh "${{ github.workspace }}" + chmod +x "${{ github.workspace }}/scripts/download-spigot.sh" + ${{ github.workspace }}/scripts/download-spigot.sh "${{ github.workspace }}" + + - name: Download Mapping dependencies + run: | + chmod +x "${{ github.workspace }}/scripts/download-mapping.sh" + ${{ github.workspace }}/scripts/download-mapping.sh "${{ github.workspace }}" + + - name: Install Mapping dependencies + run: | + chmod +x "${{ github.workspace }}/scripts/install-mapping.sh" + ${{ github.workspace }}/scripts/install-mapping.sh "${{ github.workspace }}" - name: Building maven project run: mvn -B package diff --git a/.gitignore b/.gitignore index bc12e1e..d62c125 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,17 @@ -/bin/ -/target/ -/dependencies/ +*/bin/ +*/target/ +*/dependencies/ +*/.settings/ +*/.idea/ +*/.m2/ +*/.classpath +*/.project +*/.gitlab-ci.yml +*/test/ +*/dependency-reduced-pom.xml +*.class +*.jar +/libraries/spigot/ /.settings/ -/.idea/ -/.m2/ -/.classpath /.project -/.gitlab-ci.yml -/test/ -/libraries/spigot/ -/dependency-reduced-pom.xml +/.classpath \ No newline at end of file diff --git a/.m2/settings.xml b/.m2/settings.xml index 008261e..e4c2378 100644 --- a/.m2/settings.xml +++ b/.m2/settings.xml @@ -5,6 +5,7 @@ github + build-remote diff --git a/README.md b/README.md index 71f86c8..7d4eb26 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] -[![Code quality: Java][lgtm-quality-shield]][lgtm-quality-url] @@ -88,7 +87,7 @@ ### Built With * [Spigot](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse) -* [SyntaxApi](https://github.com/SyntaxPhoenix/syntaxapi) +* [SyntaxApi](https://github.com/SyntaxPhoenix/SyntaxApi) ## Getting Started @@ -104,7 +103,7 @@ Please notice that you need to authenticate with GitHub Packages ([Maven](https: net.sourcewriters.minecraft vcompat - 2.1.8 + 3.0.0 provided @@ -118,7 +117,7 @@ plugins { } dependencies { - compileOnly group: 'net.sourcewriters.minecraft', name: 'vcompat', version: '2.1.8' + compileOnly group: 'net.sourcewriters.minecraft', name: 'vcompat', version: '3.0.0' } ``` @@ -181,6 +180,4 @@ Project Link: [https://github.com/SourceWriters/vCompat](https://github.com/Sour [issues-shield]: https://img.shields.io/github/issues/SourceWriters/vCompat.svg?style=flat-square [issues-url]: https://github.com/SourceWriters/vCompat/issues [license-shield]: https://img.shields.io/github/license/SourceWriters/vCompat.svg?style=flat-square -[license-url]: https://github.com/SourceWriters/vCompat/blob/master/LICENSE -[lgtm-quality-shield]: https://img.shields.io/lgtm/grade/java/g/SourceWriters/vCompat.svg?style=flat-square -[lgtm-quality-url]: https://lgtm.com/projects/g/SourceWriters/vCompat/context:java +[license-url]: https://github.com/SourceWriters/vCompat/blob/master/LICENSE \ No newline at end of file diff --git a/lgtm.yml b/lgtm.yml deleted file mode 100644 index c311106..0000000 --- a/lgtm.yml +++ /dev/null @@ -1,24 +0,0 @@ -path_classifiers: - test: - - exclude: / - - test - - testsuites - - "**/*.test" - - exclude: test/util - generated: - - exclude: "main" - library: - - exclude: "main" - template: - - exclude: "main" -extraction: - java: - index: - build_command: - - ./scripts/build-spigot.sh "$LGTM_SRC" - - ./scripts/lgtm-compile.sh - java_version: 8 - maven: - settings_file: /opt/share/settings.xml - version: 3.6.3 - xml_mode: default \ No newline at end of file diff --git a/pom.xml b/pom.xml index 112d38c..256aa19 100644 --- a/pom.xml +++ b/pom.xml @@ -1,26 +1,31 @@ - - + 4.0.0 net.sourcewriters.minecraft - vcompat - 2.1.8 - vCompat - - - github - GitHub OWNER Apache Maven Packages - https://maven.pkg.github.com/SourceWriters/vCompat - - + vcompat-parent + 3.0.0 + pom + - 1.8 - 1.8 UTF-8 + + + + spigot + https://hub.spigotmc.org/nexus/content/repositories/public/ + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + com.mojang authlib @@ -38,183 +43,13 @@ - com.syntaxphoenix.syntaxapi - java - 2.0.11 - - - com.syntaxphoenix.syntaxapi - data-nbtcontainer - 2.0.11 - - - com.syntaxphoenix.syntaxapi - data-base - 2.0.11 - - - com.syntaxphoenix.syntaxapi - net - 2.0.12 - - - com.syntaxphoenix.syntaxapi - command - 2.0.10 - - - com.syntaxphoenix.syntaxapi - nbt - 2.0.9 - - - com.syntaxphoenix.syntaxapi - version - 2.0.9 - - - com.syntaxphoenix.syntaxapi - reflection - 2.0.8 - - - com.syntaxphoenix.syntaxapi - key - 2.0.8 - - - com.syntaxphoenix.syntaxapi - random - 2.0.8 - - - org.junit.jupiter - junit-jupiter-api - 5.5.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.5.2 - test - - - bukkit - spigot-1.16.4 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.16.4.jar - - - bukkit - spigot-1.16.3 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.16.3.jar - - - bukkit - spigot-1.16.1 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.16.1.jar - - - bukkit - spigot-1.15.2 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.15.2.jar - - - bukkit - spigot-1.14.2 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.14.2.jar - - - bukkit - spigot-1.13.2 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.13.2.jar - - - bukkit - spigot-1.13 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.13.jar - - - bukkit - spigot-1.12.2 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.12.2.jar - - - bukkit - spigot-1.11 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.11.jar - - - bukkit - spigot-1.10.2 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.10.2.jar - - - bukkit - spigot-1.9.4 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.9.4.jar - - - bukkit - spigot-1.9 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.9.jar - - - bukkit - spigot-1.8.8 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.8.8.jar - - - bukkit - spigot-1.8.3 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.8.3.jar - - - bukkit - spigot-1.8 - 0.1 - system - ${project.basedir}/libraries/spigot/spigot-1.8.jar + org.spigotmc + spigot-api + 1.18.1-R0.1-SNAPSHOT + provided - - - spigot - https://hub.spigotmc.org/nexus/content/repositories/public/ - - - minecraft-libraries - https://libraries.minecraft.net - - + @@ -223,39 +58,21 @@ - - maven-shade-plugin - 3.1.1 - - - package - - shade - - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - true - - maven-compiler-plugin 3.8.1 - 8 - 8 + 11 + 11 - + + vcompat-api + vcompat-core + vcompat-legacy + vcompat-1_17_R1 + vcompat-1_18_R1 + + \ No newline at end of file diff --git a/scripts/build-spigot.sh b/scripts/build-spigot.sh deleted file mode 100644 index 0895b32..0000000 --- a/scripts/build-spigot.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -mkdir -p $1/libraries/spigot -echo "Downloading Spigot files..." -versions=$1/scripts/data/versions.txt -while read line; do - if [ -z "$line" ]; then - continue - fi - echo "Downloading Spigot $line" - curl "https://playuniverse.org/host/download/github/spigot-$line.jar" --output "$1/libraries/spigot/spigot-$line.jar" -done < $versions -echo "Download complete!" diff --git a/scripts/data/mappings.txt b/scripts/data/mappings.txt new file mode 100644 index 0000000..d3698f4 --- /dev/null +++ b/scripts/data/mappings.txt @@ -0,0 +1,2 @@ +1.17.1 +1.18.1 diff --git a/scripts/data/versions.txt b/scripts/data/servers.txt similarity index 86% rename from scripts/data/versions.txt rename to scripts/data/servers.txt index 8f8ab87..5c6e4ff 100644 --- a/scripts/data/versions.txt +++ b/scripts/data/servers.txt @@ -13,3 +13,5 @@ 1.16.1 1.16.3 1.16.4 +1.17.1 +1.18.1 diff --git a/scripts/download-mapping.sh b/scripts/download-mapping.sh new file mode 100644 index 0000000..4af9159 --- /dev/null +++ b/scripts/download-mapping.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +mkdir -p $1/libraries/mapping +mkdir -p $1/libraries/spigot +echo "Downloading Server Mapping files..." +versions=$1/scripts/data/mappings.txt +while read line; do + if [ -z "$line" ]; then + continue + fi + echo "Downloading Server Mappings (.txt) $line" + curl "http://test.playuniverse.org/host/download/github/mapping/mapping-$line.txt" --output "$1/libraries/mapping/mapping-$line.txt" + echo "Downloading Server Mappings (.csrg) $line" + curl "http://test.playuniverse.org/host/download/github/mapping/mapping-$line.csrg" --output "$1/libraries/mapping/mapping-$line.csrg" + echo "Downloading Server Mappings (.jar) $line" + curl "http://test.playuniverse.org/host/download/github/mapping/spigot-$line-obf.jar" --output "$1/libraries/spigot/spigot-$line-obf.jar" +done < $versions +echo "Download complete!" diff --git a/scripts/download-spigot.sh b/scripts/download-spigot.sh new file mode 100644 index 0000000..9484c46 --- /dev/null +++ b/scripts/download-spigot.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +mkdir -p $1/libraries/spigot +echo "Downloading Server files..." +versions=$1/scripts/data/servers.txt +while read line; do + if [ -z "$line" ]; then + continue + fi + echo "Downloading Server $line" + curl "http://test.playuniverse.org/host/download/github/spigot-$line.jar" --output "$1/libraries/spigot/spigot-$line.jar" +done < $versions +echo "Download complete!" diff --git a/scripts/install-mapping.sh b/scripts/install-mapping.sh new file mode 100644 index 0000000..a1bc9be --- /dev/null +++ b/scripts/install-mapping.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +mkdir -p $1/libraries/mapping +mkdir -p $1/libraries/spigot +echo "Install Server Mapping files..." +versions=$1/scripts/data/mappings.txt +while read line; do + if [ -z "$line" ]; then + continue + fi + echo "Install Server Mappings (.jar / remapped) $line" + mvn install:install-file -Dfile=$1/libraries/spigot/spigot-$line.jar -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=$line-R0.1-SNAPSHOT -Dclassifier=remapped-mojang + echo "Install Server Mappings (.jar / obfuscated) $line" + mvn install:install-file -Dfile=$1/libraries/spigot/spigot-$line-obf.jar -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=$line-R0.1-SNAPSHOT -Dclassifier=remapped-obf + echo "Install Server Mappings (.txt) $line" + mvn install:install-file -Dfile=$1/libraries/mapping/mapping-$line.txt -Dpackaging=txt -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion=$line-R0.1-SNAPSHOT -Dclassifier=maps-mojang + echo "Install Server Mappings (.csrg) $line" + mvn install:install-file -Dfile=$1/libraries/mapping/mapping-$line.csrg -Dpackaging=csrg -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion=$line-R0.1-SNAPSHOT -Dclassifier=maps-spigot +done < $versions +echo "Installation complete!" diff --git a/scripts/lgtm-compile.sh b/scripts/lgtm-compile.sh deleted file mode 100644 index 797784c..0000000 --- a/scripts/lgtm-compile.sh +++ /dev/null @@ -1 +0,0 @@ -mvn install \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PacketHandler.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PacketHandler.java deleted file mode 100644 index a8ce795..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PacketHandler.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection; - -import com.syntaxphoenix.syntaxapi.command.ArgumentMap; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; - -import net.sourcewriters.minecraft.vcompat.reflection.packet.NmsPacket; - -public abstract class PacketHandler extends VersionHandler { - - protected PacketHandler(V versionControl) { - super(versionControl); - } - - public NmsPacket buildPacket(IKey key, ArgumentMap data) { - return null; - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionControl.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionControl.java deleted file mode 100644 index 1338c40..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionControl.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection; - -import com.syntaxphoenix.syntaxapi.reflection.Reflect; -import com.syntaxphoenix.syntaxapi.utils.java.tools.Container; - -import net.sourcewriters.minecraft.vcompat.version.Versions; - -public abstract class VersionControl { - - public static final String CLASSPATH = "net.sourcewriters.minecraft.vcompat.reflection.provider.v$version.VersionControl$version"; - public static Container CURRENT = Container.of(); - - public static VersionControl get() { - if (CURRENT.isPresent()) { - return CURRENT.get(); - } - Reflect reflect = new Reflect(CLASSPATH.replace("$version", Versions.getServerAsString().substring(1))); - if (reflect.getOwner() == null || !VersionControl.class.isAssignableFrom(reflect.getOwner())) { - return null; - } - return CURRENT.replace((VersionControl) reflect.searchMethod("init", "init").run("init")).lock().get(); - } - - protected final DataProvider dataProvider = new DataProvider(this); - - public DataProvider getDataProvider() { - return dataProvider; - } - - public abstract ToolProvider getToolProvider(); - - public abstract EntityProvider getEntityProvider(); - - public abstract PlayerProvider getPlayerProvider(); - - public abstract TextureProvider getTextureProvider(); - - public abstract PacketHandler getPacketHandler(); - - public abstract BukkitConversion getBukkitConversion(); - - public void shutdown() {} - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContext.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContext.java deleted file mode 100644 index 7077627..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContext.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; - -public abstract class WrappedContext implements DataAdapterContext { - - public abstract H getHandle(); - - public abstract WrappedContainer newContainer(); - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/SkinDataType.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/SkinDataType.java deleted file mode 100644 index 37ae393..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/SkinDataType.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.type; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.PrimitiveDataType; - -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; - -public final class SkinDataType implements DataType { - - public static final DataType INSTANCE = new SkinDataType(); - public static final WrapType WRAPPED_INSTANCE = VersionControl.get().getBukkitConversion().wrap(INSTANCE); - - private SkinDataType() {} - - @Override - public Class getComplex() { - return Skin.class; - } - - @Override - public Class getPrimitive() { - return IDataContainer.class; - } - - @Override - public IDataContainer toPrimitive(DataAdapterContext context, Skin complex) { - IDataContainer container = context.newDataContainer(); - container.set("name", complex.getName(), PrimitiveDataType.STRING); - container.set("value", complex.getValue(), PrimitiveDataType.STRING); - container.set("signature", complex.getSignature(), PrimitiveDataType.STRING); - return container; - } - - @Override - public Skin fromPrimitive(DataAdapterContext context, IDataContainer container) { - String name = container.get("name", PrimitiveDataType.STRING); - String value = container.get("value", PrimitiveDataType.STRING); - String signature = container.get("signature", PrimitiveDataType.STRING); - if(name == null || value == null || signature == null) { - return null; - } - return new Skin(name, value, signature, false); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContext.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContext.java deleted file mode 100644 index 3a57af7..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContext.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.wrap; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public class SimpleSyntaxContext extends WrappedContext { - - private final DataAdapterContext context; - - public SimpleSyntaxContext(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public WrappedContainer newContainer() { - return new SimpleSyntaxContainer<>(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxType.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxType.java deleted file mode 100644 index 2b9452d..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxType.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.wrap; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; - -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; - -public class SimpleSyntaxType implements DataType { - - private final WrapType type; - - public SimpleSyntaxType(WrapType type) { - this.type = type; - } - - @Override - public Class getComplex() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitive() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(DataAdapterContext context, C complex) { - return type.wrapToPrimitive(complex, VersionControl.get().getBukkitConversion().createContext(context)); - } - - @Override - public C fromPrimitive(DataAdapterContext context, P primitive) { - return type.wrapToComplex(primitive, VersionControl.get().getBukkitConversion().createContext(context)); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityType.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityType.java deleted file mode 100644 index ef8849e..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityType.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.entity; - -public enum NmsEntityType { - - ARMOR_STAND; - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/packet/NmsPacket.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/packet/NmsPacket.java deleted file mode 100644 index e5d020e..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/packet/NmsPacket.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.packet; - -import com.syntaxphoenix.syntaxapi.utils.key.IKeyed; - -public interface NmsPacket extends IKeyed { - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java deleted file mode 100644 index 105dc93..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_10_R1 extends PacketHandler { - - protected PacketHandler1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java deleted file mode 100644 index 9c21f88..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.reflection; - -import net.minecraft.server.v1_10_R1.NBTTagEnd; -import net.minecraft.server.v1_10_R1.NBTTagList; -import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_10_R1 extends Reflections { - - public static NmsReflection1_10_R1 INSTANCE = new NmsReflection1_10_R1(); - - private NmsReflection1_10_R1() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java deleted file mode 100644 index 8423e5a..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_11_R1 extends PacketHandler { - - protected PacketHandler1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java deleted file mode 100644 index 09c2c88..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.reflection; - -import net.minecraft.server.v1_11_R1.NBTTagEnd; -import net.minecraft.server.v1_11_R1.NBTTagList; -import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_11_R1 extends Reflections { - - public static NmsReflection1_11_R1 INSTANCE = new NmsReflection1_11_R1(); - - private NmsReflection1_11_R1() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java deleted file mode 100644 index 468b6c0..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_12_R1 extends PacketHandler { - - protected PacketHandler1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java deleted file mode 100644 index 1ef4826..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.reflection; - -import net.minecraft.server.v1_12_R1.NBTTagEnd; -import net.minecraft.server.v1_12_R1.NBTTagList; -import net.minecraft.server.v1_12_R1.NBTTagLongArray; -import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_12_R1 extends Reflections { - - public static NmsReflection1_12_R1 INSTANCE = new NmsReflection1_12_R1(); - - private NmsReflection1_12_R1() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagLongArray", NBTTagLongArray.class).searchField("value", "b"); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java deleted file mode 100644 index f358a95..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_13_R1 extends PacketHandler { - - protected PacketHandler1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java deleted file mode 100644 index bcd46dc..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_13_R2 extends PacketHandler { - - protected PacketHandler1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java deleted file mode 100644 index 3fe559a..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_14_R1 extends PacketHandler { - - protected PacketHandler1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java deleted file mode 100644 index d3bb430..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public final class BukkitContext1_14_R1 extends WrappedContext implements PersistentDataAdapterContext { - - private final DataAdapterContext context; - - public BukkitContext1_14_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_14_R1 newContainer() { - return new BukkitContainer1_14_R1(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java deleted file mode 100644 index f0d5ee6..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_15_R1 extends PacketHandler { - - protected PacketHandler1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java deleted file mode 100644 index 165f155..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public final class BukkitContext1_15_R1 extends WrappedContext implements PersistentDataAdapterContext { - - private final DataAdapterContext context; - - public BukkitContext1_15_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_15_R1 newContainer() { - return new BukkitContainer1_15_R1(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java deleted file mode 100644 index 6b0ec00..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_16_R1 extends PacketHandler { - - protected PacketHandler1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java deleted file mode 100644 index 56b88d3..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public final class BukkitContext1_16_R1 extends WrappedContext implements PersistentDataAdapterContext { - - private final DataAdapterContext context; - - public BukkitContext1_16_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R1 newContainer() { - return new BukkitContainer1_16_R1(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java deleted file mode 100644 index 9a34899..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_16_R2 extends PacketHandler { - - protected PacketHandler1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java deleted file mode 100644 index da08fc2..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public final class BukkitContext1_16_R2 extends WrappedContext implements PersistentDataAdapterContext { - - private final DataAdapterContext context; - - public BukkitContext1_16_R2(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R2 newContainer() { - return new BukkitContainer1_16_R2(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java deleted file mode 100644 index ff5ae81..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_16_R3 extends PacketHandler { - - protected PacketHandler1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java deleted file mode 100644 index 41d494f..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataContainer; - -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; - -public final class BukkitContext1_16_R3 extends WrappedContext implements PersistentDataAdapterContext { - - private final DataAdapterContext context; - - public BukkitContext1_16_R3(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R3 newContainer() { - return new BukkitContainer1_16_R3(context.newDataContainer()); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java deleted file mode 100644 index c648cb5..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_8_R1 extends PacketHandler { - - protected PacketHandler1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java deleted file mode 100644 index e38ae76..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.reflection; - -import net.minecraft.server.v1_8_R1.NBTTagEnd; -import net.minecraft.server.v1_8_R1.NBTTagList; -import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_8_R1 extends Reflections { - - public static NmsReflection1_8_R1 INSTANCE = new NmsReflection1_8_R1(); - - private NmsReflection1_8_R1() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java deleted file mode 100644 index 227d58e..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_8_R2 extends PacketHandler { - - protected PacketHandler1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java deleted file mode 100644 index 8be7889..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.reflection; - -import net.minecraft.server.v1_8_R2.NBTTagEnd; -import net.minecraft.server.v1_8_R2.NBTTagList; -import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_8_R2 extends Reflections { - - public static NmsReflection1_8_R2 INSTANCE = new NmsReflection1_8_R2(); - - private NmsReflection1_8_R2() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java deleted file mode 100644 index 66e13ad..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_8_R3 extends PacketHandler { - - protected PacketHandler1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java deleted file mode 100644 index f746394..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.reflection; - -import net.minecraft.server.v1_8_R3.NBTTagEnd; -import net.minecraft.server.v1_8_R3.NBTTagList; -import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_8_R3 extends Reflections { - - public static NmsReflection1_8_R3 INSTANCE = new NmsReflection1_8_R3(); - - private NmsReflection1_8_R3() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java deleted file mode 100644 index 1ab5bfc..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_9_R1 extends PacketHandler { - - protected PacketHandler1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java deleted file mode 100644 index 2231ece..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.reflection; - -import net.minecraft.server.v1_9_R1.NBTTagEnd; -import net.minecraft.server.v1_9_R1.NBTTagList; -import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_9_R1 extends Reflections { - - public static NmsReflection1_9_R1 INSTANCE = new NmsReflection1_9_R1(); - - private NmsReflection1_9_R1() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java deleted file mode 100644 index 744764f..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; - -import net.sourcewriters.minecraft.vcompat.reflection.PacketHandler; - -public class PacketHandler1_9_R2 extends PacketHandler { - - protected PacketHandler1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java deleted file mode 100644 index 4df52a7..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.reflection; - -import net.minecraft.server.v1_9_R2.NBTTagEnd; -import net.minecraft.server.v1_9_R2.NBTTagList; -import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerListHeaderFooter; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class NmsReflection1_9_R2 extends Reflections { - - public static NmsReflection1_9_R2 INSTANCE = new NmsReflection1_9_R2(); - - private NmsReflection1_9_R2() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Create Reflects - // - - // - // Minecraft - - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) - .searchField("header", "a").searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/FakeReflect.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/FakeReflect.java deleted file mode 100644 index 22bfdcf..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/FakeReflect.java +++ /dev/null @@ -1,240 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.function.Predicate; - -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; - -public class FakeReflect extends Reflect { - - public static final FakeReflect FAKE = new FakeReflect(); - - @SuppressWarnings("rawtypes") - private final Collection collection = Collections.unmodifiableCollection(Arrays.asList()); - - private FakeReflect() { - super((Class) null); - } - - /* - * - */ - - @Override - public Class getOwner() { - return null; - } - - /* - * - */ - - @Override - public void delete() {} - - /* - * - */ - - @SuppressWarnings("unchecked") - @Override - public Collection> getConstructors() { - return collection; - } - - @SuppressWarnings("unchecked") - @Override - public Collection getMethods() { - return collection; - } - - @SuppressWarnings("unchecked") - @Override - public Collection getFields() { - return collection; - } - - /* - * - */ - - @Override - public boolean putConstructor(String name, Constructor constructor) { - return true; - } - - @Override - public boolean putMethod(String name, Method method) { - return true; - } - - @Override - public boolean putField(String name, Field field) { - return true; - } - - /* - * - */ - - @Override - public boolean containsMethod(String name) { - return false; - } - - @Override - public boolean containsField(String name) { - return false; - } - - /* - * - */ - - @Override - public Object init() { - return null; - } - - @Override - public Object init(String name, Object... args) { - return null; - } - - /* - * - */ - - @Override - public FakeReflect execute(String name, Object... args) { - return this; - } - - @Override - public FakeReflect execute(Object source, String name, Object... args) { - return this; - } - - @Override - public Object run(String name, Object... args) { - return null; - } - - @Override - public Object run(Object source, String name, Object... args) { - return null; - } - - /* - * - */ - - @Override - public Object getFieldValue(String name) { - return null; - } - - @Override - public Object getFieldValue(String name, Object source) { - return null; - } - - @Override - public void setFieldValue(String name, Object value) {} - - @Override - public void setFieldValue(Object source, String name, Object value) {} - - /* - * - */ - - @Override - public Constructor getConstructor(String name) { - return null; - } - - @Override - public Method getMethod(String name) { - return null; - } - - @Override - public Field getField(String name) { - return null; - } - - /* - * - */ - - @Override - public FakeReflect searchConstructor(Predicate predicate, String name, Class... args) { - return this; - } - - @Override - public FakeReflect searchConstructor(String name, Class... args) { - return this; - } - - @Override - public FakeReflect searchConstructorsByArguments(String base, Class... arguments) { - return this; - } - - /* - * - */ - - @Override - public FakeReflect searchMethod(Predicate predicate, String name, String methodName, Class... arguments) { - return this; - } - - @Override - public FakeReflect searchMethod(String name, String methodName, Class... arguments) { - return this; - } - - @Override - public FakeReflect searchMethodsByArguments(String base, Class... arguments) { - return this; - } - - /* - * - */ - - @Override - public FakeReflect searchField(Predicate predicate, String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchField(String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchFields(String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchField(String name, Class type) { - return this; - } - - @Override - public FakeReflect searchFields(String name, Class type) { - return this; - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/ReflectionProvider.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/ReflectionProvider.java deleted file mode 100644 index a62d6ab..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/ReflectionProvider.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.reflect; - -import static net.sourcewriters.minecraft.vcompat.reflection.reflect.FakeReflect.FAKE; - -import java.util.Optional; -import java.util.function.Consumer; - -import com.syntaxphoenix.syntaxapi.reflection.ClassCache; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; -import com.syntaxphoenix.syntaxapi.reflection.ReflectCache; - -import net.sourcewriters.minecraft.vcompat.version.ServerVersion; -import net.sourcewriters.minecraft.vcompat.version.Versions; - -public class ReflectionProvider { - - public static final String CB_PATH_FORMAT = "org.bukkit.craftbukkit.%s.%s"; - public static final String NMS_PATH_FORMAT = "net.minecraft.server.%s.%s"; - - public static final ReflectionProvider DEFAULT = new ReflectionProvider(provider -> Reflections.globalSetup(provider)); - - protected final ReflectCache cache; - - protected final String cbPath; - protected final String nmsPath; - - protected final ServerVersion version; - - private boolean skip = false; - - public ReflectionProvider() { - this((Consumer) null); - } - - public ReflectionProvider(Consumer setup) { - this(new ReflectCache(), setup); - } - - public ReflectionProvider(ReflectCache cache) { - this(cache, null); - } - - public ReflectionProvider(ReflectCache cache, Consumer setup) { - this.cache = cache; - this.version = Versions.getServer(); - this.cbPath = String.format(CB_PATH_FORMAT, Versions.getServerAsString(), "%s"); - this.nmsPath = String.format(NMS_PATH_FORMAT, Versions.getServerAsString(), "%s"); - if (setup != null) { - setup.accept(this); - } - } - - public ServerVersion getVersion() { - return version; - } - - /* - * Skip - */ - - public ReflectionProvider require(boolean skip) { - this.skip = !skip; - return this; - } - - public ReflectionProvider skip(boolean skip) { - this.skip = skip; - return this; - } - - public boolean skip() { - return skip; - } - - /* - * Reflection - */ - - public ReflectCache getReflection() { - return cache; - } - - public String getNmsPath() { - return nmsPath; - } - - public String getCbPath() { - return cbPath; - } - - public Reflect createNMSReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getNMSClass(path)); - } - - public Reflect createCBReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getCBClass(path)); - } - - public Reflect createReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getClass(path)); - } - - public Reflect createReflect(String name, Class clazz) { - return skip ? FAKE : cache.create(name, clazz); - } - - public Optional getOptionalReflect(String name) { - return cache.get(name); - } - - public Reflect getReflect(String name) { - return cache.get(name).orElse(null); - } - - public Class getNMSClass(String path) { - return getClass(String.format(nmsPath, path)); - } - - public Class getCBClass(String path) { - return getClass(String.format(cbPath, path)); - } - - public Class getClass(String path) { - return ClassCache.getClass(path); - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/provider/GeneralReflections.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/provider/GeneralReflections.java deleted file mode 100644 index 828aad8..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/provider/GeneralReflections.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.reflect.provider; - -import com.mojang.authlib.GameProfile; - -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.Reflections; - -public class GeneralReflections extends Reflections { - - public static GeneralReflections INSTANCE = new GeneralReflections(); - - private GeneralReflections() {} - - @Override - public void setup(ReflectionProvider provider) { - - // - // - // Needed classes to create Reflects - // - - // - // - // Create Reflects - // - - // - // Mojang - - provider.createReflect("mjGameProfile", GameProfile.class).searchField("name", "name"); - - } - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/ServerTools.java b/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/ServerTools.java deleted file mode 100644 index f6d136b..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/ServerTools.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.reflection.tools; - -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; - -public abstract class ServerTools { - - public abstract void setMotd(String text); - - public abstract String getMotd(); - - public abstract ConsoleReader getConsole(); - -} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ReflectionTools.java b/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ReflectionTools.java deleted file mode 100644 index 9dc8877..0000000 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ReflectionTools.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.tools; - -import java.lang.reflect.Array; - -public final class ReflectionTools { - - private ReflectionTools() {} - - public static Class subclass(Class clazz, String name) { - for (Class search : clazz.getClasses()) { - if (search.getSimpleName().split("\\.")[0].equals(name)) { - return search; - } - } - return null; - } - - public static Class arrayclass(Class clazz) { - return Array.newInstance(clazz, 1).getClass(); - } - -} \ No newline at end of file diff --git a/vcompat-1_17_R1/pom.xml b/vcompat-1_17_R1/pom.xml new file mode 100644 index 0000000..3ff304f --- /dev/null +++ b/vcompat-1_17_R1/pom.xml @@ -0,0 +1,75 @@ + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat-1_17_R1 + + + ${project.basedir}/../libraries/mapping + ${project.basedir}/../libraries/spigot + 1.17.1 + + + + + net.sourcewriters.minecraft + vcompat-api + 3.0.0 + provided + + + + + + spigot + remapped + 0.1 + system + ${spigot.libPath}/spigot-${minecraft.version}.jar + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/BukkitConversion1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/BukkitConversion1_17_R1.java new file mode 100644 index 0000000..d5816f4 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/BukkitConversion1_17_R1.java @@ -0,0 +1,209 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.entity.EntityType; + +import net.minecraft.nbt.ByteArrayTag; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.DoubleTag; +import net.minecraft.nbt.EndTag; +import net.minecraft.nbt.FloatTag; +import net.minecraft.nbt.IntArrayTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.LongArrayTag; +import net.minecraft.nbt.LongTag; +import net.minecraft.nbt.ShortTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.BukkitContext1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.BukkitType1_17_R1; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; + +public class BukkitConversion1_17_R1 extends BukkitConversion { + + protected BukkitConversion1_17_R1(VersionControl1_17_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public Tag toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case END: + return EndTag.INSTANCE; + case BYTE: + return ByteTag.valueOf(((NbtByte) tag).getValue()); + case BYTE_ARRAY: + return new ByteArrayTag(((NbtByteArray) tag).getValue()); + case DOUBLE: + return DoubleTag.valueOf(((NbtDouble) tag).getValue()); + case FLOAT: + return FloatTag.valueOf(((NbtFloat) tag).getValue()); + case INT: + return IntTag.valueOf(((NbtInt) tag).getValue()); + case INT_ARRAY: + return new IntArrayTag(((NbtIntArray) tag).getValue()); + case LONG: + return LongTag.valueOf(((NbtLong) tag).getValue()); + case LONG_ARRAY: + return new LongArrayTag(((NbtLongArray) tag).getValue()); + case SHORT: + return ShortTag.valueOf(((NbtShort) tag).getValue()); + case STRING: + return StringTag.valueOf(((NbtString) tag).getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object tag) { + if (tag != null && tag instanceof Tag) { + return fromMinecraftTag0((Tag) tag); + } + return null; + } + + public NbtTag fromMinecraftTag0(Tag tag) { + switch (NbtType.getById(tag.getId())) { + case END: + return NbtEnd.INSTANCE; + case BYTE: + return new NbtByte(((ByteTag) tag).getAsByte()); + case BYTE_ARRAY: + return new NbtByteArray(((ByteArrayTag) tag).getAsByteArray()); + case DOUBLE: + return new NbtDouble(((DoubleTag) tag).getAsDouble()); + case FLOAT: + return new NbtFloat(((FloatTag) tag).getAsFloat()); + case INT: + return new NbtInt(((IntTag) tag).getAsInt()); + case INT_ARRAY: + return new NbtIntArray(((IntArrayTag) tag).getAsIntArray()); + case LONG: + return new NbtLong(((LongTag) tag).getAsLong()); + case LONG_ARRAY: + return new NbtLongArray(((LongArrayTag) tag).getAsLongArray()); + case SHORT: + return new NbtShort(((ShortTag) tag).getAsShort()); + case STRING: + return new NbtString(((StringTag) tag).getAsString()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + default: + return null; + } + } + + @Override + public ListTag toMinecraftList(NbtList list) { + ListTag output = new ListTag(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof ListTag)) { + return null; + } + ListTag list = (ListTag) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getElementType())); + for (Tag base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public CompoundTag toMinecraftCompound(NbtCompound compound) { + NbtCompound compoundTag = compound; + CompoundTag targetCompound = new CompoundTag(); + for (String key : compoundTag.getKeys()) { + targetCompound.put(key, toMinecraftTag(compoundTag.get(key))); + } + return targetCompound; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof CompoundTag)) { + return null; + } + CompoundTag compoundTag = (CompoundTag) raw; + NbtCompound targetCompound = new NbtCompound(); + for (String key : compoundTag.getAllKeys()) { + targetCompound.set(key, fromMinecraftTag(compoundTag.get(key))); + } + return targetCompound; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.of(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag())); + } + + @Override + public WrappedContext createContext(IDataAdapterContext context) { + return new BukkitContext1_17_R1(context); + } + + @Override + public WrapType wrap(IDataType dataType) { + return new BukkitType1_17_R1<>(dataType); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/EntityProvider1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/EntityProvider1_17_R1.java new file mode 100644 index 0000000..d21abe9 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/EntityProvider1_17_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import java.util.EnumMap; +import java.util.function.Function; + +import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; + +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.utils.EntityConstructors1_17_R1; + + +public class EntityProvider1_17_R1 extends EntityProvider { + + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_17_R1(VersionControl1_17_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_17_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/PlayerProvider1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/PlayerProvider1_17_R1.java new file mode 100644 index 0000000..fe5165b --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/PlayerProvider1_17_R1.java @@ -0,0 +1,20 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import org.bukkit.entity.Player; + +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity.Player1_17_R1; + +public class PlayerProvider1_17_R1 extends PlayerProvider { + + protected PlayerProvider1_17_R1(VersionControl1_17_R1 versionControl) { + super(versionControl); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_17_R1(player); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/TextureProvider1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/TextureProvider1_17_R1.java new file mode 100644 index 0000000..027c11b --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/TextureProvider1_17_R1.java @@ -0,0 +1,101 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_17_R1.block.CraftSkull; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; + +import com.mojang.authlib.GameProfile; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.SkullBlockEntity; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; + +public class TextureProvider1_17_R1 extends TextureProvider { + + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + + protected TextureProvider1_17_R1(VersionControl1_17_R1 versionControl) { + super(versionControl); + } + + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + return entitySkull.owner; + } + + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); + if (profile == null) { + CompoundTag compound = (CompoundTag) craftMetaSkullRef.getFieldValue(meta, "serialized"); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + CompoundTag stackTag = stack.getOrCreateTag(); + if (stackTag.contains("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.contains("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = NbtUtils.readGameProfile(compound); + } + return profile; + } + + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } + + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } + + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + entitySkull.setOwner(profile); + return true; + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/ToolProvider1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/ToolProvider1_17_R1.java new file mode 100644 index 0000000..834d3da --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/ToolProvider1_17_R1.java @@ -0,0 +1,33 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools.BlockTools1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools.ServerTools1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools.SkinTools1_17_R1; + +public class ToolProvider1_17_R1 extends ToolProvider { + + private final BlockTools1_17_R1 blockTools = new BlockTools1_17_R1(); + private final SkinTools1_17_R1 skinTools = new SkinTools1_17_R1(); + private final ServerTools1_17_R1 serverTools = new ServerTools1_17_R1(); + + protected ToolProvider1_17_R1(VersionControl1_17_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_17_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_17_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_17_R1 getBlockTools() { + return blockTools; + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/VersionControl1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/VersionControl1_17_R1.java new file mode 100644 index 0000000..46edc5c --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/VersionControl1_17_R1.java @@ -0,0 +1,55 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1; + +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.hook.BukkitContainerAdapterHook1_17_R1; + +public class VersionControl1_17_R1 extends VersionControl { + + public static VersionControl1_17_R1 INSTANCE; + + public static VersionControl1_17_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_17_R1()); + } + + private final ToolProvider1_17_R1 toolProvider = new ToolProvider1_17_R1(this); + private final TextureProvider1_17_R1 textureProvider = new TextureProvider1_17_R1(this); + private final EntityProvider1_17_R1 entityProvider = new EntityProvider1_17_R1(this); + private final PlayerProvider1_17_R1 playerProvider = new PlayerProvider1_17_R1(this); + private final BukkitConversion1_17_R1 bukkitConversion = new BukkitConversion1_17_R1(this); + + private VersionControl1_17_R1() { + BukkitContainerAdapterHook1_17_R1.hookEntity(); + } + + @Override + public ToolProvider1_17_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_17_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_17_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_17_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public BukkitConversion1_17_R1 getBukkitConversion() { + return bukkitConversion; + } + + @Override + public void shutdown() { + dataProvider.getDefaultDistributor().shutdown(); + BukkitContainerAdapterHook1_17_R1.unhookAll(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContainer1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContainer1_17_R1.java new file mode 100644 index 0000000..9cbca99 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContainer1_17_R1.java @@ -0,0 +1,160 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import java.util.Arrays; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import org.bukkit.NamespacedKey; +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; + +public final class BukkitContainer1_17_R1 extends WrappedContainer implements PersistentDataContainer { + + private final IDataContainer container; + + public BukkitContainer1_17_R1(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_17_R1(key), WrappedType1_17_R1.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_17_R1(key), WrappedType1_17_R1.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_17_R1(key), value, WrappedType1_17_R1.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_17_R1(key)); + } + + @Override + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_17_R1::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getWrapContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_17_R1 getWrapContext() { + return new BukkitContext1_17_R1(container.getContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContext1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContext1_17_R1.java new file mode 100644 index 0000000..251e230 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitContext1_17_R1.java @@ -0,0 +1,38 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_17_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_17_R1(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_17_R1 newWrapContainer() { + return new BukkitContainer1_17_R1(context.newContainer()); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitKey1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitKey1_17_R1.java new file mode 100644 index 0000000..d03318e --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitKey1_17_R1.java @@ -0,0 +1,52 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.NamespacedKey; +import org.bukkit.plugin.Plugin; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; + +public final class BukkitKey1_17_R1 extends WrappedKey { + + private final NamespacedKey key; + + public BukkitKey1_17_R1(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_17_R1(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_17_R1(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_17_R1(key.getName(), key.getKey()).getHandle(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitType1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitType1_17_R1.java new file mode 100644 index 0000000..045d9f0 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/BukkitType1_17_R1.java @@ -0,0 +1,68 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public class BukkitType1_17_R1 extends WrappedType1_17_R1, P0, P1, C0, C1> + implements PersistentDataType { + + private final IDataType type; + + public BukkitType1_17_R1(IDataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public IDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_17_R1(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_17_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SimpleBukkitType1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SimpleBukkitType1_17_R1.java new file mode 100644 index 0000000..dd3335b --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SimpleBukkitType1_17_R1.java @@ -0,0 +1,36 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; + +public class SimpleBukkitType1_17_R1 implements PersistentDataType { + + private final WrapType type; + + public SimpleBukkitType1_17_R1(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_17_R1(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_17_R1(context)); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContainer1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContainer1_17_R1.java new file mode 100644 index 0000000..30cece4 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContainer1_17_R1.java @@ -0,0 +1,191 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import java.util.Set; +import java.util.stream.Collectors; + +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; + +public final class SyntaxContainer1_17_R1 extends WrappedContainer implements IDataContainer { + + private final PersistentDataContainer container; + + public SyntaxContainer1_17_R1(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_17_R1(container); + } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(String key, IDataType type) { + return has(syntaxKey(key), type); + } + + @Override + public boolean has(IKey key, IDataType type) { + return has(new SyntaxKey(key), WrappedType1_17_R1.wrap(type)); + } + + @Override + public C get(String key, IDataType type) { + return get(syntaxKey(key), type); + } + + @Override + public C get(IKey key, IDataType type) { + return get(new SyntaxKey(key), WrappedType1_17_R1.wrap(type)); + } + + @Override + public Object get(String key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public Object get(IKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public void set(String key, E value, IDataType type) { + set(wrappedKey(key), value, WrappedType1_17_R1.wrap(type)); + } + + @Override + public void set(IKey key, E value, IDataType type) { + set(new SyntaxKey(key), value, WrappedType1_17_R1.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return container.getKeys().stream().map(BukkitKey1_17_R1::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); + } + + @Override + public IDataAdapterContext getContext() { + return getWrapContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_17_R1 getWrapContext() { + return new SyntaxContext1_17_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(WrappedKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_17_R1.asBukkit(key), new SimpleBukkitType1_17_R1<>(type)); + } + + @Override + public Object get(WrappedKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_17_R1.asBukkit(key), new SimpleBukkitType1_17_R1<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_17_R1.asBukkit(key), new SimpleBukkitType1_17_R1<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + container.remove(BukkitKey1_17_R1.asBukkit(key)); + return true; // Will always return true as we don't know if it contained it + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.getKeys().size(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContext1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContext1_17_R1.java new file mode 100644 index 0000000..b2a7c61 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxContext1_17_R1.java @@ -0,0 +1,37 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class SyntaxContext1_17_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final PersistentDataAdapterContext context; + + public SyntaxContext1_17_R1(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newContainer() { + return newWrapContainer(); + } + + @Override + public SyntaxContainer1_17_R1 newWrapContainer() { + return new SyntaxContainer1_17_R1(context.newPersistentDataContainer()); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxType1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxType1_17_R1.java new file mode 100644 index 0000000..32be70a --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/SyntaxType1_17_R1.java @@ -0,0 +1,75 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public class SyntaxType1_17_R1 extends WrappedType1_17_R1, P0, P1, C0, C1> + implements IDataType { + + private final PersistentDataType type; + + public SyntaxType1_17_R1(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_17_R1(context)); + } + + @Override + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_17_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/WrappedType1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/WrappedType1_17_R1.java new file mode 100644 index 0000000..9870087 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/WrappedType1_17_R1.java @@ -0,0 +1,149 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data; + +import java.util.Arrays; + +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; + +public abstract class WrappedType1_17_R1 implements WrapType { + + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_17_R1(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_17_R1.internalState(primitive); + this.complexWrap = WrappedType1_17_R1.internalState(complex); + this.primitiveType = (Class) WrappedType1_17_R1.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_17_R1.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_17_R1((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_17_R1::new) + .toArray(SyntaxContainer1_17_R1[]::new); + case 3: + return (P0) new BukkitContainer1_17_R1((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_17_R1::new) + .toArray(BukkitContainer1_17_R1[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_17_R1((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_17_R1::new).toArray(SyntaxContainer1_17_R1[]::new); + case 3: + return (C0) new BukkitContainer1_17_R1((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_17_R1::new).toArray(BukkitContainer1_17_R1[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_17_R1((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_17_R1::new) + .toArray(BukkitContainer1_17_R1[]::new); + case 3: + return (P1) new SyntaxContainer1_17_R1((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_17_R1::new) + .toArray(SyntaxContainer1_17_R1[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_17_R1((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_17_R1::new).toArray(BukkitContainer1_17_R1[]::new); + case 3: + return (C1) new SyntaxContainer1_17_R1((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_17_R1::new).toArray(SyntaxContainer1_17_R1[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return SyntaxContainer1_17_R1.class; + case 2: + return SyntaxContainer1_17_R1[].class; + case 3: + return BukkitContainer1_17_R1.class; + case 4: + return BukkitContainer1_17_R1[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.isAssignableFrom(PersistentDataContainer.class)) { + return 1; + } + if (clazz.isAssignableFrom(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.isAssignableFrom(IDataContainer.class)) { + return 3; + } + if (clazz.isAssignableFrom(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_17_R1 wrap(IDataType type) { + return new BukkitType1_17_R1<>(type); + } + + public static SyntaxType1_17_R1 wrap(PersistentDataType type) { + return new SyntaxType1_17_R1<>(type); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/hook/BukkitContainerAdapterHook1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/hook/BukkitContainerAdapterHook1_17_R1.java new file mode 100644 index 0000000..28d86a3 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/data/hook/BukkitContainerAdapterHook1_17_R1.java @@ -0,0 +1,133 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.hook; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; + +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_17_R1.persistence.CraftPersistentDataContainer; +import org.bukkit.craftbukkit.v1_17_R1.persistence.CraftPersistentDataTypeRegistry; +import org.bukkit.persistence.PersistentDataContainer; + +import net.minecraft.nbt.CompoundTag; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.BukkitContainer1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.SyntaxContainer1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +@SuppressWarnings({ + "rawtypes", + "unchecked" +}) +public final class BukkitContainerAdapterHook1_17_R1 { + + private static final BukkitContainerAdapterHook1_17_R1 HOOK = new BukkitContainerAdapterHook1_17_R1(); + + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) + .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) + .searchField("adapters", "adapters") + .searchField("function", "CREATE_ADAPTER"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + + private BukkitContainerAdapterHook1_17_R1() {} + + private final HashMap map = new HashMap<>(); + + private CraftPersistentDataTypeRegistry getEntityRegistry() { + return (CraftPersistentDataTypeRegistry) entityRef.getFieldValue("registry"); + } + + private void uninjectAll() { + for (CraftPersistentDataTypeRegistry registry : map.keySet()) { + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); + adapters.remove(BukkitContainer1_17_R1.class); + adapters.remove(SyntaxContainer1_17_R1.class); + registryRef.setFieldValue(registry, "function", map.get(registry)); + } + map.clear(); + } + + private void inject(CraftPersistentDataTypeRegistry registry) { + if (map.containsKey(registry)) { + return; + } + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); + registryRef.setFieldValue(registry, "function", function); + } + + private E createAdapter(CraftPersistentDataTypeRegistry registry, Class adapterType, Class type) { + if (Objects.equals(BukkitContainer1_17_R1.class, type)) { + return (E) buildAdapter(registry, BukkitContainer1_17_R1.class, tag -> fromPrimitiveSyntax(tag)); + } + if (Objects.equals(SyntaxContainer1_17_R1.class, type)) { + return (E) buildAdapter(registry, SyntaxContainer1_17_R1.class, tag -> fromPrimitiveBukkit(registry, tag)); + } + return (E) map.get(registry).apply(type); + } + + private Object buildAdapter(Object handle, Class type, Function function) { + return registryRef.run(handle, "create", type, CompoundTag.class, (Function) input -> toPrimitive(input), + function); + } + + private CompoundTag toPrimitive(WrappedContainer input) { + Object handle = findFinalContainer(input).getHandle(); + if (handle instanceof PersistentDataContainer) { + if (handle instanceof CraftPersistentDataContainer) { + return ((CraftPersistentDataContainer) handle).toTagCompound(); + } + throw new IllegalArgumentException( + "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); + } + if (handle instanceof IDataContainer) { + if (handle instanceof NbtContainer) { + return (CompoundTag) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + } + throw new IllegalArgumentException( + "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); + } + throw new IllegalArgumentException("Unknown WrappedContainer implementation!"); + } + + private BukkitContainer1_17_R1 fromPrimitiveSyntax(CompoundTag data) { + VersionControl control = VersionCompatProvider.get().getControl(); + NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); + NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); + container.fromNbt(compound); + return new BukkitContainer1_17_R1(container); + } + + private SyntaxContainer1_17_R1 fromPrimitiveBukkit(CraftPersistentDataTypeRegistry registry, CompoundTag data) { + CraftPersistentDataContainer container = new CraftPersistentDataContainer(registry); + container.putAll(data); + return new SyntaxContainer1_17_R1(container); + } + + private WrappedContainer findFinalContainer(WrappedContainer container) { + WrappedContainer output = container; + while (output.getHandle() instanceof WrappedContainer) { + output = (WrappedContainer) output.getHandle(); + } + return output; + } + + public static void unhookAll() { + HOOK.uninjectAll(); + } + + public static void hookEntity() { + HOOK.inject(HOOK.getEntityRegistry()); + } + + public static void hook(CraftPersistentDataTypeRegistry registry) { + HOOK.inject(registry); + } + +} diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/ArmorStand1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/ArmorStand1_17_R1.java new file mode 100644 index 0000000..347a35a --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/ArmorStand1_17_R1.java @@ -0,0 +1,24 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; + +public class ArmorStand1_17_R1 extends EntityLiving1_17_R1 implements NmsArmorStand { + + public ArmorStand1_17_R1(Level world) { + super(new ArmorStand(EntityType.ARMOR_STAND, world)); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Entity1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Entity1_17_R1.java new file mode 100644 index 0000000..b919a15 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Entity1_17_R1.java @@ -0,0 +1,215 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; +import org.bukkit.entity.Player; + +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; + +public abstract class Entity1_17_R1 implements NmsEntity { + + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_17_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUUID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AABB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + updateVisibility(); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.isCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isPushable(); + } + + @Override + public boolean isCollidable() { + return handle.canBeCollidedWith(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getCommandSenderWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.level = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3 vector = handle.position(); + return new Location(handle.getCommandSenderWorld().getWorld(), vector.x, vector.y, vector.z); + } + + @Override + public void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().connection.send(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + ClientboundAddEntityPacket packet = new ClientboundAddEntityPacket(handle); + ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(handle.getId(), handle.getEntityData(), true); + ServerGamePacketListenerImpl connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().connection; + connection.send(packet); + connection.send(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + hide(getVisibleAsPlayer()); + handle.kill(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/EntityLiving1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/EntityLiving1_17_R1.java new file mode 100644 index 0000000..0c502ff --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/EntityLiving1_17_R1.java @@ -0,0 +1,17 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity; + +import net.minecraft.world.entity.LivingEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; + +public abstract class EntityLiving1_17_R1 extends Entity1_17_R1 implements NmsEntityLiving { + + public EntityLiving1_17_R1(E handle) { + super(handle); + } + + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Player1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Player1_17_R1.java new file mode 100644 index 0000000..1145314 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/entity/Player1_17_R1.java @@ -0,0 +1,293 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity; + +import java.util.ArrayList; +import java.util.Collections; + +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; +import com.mojang.datafixers.util.Pair; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket; +import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; +import net.minecraft.network.protocol.game.ClientboundTabListPacket; +import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.biome.BiomeManager; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.data.SyntaxContainer1_17_R1; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; + +public class Player1_17_R1 extends EntityLiving1_17_R1 implements NmsPlayer { + + private String realName; + private Skin realSkin; + + private final WrappedContainer dataAdapter; + + public Player1_17_R1(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_17_R1(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.WRAPPED_INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.WRAPPED_INSTANCE, realSkin); + } + + @Override + public Skin getRealSkin() { + return realSkin; + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.latency; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.hasDisconnected()) { + return; + } + + Component headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + Component footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + handle.connection.send(new ClientboundTabListPacket(headerComponent, footerComponent)); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetTitlesAnimationPacket(fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetSubtitleTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetTitleTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetActionBarTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.hasDisconnected()) { + return; + } + ClientboundPlayerInfoPacket remInfoPacket = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, + handle); + ClientboundPlayerInfoPacket addInfoPacket = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, handle); + + ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(handle.getId()); + ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(handle); + ClientboundRotateHeadPacket rotationPacket = new ClientboundRotateHeadPacket(handle, + (byte) Mth.floor(handle.getYHeadRot() * 256F / 360F)); + + ArrayList> list = new ArrayList<>(); + for (EquipmentSlot slot : EquipmentSlot.values()) { + list.add(Pair.of(slot, handle.getItemBySlot(slot))); + } + ClientboundSetEquipmentPacket equipmentPacket = new ClientboundSetEquipmentPacket(handle.getId(), list); + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; + connection.send(remInfoPacket); + connection.send(addInfoPacket); + connection.send(destroyPacket); + connection.send(spawnPacket); + connection.send(rotationPacket); + connection.send(equipmentPacket); + } + + ServerLevel world = (ServerLevel) handle.level; + + ClientboundRespawnPacket respawnPacket = new ClientboundRespawnPacket(world.dimensionType(), world.dimension(), + BiomeManager.obfuscateSeed(world.getSeed()), handle.gameMode.getGameModeForPlayer(), + handle.gameMode.getPreviousGameModeForPlayer(), world.isDebug(), world.isFlat(), true); + ClientboundPlayerPositionPacket positionPacket = new ClientboundPlayerPositionPacket(handle.getX(), handle.getY(), handle.getZ(), + handle.xRotO, handle.yRotO, Collections.emptySet(), 0, false); + ClientboundSetCarriedItemPacket itemPacket = new ClientboundSetCarriedItemPacket(handle.getInventory().selected); + ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(handle, (byte) 28); + ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(handle.getId(), handle.getEntityData(), true); + + ServerGamePacketListenerImpl connection = handle.connection; + connection.send(remInfoPacket); + connection.send(addInfoPacket); + connection.send(respawnPacket); + connection.send(positionPacket); + connection.send(itemPacket); + connection.send(statusPacket); + connection.send(metadataPacket); + + handle.onUpdateAbilities(); + handle.resetSentInfo(); + handle.inventoryMenu.broadcastChanges(); + handle.inventoryMenu.sendAllDataToRemote(); + if (handle.containerMenu != handle.inventoryMenu) { + handle.containerMenu.broadcastChanges(); + handle.containerMenu.sendAllDataToRemote(); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.connection.isDisconnected()) { + return; + } + handle.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> { + realName = MojangProfileServer.getName(getUniqueId()); + realSkin = MojangProfileServer.getSkin(realName, getUniqueId()); + }); + if (flag) { + GameProfile profile = handle.getGameProfile(); + + Skin skin = getSkin(); + if (skin != null) { + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + } + + String name = getName(); + if (name != null) { + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); + } + + if (!(name == null && skin == null)) { + fakeRespawn(); + } + } + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/BlockTools1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/BlockTools1_17_R1.java new file mode 100644 index 0000000..8beb61e --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/BlockTools1_17_R1.java @@ -0,0 +1,38 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools; + +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_17_R1.block.CraftSkull; + +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; + +import net.minecraft.world.level.block.entity.SkullBlockEntity; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; + +public class BlockTools1_17_R1 extends BlockTools { + + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + PropertyMap map = entitySkull.owner.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + return entitySkull.owner.getProperties().get("textures").iterator().next().getValue(); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/ServerTools1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/ServerTools1_17_R1.java new file mode 100644 index 0000000..6777320 --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/ServerTools1_17_R1.java @@ -0,0 +1,26 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; + +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.wrapper.ConsoleReaderWrapper1_17_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; + +public class ServerTools1_17_R1 extends ServerTools { + + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } + + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } + + @Override + public ConsoleReaderWrapper1_17_R1 getConsole() { + return ConsoleReaderWrapper1_17_R1.INSTANCE; + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/SkinTools1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/SkinTools1_17_R1.java new file mode 100644 index 0000000..69c1d2f --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/tools/SkinTools1_17_R1.java @@ -0,0 +1,16 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.tools; + +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; + +public class SkinTools1_17_R1 extends SkinTools { + + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getGameProfile()); + } + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/utils/EntityConstructors1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/utils/EntityConstructors1_17_R1.java new file mode 100644 index 0000000..a80891f --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/utils/EntityConstructors1_17_R1.java @@ -0,0 +1,12 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.utils; + +import java.util.function.Function; + +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.entity.ArmorStand1_17_R1; + +public abstract class EntityConstructors1_17_R1 { + + public static final Function ARMOR_STAND = (world -> new ArmorStand1_17_R1(world)); + +} \ No newline at end of file diff --git a/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/wrapper/ConsoleReaderWrapper1_17_R1.java b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/wrapper/ConsoleReaderWrapper1_17_R1.java new file mode 100644 index 0000000..ab2759b --- /dev/null +++ b/vcompat-1_17_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_17_R1/wrapper/ConsoleReaderWrapper1_17_R1.java @@ -0,0 +1,50 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_17_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +public final class ConsoleReaderWrapper1_17_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_17_R1 INSTANCE = new ConsoleReaderWrapper1_17_R1(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_17_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/vcompat-1_18_R1/pom.xml b/vcompat-1_18_R1/pom.xml new file mode 100644 index 0000000..6c0e105 --- /dev/null +++ b/vcompat-1_18_R1/pom.xml @@ -0,0 +1,100 @@ + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat-1_18_R1 + + + ${project.basedir}/../libraries/mapping + ${project.basedir}/../libraries/spigot + 1.18.1 + + + + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + + + + + + net.sourcewriters.minecraft + vcompat-api + 3.0.0 + provided + + + + + + spigot + remapped + 0.1 + system + ${spigot.libPath}/spigot-${minecraft.version}.jar + + + it.unimi.dsi + fastutil + 8.5.6 + provided + + + com.mojang + datafixerupper + 1.0.20 + provided + + + jline + jline + 2.12.1 + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/BukkitConversion1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/BukkitConversion1_18_R1.java new file mode 100644 index 0000000..dd6dd0d --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/BukkitConversion1_18_R1.java @@ -0,0 +1,209 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; +import org.bukkit.entity.EntityType; + +import net.minecraft.nbt.ByteArrayTag; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.DoubleTag; +import net.minecraft.nbt.EndTag; +import net.minecraft.nbt.FloatTag; +import net.minecraft.nbt.IntArrayTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.LongArrayTag; +import net.minecraft.nbt.LongTag; +import net.minecraft.nbt.ShortTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.BukkitContext1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.BukkitType1_18_R1; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; + +public class BukkitConversion1_18_R1 extends BukkitConversion { + + protected BukkitConversion1_18_R1(VersionControl1_18_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public Tag toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case END: + return EndTag.INSTANCE; + case BYTE: + return ByteTag.valueOf(((NbtByte) tag).getValue()); + case BYTE_ARRAY: + return new ByteArrayTag(((NbtByteArray) tag).getValue()); + case DOUBLE: + return DoubleTag.valueOf(((NbtDouble) tag).getValue()); + case FLOAT: + return FloatTag.valueOf(((NbtFloat) tag).getValue()); + case INT: + return IntTag.valueOf(((NbtInt) tag).getValue()); + case INT_ARRAY: + return new IntArrayTag(((NbtIntArray) tag).getValue()); + case LONG: + return LongTag.valueOf(((NbtLong) tag).getValue()); + case LONG_ARRAY: + return new LongArrayTag(((NbtLongArray) tag).getValue()); + case SHORT: + return ShortTag.valueOf(((NbtShort) tag).getValue()); + case STRING: + return StringTag.valueOf(((NbtString) tag).getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object tag) { + if (tag != null && tag instanceof Tag) { + return fromMinecraftTag0((Tag) tag); + } + return null; + } + + public NbtTag fromMinecraftTag0(Tag tag) { + switch (NbtType.getById(tag.getId())) { + case END: + return NbtEnd.INSTANCE; + case BYTE: + return new NbtByte(((ByteTag) tag).getAsByte()); + case BYTE_ARRAY: + return new NbtByteArray(((ByteArrayTag) tag).getAsByteArray()); + case DOUBLE: + return new NbtDouble(((DoubleTag) tag).getAsDouble()); + case FLOAT: + return new NbtFloat(((FloatTag) tag).getAsFloat()); + case INT: + return new NbtInt(((IntTag) tag).getAsInt()); + case INT_ARRAY: + return new NbtIntArray(((IntArrayTag) tag).getAsIntArray()); + case LONG: + return new NbtLong(((LongTag) tag).getAsLong()); + case LONG_ARRAY: + return new NbtLongArray(((LongArrayTag) tag).getAsLongArray()); + case SHORT: + return new NbtShort(((ShortTag) tag).getAsShort()); + case STRING: + return new NbtString(((StringTag) tag).getAsString()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + default: + return null; + } + } + + @Override + public ListTag toMinecraftList(NbtList list) { + ListTag output = new ListTag(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof ListTag)) { + return null; + } + ListTag list = (ListTag) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getElementType())); + for (Tag base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public CompoundTag toMinecraftCompound(NbtCompound compound) { + NbtCompound compoundTag = compound; + CompoundTag targetCompound = new CompoundTag(); + for (String key : compoundTag.getKeys()) { + targetCompound.put(key, toMinecraftTag(compoundTag.get(key))); + } + return targetCompound; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof CompoundTag)) { + return null; + } + CompoundTag compoundTag = (CompoundTag) raw; + NbtCompound targetCompound = new NbtCompound(); + for (String key : compoundTag.getAllKeys()) { + targetCompound.set(key, fromMinecraftTag(compoundTag.get(key))); + } + return targetCompound; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.of(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).save(new CompoundTag())); + } + + @Override + public WrappedContext createContext(IDataAdapterContext context) { + return new BukkitContext1_18_R1(context); + } + + @Override + public WrapType wrap(IDataType dataType) { + return new BukkitType1_18_R1<>(dataType); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/EntityProvider1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/EntityProvider1_18_R1.java new file mode 100644 index 0000000..c8b45fc --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/EntityProvider1_18_R1.java @@ -0,0 +1,47 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import java.util.EnumMap; +import java.util.function.Function; + +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; + +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.utils.EntityConstructors1_18_R1; + +public class EntityProvider1_18_R1 extends EntityProvider { + + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_18_R1(VersionControl1_18_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_18_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/PlayerProvider1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/PlayerProvider1_18_R1.java new file mode 100644 index 0000000..6a24059 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/PlayerProvider1_18_R1.java @@ -0,0 +1,20 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import org.bukkit.entity.Player; + +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity.Player1_18_R1; + +public class PlayerProvider1_18_R1 extends PlayerProvider { + + protected PlayerProvider1_18_R1(VersionControl1_18_R1 versionControl) { + super(versionControl); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_18_R1(player); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/TextureProvider1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/TextureProvider1_18_R1.java new file mode 100644 index 0000000..33d39ac --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/TextureProvider1_18_R1.java @@ -0,0 +1,101 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_18_R1.block.CraftSkull; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; + +import com.mojang.authlib.GameProfile; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.SkullBlockEntity; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; + +public class TextureProvider1_18_R1 extends TextureProvider { + + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + + protected TextureProvider1_18_R1(VersionControl1_18_R1 versionControl) { + super(versionControl); + } + + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + return entitySkull.owner; + } + + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); + if (profile == null) { + CompoundTag compound = (CompoundTag) craftMetaSkullRef.getFieldValue(meta, "serialized"); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + CompoundTag stackTag = stack.getOrCreateTag(); + if (stackTag.contains("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.contains("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = NbtUtils.readGameProfile(compound); + } + return profile; + } + + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } + + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } + + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + entitySkull.setOwner(profile); + return true; + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/ToolProvider1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/ToolProvider1_18_R1.java new file mode 100644 index 0000000..6970e27 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/ToolProvider1_18_R1.java @@ -0,0 +1,33 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools.BlockTools1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools.ServerTools1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools.SkinTools1_18_R1; + +public class ToolProvider1_18_R1 extends ToolProvider { + + private final BlockTools1_18_R1 blockTools = new BlockTools1_18_R1(); + private final SkinTools1_18_R1 skinTools = new SkinTools1_18_R1(); + private final ServerTools1_18_R1 serverTools = new ServerTools1_18_R1(); + + protected ToolProvider1_18_R1(VersionControl1_18_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_18_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_18_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_18_R1 getBlockTools() { + return blockTools; + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/VersionControl1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/VersionControl1_18_R1.java new file mode 100644 index 0000000..87eb8b3 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/VersionControl1_18_R1.java @@ -0,0 +1,55 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1; + +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.hook.BukkitContainerAdapterHook1_18_R1; + +public class VersionControl1_18_R1 extends VersionControl { + + public static VersionControl1_18_R1 INSTANCE; + + public static VersionControl1_18_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_18_R1()); + } + + private final ToolProvider1_18_R1 toolProvider = new ToolProvider1_18_R1(this); + private final TextureProvider1_18_R1 textureProvider = new TextureProvider1_18_R1(this); + private final EntityProvider1_18_R1 entityProvider = new EntityProvider1_18_R1(this); + private final PlayerProvider1_18_R1 playerProvider = new PlayerProvider1_18_R1(this); + private final BukkitConversion1_18_R1 bukkitConversion = new BukkitConversion1_18_R1(this); + + private VersionControl1_18_R1() { + BukkitContainerAdapterHook1_18_R1.hookEntity(); + } + + @Override + public ToolProvider1_18_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_18_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_18_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_18_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public BukkitConversion1_18_R1 getBukkitConversion() { + return bukkitConversion; + } + + @Override + public void shutdown() { + dataProvider.getDefaultDistributor().shutdown(); + BukkitContainerAdapterHook1_18_R1.unhookAll(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContainer1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContainer1_18_R1.java new file mode 100644 index 0000000..8fa244a --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContainer1_18_R1.java @@ -0,0 +1,160 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import java.util.Arrays; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import org.bukkit.NamespacedKey; +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; + +public final class BukkitContainer1_18_R1 extends WrappedContainer implements PersistentDataContainer { + + private final IDataContainer container; + + public BukkitContainer1_18_R1(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_18_R1(key), WrappedType1_18_R1.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_18_R1(key), WrappedType1_18_R1.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_18_R1(key), value, WrappedType1_18_R1.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_18_R1(key)); + } + + @Override + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_18_R1::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getWrapContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_18_R1 getWrapContext() { + return new BukkitContext1_18_R1(container.getContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContext1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContext1_18_R1.java new file mode 100644 index 0000000..f9b09b1 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitContext1_18_R1.java @@ -0,0 +1,38 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_18_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_18_R1(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_18_R1 newWrapContainer() { + return new BukkitContainer1_18_R1(context.newContainer()); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitKey1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitKey1_18_R1.java new file mode 100644 index 0000000..4e6d179 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitKey1_18_R1.java @@ -0,0 +1,52 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.NamespacedKey; +import org.bukkit.plugin.Plugin; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; + +public final class BukkitKey1_18_R1 extends WrappedKey { + + private final NamespacedKey key; + + public BukkitKey1_18_R1(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_18_R1(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_18_R1(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_18_R1(key.getName(), key.getKey()).getHandle(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitType1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitType1_18_R1.java new file mode 100644 index 0000000..f8573fe --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/BukkitType1_18_R1.java @@ -0,0 +1,68 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public class BukkitType1_18_R1 extends WrappedType1_18_R1, P0, P1, C0, C1> + implements PersistentDataType { + + private final IDataType type; + + public BukkitType1_18_R1(IDataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public IDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_18_R1(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_18_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SimpleBukkitType1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SimpleBukkitType1_18_R1.java new file mode 100644 index 0000000..4be725a --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SimpleBukkitType1_18_R1.java @@ -0,0 +1,36 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; + +public class SimpleBukkitType1_18_R1 implements PersistentDataType { + + private final WrapType type; + + public SimpleBukkitType1_18_R1(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_18_R1(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_18_R1(context)); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContainer1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContainer1_18_R1.java new file mode 100644 index 0000000..d37883d --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContainer1_18_R1.java @@ -0,0 +1,191 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import java.util.Set; +import java.util.stream.Collectors; + +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; + +public final class SyntaxContainer1_18_R1 extends WrappedContainer implements IDataContainer { + + private final PersistentDataContainer container; + + public SyntaxContainer1_18_R1(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_18_R1(container); + } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(String key, IDataType type) { + return has(syntaxKey(key), type); + } + + @Override + public boolean has(IKey key, IDataType type) { + return has(new SyntaxKey(key), WrappedType1_18_R1.wrap(type)); + } + + @Override + public C get(String key, IDataType type) { + return get(syntaxKey(key), type); + } + + @Override + public C get(IKey key, IDataType type) { + return get(new SyntaxKey(key), WrappedType1_18_R1.wrap(type)); + } + + @Override + public Object get(String key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public Object get(IKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public void set(String key, E value, IDataType type) { + set(wrappedKey(key), value, WrappedType1_18_R1.wrap(type)); + } + + @Override + public void set(IKey key, E value, IDataType type) { + set(new SyntaxKey(key), value, WrappedType1_18_R1.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return container.getKeys().stream().map(BukkitKey1_18_R1::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); + } + + @Override + public IDataAdapterContext getContext() { + return getWrapContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_18_R1 getWrapContext() { + return new SyntaxContext1_18_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(WrappedKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_18_R1.asBukkit(key), new SimpleBukkitType1_18_R1<>(type)); + } + + @Override + public Object get(WrappedKey key) { + throw new UnsupportedOperationException("Can't be used with PersistentDataContainer of Bukkit"); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_18_R1.asBukkit(key), new SimpleBukkitType1_18_R1<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_18_R1.asBukkit(key), new SimpleBukkitType1_18_R1<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + container.remove(BukkitKey1_18_R1.asBukkit(key)); + return true; // Will always return true as we don't know if it contained it + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.getKeys().size(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContext1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContext1_18_R1.java new file mode 100644 index 0000000..aa5e9b1 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxContext1_18_R1.java @@ -0,0 +1,37 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class SyntaxContext1_18_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final PersistentDataAdapterContext context; + + public SyntaxContext1_18_R1(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newContainer() { + return newWrapContainer(); + } + + @Override + public SyntaxContainer1_18_R1 newWrapContainer() { + return new SyntaxContainer1_18_R1(context.newPersistentDataContainer()); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxType1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxType1_18_R1.java new file mode 100644 index 0000000..7759f65 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/SyntaxType1_18_R1.java @@ -0,0 +1,75 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public class SyntaxType1_18_R1 extends WrappedType1_18_R1, P0, P1, C0, C1> + implements IDataType { + + private final PersistentDataType type; + + public SyntaxType1_18_R1(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_18_R1(context)); + } + + @Override + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_18_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/WrappedType1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/WrappedType1_18_R1.java new file mode 100644 index 0000000..3766fd2 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/WrappedType1_18_R1.java @@ -0,0 +1,149 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data; + +import java.util.Arrays; + +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; + +public abstract class WrappedType1_18_R1 implements WrapType { + + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_18_R1(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_18_R1.internalState(primitive); + this.complexWrap = WrappedType1_18_R1.internalState(complex); + this.primitiveType = (Class) WrappedType1_18_R1.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_18_R1.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_18_R1((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_18_R1::new) + .toArray(SyntaxContainer1_18_R1[]::new); + case 3: + return (P0) new BukkitContainer1_18_R1((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_18_R1::new) + .toArray(BukkitContainer1_18_R1[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_18_R1((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_18_R1::new).toArray(SyntaxContainer1_18_R1[]::new); + case 3: + return (C0) new BukkitContainer1_18_R1((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_18_R1::new).toArray(BukkitContainer1_18_R1[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_18_R1((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_18_R1::new) + .toArray(BukkitContainer1_18_R1[]::new); + case 3: + return (P1) new SyntaxContainer1_18_R1((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_18_R1::new) + .toArray(SyntaxContainer1_18_R1[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_18_R1((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_18_R1::new).toArray(BukkitContainer1_18_R1[]::new); + case 3: + return (C1) new SyntaxContainer1_18_R1((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_18_R1::new).toArray(SyntaxContainer1_18_R1[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return SyntaxContainer1_18_R1.class; + case 2: + return SyntaxContainer1_18_R1[].class; + case 3: + return BukkitContainer1_18_R1.class; + case 4: + return BukkitContainer1_18_R1[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.isAssignableFrom(PersistentDataContainer.class)) { + return 1; + } + if (clazz.isAssignableFrom(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.isAssignableFrom(IDataContainer.class)) { + return 3; + } + if (clazz.isAssignableFrom(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_18_R1 wrap(IDataType type) { + return new BukkitType1_18_R1<>(type); + } + + public static SyntaxType1_18_R1 wrap(PersistentDataType type) { + return new SyntaxType1_18_R1<>(type); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/hook/BukkitContainerAdapterHook1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/hook/BukkitContainerAdapterHook1_18_R1.java new file mode 100644 index 0000000..acb914c --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/data/hook/BukkitContainerAdapterHook1_18_R1.java @@ -0,0 +1,133 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.hook; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; + +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_18_R1.persistence.CraftPersistentDataContainer; +import org.bukkit.craftbukkit.v1_18_R1.persistence.CraftPersistentDataTypeRegistry; +import org.bukkit.persistence.PersistentDataContainer; + +import net.minecraft.nbt.CompoundTag; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.BukkitContainer1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.SyntaxContainer1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +@SuppressWarnings({ + "rawtypes", + "unchecked" +}) +public final class BukkitContainerAdapterHook1_18_R1 { + + private static final BukkitContainerAdapterHook1_18_R1 HOOK = new BukkitContainerAdapterHook1_18_R1(); + + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) + .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) + .searchField("adapters", "adapters") + .searchField("function", "CREATE_ADAPTER"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + + private BukkitContainerAdapterHook1_18_R1() {} + + private final HashMap map = new HashMap<>(); + + private CraftPersistentDataTypeRegistry getEntityRegistry() { + return (CraftPersistentDataTypeRegistry) entityRef.getFieldValue("registry"); + } + + private void uninjectAll() { + for (CraftPersistentDataTypeRegistry registry : map.keySet()) { + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); + adapters.remove(BukkitContainer1_18_R1.class); + adapters.remove(SyntaxContainer1_18_R1.class); + registryRef.setFieldValue(registry, "function", map.get(registry)); + } + map.clear(); + } + + private void inject(CraftPersistentDataTypeRegistry registry) { + if (map.containsKey(registry)) { + return; + } + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); + registryRef.setFieldValue(registry, "function", function); + } + + private E createAdapter(CraftPersistentDataTypeRegistry registry, Class adapterType, Class type) { + if (Objects.equals(BukkitContainer1_18_R1.class, type)) { + return (E) buildAdapter(registry, BukkitContainer1_18_R1.class, tag -> fromPrimitiveSyntax(tag)); + } + if (Objects.equals(SyntaxContainer1_18_R1.class, type)) { + return (E) buildAdapter(registry, SyntaxContainer1_18_R1.class, tag -> fromPrimitiveBukkit(registry, tag)); + } + return (E) map.get(registry).apply(type); + } + + private Object buildAdapter(Object handle, Class type, Function function) { + return registryRef.run(handle, "create", type, CompoundTag.class, (Function) input -> toPrimitive(input), + function); + } + + private CompoundTag toPrimitive(WrappedContainer input) { + Object handle = findFinalContainer(input).getHandle(); + if (handle instanceof PersistentDataContainer) { + if (handle instanceof CraftPersistentDataContainer) { + return ((CraftPersistentDataContainer) handle).toTagCompound(); + } + throw new IllegalArgumentException( + "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); + } + if (handle instanceof IDataContainer) { + if (handle instanceof NbtContainer) { + return (CompoundTag) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + } + throw new IllegalArgumentException( + "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); + } + throw new IllegalArgumentException("Unknown WrappedContainer implementation!"); + } + + private BukkitContainer1_18_R1 fromPrimitiveSyntax(CompoundTag data) { + VersionControl control = VersionCompatProvider.get().getControl(); + NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); + NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); + container.fromNbt(compound); + return new BukkitContainer1_18_R1(container); + } + + private SyntaxContainer1_18_R1 fromPrimitiveBukkit(CraftPersistentDataTypeRegistry registry, CompoundTag data) { + CraftPersistentDataContainer container = new CraftPersistentDataContainer(registry); + container.putAll(data); + return new SyntaxContainer1_18_R1(container); + } + + private WrappedContainer findFinalContainer(WrappedContainer container) { + WrappedContainer output = container; + while (output.getHandle() instanceof WrappedContainer) { + output = (WrappedContainer) output.getHandle(); + } + return output; + } + + public static void unhookAll() { + HOOK.uninjectAll(); + } + + public static void hookEntity() { + HOOK.inject(HOOK.getEntityRegistry()); + } + + public static void hook(CraftPersistentDataTypeRegistry registry) { + HOOK.inject(registry); + } + +} diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/ArmorStand1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/ArmorStand1_18_R1.java new file mode 100644 index 0000000..4f2a3c9 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/ArmorStand1_18_R1.java @@ -0,0 +1,24 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; + +public class ArmorStand1_18_R1 extends EntityLiving1_18_R1 implements NmsArmorStand { + + public ArmorStand1_18_R1(Level world) { + super(new ArmorStand(EntityType.ARMOR_STAND, world)); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Entity1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Entity1_18_R1.java new file mode 100644 index 0000000..c9f5151 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Entity1_18_R1.java @@ -0,0 +1,215 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; +import org.bukkit.entity.Player; + +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; + +public abstract class Entity1_18_R1 implements NmsEntity { + + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_18_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUUID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AABB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + updateVisibility(); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.isCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isPushable(); + } + + @Override + public boolean isCollidable() { + return handle.canBeCollidedWith(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getCommandSenderWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.level = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3 vector = handle.position(); + return new Location(handle.getCommandSenderWorld().getWorld(), vector.x, vector.y, vector.z); + } + + @Override + public void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().connection.send(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + ClientboundAddEntityPacket packet = new ClientboundAddEntityPacket(handle); + ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(handle.getId(), handle.getEntityData(), true); + ServerGamePacketListenerImpl connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().connection; + connection.send(packet); + connection.send(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + hide(getVisibleAsPlayer()); + handle.kill(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/EntityLiving1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/EntityLiving1_18_R1.java new file mode 100644 index 0000000..eaa5142 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/EntityLiving1_18_R1.java @@ -0,0 +1,17 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity; + +import net.minecraft.world.entity.LivingEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; + +public abstract class EntityLiving1_18_R1 extends Entity1_18_R1 implements NmsEntityLiving { + + public EntityLiving1_18_R1(E handle) { + super(handle); + } + + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Player1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Player1_18_R1.java new file mode 100644 index 0000000..a3ac23a --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/entity/Player1_18_R1.java @@ -0,0 +1,293 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity; + +import java.util.ArrayList; +import java.util.Collections; + +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; +import com.mojang.datafixers.util.Pair; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket; +import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; +import net.minecraft.network.protocol.game.ClientboundTabListPacket; +import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.biome.BiomeManager; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.data.SyntaxContainer1_18_R1; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; + +public class Player1_18_R1 extends EntityLiving1_18_R1 implements NmsPlayer { + + private String realName; + private Skin realSkin; + + private final WrappedContainer dataAdapter; + + public Player1_18_R1(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_18_R1(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.WRAPPED_INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.WRAPPED_INSTANCE, realSkin); + } + + @Override + public Skin getRealSkin() { + return realSkin; + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.latency; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.hasDisconnected()) { + return; + } + + Component headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + Component footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + handle.connection.send(new ClientboundTabListPacket(headerComponent, footerComponent)); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetTitlesAnimationPacket(fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetSubtitleTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetTitleTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.hasDisconnected()) { + return; + } + handle.connection.send(new ClientboundSetActionBarTextPacket(CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.hasDisconnected()) { + return; + } + ClientboundPlayerInfoPacket remInfoPacket = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, + handle); + ClientboundPlayerInfoPacket addInfoPacket = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, handle); + + ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(handle.getId()); + ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(handle); + ClientboundRotateHeadPacket rotationPacket = new ClientboundRotateHeadPacket(handle, + (byte) Mth.floor(handle.getYHeadRot() * 256F / 360F)); + + ArrayList> list = new ArrayList<>(); + for (EquipmentSlot slot : EquipmentSlot.values()) { + list.add(Pair.of(slot, handle.getItemBySlot(slot))); + } + ClientboundSetEquipmentPacket equipmentPacket = new ClientboundSetEquipmentPacket(handle.getId(), list); + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; + connection.send(remInfoPacket); + connection.send(addInfoPacket); + connection.send(destroyPacket); + connection.send(spawnPacket); + connection.send(rotationPacket); + connection.send(equipmentPacket); + } + + ServerLevel world = (ServerLevel) handle.level; + + ClientboundRespawnPacket respawnPacket = new ClientboundRespawnPacket(world.dimensionType(), world.dimension(), + BiomeManager.obfuscateSeed(world.getSeed()), handle.gameMode.getGameModeForPlayer(), + handle.gameMode.getPreviousGameModeForPlayer(), world.isDebug(), world.isFlat(), true); + ClientboundPlayerPositionPacket positionPacket = new ClientboundPlayerPositionPacket(handle.getX(), handle.getY(), handle.getZ(), + handle.xRotO, handle.yRotO, Collections.emptySet(), 0, false); + ClientboundSetCarriedItemPacket itemPacket = new ClientboundSetCarriedItemPacket(handle.getInventory().selected); + ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(handle, (byte) 28); + ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(handle.getId(), handle.getEntityData(), true); + + ServerGamePacketListenerImpl connection = handle.connection; + connection.send(remInfoPacket); + connection.send(addInfoPacket); + connection.send(respawnPacket); + connection.send(positionPacket); + connection.send(itemPacket); + connection.send(statusPacket); + connection.send(metadataPacket); + + handle.onUpdateAbilities(); + handle.resetSentInfo(); + handle.inventoryMenu.broadcastChanges(); + handle.inventoryMenu.sendAllDataToRemote(); + if (handle.containerMenu != handle.inventoryMenu) { + handle.containerMenu.broadcastChanges(); + handle.containerMenu.sendAllDataToRemote(); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.connection.isDisconnected()) { + return; + } + handle.connection.send(new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> { + realName = MojangProfileServer.getName(getUniqueId()); + realSkin = MojangProfileServer.getSkin(realName, getUniqueId()); + }); + if (flag) { + GameProfile profile = handle.getGameProfile(); + + Skin skin = getSkin(); + if (skin != null) { + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + } + + String name = getName(); + if (name != null) { + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); + } + + if (!(name == null && skin == null)) { + fakeRespawn(); + } + } + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/BlockTools1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/BlockTools1_18_R1.java new file mode 100644 index 0000000..7f81b89 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/BlockTools1_18_R1.java @@ -0,0 +1,38 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools; + +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_18_R1.block.CraftSkull; + +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; + +import net.minecraft.world.level.block.entity.SkullBlockEntity; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; + +public class BlockTools1_18_R1 extends BlockTools { + + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + PropertyMap map = entitySkull.owner.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + SkullBlockEntity entitySkull = (SkullBlockEntity) craftEntityStateRef.getFieldValue(block, "tileEntity"); + return entitySkull.owner.getProperties().get("textures").iterator().next().getValue(); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/ServerTools1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/ServerTools1_18_R1.java new file mode 100644 index 0000000..4a18f4f --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/ServerTools1_18_R1.java @@ -0,0 +1,26 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R1.CraftServer; + +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.wrapper.ConsoleReaderWrapper1_18_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; + +public class ServerTools1_18_R1 extends ServerTools { + + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } + + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } + + @Override + public ConsoleReaderWrapper1_18_R1 getConsole() { + return ConsoleReaderWrapper1_18_R1.INSTANCE; + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/SkinTools1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/SkinTools1_18_R1.java new file mode 100644 index 0000000..77332cc --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/tools/SkinTools1_18_R1.java @@ -0,0 +1,16 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.tools; + +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; + +public class SkinTools1_18_R1 extends SkinTools { + + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getGameProfile()); + } + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/utils/EntityConstructors1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/utils/EntityConstructors1_18_R1.java new file mode 100644 index 0000000..910cb06 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/utils/EntityConstructors1_18_R1.java @@ -0,0 +1,12 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.utils; + +import java.util.function.Function; + +import net.minecraft.world.level.Level; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.entity.ArmorStand1_18_R1; + +public abstract class EntityConstructors1_18_R1 { + + public static final Function ARMOR_STAND = (world -> new ArmorStand1_18_R1(world)); + +} \ No newline at end of file diff --git a/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/wrapper/ConsoleReaderWrapper1_18_R1.java b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/wrapper/ConsoleReaderWrapper1_18_R1.java new file mode 100644 index 0000000..3500896 --- /dev/null +++ b/vcompat-1_18_R1/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_18_R1/wrapper/ConsoleReaderWrapper1_18_R1.java @@ -0,0 +1,51 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_18_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.v1_18_R1.CraftServer; + +import jline.console.ConsoleReader; + +public final class ConsoleReaderWrapper1_18_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_18_R1 INSTANCE = new ConsoleReaderWrapper1_18_R1(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_18_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/vcompat-api/.gitignore b/vcompat-api/.gitignore new file mode 100644 index 0000000..e5d0d0e --- /dev/null +++ b/vcompat-api/.gitignore @@ -0,0 +1,12 @@ +*/bin/ +*/target/ +*/dependencies/ +*/.settings/ +*/.idea/ +*/.m2/ +*/.classpath +*/.project +*/.gitlab-ci.yml +*/test/ +*/dependency-reduced-pom.xml +*.class \ No newline at end of file diff --git a/vcompat-api/pom.xml b/vcompat-api/pom.xml new file mode 100644 index 0000000..b21e03b --- /dev/null +++ b/vcompat-api/pom.xml @@ -0,0 +1,96 @@ + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat-api + + + + + + + com.syntaxphoenix.syntaxapi + java + 2.0.14 + + + com.syntaxphoenix.syntaxapi + nbt + 2.0.12 + + + com.syntaxphoenix.syntaxapi + version + 2.0.12 + + + com.syntaxphoenix.syntaxapi + key + 2.0.11 + + + com.syntaxphoenix.syntaxapi + random + 2.0.11 + + + com.syntaxphoenix.syntaxapi + logging + 2.0.11 + + + com.syntaxphoenix.syntaxapi + json-lib + 2.0.11 + + + + + + jline + jline + 2.12.1 + provided + + + + + + + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.syntaxphoenix.syntaxapi + net.sourcewriters.minecraft.vcompat.shaded.syntaxapi + + + + + + + \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java new file mode 100644 index 0000000..40d6a04 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompatProvider.java @@ -0,0 +1,36 @@ +package net.sourcewriters.minecraft.vcompat; + +import com.syntaxphoenix.syntaxapi.utils.java.tools.Container; + +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; + +public abstract class VersionCompatProvider { + + protected static final Container PROVIDER = Container.of(); + + public static VersionCompatProvider get() { + if (PROVIDER.isPresent()) { + return PROVIDER.get(); + } + Object object = ClassLookup.of(VersionCompatProvider.class.getPackageName() + ".VersionCompat").init(); + if (object == null || !(object instanceof VersionCompatProvider)) { + throw new IllegalStateException("Can't initialize VersionCompatProvider!"); + } + return PROVIDER.replace((VersionCompatProvider) object).lock().get(); + } + + protected final ClassLookupProvider lookupProvider = new ClassLookupProvider(); + + /* + * Impl + */ + + public abstract VersionControl getControl(); + + public final ClassLookupProvider getLookupProvider() { + return lookupProvider; + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapter.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapter.java new file mode 100644 index 0000000..e8d2da8 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapter.java @@ -0,0 +1,46 @@ +package net.sourcewriters.minecraft.vcompat.data; + +import java.util.function.Function; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapter; + +public abstract class AbstractDataAdapter implements IDataAdapter { + + private final Function builder; + private final Function extractor; + + private final Class

primitiveType; + private final Class complexType; + + public AbstractDataAdapter(Class

primitiveType, Class complexType, Function builder, Function extractor) { + this.primitiveType = primitiveType; + this.complexType = complexType; + this.builder = builder; + this.extractor = extractor; + } + + public abstract Class getBaseType(); + + @Override + public Class

getPrimitiveType() { + return primitiveType; + } + + @Override + public Class getComplexType() { + return complexType; + } + + public P extract(B input) { + return complexType.isInstance(input) ? extractor.apply(complexType.cast(input)) : null; + } + + public C build(Object input) { + return primitiveType.isInstance(input) ? builder.apply(primitiveType.cast(input)) : null; + } + + public boolean isInstance(B base) { + return complexType.isInstance(base); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapterRegistry.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapterRegistry.java new file mode 100644 index 0000000..1f93f1e --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataAdapterRegistry.java @@ -0,0 +1,60 @@ +package net.sourcewriters.minecraft.vcompat.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +import com.google.common.base.Objects; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapter; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; + +public abstract class AbstractDataAdapterRegistry implements IDataAdapterRegistry { + + protected final List> adapters = Collections.synchronizedList(new ArrayList<>()); + + protected abstract IDataAdapter build(Class clazz); + + public abstract IDataAdapter create(Class

primitiveType, Class complexType, Function builder, + Function extractor); + + public AbstractDataAdapterRegistry() { + for (IDataType type : IDataType.PRIMITIVES) { + adapters.add(build(type.getPrimitive())); + } + } + + @Override + public B wrap(Object value) { + if (value == null) { + return null; + } + IDataAdapter adapter = find(value.getClass(), IDataAdapter::getPrimitiveType); + if (adapter == null) { + return null; + } + return adapter.getPrimitiveType().isInstance(value) ? adapter.build(value) : null; + } + + @Override + public Object extract(B base) { + if (base == null) { + return null; + } + IDataAdapter adapter = find(base.getClass(), IDataAdapter::getComplexType); + return adapter == null ? null : adapter.extract(base); + } + + @Override + public boolean has(Class clazz) { + return adapters.stream() + .anyMatch(adapter -> Objects.equal(clazz, adapter.getPrimitiveType()) || Objects.equal(clazz, adapter.getComplexType())); + } + + private IDataAdapter find(Class clazz, Function, Class> mapper) { + return adapters.stream().filter(adapter -> mapper.apply(adapter).isAssignableFrom(clazz)).findAny().orElseGet(() -> build(clazz)); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataContainer.java new file mode 100644 index 0000000..3bd1b3c --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataContainer.java @@ -0,0 +1,118 @@ +package net.sourcewriters.minecraft.vcompat.data; + +import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.util.NumberConversion; + +public abstract class AbstractDataContainer implements IDataContainer { + + protected final IDataAdapterRegistry registry; + + public AbstractDataContainer(IDataAdapterRegistry registry) { + this.registry = registry; + } + + @Override + public IDataAdapterRegistry getRegistry() { + return registry; + } + + @Override + public Object get(String key) { + B raw = getRaw(key); + if (raw == null) { + return raw; + } + return registry.extract(raw); + } + + @Override + public E get(String key, IDataType type) { + Object value = registry.getBase().isAssignableFrom(type.getPrimitive()) ? getRaw(key) : get(key); + if (value == null || !type.isPrimitive(value)) { + if (Number.class.isAssignableFrom(type.getComplex())) { + return NumberConversion.convert(0, type.getComplex()); + } + return null; + } + E output = type.fromPrimitiveObj(getContext(), value); + if (output == null && Number.class.isAssignableFrom(type.getComplex())) { + return NumberConversion.convert(0, type.getComplex()); + } + return output; + } + + @Override + public boolean has(String key, IDataType type) { + if (!has(key)) { + return false; + } + Object value = registry.getBase().isAssignableFrom(type.getPrimitive()) ? getRaw(key) : get(key); + return value != null && type.isPrimitive(value); + } + + @Override + public void set(String key, E value, IDataType type) { + set(key, registry.wrap(type.toPrimitive(getContext(), value))); + } + + /* + * Key conversion + */ + + @Override + public Object get(IKey key) { + return get(key.asString()); + } + + @Override + public E get(IKey key, IDataType type) { + return get(key.asString(), type); + } + + @Override + public void set(IKey key, E value, IDataType type) { + set(key.asString(), value, type); + } + + @Override + public boolean has(IKey key) { + return has(key.asString()); + } + + @Override + public boolean has(IKey key, IDataType type) { + return has(key.asString(), type); + } + + @Override + public boolean remove(IKey key) { + return remove(key.asString()); + } + + @Override + public IKey[] getKeys() { + return getKeyspaces().stream().map(NamespacedKey::fromString).toArray(IKey[]::new); + } + + /* + * Abstract + */ + + public abstract B getRaw(String key); + + public B getRaw(IKey key) { + return getRaw(key.asString()); + } + + public abstract void set(String key, B value); + + public void set(IKey key, B value) { + set(key.asString(), value); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataFactory.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataFactory.java new file mode 100644 index 0000000..4561e64 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/AbstractDataFactory.java @@ -0,0 +1,42 @@ +package net.sourcewriters.minecraft.vcompat.data; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataFactory; + +public abstract class AbstractDataFactory implements IDataFactory { + + protected final IDataAdapterRegistry registry; + + public AbstractDataFactory(IDataAdapterRegistry registry) { + this.registry = registry; + } + + @Override + public IDataAdapterRegistry getRegistry() { + return registry; + } + + @Override + public abstract AbstractDataFactory toFile(IDataContainer container, File file); + + @Override + public abstract AbstractDataFactory toStream(IDataContainer container, OutputStream stream); + + @Override + public abstract AbstractDataFactory toString(IDataContainer container, StringBuilder builder); + + @Override + public abstract AbstractDataFactory fromFile(IDataContainer container, File file); + + @Override + public abstract AbstractDataFactory fromStream(IDataContainer container, InputStream stream); + + @Override + public abstract AbstractDataFactory fromString(IDataContainer container, String string); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/ChainDataType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/ChainDataType.java new file mode 100644 index 0000000..8bff681 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/ChainDataType.java @@ -0,0 +1,191 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Objects; +import java.util.Optional; + +public class ChainDataType

implements IDataType { + + private final ArrayList> types = new ArrayList<>(); + + /* + * Contains + */ + + public boolean has(IDataType type) { + return hasExact(type) || hasComplex(type.getComplex()); + } + + public boolean hasExact(IDataType type) { + return types.contains(type); + } + + public boolean hasComplex(Class complex) { + return types.stream().anyMatch(type -> Objects.equals(type.getComplex(), complex)); + } + + /* + * Add + */ + + public ChainDataType add(IDataType type) { + if (type == null) { + return this; + } + if (has(type)) { + return this; + } + types.add(type); + return this; + } + + public ChainDataType addAll(IDataType... types) { + if (types == null) { + return this; + } + for (int index = 0; index < types.length; index++) { + add(types[index]); + } + return this; + } + + public ChainDataType addAll(Iterable> types) { + if (types == null) { + return this; + } + return addAll(types.iterator()); + } + + public ChainDataType addAll(Iterator> types) { + if (types == null) { + return this; + } + while (types.hasNext()) { + add(types.next()); + } + return this; + } + + /* + * Remove + */ + + public ChainDataType remove(IDataType type) { + types.remove(type); + return this; + } + + public ChainDataType removeAll(IDataType... types) { + if (types == null) { + return this; + } + for (int index = 0; index < types.length; index++) { + remove(types[index]); + } + return this; + } + + public ChainDataType removeAll(Iterable> types) { + if (types == null) { + return this; + } + return removeAll(types.iterator()); + } + + public ChainDataType removeAll(Iterator> types) { + if (types == null) { + return this; + } + while (types.hasNext()) { + remove(types.next()); + } + return this; + } + + /* + * Get + */ + + public IDataType get(int index) { + return types.get(index); + } + + public IDataType[] get(int start, int length) { + return types.subList(start, start + length).toArray(new IDataType[0]); + } + + /* + * Other + */ + + public int size() { + return types.size(); + } + + public boolean isEmpty() { + return types.isEmpty(); + } + + public ChainDataType clear() { + types.clear(); + return this; + } + + /* + * Cast + */ + + @SuppressWarnings("unchecked") + public Optional> asComplex(Class complex) { + return Optional.ofNullable(Objects.equals(getComplex(), complex) ? (ChainDataType) this : null); + } + + @SuppressWarnings("unchecked") + public Optional> asPrimitive(Class primitive) { + return Optional.ofNullable(Objects.equals(getPrimitive(), primitive) ? (ChainDataType) this : null); + } + + /* + * DataType + */ + + @SuppressWarnings("unchecked") + @Override + public Class getComplex() { + return isEmpty() ? null : (Class) types.get(size() - 1).getComplex(); + } + + @SuppressWarnings("unchecked") + @Override + public Class

getPrimitive() { + return isEmpty() ? null : (Class

) types.get(0).getPrimitive(); + } + + @SuppressWarnings("unchecked") + @Override + public C fromPrimitive(IDataAdapterContext context, P primitive) { + Object output = primitive; + for (int index = size() - 1; index > -1; index--) { + if (output == null) { + return null; + } + output = types.get(index).fromPrimitiveObj(context, output); + } + return isComplex(output) ? (C) output : null; + } + + @SuppressWarnings("unchecked") + @Override + public P toPrimitive(IDataAdapterContext context, C complex) { + Object output = complex; + for (int index = size() - 1; index > -1; index--) { + if (output == null) { + return null; + } + output = types.get(index).toPrimitiveObj(context, output); + } + return isPrimitive(output) ? (P) output : null; + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/DefaultDataType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/DefaultDataType.java new file mode 100644 index 0000000..25f7a32 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/DefaultDataType.java @@ -0,0 +1,41 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +import java.util.function.BiFunction; + +class DefaultDataType implements IDataType { + + private final Class

primitiveType; + private final Class complexType; + + private final BiFunction fromPrimitive; + private final BiFunction toPrimitive; + + DefaultDataType(Class

primitiveType, Class complexType, BiFunction fromPrimitive, + BiFunction toPrimitive) { + this.primitiveType = primitiveType; + this.complexType = complexType; + this.fromPrimitive = fromPrimitive; + this.toPrimitive = toPrimitive; + } + + @Override + public Class getComplex() { + return this.complexType; + } + + @Override + public Class

getPrimitive() { + return this.primitiveType; + } + + @Override + public P toPrimitive(IDataAdapterContext context, C complex) { + return toPrimitive.apply(complex, context); + } + + @Override + public C fromPrimitive(IDataAdapterContext context, P primitive) { + return fromPrimitive.apply(primitive, context); + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapter.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapter.java new file mode 100644 index 0000000..6963c1a --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapter.java @@ -0,0 +1,17 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +public interface IDataAdapter { + + Class getBaseType(); + + Class

getPrimitiveType(); + + Class getComplexType(); + + P extract(B input); + + C build(Object input); + + boolean isInstance(B base); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterContext.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterContext.java new file mode 100644 index 0000000..ee53cc3 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterContext.java @@ -0,0 +1,7 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +public interface IDataAdapterContext { + + public IDataContainer newContainer(); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterRegistry.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterRegistry.java new file mode 100644 index 0000000..55a8ef6 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataAdapterRegistry.java @@ -0,0 +1,13 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +public interface IDataAdapterRegistry { + + Class getBase(); + + boolean has(Class clazz); // == isRegistered + + Object extract(B base); + + B wrap(Object value); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataContainer.java new file mode 100644 index 0000000..bdeac01 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataContainer.java @@ -0,0 +1,45 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +import java.util.Set; + +import com.syntaxphoenix.syntaxapi.utils.key.IKey; + +public interface IDataContainer { + + IDataAdapterRegistry getRegistry(); + + IDataAdapterContext getContext(); + + boolean has(String key); + + boolean has(IKey key); + + boolean has(String key, IDataType type); + + boolean has(IKey key, IDataType type); + + Object get(String key); + + Object get(IKey key); + + E get(String key, IDataType type); + + E get(IKey key, IDataType type); + + boolean remove(String key); + + boolean remove(IKey key); + + void set(String key, E value, IDataType type); + + void set(IKey key, E value, IDataType type); + + Set getKeyspaces(); + + IKey[] getKeys(); + + boolean isEmpty(); + + int size(); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataFactory.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataFactory.java new file mode 100644 index 0000000..efb04b5 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataFactory.java @@ -0,0 +1,23 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; + +public interface IDataFactory { + + IDataAdapterRegistry getRegistry(); + + IDataFactory toFile(IDataContainer container, File file); + + IDataFactory toStream(IDataContainer container, OutputStream stream); + + IDataFactory toString(IDataContainer container, StringBuilder builder); + + IDataFactory fromFile(IDataContainer container, File file); + + IDataFactory fromStream(IDataContainer container, InputStream stream); + + IDataFactory fromString(IDataContainer container, String string); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataType.java new file mode 100644 index 0000000..0ea2f49 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/api/IDataType.java @@ -0,0 +1,142 @@ +package net.sourcewriters.minecraft.vcompat.data.api; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.function.BiFunction; +import java.util.function.Function; + +import com.syntaxphoenix.syntaxapi.utils.java.Primitives; + +public interface IDataType

{ + + public static final IDataType BYTE = of(Byte.class); + public static final IDataType SHORT = of(Short.class); + public static final IDataType INTEGER = of(Integer.class); + public static final IDataType LONG = of(Long.class); + + public static final IDataType FLOAT = of(Float.class); + public static final IDataType DOUBLE = of(Double.class); + + public static final IDataType BIG_INTEGER = of(BigInteger.class); + public static final IDataType BIG_DECIMAL = of(BigDecimal.class); + + public static final IDataType BOOLEAN = of(Boolean.class); + + public static final IDataType STRING = of(String.class); + + public static final IDataType INT_ARRAY = of(int[].class); + public static final IDataType BYTE_ARRAY = of(byte[].class); + public static final IDataType LONG_ARRAY = of(long[].class); + + public static final IDataType CONTAINER = of(IDataContainer.class); + public static final IDataType CONTAINER_ARRAY = of(IDataContainer[].class); + + public static final IDataType UUID = of(byte[].class, UUID.class, array -> { + ByteBuffer buffer = ByteBuffer.wrap(array); + long mostSignificant = buffer.getLong(); + long leastSignificant = buffer.getLong(); + return new UUID(mostSignificant, leastSignificant); + }, uniqueId -> { + ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); + buffer.putLong(uniqueId.getMostSignificantBits()); + buffer.putLong(uniqueId.getLeastSignificantBits()); + return buffer.array(); + }); + + public static final IDataType[] PRIMITIVES = new IDataType[] { + BYTE, + SHORT, + INTEGER, + LONG, + FLOAT, + DOUBLE, + BIG_INTEGER, + BIG_DECIMAL, + BOOLEAN, + STRING, + INT_ARRAY, + BYTE_ARRAY, + LONG_ARRAY, + CONTAINER, + CONTAINER_ARRAY + }; + + public static Optional> getPrimitiveType(Object object) { + Class clazz = Primitives.fromPrimitive(object.getClass()); + return Arrays.stream(PRIMITIVES).filter(type -> Objects.equals(clazz, type.getComplex())).findFirst(); + } + + public static boolean isPrimitiveType(Object object) { + Class clazz = Primitives.fromPrimitive(object.getClass()); + return Arrays.stream(PRIMITIVES).anyMatch(type -> Objects.equals(clazz, type.getComplex())); + } + + public default boolean isComplex(Object object) { + if (object == null) { + return false; + } + return getComplex().isAssignableFrom(Primitives.fromPrimitive(object.getClass())); + } + + public default boolean isPrimitive(Object object) { + if (object == null) { + return false; + } + return getPrimitive().isAssignableFrom(Primitives.fromPrimitive(object.getClass())); + } + + public Class getComplex(); + + public Class

getPrimitive(); + + public P toPrimitive(IDataAdapterContext context, C complex); + + public C fromPrimitive(IDataAdapterContext context, P primitive); + + @SuppressWarnings("unchecked") + public default P toPrimitiveObj(IDataAdapterContext context, Object complex) { + if (complex == null) { + return null; + } + if (isComplex(complex)) { + return toPrimitive(context, (C) complex); + } + if (isPrimitive(complex)) { + return (P) complex; + } + return null; + } + + @SuppressWarnings("unchecked") + public default C fromPrimitiveObj(IDataAdapterContext context, Object primitive) { + if (primitive == null) { + return null; + } + if (isPrimitive(primitive)) { + return fromPrimitive(context, (P) primitive); + } + if (isComplex(primitive)) { + return (C) primitive; + } + return null; + } + + public static

IDataType of(Class

type) { + return new DefaultDataType<>(type, type, (value, context) -> value, (value, context) -> value); + } + + public static IDataType of(Class

primitive, Class complex, Function from, Function to) { + return new DefaultDataType<>(primitive, complex, (value, context) -> from.apply(value), (value, context) -> to.apply(value)); + } + + public static IDataType of(Class

primitive, Class complex, BiFunction from, + BiFunction to) { + return new DefaultDataType<>(primitive, complex, from, to); + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapter.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapter.java new file mode 100644 index 0000000..8847259 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapter.java @@ -0,0 +1,225 @@ +package net.sourcewriters.minecraft.vcompat.data.nbt; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Objects; +import java.util.function.Function; + +import com.syntaxphoenix.syntaxapi.nbt.NbtBigDecimal; +import com.syntaxphoenix.syntaxapi.nbt.NbtBigInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import com.syntaxphoenix.syntaxapi.utils.java.Primitives; + +import net.sourcewriters.minecraft.vcompat.data.AbstractDataAdapter; +import net.sourcewriters.minecraft.vcompat.data.AbstractDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +public class NbtAdapter extends AbstractDataAdapter { + + protected NbtAdapter(Class

primitiveType, Class resultType, Function builder, Function extractor) { + super(primitiveType, resultType, builder, extractor); + } + + @Override + public Class getBaseType() { + return NbtTag.class; + } + + /* + * + */ + + @SuppressWarnings({ + "rawtypes", + "unchecked" + }) + protected static AbstractDataAdapter createAdapter(NbtAdapterRegistry registry, Class type) { + type = Primitives.fromPrimitive(type); + + /* + * Numbers + */ + + if (Objects.equals(Boolean.class, type)) { + return new NbtAdapter(Boolean.class, NbtByte.class, state -> new NbtByte((byte) (state ? 1 : 0)), + value -> value.getByteValue() == 1); + } + + if (Objects.equals(Byte.class, type)) { + return new NbtAdapter(Byte.class, NbtByte.class, NbtByte::new, value -> value.getByteValue()); + } + + if (Objects.equals(Short.class, type)) { + return new NbtAdapter(Short.class, NbtShort.class, NbtShort::new, value -> value.getShortValue()); + } + + if (Objects.equals(Integer.class, type)) { + return new NbtAdapter(Integer.class, NbtInt.class, NbtInt::new, value -> value.getIntValue()); + } + + if (Objects.equals(Long.class, type)) { + return new NbtAdapter(Long.class, NbtLong.class, NbtLong::new, value -> value.getLongValue()); + } + + if (Objects.equals(BigInteger.class, type)) { + return new NbtAdapter(BigInteger.class, NbtBigInt.class, NbtBigInt::new, value -> value.getInteger()); + } + + if (Objects.equals(Float.class, type)) { + return new NbtAdapter(Float.class, NbtFloat.class, NbtFloat::new, value -> value.getFloatValue()); + } + + if (Objects.equals(Double.class, type)) { + return new NbtAdapter(Double.class, NbtDouble.class, NbtDouble::new, value -> value.getDoubleValue()); + } + + if (Objects.equals(BigDecimal.class, type)) { + return new NbtAdapter(BigDecimal.class, NbtBigDecimal.class, NbtBigDecimal::new, + value -> value.getDecimal()); + } + + /* + * String + */ + + if (Objects.equals(String.class, type)) { + return new NbtAdapter(String.class, NbtString.class, NbtString::new, value -> value.getValue()); + } + + /* + * Number Arrays + */ + + if (Objects.equals(byte[].class, type)) { + return new NbtAdapter(byte[].class, NbtByteArray.class, NbtByteArray::new, value -> value.getValue()); + } + + if (Objects.equals(int[].class, type)) { + return new NbtAdapter(int[].class, NbtIntArray.class, NbtIntArray::new, value -> value.getValue()); + } + + if (Objects.equals(long[].class, type)) { + return new NbtAdapter(long[].class, NbtLongArray.class, NbtLongArray::new, value -> value.getValue()); + } + + /* + * Complex Arrays + */ + + if (Objects.equals(IDataContainer[].class, type)) { + return new NbtAdapter(IDataContainer[].class, NbtList.class, containers -> { + NbtList list = new NbtList<>(NbtType.COMPOUND); + for (IDataContainer container : containers) { + list.add(toNbtCompound(registry, container)); + } + return list; + }, list -> { + if (list.getElementType() != NbtType.COMPOUND) { + return new IDataContainer[0]; + } + NbtList nbtList = list; + ArrayList containers = new ArrayList<>(); + for (NbtTag tag : nbtList) { + containers.add(fromNbtCompound(registry, (NbtCompound) tag)); + } + return containers.toArray(new IDataContainer[0]); + }); + } + + if (Objects.equals(AbstractDataContainer[].class, type)) { + return new NbtAdapter(AbstractDataContainer[].class, NbtList.class, containers -> { + NbtList list = new NbtList<>(NbtType.COMPOUND); + for (AbstractDataContainer container : containers) { + list.add(toNbtCompound(registry, container)); + } + return list; + }, list -> { + if (list.getElementType() != NbtType.COMPOUND) { + return new AbstractDataContainer[0]; + } + NbtList nbtList = list; + ArrayList containers = new ArrayList<>(); + for (NbtTag tag : nbtList) { + containers.add(fromNbtCompound(registry, (NbtCompound) tag)); + } + return containers.toArray(new AbstractDataContainer[0]); + }); + } + + if (Objects.equals(NbtContainer[].class, type)) { + return new NbtAdapter(NbtContainer[].class, NbtList.class, containers -> { + NbtList list = new NbtList<>(NbtType.COMPOUND); + for (NbtContainer container : containers) { + list.add(toNbtCompound(registry, container)); + } + return list; + }, list -> { + if (list.getElementType() != NbtType.COMPOUND) { + return new NbtContainer[0]; + } + NbtList nbtList = list; + ArrayList containers = new ArrayList<>(); + for (NbtTag tag : nbtList) { + containers.add(fromNbtCompound(registry, (NbtCompound) tag)); + } + return containers.toArray(new NbtContainer[0]); + }); + } + + /* + * Complex + */ + + if (IDataContainer.class.isAssignableFrom(type)) { + return new NbtAdapter(IDataContainer.class, NbtCompound.class, container -> { + return toNbtCompound(registry, container); + }, compound -> { + return fromNbtCompound(registry, compound); + }); + } + + /* + * NbtTag + */ + + if (NbtTag.class.isAssignableFrom(type)) { + return new NbtAdapter(NbtTag.class, NbtTag.class, tag -> tag, tag -> tag); + } + + return null; + } + + private static NbtCompound toNbtCompound(NbtAdapterRegistry registry, IDataContainer container) { + if (container instanceof NbtContainer) { + return ((NbtContainer) container).getRoot().clone(); + } + NbtCompound compound = new NbtCompound(); + for (String key : container.getKeyspaces()) { + Object object = container.get(key); + NbtTag tag = registry.wrap(object); + if (tag != null) { + compound.set(key, tag); + } + } + return compound; + } + + private static NbtContainer fromNbtCompound(NbtAdapterRegistry registry, NbtCompound compound) { + return new NbtContainer(compound.clone(), registry); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapterRegistry.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapterRegistry.java new file mode 100644 index 0000000..664dde8 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtAdapterRegistry.java @@ -0,0 +1,47 @@ +package net.sourcewriters.minecraft.vcompat.data.nbt; + +import java.util.function.Function; + +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; + +import net.sourcewriters.minecraft.vcompat.data.AbstractDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.AbstractDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapter; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +public class NbtAdapterRegistry extends AbstractDataAdapterRegistry { + + public NbtAdapterRegistry() { + adapters.add(build(IDataContainer.class)); + adapters.add(build(IDataContainer[].class)); + adapters.add(build(AbstractDataContainer[].class)); + adapters.add(build(NbtContainer[].class)); + } + + @Override + public Object extract(NbtTag base) { + if (base.getType() == NbtType.END) { + return null; + } + return super.extract(base); + } + + @Override + public Class getBase() { + return NbtTag.class; + } + + @SuppressWarnings("unchecked") + @Override + protected IDataAdapter build(Class clazz) { + return (IDataAdapter) NbtAdapter.createAdapter(this, clazz); + } + + @Override + public IDataAdapter create(Class

primitiveType, Class complexType, Function builder, + Function extractor) { + return new NbtAdapter<>(primitiveType, complexType, builder, extractor); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtContainer.java new file mode 100644 index 0000000..d1eaace --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/nbt/NbtContainer.java @@ -0,0 +1,92 @@ +package net.sourcewriters.minecraft.vcompat.data.nbt; + +import java.util.Set; + +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.utils.NbtStorage; + +import net.sourcewriters.minecraft.vcompat.data.AbstractDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; + +public class NbtContainer extends AbstractDataContainer implements IDataAdapterContext, NbtStorage { + + protected final NbtCompound root; + + public NbtContainer(IDataAdapterRegistry registry) { + this(new NbtCompound(), registry); + } + + protected NbtContainer(NbtCompound root, IDataAdapterRegistry registry) { + super(registry); + this.root = root; + } + + @Override + public NbtContainer newContainer() { + return new NbtContainer(registry); + } + + @Override + public IDataAdapterContext getContext() { + return this; + } + + public NbtCompound getRoot() { + return root; + } + + @Override + public void fromNbt(NbtCompound nbt) { + root.clear(); + for (String key : nbt.getKeys()) { + set(key, nbt.get(key)); + } + } + + @Override + public NbtCompound asNbt() { + return root.clone(); + } + + @Override + public boolean has(String key) { + return root.hasKey(key); + } + + @Override + public NbtTag getRaw(String key) { + return root.get(key); + } + + @Override + public boolean remove(String key) { + return root.remove(key) != null; + } + + @Override + public void set(String key, NbtTag value) { + if(value == null) { + remove(key); + return; + } + root.set(key, value); + } + + @Override + public Set getKeyspaces() { + return root.getKeys(); + } + + @Override + public boolean isEmpty() { + return root.isEmpty(); + } + + @Override + public int size() { + return root.size(); + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/util/NumberConversion.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/util/NumberConversion.java new file mode 100644 index 0000000..285aa77 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/data/util/NumberConversion.java @@ -0,0 +1,33 @@ +package net.sourcewriters.minecraft.vcompat.data.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.HashMap; +import java.util.function.Function; + +public final class NumberConversion { + + private static final HashMap, Function> MAP = new HashMap<>(); + + static { + MAP.put(Byte.class, Number::byteValue); + MAP.put(Short.class, Number::shortValue); + MAP.put(Integer.class, Number::intValue); + MAP.put(Float.class, Number::floatValue); + MAP.put(Long.class, Number::longValue); + MAP.put(Double.class, Number::doubleValue); + MAP.put(BigInteger.class, number -> BigInteger.valueOf(number.longValue())); + MAP.put(BigDecimal.class, number -> BigDecimal.valueOf(number.doubleValue())); + } + + private NumberConversion() {} + + public static E convert(Number number, Class clazz) { + Function mapper = MAP.get(clazz); + if (mapper == null) { + return null; + } + return clazz.cast(mapper.apply(number)); + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java index 0ed0dff..6a1ebc8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/Hologram.java @@ -9,17 +9,20 @@ import org.bukkit.Location; import org.bukkit.entity.Player; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; import net.sourcewriters.minecraft.vcompat.entity.handler.CustomEntity; import net.sourcewriters.minecraft.vcompat.entity.handler.DefaultEntityType; import net.sourcewriters.minecraft.vcompat.entity.handler.EntityBuilder; import net.sourcewriters.minecraft.vcompat.entity.handler.EntityType; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class Hologram extends CustomEntity { public static final EntityBuilder BUILDER = new HologramBuilder(); + + private final EntityProvider entityProvider = VersionCompatProvider.get().getControl().getEntityProvider(); private final ArrayList entities = new ArrayList<>(); private final ArrayList lines = new ArrayList<>(); @@ -213,7 +216,7 @@ private void updateOrder(int offset) { private void spawnEntity(String line) { - NmsArmorStand entity = (NmsArmorStand) VersionControl.get().getEntityProvider().createEntity(location.getWorld(), + NmsArmorStand entity = (NmsArmorStand) entityProvider.createEntity(location.getWorld(), NmsEntityType.ARMOR_STAND); entity.setCustomName(line); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/attributes/Nameable.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/attributes/Nameable.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/attributes/Nameable.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/attributes/Nameable.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/CustomEntity.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/CustomEntity.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/CustomEntity.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/CustomEntity.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/DefaultEntityType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/DefaultEntityType.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/DefaultEntityType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/DefaultEntityType.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityBuilder.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityBuilder.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityBuilder.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityBuilder.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java similarity index 97% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java index 10027ae..263073f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityManager.java @@ -10,7 +10,7 @@ import net.sourcewriters.minecraft.vcompat.listener.PlayerListener; import net.sourcewriters.minecraft.vcompat.listener.handler.IPlayerHandler; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class EntityManager implements IPlayerHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityRegistry.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityRegistry.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityRegistry.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityRegistry.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityType.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/entity/handler/EntityType.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java index a9e07b1..303889e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/PlayerListener.java @@ -16,10 +16,10 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.Plugin; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; import net.sourcewriters.minecraft.vcompat.listener.handler.IPlayerHandler; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public final class PlayerListener implements Listener { @@ -37,7 +37,7 @@ public static void unregisterHandler(IPlayerHandler handler) { INSTANCE.unregister(handler); } - private final PlayerProvider provider = VersionControl.get().getPlayerProvider(); + private final PlayerProvider provider = VersionCompatProvider.get().getControl().getPlayerProvider(); private final List handlers = Collections.synchronizedList(new ArrayList<>()); private final Set set = Collections.synchronizedSet(new HashSet<>()); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java similarity index 73% rename from src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java index e3f789e..1f1a160 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/listener/handler/IPlayerHandler.java @@ -1,6 +1,6 @@ package net.sourcewriters.minecraft.vcompat.listener.handler; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public interface IPlayerHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/BukkitConversion.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/BukkitConversion.java similarity index 65% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/BukkitConversion.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/BukkitConversion.java index ac2b569..43402e3 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/BukkitConversion.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/BukkitConversion.java @@ -1,17 +1,17 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; import com.syntaxphoenix.syntaxapi.nbt.NbtList; import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public abstract class BukkitConversion extends VersionHandler { @@ -39,8 +39,8 @@ protected BukkitConversion(V versionControl) { public abstract NbtCompound itemToCompound(ItemStack itemStack); - public abstract WrappedContext createContext(DataAdapterContext context); + public abstract WrappedContext createContext(IDataAdapterContext context); - public abstract WrapType wrap(DataType dataType); + public abstract WrapType wrap(IDataType dataType); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/DataProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/DataProvider.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/DataProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/DataProvider.java index 20971fa..d7c7943 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/DataProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/DataProvider.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; import java.io.File; import java.util.UUID; @@ -7,12 +7,11 @@ import org.bukkit.Bukkit; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtAdapterRegistry; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; public class DataProvider extends VersionHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/EntityProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/EntityProvider.java similarity index 70% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/EntityProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/EntityProvider.java index 4403e9f..e06d062 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/EntityProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/EntityProvider.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; import org.bukkit.World; import org.bukkit.entity.EntityType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public abstract class EntityProvider extends VersionHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PlayerProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/PlayerProvider.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PlayerProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/PlayerProvider.java index 04936e2..e48f3f9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/PlayerProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/PlayerProvider.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; import java.util.Collections; import java.util.HashMap; @@ -8,8 +8,8 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public abstract class PlayerProvider extends VersionHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/TextureProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/TextureProvider.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/TextureProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/TextureProvider.java index 5a7caa2..461e079 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/TextureProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/TextureProvider.java @@ -1,6 +1,6 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; -import static net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants.TEXTURE_SIGNATURE; +import static net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants.TEXTURE_SIGNATURE; import java.util.Collections; import java.util.HashMap; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/ToolProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/ToolProvider.java similarity index 55% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/ToolProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/ToolProvider.java index 0222b29..01e414a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/ToolProvider.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/ToolProvider.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; public abstract class ToolProvider extends VersionHandler { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionControl.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionControl.java new file mode 100644 index 0000000..7a95c6c --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionControl.java @@ -0,0 +1,23 @@ +package net.sourcewriters.minecraft.vcompat.provider; + +public abstract class VersionControl { + + protected final DataProvider dataProvider = new DataProvider(this); + + public DataProvider getDataProvider() { + return dataProvider; + } + + public abstract ToolProvider getToolProvider(); + + public abstract EntityProvider getEntityProvider(); + + public abstract PlayerProvider getPlayerProvider(); + + public abstract TextureProvider getTextureProvider(); + + public abstract BukkitConversion getBukkitConversion(); + + public void shutdown() {} + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionHandler.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionHandler.java similarity index 83% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionHandler.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionHandler.java index f5da047..f6f076a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/VersionHandler.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/VersionHandler.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection; +package net.sourcewriters.minecraft.vcompat.provider; public abstract class VersionHandler { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrapType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrapType.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrapType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrapType.java index 109f328..9c9e678 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrapType.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrapType.java @@ -1,34 +1,32 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data; +package net.sourcewriters.minecraft.vcompat.provider.data; import java.math.BigDecimal; import java.math.BigInteger; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.PrimitiveDataType; - -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; public interface WrapType { - public static final SimpleWrapType BYTE = new SimpleWrapType<>(PrimitiveDataType.BYTE); - public static final SimpleWrapType SHORT = new SimpleWrapType<>(PrimitiveDataType.SHORT); - public static final SimpleWrapType INTEGER = new SimpleWrapType<>(PrimitiveDataType.INTEGER); - public static final SimpleWrapType LONG = new SimpleWrapType<>(PrimitiveDataType.LONG); + public static final SimpleWrapType BYTE = new SimpleWrapType<>(IDataType.BYTE); + public static final SimpleWrapType SHORT = new SimpleWrapType<>(IDataType.SHORT); + public static final SimpleWrapType INTEGER = new SimpleWrapType<>(IDataType.INTEGER); + public static final SimpleWrapType LONG = new SimpleWrapType<>(IDataType.LONG); - public static final SimpleWrapType FLOAT = new SimpleWrapType<>(PrimitiveDataType.FLOAT); - public static final SimpleWrapType DOUBLE = new SimpleWrapType<>(PrimitiveDataType.DOUBLE); + public static final SimpleWrapType FLOAT = new SimpleWrapType<>(IDataType.FLOAT); + public static final SimpleWrapType DOUBLE = new SimpleWrapType<>(IDataType.DOUBLE); - public static final SimpleWrapType BIG_INTEGER = new SimpleWrapType<>(PrimitiveDataType.BIG_INTEGER); - public static final SimpleWrapType BIG_DECIMAL = new SimpleWrapType<>(PrimitiveDataType.BIG_DECIMAL); + public static final SimpleWrapType BIG_INTEGER = new SimpleWrapType<>(IDataType.BIG_INTEGER); + public static final SimpleWrapType BIG_DECIMAL = new SimpleWrapType<>(IDataType.BIG_DECIMAL); - public static final SimpleWrapType BOOLEAN = new SimpleWrapType<>(PrimitiveDataType.BOOLEAN); + public static final SimpleWrapType BOOLEAN = new SimpleWrapType<>(IDataType.BOOLEAN); - public static final SimpleWrapType STRING = new SimpleWrapType<>(PrimitiveDataType.STRING); + public static final SimpleWrapType STRING = new SimpleWrapType<>(IDataType.STRING); - public static final SimpleWrapType INT_ARRAY = new SimpleWrapType<>(PrimitiveDataType.INT_ARRAY); - public static final SimpleWrapType BYTE_ARRAY = new SimpleWrapType<>(PrimitiveDataType.BYTE_ARRAY); - public static final SimpleWrapType LONG_ARRAY = new SimpleWrapType<>(PrimitiveDataType.LONG_ARRAY); + public static final SimpleWrapType INT_ARRAY = new SimpleWrapType<>(IDataType.INT_ARRAY); + public static final SimpleWrapType BYTE_ARRAY = new SimpleWrapType<>(IDataType.BYTE_ARRAY); + public static final SimpleWrapType LONG_ARRAY = new SimpleWrapType<>(IDataType.LONG_ARRAY); /* * Interface @@ -42,7 +40,7 @@ public interface WrapType { C wrapToComplex(P primitive, WrappedContext context); - public default DataType syntaxType() { + public default IDataType syntaxType() { return new SimpleSyntaxType<>(this); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContainer.java similarity index 83% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContainer.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContainer.java index 08e6aeb..53fa597 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedContainer.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContainer.java @@ -1,22 +1,22 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data; +package net.sourcewriters.minecraft.vcompat.provider.data; -import static net.sourcewriters.minecraft.vcompat.utils.constants.DefaultConstants.NAMESPACE_STRING; +import static net.sourcewriters.minecraft.vcompat.util.constants.DefaultConstants.NAMESPACE_STRING; import java.util.Optional; import java.util.Set; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; import com.syntaxphoenix.syntaxapi.utils.key.IKey; import com.syntaxphoenix.syntaxapi.utils.key.Namespace; import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public abstract class WrappedContainer { public abstract Object getHandle(); - public abstract WrappedContext getContext(); + public abstract WrappedContext getWrapContext(); public abstract IDataContainer getAsSyntaxContainer(); diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContext.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContext.java new file mode 100644 index 0000000..167cf9a --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedContext.java @@ -0,0 +1,11 @@ +package net.sourcewriters.minecraft.vcompat.provider.data; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; + +public abstract class WrappedContext implements IDataAdapterContext { + + public abstract H getHandle(); + + public abstract WrappedContainer newWrapContainer(); + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedKey.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedKey.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedKey.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedKey.java index 59bd378..6e1f4fe 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/WrappedKey.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/WrappedKey.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data; +package net.sourcewriters.minecraft.vcompat.provider.data; import com.syntaxphoenix.syntaxapi.utils.key.Namespace; import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataDistributor.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataDistributor.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataDistributor.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataDistributor.java index fd89ce1..2f3e1cf 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataDistributor.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataDistributor.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.persistence; +package net.sourcewriters.minecraft.vcompat.provider.data.persistence; import java.io.File; import java.util.Collections; @@ -7,7 +7,7 @@ import java.util.function.Function; import java.util.function.Supplier; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; public class DataDistributor { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataObserver.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataObserver.java similarity index 97% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataObserver.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataObserver.java index a306136..3e15c47 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/DataObserver.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/DataObserver.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.persistence; +package net.sourcewriters.minecraft.vcompat.provider.data.persistence; import java.io.IOException; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/PersistentContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/PersistentContainer.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/PersistentContainer.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/PersistentContainer.java index c70a125..73b9f04 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/persistence/PersistentContainer.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/persistence/PersistentContainer.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.persistence; +package net.sourcewriters.minecraft.vcompat.provider.data.persistence; import java.io.File; import java.util.LinkedHashSet; @@ -7,12 +7,13 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Consumer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtAdapterRegistry; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; import com.syntaxphoenix.syntaxapi.nbt.NbtTag; import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; + public class PersistentContainer extends NbtContainer { protected final ReadWriteLock lock = new ReentrantReadWriteLock(); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/ObjectType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/ObjectType.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/ObjectType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/ObjectType.java index 6eb67bd..c19cf3f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/type/ObjectType.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/ObjectType.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.type; +package net.sourcewriters.minecraft.vcompat.provider.data.type; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class ObjectType implements WrapType { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/SkinDataType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/SkinDataType.java new file mode 100644 index 0000000..1926175 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/type/SkinDataType.java @@ -0,0 +1,47 @@ +package net.sourcewriters.minecraft.vcompat.provider.data.type; + +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; + +public final class SkinDataType implements IDataType { + + public static final IDataType INSTANCE = new SkinDataType(); + public static final WrapType WRAPPED_INSTANCE = VersionCompatProvider.get().getControl().getBukkitConversion().wrap(INSTANCE); + + private SkinDataType() {} + + @Override + public Class getComplex() { + return Skin.class; + } + + @Override + public Class getPrimitive() { + return IDataContainer.class; + } + + @Override + public IDataContainer toPrimitive(IDataAdapterContext context, Skin complex) { + IDataContainer container = context.newContainer(); + container.set("name", complex.getName(), IDataType.STRING); + container.set("value", complex.getValue(), IDataType.STRING); + container.set("signature", complex.getSignature(), IDataType.STRING); + return container; + } + + @Override + public Skin fromPrimitive(IDataAdapterContext context, IDataContainer container) { + String name = container.get("name", IDataType.STRING); + String value = container.get("value", IDataType.STRING); + String signature = container.get("signature", IDataType.STRING); + if(name == null || value == null || signature == null) { + return null; + } + return new Skin(name, value, signature, false); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContainer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContainer.java similarity index 82% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContainer.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContainer.java index fac02a0..5edc9de 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleSyntaxContainer.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContainer.java @@ -1,12 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.wrap; +package net.sourcewriters.minecraft.vcompat.provider.data.wrap; import java.util.Set; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class SimpleSyntaxContainer extends WrappedContainer { @@ -31,8 +30,8 @@ public E getAsSyntaxContainer() { */ @Override - public SimpleSyntaxContext getContext() { - return new SimpleSyntaxContext(container.getAdapterContext()); + public SimpleSyntaxContext getWrapContext() { + return new SimpleSyntaxContext(container.getContext()); } @Override diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContext.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContext.java new file mode 100644 index 0000000..4222315 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxContext.java @@ -0,0 +1,31 @@ +package net.sourcewriters.minecraft.vcompat.provider.data.wrap; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public class SimpleSyntaxContext extends WrappedContext { + + private final IDataAdapterContext context; + + public SimpleSyntaxContext(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public WrappedContainer newWrapContainer() { + return new SimpleSyntaxContainer<>(context.newContainer()); + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxType.java new file mode 100644 index 0000000..1326584 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleSyntaxType.java @@ -0,0 +1,41 @@ +package net.sourcewriters.minecraft.vcompat.provider.data.wrap; + +import java.util.Objects; + +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; + +public class SimpleSyntaxType implements IDataType { + + private final WrapType type; + private final BukkitConversion conversion; + + public SimpleSyntaxType(WrapType type) { + this.conversion = Objects.requireNonNull(VersionCompatProvider.get(), "Can't initialize before VersionCompatProvider isn't loaded").getControl().getBukkitConversion(); + this.type = type; + } + + @Override + public Class getComplex() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitive() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(IDataAdapterContext context, C complex) { + return type.wrapToPrimitive(complex, conversion.createContext(context)); + } + + @Override + public C fromPrimitive(IDataAdapterContext context, P primitive) { + return type.wrapToComplex(primitive, conversion.createContext(context)); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleWrapType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleWrapType.java similarity index 62% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleWrapType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleWrapType.java index 5929388..82b1434 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SimpleWrapType.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SimpleWrapType.java @@ -1,15 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.wrap; +package net.sourcewriters.minecraft.vcompat.provider.data.wrap; -import com.syntaxphoenix.syntaxapi.data.DataType; - -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SimpleWrapType implements WrapType { - private final DataType type; + private final IDataType type; - public SimpleWrapType(DataType type) { + public SimpleWrapType(IDataType type) { this.type = type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SyntaxKey.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SyntaxKey.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SyntaxKey.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SyntaxKey.java index f69d5a3..e3fea8a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/data/wrap/SyntaxKey.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/data/wrap/SyntaxKey.java @@ -1,6 +1,6 @@ -package net.sourcewriters.minecraft.vcompat.reflection.data.wrap; +package net.sourcewriters.minecraft.vcompat.provider.data.wrap; -import static net.sourcewriters.minecraft.vcompat.utils.constants.DefaultConstants.NAMESPACE_STRING; +import static net.sourcewriters.minecraft.vcompat.util.constants.DefaultConstants.NAMESPACE_STRING; import org.bukkit.plugin.Plugin; @@ -8,7 +8,7 @@ import com.syntaxphoenix.syntaxapi.utils.key.Namespace; import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class SyntaxKey extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsArmorStand.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsArmorStand.java similarity index 65% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsArmorStand.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsArmorStand.java index 467c16d..6f64b98 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsArmorStand.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsArmorStand.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.entity; +package net.sourcewriters.minecraft.vcompat.provider.entity; public interface NmsArmorStand extends NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntity.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntity.java similarity index 87% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntity.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntity.java index ea115fa..204a900 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntity.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntity.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.entity; +package net.sourcewriters.minecraft.vcompat.provider.entity; import java.util.UUID; import org.bukkit.Location; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public interface NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityLiving.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityLiving.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityLiving.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityLiving.java index fe8d70a..4f6743b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsEntityLiving.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityLiving.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.entity; +package net.sourcewriters.minecraft.vcompat.provider.entity; public interface NmsEntityLiving extends NmsEntity { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityType.java new file mode 100644 index 0000000..6463bc7 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsEntityType.java @@ -0,0 +1,7 @@ +package net.sourcewriters.minecraft.vcompat.provider.entity; + +public enum NmsEntityType { + + ARMOR_STAND; + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsPlayer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsPlayer.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsPlayer.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsPlayer.java index d4f43af..166610d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/entity/NmsPlayer.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/entity/NmsPlayer.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.entity; +package net.sourcewriters.minecraft.vcompat.provider.entity; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public interface NmsPlayer extends NmsEntityLiving { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookupProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookupProvider.java new file mode 100644 index 0000000..5186b37 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookupProvider.java @@ -0,0 +1,128 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup; + +import java.util.Map.Entry; +import java.util.Optional; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookupCache; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.FakeLookup; +import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools; +import net.sourcewriters.minecraft.vcompat.version.Versions; + +public final class ClassLookupProvider { + + public static final String CB_PATH_FORMAT = "org.bukkit.craftbukkit.%s.%s"; + + public static final String NMS_PATH_FORMAT_LEGACY = "net.minecraft.server.%s.%s"; + public static final String NMS_PATH_FORMAT_REMAP = "net.minecraft.%s"; + + private final ClassLookupCache cache; + + private final String cbPath; + private final String nmsPath; + + private boolean skip = false; + + public ClassLookupProvider() { + this(new ClassLookupCache()); + } + + public ClassLookupProvider(final ClassLookupCache cache) { + this.cache = cache; + this.cbPath = String.format(CB_PATH_FORMAT, Versions.getServerAsString(), "%s"); + this.nmsPath = Versions.getServer().getMinor() >= 17 ? NMS_PATH_FORMAT_REMAP + : String.format(NMS_PATH_FORMAT_LEGACY, Versions.getServerAsString(), "%s"); + } + + /* + * Delete + */ + + public void deleteAll() { + cache.clear(); + } + + public void deleteByName(final String name) { + cache.delete(name); + } + + public void deleteByPackage(final String path) { + final Entry[] array = cache.entries(); + for (final Entry entry : array) { + if (!entry.getValue().getOwner().getPackageName().equals(path)) { + continue; + } + cache.delete(entry.getKey()); + } + } + + /* + * Skip + */ + + public ClassLookupProvider require(final boolean skip) { + this.skip = !skip; + return this; + } + + public ClassLookupProvider skip(final boolean skip) { + this.skip = skip; + return this; + } + + public boolean skip() { + return skip; + } + + /* + * Reflection + */ + + public ClassLookupCache getReflection() { + return cache; + } + + public String getNmsPath() { + return nmsPath; + } + + public String getCbPath() { + return cbPath; + } + + public ClassLookup createNMSLookup(final String name, final String path) { + return skip ? FakeLookup.FAKE : cache.create(name, getNMSClass(path)); + } + + public ClassLookup createCBLookup(final String name, final String path) { + return skip ? FakeLookup.FAKE : cache.create(name, getCBClass(path)); + } + + public ClassLookup createLookup(final String name, final String path) { + return skip ? FakeLookup.FAKE : cache.create(name, getClass(path)); + } + + public ClassLookup createLookup(final String name, final Class clazz) { + return skip ? FakeLookup.FAKE : cache.create(name, clazz); + } + + public Optional getOptionalLookup(final String name) { + return cache.get(name); + } + + public ClassLookup getLookup(final String name) { + return cache.get(name).orElse(null); + } + + public Class getNMSClass(final String path) { + return getClass(String.format(nmsPath, path)); + } + + public Class getCBClass(final String path) { + return getClass(String.format(cbPath, path)); + } + + public Class getClass(final String path) { + return ReflectionTools.getClass(path); + } +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/Reflections.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookups.java similarity index 51% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/Reflections.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookups.java index 0329bcd..3f7bec2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/reflect/Reflections.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/ClassLookups.java @@ -1,16 +1,16 @@ -package net.sourcewriters.minecraft.vcompat.reflection.reflect; +package net.sourcewriters.minecraft.vcompat.provider.lookup; import java.util.function.Consumer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.provider.GeneralReflections; +import net.sourcewriters.minecraft.vcompat.provider.lookup.provider.GeneralReflections; -public abstract class Reflections { +public abstract class ClassLookups { - public static void globalSetup(ReflectionProvider provider) { + public static void globalSetup(ClassLookupProvider provider) { GeneralReflections.INSTANCE.setup(provider); } - public abstract void setup(ReflectionProvider provider); + public abstract void setup(ClassLookupProvider provider); public static T predicate(boolean condition, T value, Consumer action) { if (condition) { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookup.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookup.java new file mode 100644 index 0000000..c5b2507 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookup.java @@ -0,0 +1,510 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodHandles.Lookup; +import java.lang.invoke.VarHandle; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.HashMap; +import java.util.function.Predicate; + +import com.syntaxphoenix.syntaxapi.utils.java.Arrays; +import com.syntaxphoenix.syntaxapi.utils.java.Exceptions; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field.IFieldHandle; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field.SafeFieldHandle; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field.UnsafeDeclaredFieldHandle; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field.UnsafeStaticFieldHandle; +import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools; + +public class ClassLookup { + + public static final Lookup LOOKUP = MethodHandles.lookup(); + + private Class owner; + private Lookup privateLookup; + + private final HashMap constructors = new HashMap<>(); + private final HashMap methods = new HashMap<>(); + private final HashMap> fields = new HashMap<>(); + + protected ClassLookup(final String classPath) throws IllegalAccessException { + this(ReflectionTools.getClass(classPath)); + } + + protected ClassLookup(final Class owner) throws IllegalAccessException { + this.owner = owner; + this.privateLookup = owner != null ? MethodHandles.privateLookupIn(owner, LOOKUP) : null; + } + + /* + * + */ + + public Class getOwner() { + return owner; + } + + public Lookup getPrivateLockup() { + return privateLookup; + } + + /* + * + */ + + public void delete() { + constructors.clear(); + methods.clear(); + fields.clear(); + owner = null; + privateLookup = null; + } + + public boolean isValid() { + return owner != null; + } + + /* + * + */ + + public Collection getConstructors() { + return constructors.values(); + } + + public Collection getMethods() { + return methods.values(); + } + + public Collection> getFields() { + return fields.values(); + } + + /* + * + */ + + public MethodHandle getConstructor(final String name) { + return isValid() ? constructors.get(name) : null; + } + + public MethodHandle getMethod(final String name) { + return isValid() ? methods.get(name) : null; + } + + public IFieldHandle getField(final String name) { + return isValid() ? fields.get(name) : null; + } + + /* + * + */ + + public boolean hasConstructor(final String name) { + return isValid() && constructors.containsKey(name); + } + + public boolean hasMethod(final String name) { + return isValid() && methods.containsKey(name); + } + + public boolean hasField(final String name) { + return isValid() && fields.containsKey(name); + } + + /* + * + */ + + public Object init() { + if (!isValid()) { + return null; + } + final MethodHandle handle = constructors.computeIfAbsent("$base#empty", ignore -> { + try { + return LOOKUP.unreflectConstructor(owner.getConstructor()); + } catch (IllegalAccessException | NoSuchMethodException | SecurityException e) { + return null; + } + }); + if (handle == null) { + constructors.remove("$base#empty"); + return null; + } + try { + return handle.invoke(); + } catch (final Throwable e) { + e.printStackTrace(); + } + return null; + } + + public Object init(final String name, final Object... args) { + if (!isValid() || !constructors.containsKey(name)) { + return null; + } + try { + return constructors.get(name).invokeWithArguments(args); + } catch (final Throwable e) { + e.printStackTrace(); + } + return null; + } + + /* + * + */ + + public ClassLookup execute(final String name, final Object... args) { + run(name, args); + return this; + } + + public ClassLookup execute(final Object source, final String name, final Object... args) { + run(source, name, args); + return this; + } + + public Object run(final String name, final Object... args) { + if (!isValid() || !methods.containsKey(name)) { + return null; + } + try { + return methods.get(name).invokeWithArguments(args); + } catch (final Throwable e) { + e.printStackTrace(); + } + return null; + } + + public Object run(final Object source, final String name, final Object... args) { + if (!isValid() || !methods.containsKey(name)) { + return null; + } + try { + return methods.get(name).invokeWithArguments(mergeBack(args, source)); + } catch (final Throwable e) { + e.printStackTrace(); + } + return null; + } + + /* + * + */ + + public Object getFieldValue(final String name) { + return isValid() && fields.containsKey(name) ? fields.get(name).getValue() : null; + } + + public Object getFieldValue(final Object source, final String name) { + return isValid() && fields.containsKey(name) ? fields.get(name).getValue(source) : null; + } + + public void setFieldValue(final String name, final Object value) { + if (!isValid() || !fields.containsKey(name)) { + return; + } + fields.get(name).setValue(value); + } + + public void setFieldValue(final Object source, final String name, final Object value) { + if (!isValid() || !fields.containsKey(name)) { + return; + } + fields.get(name).setValue(source, value); + } + + /* + * + */ + + public ClassLookup searchConstructor(final Predicate predicate, final String name, final Class... args) { + return predicate.test(this) ? searchConstructor(name, args) : this; + } + + public ClassLookup searchConstructor(final String name, final Class... arguments) { + if (hasConstructor(name)) { + return this; + } + Constructor constructor = null; + try { + constructor = owner.getDeclaredConstructor(arguments); + } catch (NoSuchMethodException | SecurityException e) { + } + if (constructor == null) { + try { + constructor = owner.getConstructor(arguments); + } catch (NoSuchMethodException | SecurityException e) { + } + } + if (constructor != null) { + try { + constructors.put(name, unreflect(constructor)); + } catch (final IllegalAccessException e) { + } + } + return this; + } + + public ClassLookup searchConstructorsByArguments(String base, final Class... arguments) { + final Constructor[] constructors = Arrays.merge(Constructor[]::new, owner.getDeclaredConstructors(), owner.getConstructors()); + if (constructors.length == 0) { + return this; + } + base += '-'; + int current = 0; + for (final Constructor constructor : constructors) { + final Class[] args = constructor.getParameterTypes(); + if (args.length != arguments.length) { + continue; + } + try { + if (ReflectionTools.hasSameArguments(arguments, args)) { + this.constructors.put(base + current, unreflect(constructor)); + current++; + } + } catch (final IllegalAccessException e) { + } + } + return this; + } + + /* + * + */ + + public ClassLookup searchMethod(final Predicate predicate, final String name, final String methodName, + final Class... arguments) { + return predicate.test(this) ? searchMethod(name, methodName, arguments) : this; + } + + public ClassLookup searchMethod(final String name, final String methodName, final Class... arguments) { + if (hasMethod(name)) { + return this; + } + Method method = null; + try { + method = owner.getDeclaredMethod(methodName, arguments); + } catch (NoSuchMethodException | SecurityException e) { + } + if (method == null) { + try { + method = owner.getMethod(methodName, arguments); + } catch (NoSuchMethodException | SecurityException e) { + } + } + if (method != null) { + try { + methods.put(name, unreflect(method)); + } catch (IllegalAccessException | SecurityException e) { + System.out.println(Exceptions.stackTraceToString(e)); + } + } + return this; + } + + public ClassLookup searchMethodsByArguments(String base, final Class... arguments) { + final Method[] methods = Arrays.merge(Method[]::new, owner.getDeclaredMethods(), owner.getMethods()); + if (methods.length == 0) { + return this; + } + base += '-'; + int current = 0; + for (final Method method : methods) { + final Class[] args = method.getParameterTypes(); + if (args.length != arguments.length) { + continue; + } + try { + if (ReflectionTools.hasSameArguments(arguments, args)) { + this.methods.put(base + current, unreflect(method)); + current++; + } + } catch (IllegalAccessException | SecurityException e) { + } + } + return this; + } + + /* + * + */ + + public ClassLookup searchField(final Predicate predicate, final String name, final String fieldName, final Class type) { + return predicate.test(this) ? searchField(name, fieldName, type) : this; + } + + public ClassLookup searchField(final String name, final String fieldName) { + if (hasMethod(name)) { + return this; + } + Field field = null; + try { + field = owner.getDeclaredField(fieldName); + } catch (NoSuchFieldException | SecurityException e) { + } + if (field == null) { + try { + field = owner.getField(fieldName); + } catch (NoSuchFieldException | SecurityException e) { + } + } + if (field != null) { + storeField(name, field); + } + return this; + } + + public ClassLookup searchField(final String name, final String fieldName, final Class type) { + if (hasField(name)) { + return this; + } + VarHandle handle = null; + try { + handle = privateLookup.findVarHandle(owner, fieldName, type); + } catch (NoSuchFieldException | IllegalAccessException e) { + } + if (handle == null) { + try { + handle = privateLookup.findStaticVarHandle(owner, fieldName, type); + } catch (SecurityException | NoSuchFieldException | IllegalAccessException e) { + } + } + if (handle != null) { + fields.put(name, new SafeFieldHandle(handle)); + } + return this; + } + + /* + * + */ + + public boolean putField(final String name, final Field field) { + return putField(name, field, false); + } + + public boolean putField(final String name, final Field field, final boolean forceSafe) { + if (field == null || name == null || field.getDeclaringClass() != owner || fields.containsKey(name)) { + return false; + } + storeField(name, field, forceSafe); + return true; + } + + /* + * + */ + + private void storeField(final String name, final Field field) { + storeField(name, field, false); + } + + private void storeField(final String name, final Field field, final boolean forceSafe) { + if (forceSafe || !Modifier.isFinal(field.getModifiers())) { + try { + fields.put(name, new SafeFieldHandle(unreflect(field))); + return; + } catch (IllegalAccessException | SecurityException e) { + if (forceSafe) { + return; + } + } + } + if (!Modifier.isStatic(field.getModifiers())) { + fields.put(name, new UnsafeDeclaredFieldHandle(field)); + return; + } + fields.put(name, new UnsafeStaticFieldHandle(field)); + } + + private VarHandle unreflect(final Field field) throws IllegalAccessException, SecurityException { + if (Modifier.isStatic(field.getModifiers())) { + final boolean access = field.canAccess(null); + if (!access) { + field.setAccessible(true); + } + final VarHandle out = LOOKUP.unreflectVarHandle(field); + if (!access) { + field.setAccessible(false); + } + return out; + } + if (field.trySetAccessible()) { + final VarHandle out = LOOKUP.unreflectVarHandle(field); + field.setAccessible(false); + return out; + } + return LOOKUP.unreflectVarHandle(field); + } + + private MethodHandle unreflect(final Method method) throws IllegalAccessException, SecurityException { + if (Modifier.isStatic(method.getModifiers())) { + final boolean access = method.canAccess(null); + if (!access) { + method.setAccessible(true); + } + final MethodHandle out = LOOKUP.unreflect(method); + if (!access) { + method.setAccessible(false); + } + return out; + } + if (method.trySetAccessible()) { + final MethodHandle out = LOOKUP.unreflect(method); + method.setAccessible(false); + return out; + } + return LOOKUP.unreflect(method); + } + + private MethodHandle unreflect(final Constructor constructor) throws IllegalAccessException { + final boolean access = constructor.canAccess(null); + if (!access) { + constructor.setAccessible(true); + } + final MethodHandle out = LOOKUP.unreflectConstructor(constructor); + if (!access) { + constructor.setAccessible(false); + } + return out; + } + + /* + * + */ + + public static Object[] mergeBack(final Object[] array1, final Object... array2) { + final Object[] output = new Object[array1.length + array2.length]; + System.arraycopy(array2, 0, output, 0, array2.length); + System.arraycopy(array1, 0, output, array2.length, array1.length); + return output; + } + + /* + * + */ + + public static final ClassLookup of(final Class clazz) { + try { + return new ClassLookup(clazz); + } catch (final IllegalAccessException e) { + return null; + } + } + + public static final ClassLookup of(final String path) { + try { + return new ClassLookup(path); + } catch (final IllegalAccessException e) { + return null; + } + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookupCache.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookupCache.java new file mode 100644 index 0000000..dca1c2f --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/ClassLookupCache.java @@ -0,0 +1,59 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle; + +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Optional; + +public class ClassLookupCache { + + protected final HashMap cache = new HashMap<>(); + + public void clear() { + cache.values().forEach(ClassLookup::delete); + cache.clear(); + } + + public Optional get(final String name) { + return Optional.ofNullable(cache.get(name)); + } + + public boolean has(final String name) { + return cache.containsKey(name); + } + + public ClassLookup create(final String name, final String path) { + if (has(name)) { + return cache.get(name); + } + final ClassLookup reflect = create(path); + cache.put(name, reflect); + return reflect; + } + + public ClassLookup create(final String name, final Class clazz) { + if (has(name)) { + return cache.get(name); + } + final ClassLookup reflect = create(clazz); + cache.put(name, reflect); + return reflect; + } + + public void delete(final String name) { + cache.remove(name); + } + + @SuppressWarnings("unchecked") + public Entry[] entries() { + return cache.entrySet().toArray(Entry[]::new); + } + + private ClassLookup create(final Class clazz) { + return ClassLookup.of(clazz); + } + + private ClassLookup create(final String path) { + return ClassLookup.of(path); + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/FakeLookup.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/FakeLookup.java new file mode 100644 index 0000000..2e75086 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/FakeLookup.java @@ -0,0 +1,19 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle; + +public class FakeLookup extends ClassLookup { + + public static final FakeLookup FAKE = build(); + + private FakeLookup() throws IllegalAccessException { + super((Class) null); + } + + private static final FakeLookup build() { + try { + return new FakeLookup(); + } catch (IllegalAccessException e) { + return null; + } + } + +} \ No newline at end of file diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/IFieldHandle.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/IFieldHandle.java new file mode 100644 index 0000000..e6391dc --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/IFieldHandle.java @@ -0,0 +1,17 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field; + +public interface IFieldHandle { + + Object getValue(); + + Object getValue(Object source); + + IFieldHandle setValue(Object value); + + IFieldHandle setValue(Object source, Object value); + + O getHandle(); + + boolean isUnsafe(); + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/SafeFieldHandle.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/SafeFieldHandle.java new file mode 100644 index 0000000..7993890 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/SafeFieldHandle.java @@ -0,0 +1,45 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field; + +import java.lang.invoke.VarHandle; + +public class SafeFieldHandle implements IFieldHandle { + + private final VarHandle handle; + + public SafeFieldHandle(VarHandle handle) { + this.handle = handle; + } + + @Override + public Object getValue() { + return handle.get(); + } + + @Override + public Object getValue(Object source) { + return handle.get(source); + } + + @Override + public IFieldHandle setValue(Object value) { + handle.set(value); + return this; + } + + @Override + public IFieldHandle setValue(Object source, Object value) { + handle.set(source, value); + return this; + } + + @Override + public VarHandle getHandle() { + return handle; + } + + @Override + public boolean isUnsafe() { + return false; + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeDeclaredFieldHandle.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeDeclaredFieldHandle.java new file mode 100644 index 0000000..ce9bd1c --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeDeclaredFieldHandle.java @@ -0,0 +1,40 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field; + +import java.lang.reflect.Field; + +public final class UnsafeDeclaredFieldHandle extends UnsafeFieldHandle { + + private final Field handle; + private final long offset; + + public UnsafeDeclaredFieldHandle(Field handle) { + this.handle = handle; + this.offset = UNSAFE.objectFieldOffset(handle); + } + + @Override + public Object getValue() { + return null; // Stay null because its not static + } + + @Override + public Object getValue(Object source) { + return getMemoryValue(source, offset); + } + + @Override + public IFieldHandle setValue(Object value) { + return this; // Do nothing because its not static + } + + @Override + public IFieldHandle setValue(Object source, Object value) { + return setMemoryValue(source, offset, value); + } + + @Override + public Field getHandle() { + return handle; + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeFieldHandle.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeFieldHandle.java new file mode 100644 index 0000000..b0b3a7f --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeFieldHandle.java @@ -0,0 +1,35 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +public abstract class UnsafeFieldHandle implements IFieldHandle { + + protected static final Unsafe UNSAFE = getUnsafe(); + + protected final IFieldHandle setMemoryValue(Object base, long offset, Object value) { + UNSAFE.putObject(base, offset, value); + return this; + } + + protected final Object getMemoryValue(Object base, long offset) { + return UNSAFE.getObject(base, offset); + } + + @Override + public final boolean isUnsafe() { + return true; + } + + private static Unsafe getUnsafe() { + try { + Field field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + return (Unsafe) field.get(null); + } catch (Exception ignore) { + return null; + } + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeStaticFieldHandle.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeStaticFieldHandle.java new file mode 100644 index 0000000..df013ba --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/handle/field/UnsafeStaticFieldHandle.java @@ -0,0 +1,42 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.handle.field; + +import java.lang.reflect.Field; + +public final class UnsafeStaticFieldHandle extends UnsafeFieldHandle { + + private final Field handle; + private final Object base; + private final long offset; + + public UnsafeStaticFieldHandle(Field handle) { + this.handle = handle; + this.base = UNSAFE.staticFieldBase(handle); + this.offset = UNSAFE.staticFieldOffset(handle); + } + + @Override + public Object getValue() { + return getMemoryValue(base, offset); + } + + @Override + public Object getValue(Object source) { + return null; // Stay null because its static + } + + @Override + public IFieldHandle setValue(Object value) { + return setMemoryValue(base, offset, value); + } + + @Override + public IFieldHandle setValue(Object source, Object value) { + return this; // Do nothing because its static + } + + @Override + public Field getHandle() { + return handle; + } + +} diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/provider/GeneralReflections.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/provider/GeneralReflections.java new file mode 100644 index 0000000..fcfa429 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/lookup/provider/GeneralReflections.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.lookup.provider; + +import com.mojang.authlib.GameProfile; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class GeneralReflections extends ClassLookups { + + public static GeneralReflections INSTANCE = new GeneralReflections(); + + private GeneralReflections() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Needed classes to create Reflects + // + + // + // + // Create Reflects + // + + // + // Mojang + + provider.createLookup("mjGameProfile", GameProfile.class).searchField("name", "name"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/BlockTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/BlockTools.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/BlockTools.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/BlockTools.java index c3cb1a6..b6a28c5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/BlockTools.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/BlockTools.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.tools; +package net.sourcewriters.minecraft.vcompat.provider.tools; import org.bukkit.block.Block; diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/ServerTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/ServerTools.java new file mode 100644 index 0000000..a28d521 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/ServerTools.java @@ -0,0 +1,13 @@ +package net.sourcewriters.minecraft.vcompat.provider.tools; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public abstract class ServerTools { + + public abstract void setMotd(String text); + + public abstract String getMotd(); + + public abstract ConsoleReaderWrapper getConsole(); + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/SkinTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/SkinTools.java similarity index 83% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/SkinTools.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/SkinTools.java index 6a8e2b7..7466930 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/tools/SkinTools.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/tools/SkinTools.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.tools; +package net.sourcewriters.minecraft.vcompat.provider.tools; import org.bukkit.entity.Player; @@ -6,7 +6,7 @@ import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public abstract class SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/NmsBoundingBox.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/NmsBoundingBox.java similarity index 99% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/NmsBoundingBox.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/NmsBoundingBox.java index fb5e48b..1b79b32 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/NmsBoundingBox.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/NmsBoundingBox.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.utils; +package net.sourcewriters.minecraft.vcompat.provider.utils; import static org.bukkit.util.NumberConversions.checkFinite; @@ -10,7 +10,7 @@ import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; -import net.sourcewriters.minecraft.vcompat.utils.validation.ValidationHelper; +import net.sourcewriters.minecraft.vcompat.util.validation.ValidationHelper; public class NmsBoundingBox { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/Tracker.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/Tracker.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/Tracker.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/Tracker.java index f2f41aa..4c62571 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/utils/Tracker.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/utils/Tracker.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.utils; +package net.sourcewriters.minecraft.vcompat.provider.utils; import java.util.Optional; diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/wrapper/ConsoleReaderWrapper.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/wrapper/ConsoleReaderWrapper.java new file mode 100644 index 0000000..387be25 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/provider/wrapper/ConsoleReaderWrapper.java @@ -0,0 +1,18 @@ +package net.sourcewriters.minecraft.vcompat.provider.wrapper; + +import java.io.IOException; +import java.io.Writer; + +public abstract class ConsoleReaderWrapper { + + public abstract Writer getOutput(); + + public abstract boolean isAnsiSupported(); + + public abstract boolean isJLineSupported(); + + public abstract void flush() throws IOException; + + public abstract void drawLine() throws IOException; + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultMojangProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultMojangProvider.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultMojangProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultMojangProvider.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java index 87f6d11..ae16dc8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/DefaultSkinStore.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.Optional; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class DefaultSkinStore extends SkinStore { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java similarity index 92% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java index a3ea2bc..338d2e3 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Mojang.java @@ -14,18 +14,18 @@ import com.syntaxphoenix.syntaxapi.logging.ILogger; import com.syntaxphoenix.syntaxapi.logging.LogTypeId; -import com.syntaxphoenix.syntaxapi.net.http.RequestType; -import com.syntaxphoenix.syntaxapi.net.http.ResponseCode; - -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.utils.java.net.EasyRequest; -import net.sourcewriters.minecraft.vcompat.utils.java.net.EasyResponse; -import net.sourcewriters.minecraft.vcompat.utils.java.net.content.EasyUrlEncodedContent; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.SkinModel; + +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyRequest; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyRequestType; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyResponse; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyResponseCode; +import net.sourcewriters.minecraft.vcompat.util.java.net.content.EasyUrlEncodedContent; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.minecraft.SkinModel; public class Mojang { @@ -36,7 +36,7 @@ public class Mojang { private final SkinStore store; private final ILogger logger; - private final PlayerProvider playerProvider = VersionControl.get().getPlayerProvider(); + private final PlayerProvider playerProvider = VersionCompatProvider.get().getControl().getPlayerProvider(); private boolean debug = false; @@ -170,11 +170,11 @@ public Skin getSkinFrom(URL url, SkinModel model, int timeout) { logger.log(LogTypeId.ERROR, "Can't connect to url!"); return null; } - EasyRequest request = new EasyRequest(RequestType.POST); + EasyRequest request = new EasyRequest(EasyRequestType.POST); request.header("Authorization", "Bearer " + profile.getAuthToken()); request.data("url", url.toString()).data("model", model.toString()); EasyResponse response = request.run(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()), EasyUrlEncodedContent.URL_ENCODED); - if (response.getCode() != ResponseCode.NO_CONTENT) { + if (response.getCode() != EasyResponseCode.NO_CONTENT) { if (debug) { logger.log(LogTypeId.DEBUG, "Code: " + response.getCode() + " / Length: " + response.getData().length); logger.log(LogTypeId.DEBUG, response.getDataAsJson().toPrettyString().split("\n")); @@ -234,11 +234,11 @@ public Skin getSkinFrom(String name, URL url, SkinModel model, int timeout) { logger.log(LogTypeId.ERROR, "Can't connect to url!"); return null; } - EasyRequest request = new EasyRequest(RequestType.POST); + EasyRequest request = new EasyRequest(EasyRequestType.POST); request.header("Authorization", "Bearer " + profile.getAuthToken()); request.data("url", url.toString()).data("model", model.toString()); EasyResponse response = request.run(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()), EasyUrlEncodedContent.URL_ENCODED); - if (response.getCode() != ResponseCode.NO_CONTENT) { + if (response.getCode() != EasyResponseCode.NO_CONTENT) { if (debug) { logger.log(LogTypeId.DEBUG, "Code: " + response.getCode() + " / Length: " + response.getData().length); logger.log(LogTypeId.DEBUG, response.getDataAsJson().toPrettyString().split("\n")); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/MojangProvider.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/MojangProvider.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/MojangProvider.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/MojangProvider.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java similarity index 87% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java index ab732ec..b1a8294 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/PersistentSkinStore.java @@ -5,9 +5,9 @@ import com.syntaxphoenix.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class PersistentSkinStore extends SkinStore { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java index 2723a02..07cc99f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/Profile.java @@ -7,9 +7,9 @@ import com.syntaxphoenix.syntaxapi.json.JsonObject; import com.syntaxphoenix.syntaxapi.json.JsonValue; import com.syntaxphoenix.syntaxapi.json.ValueType; -import com.syntaxphoenix.syntaxapi.net.http.RequestType; -import net.sourcewriters.minecraft.vcompat.utils.java.net.EasyRequest; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyRequest; +import net.sourcewriters.minecraft.vcompat.util.java.net.EasyRequestType; public class Profile { @@ -77,7 +77,7 @@ public boolean validate() { return false; } try { - EasyRequest request = new EasyRequest(RequestType.POST).data("accessToken", authToken).data("clientToken", + EasyRequest request = new EasyRequest(EasyRequestType.POST).data("accessToken", authToken).data("clientToken", provider.getClientIdentifier().toString()); return request.run(String.format(AUTH_SERVER, "validate")).getCode() == 204; } catch (IOException ignore) { @@ -90,7 +90,7 @@ public Profile refresh() { return this; } try { - EasyRequest request = new EasyRequest(RequestType.POST).data("accessToken", authToken).data("clientToken", + EasyRequest request = new EasyRequest(EasyRequestType.POST).data("accessToken", authToken).data("clientToken", provider.getClientIdentifier().toString()); JsonValue responseRaw = request.run(String.format(AUTH_SERVER, "refresh")).getDataAsJson(); if (!responseRaw.hasType(ValueType.OBJECT)) { @@ -110,7 +110,7 @@ public Profile refresh() { public Profile authenticate() { try { - EasyRequest request = new EasyRequest(RequestType.POST); + EasyRequest request = new EasyRequest(EasyRequestType.POST); JsonObject object = new JsonObject(); JsonObject agent = new JsonObject(); agent.set("name", "Minecraft"); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java index 72c6681..baafbce 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/skin/SkinStore.java @@ -7,7 +7,7 @@ import com.syntaxphoenix.syntaxapi.nbt.NbtType; import com.syntaxphoenix.syntaxapi.nbt.utils.NbtStorage; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public abstract class SkinStore implements NbtStorage> { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/BukkitColor.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/BukkitColor.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/BukkitColor.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/BukkitColor.java index 0294f49..f9b9d92 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/BukkitColor.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/BukkitColor.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.bukkit; +package net.sourcewriters.minecraft.vcompat.util.bukkit; import java.util.regex.Pattern; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/Players.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/Players.java similarity index 97% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/Players.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/Players.java index 7f3077e..d2d1dec 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/Players.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/Players.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.bukkit; +package net.sourcewriters.minecraft.vcompat.util.bukkit; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/unsafe/KeyCache.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/unsafe/KeyCache.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/unsafe/KeyCache.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/unsafe/KeyCache.java index ba655b9..aea98b2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/bukkit/unsafe/KeyCache.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/bukkit/unsafe/KeyCache.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.bukkit.unsafe; +package net.sourcewriters.minecraft.vcompat.util.bukkit.unsafe; import java.util.Collections; import java.util.HashMap; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/DefaultConstants.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/DefaultConstants.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/DefaultConstants.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/DefaultConstants.java index 3482b0d..ef273ae 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/DefaultConstants.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/DefaultConstants.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.constants; +package net.sourcewriters.minecraft.vcompat.util.constants; import com.syntaxphoenix.syntaxapi.utils.key.Namespace; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/MinecraftConstants.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/MinecraftConstants.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/MinecraftConstants.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/MinecraftConstants.java index 8b11a60..edbd527 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/constants/MinecraftConstants.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/constants/MinecraftConstants.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.constants; +package net.sourcewriters.minecraft.vcompat.util.constants; public class MinecraftConstants { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/function/TriPredicate.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/function/TriPredicate.java similarity index 98% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/function/TriPredicate.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/function/TriPredicate.java index 3330406..f2c34e0 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/function/TriPredicate.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/function/TriPredicate.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.function; +package net.sourcewriters.minecraft.vcompat.util.java.function; import java.util.Objects; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyContentRegistry.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyContentRegistry.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyContentRegistry.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyContentRegistry.java index a031195..ead169a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyContentRegistry.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyContentRegistry.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net; +package net.sourcewriters.minecraft.vcompat.util.java.net; import java.util.concurrent.ConcurrentHashMap; -import net.sourcewriters.minecraft.vcompat.utils.java.net.content.EasyJsonContent; -import net.sourcewriters.minecraft.vcompat.utils.java.net.content.EasyUrlEncodedContent; +import net.sourcewriters.minecraft.vcompat.util.java.net.content.EasyJsonContent; +import net.sourcewriters.minecraft.vcompat.util.java.net.content.EasyUrlEncodedContent; public final class EasyContentRegistry { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyRequest.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequest.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyRequest.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequest.java index dd7bf25..e75a75a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyRequest.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequest.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net; +package net.sourcewriters.minecraft.vcompat.util.java.net; import java.io.IOException; import java.io.InputStream; @@ -17,17 +17,16 @@ import com.syntaxphoenix.syntaxapi.json.JsonValue; import com.syntaxphoenix.syntaxapi.json.ValueType; import com.syntaxphoenix.syntaxapi.json.value.JsonNull; -import com.syntaxphoenix.syntaxapi.net.http.RequestType; import com.syntaxphoenix.syntaxapi.utils.java.Streams; -import net.sourcewriters.minecraft.vcompat.utils.java.net.content.EasyJsonContent; +import net.sourcewriters.minecraft.vcompat.util.java.net.content.EasyJsonContent; public class EasyRequest { private static final String[] EMPTY = new String[0]; private final HashMap> headers = new HashMap<>(); - private final RequestType requestType; + private final EasyRequestType requestType; private JsonValue data; @@ -36,11 +35,11 @@ public class EasyRequest { private String agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"; - public EasyRequest(RequestType requestType) { - this.requestType = Objects.requireNonNull(requestType, "RequestType is needed to cast an Http request"); + public EasyRequest(EasyRequestType requestType) { + this.requestType = Objects.requireNonNull(requestType, "EasyRequestType is needed to cast an Http request"); } - public RequestType getRequestType() { + public EasyRequestType getRequestType() { return requestType; } diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequestType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequestType.java new file mode 100644 index 0000000..5ff6ab7 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyRequestType.java @@ -0,0 +1,40 @@ +package net.sourcewriters.minecraft.vcompat.util.java.net; + +public enum EasyRequestType { + + GET, + HEAD, + PUT(true), + POST(true), + DELETE(true), + OPTIONS(true), + PATCH(true), + CONNECT, + TRACE, + NONE; + + private final boolean output; + + private EasyRequestType() { + output = false; + } + + private EasyRequestType(boolean state) { + output = state; + } + + public boolean hasOutput() { + return output; + } + + public static EasyRequestType fromString(String value) { + value = value.toUpperCase(); + for (EasyRequestType type : values()) { + if (type.name().equals(value)) { + return type; + } + } + return NONE; + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyResponse.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponse.java similarity index 93% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyResponse.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponse.java index ced984c..de1e14c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/EasyResponse.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponse.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net; +package net.sourcewriters.minecraft.vcompat.util.java.net; import java.util.List; import java.util.Map; @@ -10,7 +10,7 @@ import com.syntaxphoenix.syntaxapi.json.ValueType; import com.syntaxphoenix.syntaxapi.json.value.JsonNull; -import net.sourcewriters.minecraft.vcompat.utils.java.net.tools.HeaderParser; +import net.sourcewriters.minecraft.vcompat.util.java.net.tools.HeaderParser; public class EasyResponse { diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponseCode.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponseCode.java new file mode 100644 index 0000000..aeae3c2 --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/EasyResponseCode.java @@ -0,0 +1,126 @@ +package net.sourcewriters.minecraft.vcompat.util.java.net; + +import java.lang.reflect.Field; + +import com.syntaxphoenix.syntaxapi.utils.java.Strings; + +import net.sourcewriters.minecraft.vcompat.util.java.tools.ReflectionTools; + +public final class EasyResponseCode { + + private EasyResponseCode() { + throw new UnsupportedOperationException("Constant class"); + } + + /** + * Informations + */ + + public static final int CONTINUE = 100; + public static final int SWITCHING_PROTOCOLS = 101; + public static final int PROCESSING = 102; + + /** + * Succeeded Operations + */ + + public static final int OK = 200; + public static final int CREATED = 201; + public static final int ACCEPTED = 202; + public static final int NON_AUTHORITATIVE_INFORMATION = 203; + public static final int NO_CONTENT = 204; + public static final int RESET_CONTENT = 205; + public static final int PARTIAL_CONTENT = 206; + public static final int MULTI_STATUS = 207; + public static final int ALREADY_REPORTED = 208; + public static final int IM_USED = 226; + + /** + * Redirects + */ + + public static final int MULTIPLE_CHOICES = 300; + public static final int MOVED_PERMANENTLY = 301; + public static final int FOUND_MOVE_TEMPORARILLY = 302; + public static final int SEE_OTHER = 303; + public static final int NOT_MODIFIED = 304; + public static final int USE_PROXY = 305; + public static final int TEMPORARY_REDIRECT = 307; + public static final int PERMANENT_REDIRECT = 308; + + /** + * Client Errors + */ + + public static final int BAD_REQUEST = 400; + public static final int UNAUTHORIZED = 401; + public static final int PAYMENT_REQUIRED = 402; + public static final int FORBIDDEN = 403; + public static final int NOT_FOUND = 404; + public static final int METHOD_NOT_ALLOWED = 405; + public static final int NOT_ACCEPTABLE = 406; + public static final int PROXY_AUTHENTICATION_REQUIRED = 407; + public static final int REQUEST_TIMOEOUT = 408; + public static final int CONFLICT = 409; + public static final int GONE = 410; + public static final int LENGTH_REQUIRED = 411; + public static final int PRECONDITION_FAILED = 412; + public static final int REQUEST_ENTITY_TOO_LARGE = 413; + public static final int URI_TOO_LONG = 414; + public static final int UNSUPPORTED_MEDIA_TYPE = 415; + public static final int REQUESTED_RANGE_NOT_SATISFIABLE = 416; + public static final int EXPECTATION_FAILED = 417; + public static final int POLICY_NOT_FULFILLED = 420; + public static final int MISDIRECTED_REQUEST = 421; + public static final int UNPROCESSABLE_ENTITY = 422; + public static final int LOCKED = 423; + public static final int FAILED_DEPENDENCY = 424; + public static final int UPGRADE_REQUIRED = 426; + public static final int PRECONDITION_REQUIRED = 428; + public static final int TOO_MANY_REQUESTS = 429; + public static final int REQUEST_HEADER_FIELDS_TOO_LARGE = 431; + public static final int UNAVAILABLE_FOR_LEGAL_REASONS = 451; + + /** + * Server Errors + */ + + public static final int INTERNAL_SERVER_ERROR = 500; + public static final int NOT_IMPLEMENTED = 501; + public static final int BAD_GATEWAY = 502; + public static final int SERVICE_UNAVAILABLE = 503; + public static final int GATEWAY_TIMEOUT = 504; + public static final int HTTP_VERSION_NOT_SUPPORTED = 505; + public static final int VARIANT_ALSO_NEGOTIATES = 506; + public static final int INSUFFICIENT_STORAGE = 507; + public static final int LOOP_DETECTED = 508; + public static final int BANDWITH_LIMIT_EXCEEDED = 509; + public static final int NOT_EXTENDED = 510; + public static final int NETWORK_AUTHENTICATION_REQUIRED = 511; + + /* + * + */ + + public static final String getName(int code) { + Field[] fields = EasyResponseCode.class.getFields(); + for (Field field : fields) { + if (((int) ReflectionTools.getValue(field)) == code) { + return format(field.getName()); + } + } + return ""; + } + + private static final String format(String name) { + if (!name.contains("_")) { + return Strings.firstLetterToUpperCase(name); + } + String[] parts = name.split("_"); + for (int index = 0; index < parts.length; index++) { + parts[index] = Strings.firstLetterToUpperCase(parts[index]); + } + return String.join(" ", parts); + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyContent.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyContent.java similarity index 71% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyContent.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyContent.java index 52889c9..fbe0777 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyContent.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyContent.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net; +package net.sourcewriters.minecraft.vcompat.util.java.net; import java.net.URL; @@ -20,6 +20,8 @@ default String type() { JsonValue deserialize(byte[] data); - default void modify(URL url, JsonValue value) {} + default URL modify(URL url, JsonValue value) { + return url; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyTextContent.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyTextContent.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyTextContent.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyTextContent.java index 9e4674e..cd5c962 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/IEasyTextContent.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/IEasyTextContent.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net; +package net.sourcewriters.minecraft.vcompat.util.java.net; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyJsonContent.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyJsonContent.java similarity index 87% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyJsonContent.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyJsonContent.java index bbbc1d2..6617858 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyJsonContent.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyJsonContent.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net.content; +package net.sourcewriters.minecraft.vcompat.util.java.net.content; import java.io.IOException; @@ -7,7 +7,7 @@ import com.syntaxphoenix.syntaxapi.json.io.JsonSyntaxException; import com.syntaxphoenix.syntaxapi.json.value.JsonNull; -import net.sourcewriters.minecraft.vcompat.utils.java.net.IEasyTextContent; +import net.sourcewriters.minecraft.vcompat.util.java.net.IEasyTextContent; public class EasyJsonContent implements IEasyTextContent { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyUrlEncodedContent.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyUrlEncodedContent.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyUrlEncodedContent.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyUrlEncodedContent.java index 9453129..9fa330f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/content/EasyUrlEncodedContent.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/content/EasyUrlEncodedContent.java @@ -1,5 +1,6 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net.content; +package net.sourcewriters.minecraft.vcompat.util.java.net.content; +import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -7,11 +8,10 @@ import com.syntaxphoenix.syntaxapi.json.JsonObject; import com.syntaxphoenix.syntaxapi.json.JsonValue; import com.syntaxphoenix.syntaxapi.json.ValueType; -import com.syntaxphoenix.syntaxapi.utils.net.UrlReflection; -import net.sourcewriters.minecraft.vcompat.utils.java.net.IEasyTextContent; -import net.sourcewriters.minecraft.vcompat.utils.java.net.tools.HeaderParser; -import net.sourcewriters.minecraft.vcompat.utils.java.net.tools.UrlEncoder; +import net.sourcewriters.minecraft.vcompat.util.java.net.IEasyTextContent; +import net.sourcewriters.minecraft.vcompat.util.java.net.tools.HeaderParser; +import net.sourcewriters.minecraft.vcompat.util.java.net.tools.UrlEncoder; public class EasyUrlEncodedContent implements IEasyTextContent { @@ -36,12 +36,16 @@ public final boolean modifyUrl() { } @Override - public void modify(URL url, JsonValue value) { + public URL modify(URL url, JsonValue value) { String data = toString(value); if (data == null) { - return; + return url; + } + try { + return new URL(url.toString() + '?' + data); + } catch (MalformedURLException e) { + return url; } - UrlReflection.applyQuery(url, '?' + data); } @Override diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/HeaderParser.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/HeaderParser.java similarity index 97% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/HeaderParser.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/HeaderParser.java index b0ea414..f9b52a6 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/HeaderParser.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/HeaderParser.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net.tools; +package net.sourcewriters.minecraft.vcompat.util.java.net.tools; import java.math.BigDecimal; import java.math.BigInteger; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/UrlEncoder.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/UrlEncoder.java similarity index 99% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/UrlEncoder.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/UrlEncoder.java index 81562b9..bf673e5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/net/tools/UrlEncoder.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/net/tools/UrlEncoder.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.net.tools; +package net.sourcewriters.minecraft.vcompat.util.java.net.tools; import java.io.CharArrayWriter; import java.io.UnsupportedEncodingException; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ArrayTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ArrayTools.java similarity index 90% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ArrayTools.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ArrayTools.java index cad79fc..d2ff1cb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/ArrayTools.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ArrayTools.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.tools; +package net.sourcewriters.minecraft.vcompat.util.java.tools; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/OptionTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/OptionTools.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/OptionTools.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/OptionTools.java index d430aed..fb84282 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/OptionTools.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/OptionTools.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.tools; +package net.sourcewriters.minecraft.vcompat.util.java.tools; import java.util.Optional; diff --git a/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java new file mode 100644 index 0000000..a86ac9b --- /dev/null +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/ReflectionTools.java @@ -0,0 +1,79 @@ +package net.sourcewriters.minecraft.vcompat.util.java.tools; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; + +public final class ReflectionTools { + + private ReflectionTools() {} + + public static boolean hasSameArguments(Class[] compare1, Class[] compare2) { + if (compare1.length == 0 && compare2.length == 0) { + return true; + } else if (compare1.length != compare2.length) { + return false; + } + for (Class arg1 : compare1) { + boolean found = true; + for (Class arg2 : compare2) { + if (!arg1.isAssignableFrom(arg2)) { + found = false; + break; + } + } + if (!found) { + return false; + } + } + return true; + } + + public static Class subclass(Class clazz, String name) { + for (Class search : clazz.getClasses()) { + if (search.getSimpleName().split("\\.")[0].equals(name)) { + return search; + } + } + return null; + } + + public static Class arrayclass(Class clazz) { + return Array.newInstance(clazz, 1).getClass(); + } + + public static Class getClass(String classPath) { + try { + return Class.forName(classPath); + } catch (ClassNotFoundException ignored) { + return null; + } + } + + public static Object getValue(Field field, Object source) { + if (field != null) { + boolean access = field.canAccess(source); + if (!access) { + field.setAccessible(true); + } + Object output = null; + try { + output = field.get(source); + } catch (IllegalArgumentException | IllegalAccessException e) { + if (!access) { + field.setAccessible(access); + } + e.printStackTrace(); + } + if (!access) { + field.setAccessible(access); + } + return output; + } + return null; + } + + public static Object getValue(Field field) { + return getValue(field, null); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/UUIDHelper.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/UUIDHelper.java similarity index 95% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/UUIDHelper.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/UUIDHelper.java index 057eeaa..aaa781c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/java/tools/UUIDHelper.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/java/tools/UUIDHelper.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.java.tools; +package net.sourcewriters.minecraft.vcompat.util.java.tools; import java.security.SecureRandom; import java.util.UUID; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogType.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogType.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogType.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogType.java index e5fc0cc..87d3e30 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogType.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogType.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.logging; +package net.sourcewriters.minecraft.vcompat.util.logging; import com.syntaxphoenix.syntaxapi.logging.color.ColorTools; import com.syntaxphoenix.syntaxapi.logging.color.LogTypeColor; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogger.java similarity index 92% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogger.java index da16286..826d47d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/BukkitLogger.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/BukkitLogger.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.logging; +package net.sourcewriters.minecraft.vcompat.util.logging; import com.syntaxphoenix.syntaxapi.logging.ILogger; import com.syntaxphoenix.syntaxapi.logging.LogTypeId; @@ -10,11 +10,10 @@ import com.syntaxphoenix.syntaxapi.utils.java.Times; import com.syntaxphoenix.syntaxapi.utils.java.tools.Container; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.Main; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.plugin.Plugin; import org.fusesource.jansi.Ansi; @@ -28,19 +27,18 @@ public class BukkitLogger implements ILogger { private static final String ANSI_RESET = Ansi.ansi().reset().toString(); - private static final Container READER = Container.of(); + private static final Container READER = Container.of(); - private static ConsoleReader getReader() { + private static ConsoleReaderWrapper getReader() { return READER.isPresent() ? READER.get() - : READER.replace(VersionControl.get().getToolProvider().getServerTools().getConsole()).get(); + : READER.replace(VersionCompatProvider.get().getControl().getToolProvider().getServerTools().getConsole()).get(); } - private final boolean ansiSupported, jLine; private final HashSet colorMessage = new HashSet<>(); private final LogTypeMap typeMap = new LogTypeMap(); private final Writer writer; - private final ConsoleReader reader; + private final ConsoleReaderWrapper reader; private final String plugin; private BiConsumer custom; @@ -57,8 +55,8 @@ public BukkitLogger(String plugin) { this.plugin = plugin; this.reader = getReader(); this.writer = reader.getOutput(); - this.colored = this.ansiSupported = reader.getTerminal().isAnsiSupported(); - this.jLine = Main.useJline; + this.colored = this.ansiSupported = reader.isAnsiSupported(); + this.jLine = reader.isJLineSupported(); setDefaults(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/LoggingColors.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/LoggingColors.java similarity index 98% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/LoggingColors.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/LoggingColors.java index 1b458f3..a7c2305 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/logging/LoggingColors.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/logging/LoggingColors.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.logging; +package net.sourcewriters.minecraft.vcompat.util.logging; import org.bukkit.ChatColor; import org.fusesource.jansi.Ansi; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/MojangProfileServer.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/MojangProfileServer.java similarity index 98% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/MojangProfileServer.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/MojangProfileServer.java index acc6a78..97a1ef4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/MojangProfileServer.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/MojangProfileServer.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.minecraft; +package net.sourcewriters.minecraft.vcompat.util.minecraft; import java.io.IOException; import java.net.URL; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/Skin.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/Skin.java similarity index 98% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/Skin.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/Skin.java index 761e1a5..1a63044 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/Skin.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/Skin.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.minecraft; +package net.sourcewriters.minecraft.vcompat.util.minecraft; import java.io.IOException; import java.io.Serializable; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/SkinModel.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/SkinModel.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/SkinModel.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/SkinModel.java index 1276e1b..3e2b162 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/minecraft/SkinModel.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/minecraft/SkinModel.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.minecraft; +package net.sourcewriters.minecraft.vcompat.util.minecraft; public enum SkinModel { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/thread/PostAsync.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/thread/PostAsync.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/thread/PostAsync.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/thread/PostAsync.java index ab6c747..eaab63a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/thread/PostAsync.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/thread/PostAsync.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.thread; +package net.sourcewriters.minecraft.vcompat.util.thread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/validation/ValidationHelper.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/validation/ValidationHelper.java similarity index 83% rename from src/main/java/net/sourcewriters/minecraft/vcompat/utils/validation/ValidationHelper.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/validation/ValidationHelper.java index e9796c6..90ea561 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/utils/validation/ValidationHelper.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/util/validation/ValidationHelper.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.utils.validation; +package net.sourcewriters.minecraft.vcompat.util.validation; public class ValidationHelper { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/version/ServerVersion.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/version/ServerVersion.java similarity index 100% rename from src/main/java/net/sourcewriters/minecraft/vcompat/version/ServerVersion.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/version/ServerVersion.java diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java similarity index 97% rename from src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java rename to vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java index efcdd34..6941397 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java +++ b/vcompat-api/src/main/java/net/sourcewriters/minecraft/vcompat/version/Versions.java @@ -8,7 +8,7 @@ import com.syntaxphoenix.syntaxapi.version.DefaultVersion; import com.syntaxphoenix.syntaxapi.version.Version; -import net.sourcewriters.minecraft.vcompat.utils.java.function.TriPredicate; +import net.sourcewriters.minecraft.vcompat.util.java.function.TriPredicate; public abstract class Versions { diff --git a/vcompat-core/.gitignore b/vcompat-core/.gitignore new file mode 100644 index 0000000..e5d0d0e --- /dev/null +++ b/vcompat-core/.gitignore @@ -0,0 +1,12 @@ +*/bin/ +*/target/ +*/dependencies/ +*/.settings/ +*/.idea/ +*/.m2/ +*/.classpath +*/.project +*/.gitlab-ci.yml +*/test/ +*/dependency-reduced-pom.xml +*.class \ No newline at end of file diff --git a/vcompat-core/pom.xml b/vcompat-core/pom.xml new file mode 100644 index 0000000..213d038 --- /dev/null +++ b/vcompat-core/pom.xml @@ -0,0 +1,83 @@ + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat + + + + github + GitHub OWNER Apache Maven Packages + https://maven.pkg.github.com/SourceWriters/vCompat + + + + + + + + + net.sourcewriters.minecraft + vcompat-api + 3.0.0 + + + + + + net.sourcewriters.minecraft + vcompat-legacy + 3.0.0 + + + net.sourcewriters.minecraft + vcompat-1_17_R1 + 3.0.0 + + + net.sourcewriters.minecraft + vcompat-1_18_R1 + 3.0.0 + + + + + + + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.syntaxphoenix.syntaxapi + net.sourcewriters.minecraft.vcompat.shaded.syntaxapi + + + + + + + \ No newline at end of file diff --git a/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java b/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java new file mode 100644 index 0000000..3dc33df --- /dev/null +++ b/vcompat-core/src/main/java/net/sourcewriters/minecraft/vcompat/VersionCompat.java @@ -0,0 +1,33 @@ +package net.sourcewriters.minecraft.vcompat; + +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; +import net.sourcewriters.minecraft.vcompat.version.Versions; + +final class VersionCompat extends VersionCompatProvider { + + public static final String CLASSPATH = "%s.provider.impl.v%s.VersionControl%s"; + + private final VersionControl control; + + public VersionCompat() { + this.control = initControl(); + Runtime.getRuntime().addShutdownHook(new Thread(control::shutdown)); + } + + private final VersionControl initControl() { + Object object = ClassLookup + .of(String.format(CLASSPATH, VersionCompat.class.getPackageName(), Versions.getServerAsString(), Versions.getServerAsString())) + .init(); + if (object == null || !(object instanceof VersionControl)) { + throw new IllegalStateException("Can't initialize VersionControl"); + } + return (VersionControl) object; + } + + @Override + public final VersionControl getControl() { + return control; + } + +} diff --git a/vcompat-legacy/.gitignore b/vcompat-legacy/.gitignore new file mode 100644 index 0000000..226a4f4 --- /dev/null +++ b/vcompat-legacy/.gitignore @@ -0,0 +1,13 @@ +*/bin/ +*/target/ +*/dependencies/ +*/.settings/ +*/.idea/ +*/.m2/ +*/.classpath +*/.project +*/.gitlab-ci.yml +*/test/ +*/dependency-reduced-pom.xml +*.class +*.jar \ No newline at end of file diff --git a/vcompat-legacy/pom.xml b/vcompat-legacy/pom.xml new file mode 100644 index 0000000..654cf49 --- /dev/null +++ b/vcompat-legacy/pom.xml @@ -0,0 +1,130 @@ + + 4.0.0 + + net.sourcewriters.minecraft + vcompat-parent + 3.0.0 + + vcompat-legacy + + + ${project.basedir}/../libraries/spigot + + + + + net.sourcewriters.minecraft + vcompat-api + 3.0.0 + provided + + + + + + bukkit + spigot-1.16.4 + 0.1 + system + ${spigot.libPath}/spigot-1.16.4.jar + + + bukkit + spigot-1.16.3 + 0.1 + system + ${spigot.libPath}/spigot-1.16.3.jar + + + bukkit + spigot-1.16.1 + 0.1 + system + ${spigot.libPath}/spigot-1.16.1.jar + + + bukkit + spigot-1.15.2 + 0.1 + system + ${spigot.libPath}/spigot-1.15.2.jar + + + bukkit + spigot-1.14.2 + 0.1 + system + ${spigot.libPath}/spigot-1.14.2.jar + + + bukkit + spigot-1.13.2 + 0.1 + system + ${spigot.libPath}/spigot-1.13.2.jar + + + bukkit + spigot-1.13 + 0.1 + system + ${spigot.libPath}/spigot-1.13.jar + + + bukkit + spigot-1.12.2 + 0.1 + system + ${spigot.libPath}/spigot-1.12.2.jar + + + bukkit + spigot-1.11 + 0.1 + system + ${spigot.libPath}/spigot-1.11.jar + + + bukkit + spigot-1.10.2 + 0.1 + system + ${spigot.libPath}/spigot-1.10.2.jar + + + bukkit + spigot-1.9.4 + 0.1 + system + ${spigot.libPath}/spigot-1.9.4.jar + + + bukkit + spigot-1.9 + 0.1 + system + ${spigot.libPath}/spigot-1.9.jar + + + bukkit + spigot-1.8.8 + 0.1 + system + ${spigot.libPath}/spigot-1.8.8.jar + + + bukkit + spigot-1.8.3 + 0.1 + system + ${spigot.libPath}/spigot-1.8.3.jar + + + bukkit + spigot-1.8 + 0.1 + system + ${spigot.libPath}/spigot-1.8.jar + + + \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/BukkitConversion1_10_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/BukkitConversion1_10_R1.java index cbf6915..32c966a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/BukkitConversion1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_10_R1.NBTTagLong; import net.minecraft.server.v1_10_R1.NBTTagShort; import net.minecraft.server.v1_10_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_10_R1 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -219,12 +219,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/EntityProvider1_10_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/EntityProvider1_10_R1.java index ee14b13..6c3e98b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/EntityProvider1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import net.minecraft.server.v1_10_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.utils.EntityConstructors1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.utils.EntityConstructors1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_10_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/PlayerProvider1_10_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/PlayerProvider1_10_R1.java index 41411a6..165c32a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/PlayerProvider1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity.Player1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity.Player1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_10_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/TextureProvider1_10_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/TextureProvider1_10_R1.java index 6ab83c9..eea1e46 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/TextureProvider1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_10_R1.GameProfileSerializer; import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_10_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_10_R1.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_10_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/ToolProvider1_10_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/ToolProvider1_10_R1.java index f824ba9..fca01d9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/ToolProvider1_10_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools.BlockTools1_10_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools.ServerTools1_10_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools.SkinTools1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools.BlockTools1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools.ServerTools1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools.SkinTools1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_10_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/VersionControl1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/VersionControl1_10_R1.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/VersionControl1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/VersionControl1_10_R1.java index 77fe497..42a75b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/VersionControl1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/VersionControl1_10_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.reflection.NmsReflection1_10_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.reflection.NmsReflection1_10_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_10_R1 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_10_R1 init() { private final ToolProvider1_10_R1 toolProvider = new ToolProvider1_10_R1(this); private final TextureProvider1_10_R1 textureProvider = new TextureProvider1_10_R1(this); - private final PacketHandler1_10_R1 packetHandler = new PacketHandler1_10_R1(this); private final EntityProvider1_10_R1 entityProvider = new EntityProvider1_10_R1(this); private final PlayerProvider1_10_R1 playerProvider = new PlayerProvider1_10_R1(this); private final BukkitConversion1_10_R1 bukkitConversion = new BukkitConversion1_10_R1(this); private VersionControl1_10_R1() { - NmsReflection1_10_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_10_R1.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_10_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_10_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_10_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/ArmorStand1_10_R1.java similarity index 75% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/ArmorStand1_10_R1.java index a357fd4..9c6d319 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/ArmorStand1_10_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity; import net.minecraft.server.v1_10_R1.EntityArmorStand; import net.minecraft.server.v1_10_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_10_R1 extends EntityLiving1_10_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Entity1_10_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Entity1_10_R1.java index 1d3cd41..5918f46 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Entity1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_10_R1.PlayerConnection; import net.minecraft.server.v1_10_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_10_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/EntityLiving1_10_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/EntityLiving1_10_R1.java index 9ea5d39..09faf89 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/EntityLiving1_10_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity; import net.minecraft.server.v1_10_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_10_R1 extends Entity1_10_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Player1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Player1_10_R1.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Player1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Player1_10_R1.java index 773251a..a28a3a8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/entity/Player1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/entity/Player1_10_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EnumItemSlot; @@ -33,17 +33,17 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_10_R1.PacketPlayOutTitle; import net.minecraft.server.v1_10_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_10_R1.PlayerConnection; import net.minecraft.server.v1_10_R1.WorldServer; @@ -152,7 +152,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -284,7 +284,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/reflection/NmsReflection1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/reflection/NmsReflection1_10_R1.java new file mode 100644 index 0000000..79b4e6f --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/reflection/NmsReflection1_10_R1.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.reflection; + +import net.minecraft.server.v1_10_R1.NBTTagEnd; +import net.minecraft.server.v1_10_R1.NBTTagList; +import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_10_R1 extends ClassLookups { + + public static NmsReflection1_10_R1 INSTANCE = new NmsReflection1_10_R1(); + + private NmsReflection1_10_R1() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/BlockTools1_10_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/BlockTools1_10_R1.java index 3bd1004..8bafd8e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/BlockTools1_10_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_10_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_10_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_10_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/ServerTools1_10_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/ServerTools1_10_R1.java index 3e1c3de..3991040 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/ServerTools1_10_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.wrapper.ConsoleReaderWrapper1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_10_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_10_R1 getConsole() { + return ConsoleReaderWrapper1_10_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/SkinTools1_10_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/SkinTools1_10_R1.java index 6f36635..9b5d5a4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/tools/SkinTools1_10_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.tools; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_10_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/utils/EntityConstructors1_10_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/utils/EntityConstructors1_10_R1.java index 959b60c..139a92b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/utils/EntityConstructors1_10_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_10_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_10_R1.entity.ArmorStand1_10_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.entity.ArmorStand1_10_R1; public abstract class EntityConstructors1_10_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/wrapper/ConsoleReaderWrapper1_10_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/wrapper/ConsoleReaderWrapper1_10_R1.java new file mode 100644 index 0000000..02b9985 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_10_R1/wrapper/ConsoleReaderWrapper1_10_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_10_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_10_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_10_R1 INSTANCE = new ConsoleReaderWrapper1_10_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_10_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/BukkitConversion1_11_R1.java similarity index 73% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/BukkitConversion1_11_R1.java index 28af2d7..348b109 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/BukkitConversion1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_11_R1.NBTTagLong; import net.minecraft.server.v1_11_R1.NBTTagShort; import net.minecraft.server.v1_11_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_11_R1 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -216,12 +216,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/EntityProvider1_11_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/EntityProvider1_11_R1.java index cd61fcb..1ee1c68 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/EntityProvider1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; import net.minecraft.server.v1_11_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.utils.EntityConstructors1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.utils.EntityConstructors1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_11_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/PlayerProvider1_11_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/PlayerProvider1_11_R1.java index 302fe37..1d80788 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/PlayerProvider1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity.Player1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity.Player1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_11_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/TextureProvider1_11_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/TextureProvider1_11_R1.java index 858b989..ee263d1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/TextureProvider1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_11_R1.GameProfileSerializer; import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_11_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_11_R1.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_11_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/ToolProvider1_11_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/ToolProvider1_11_R1.java index edc47bb..e35c518 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/ToolProvider1_11_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools.BlockTools1_11_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools.ServerTools1_11_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools.SkinTools1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools.BlockTools1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools.ServerTools1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools.SkinTools1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_11_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/VersionControl1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/VersionControl1_11_R1.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/VersionControl1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/VersionControl1_11_R1.java index 767789b..08a6494 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/VersionControl1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/VersionControl1_11_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.reflection.NmsReflection1_11_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.reflection.NmsReflection1_11_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_11_R1 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_11_R1 init() { private final ToolProvider1_11_R1 toolProvider = new ToolProvider1_11_R1(this); private final TextureProvider1_11_R1 textureProvider = new TextureProvider1_11_R1(this); - private final PacketHandler1_11_R1 packetHandler = new PacketHandler1_11_R1(this); private final EntityProvider1_11_R1 entityProvider = new EntityProvider1_11_R1(this); private final PlayerProvider1_11_R1 playerProvider = new PlayerProvider1_11_R1(this); private final BukkitConversion1_11_R1 bukkitConversion = new BukkitConversion1_11_R1(this); private VersionControl1_11_R1() { - NmsReflection1_11_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_11_R1.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_11_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_11_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_11_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/ArmorStand1_11_R1.java similarity index 75% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/ArmorStand1_11_R1.java index 0937819..d91b85c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/ArmorStand1_11_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity; import net.minecraft.server.v1_11_R1.EntityArmorStand; import net.minecraft.server.v1_11_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_11_R1 extends EntityLiving1_11_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Entity1_11_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Entity1_11_R1.java index f8209e0..a576851 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Entity1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_11_R1.PlayerConnection; import net.minecraft.server.v1_11_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_11_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/EntityLiving1_11_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/EntityLiving1_11_R1.java index 997a931..94dc7ec 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/EntityLiving1_11_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity; import net.minecraft.server.v1_11_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_11_R1 extends Entity1_11_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Player1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Player1_11_R1.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Player1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Player1_11_R1.java index 1507cf0..0465baa 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/entity/Player1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/entity/Player1_11_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EnumItemSlot; @@ -32,17 +32,17 @@ import net.minecraft.server.v1_11_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_11_R1.PacketPlayOutTitle; import net.minecraft.server.v1_11_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_11_R1.PlayerConnection; import net.minecraft.server.v1_11_R1.WorldServer; @@ -151,7 +151,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/reflection/NmsReflection1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/reflection/NmsReflection1_11_R1.java new file mode 100644 index 0000000..36012d0 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/reflection/NmsReflection1_11_R1.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.reflection; + +import net.minecraft.server.v1_11_R1.NBTTagEnd; +import net.minecraft.server.v1_11_R1.NBTTagList; +import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_11_R1 extends ClassLookups { + + public static NmsReflection1_11_R1 INSTANCE = new NmsReflection1_11_R1(); + + private NmsReflection1_11_R1() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/BlockTools1_11_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/BlockTools1_11_R1.java index 2305684..029f1d4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/BlockTools1_11_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_11_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_11_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_11_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/ServerTools1_11_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/ServerTools1_11_R1.java index 2d240ad..a57cdfd 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/ServerTools1_11_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_11_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.wrapper.ConsoleReaderWrapper1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_11_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_11_R1 getConsole() { + return ConsoleReaderWrapper1_11_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/SkinTools1_11_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/SkinTools1_11_R1.java index 6207436..6539288 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/tools/SkinTools1_11_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.tools; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_11_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/utils/EntityConstructors1_11_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/utils/EntityConstructors1_11_R1.java index 947ca08..3a2b018 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/utils/EntityConstructors1_11_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_11_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_11_R1.entity.ArmorStand1_11_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.entity.ArmorStand1_11_R1; public abstract class EntityConstructors1_11_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/wrapper/ConsoleReaderWrapper1_11_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/wrapper/ConsoleReaderWrapper1_11_R1.java new file mode 100644 index 0000000..fae0c3a --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_11_R1/wrapper/ConsoleReaderWrapper1_11_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_11_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_11_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_11_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_11_R1 INSTANCE = new ConsoleReaderWrapper1_11_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_11_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/BukkitConversion1_12_R1.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/BukkitConversion1_12_R1.java index 6da5ef7..b3e9809 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/BukkitConversion1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.NBTBase; @@ -39,13 +40,12 @@ import net.minecraft.server.v1_12_R1.NBTTagLongArray; import net.minecraft.server.v1_12_R1.NBTTagShort; import net.minecraft.server.v1_12_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_12_R1 extends BukkitConversion { @@ -99,7 +99,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -133,7 +133,7 @@ public NbtTag fromMinecraftTag(Object raw) { return new NbtIntArray(((NBTTagIntArray) tag).d()); case LONG_ARRAY: return new NbtLongArray( - (long[]) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagLongArray").getFieldValue("value", ((NBTTagLongArray) tag).c())); + (long[]) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagLongArray").getFieldValue(((NBTTagLongArray) tag).c(), "value")); case LIST: return fromMinecraftList(tag); case COMPOUND: @@ -161,7 +161,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -214,12 +214,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/EntityProvider1_12_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/EntityProvider1_12_R1.java index 593fc8c..7348357 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/EntityProvider1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import net.minecraft.server.v1_12_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.utils.EntityConstructors1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.utils.EntityConstructors1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_12_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/PlayerProvider1_12_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/PlayerProvider1_12_R1.java index a12557f..de78a7f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/PlayerProvider1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity.Player1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity.Player1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_12_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/TextureProvider1_12_R1.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/TextureProvider1_12_R1.java index 414681a..623ce0b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/TextureProvider1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -10,21 +10,21 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_12_R1.GameProfileSerializer; import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.NBTTagCompound; import net.minecraft.server.v1_12_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_12_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -37,7 +37,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile(); } @@ -47,13 +47,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -100,7 +100,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/ToolProvider1_12_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/ToolProvider1_12_R1.java index a504669..1c4950e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/ToolProvider1_12_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools.BlockTools1_12_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools.ServerTools1_12_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools.SkinTools1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools.BlockTools1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools.ServerTools1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools.SkinTools1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_12_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/VersionControl1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/VersionControl1_12_R1.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/VersionControl1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/VersionControl1_12_R1.java index 1ddee0f..04fb6ae 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/VersionControl1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/VersionControl1_12_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.reflection.NmsReflection1_12_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.reflection.NmsReflection1_12_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_12_R1 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_12_R1 init() { private final ToolProvider1_12_R1 toolProvider = new ToolProvider1_12_R1(this); private final TextureProvider1_12_R1 textureProvider = new TextureProvider1_12_R1(this); - private final PacketHandler1_12_R1 packetHandler = new PacketHandler1_12_R1(this); private final EntityProvider1_12_R1 entityProvider = new EntityProvider1_12_R1(this); private final PlayerProvider1_12_R1 playerProvider = new PlayerProvider1_12_R1(this); private final BukkitConversion1_12_R1 bukkitConversion = new BukkitConversion1_12_R1(this); private VersionControl1_12_R1() { - NmsReflection1_12_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_12_R1.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_12_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_12_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_12_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/ArmorStand1_12_R1.java similarity index 75% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/ArmorStand1_12_R1.java index 3f27990..f43b5e8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/ArmorStand1_12_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity; import net.minecraft.server.v1_12_R1.EntityArmorStand; import net.minecraft.server.v1_12_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_12_R1 extends EntityLiving1_12_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Entity1_12_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Entity1_12_R1.java index b0bf472..0190559 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Entity1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_12_R1.PlayerConnection; import net.minecraft.server.v1_12_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_12_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/EntityLiving1_12_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/EntityLiving1_12_R1.java index ce184e6..2683f29 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/EntityLiving1_12_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity; import net.minecraft.server.v1_12_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_12_R1 extends Entity1_12_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Player1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Player1_12_R1.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Player1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Player1_12_R1.java index d516e49..925d78a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/entity/Player1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/entity/Player1_12_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_12_R1.EntityPlayer; import net.minecraft.server.v1_12_R1.EnumItemSlot; @@ -32,17 +32,17 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_12_R1.PacketPlayOutTitle; import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_12_R1.PlayerConnection; import net.minecraft.server.v1_12_R1.WorldServer; @@ -151,7 +151,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/reflection/NmsReflection1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/reflection/NmsReflection1_12_R1.java new file mode 100644 index 0000000..7c2794f --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/reflection/NmsReflection1_12_R1.java @@ -0,0 +1,36 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.reflection; + +import net.minecraft.server.v1_12_R1.NBTTagEnd; +import net.minecraft.server.v1_12_R1.NBTTagList; +import net.minecraft.server.v1_12_R1.NBTTagLongArray; +import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_12_R1 extends ClassLookups { + + public static NmsReflection1_12_R1 INSTANCE = new NmsReflection1_12_R1(); + + private NmsReflection1_12_R1() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagLongArray", NBTTagLongArray.class).searchField("value", "b"); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/BlockTools1_12_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/BlockTools1_12_R1.java index e414d4e..043205c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/BlockTools1_12_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_12_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_12_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_12_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/ServerTools1_12_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/ServerTools1_12_R1.java index fd6ec78..a97ade4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/ServerTools1_12_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_12_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.wrapper.ConsoleReaderWrapper1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_12_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_12_R1 getConsole() { + return ConsoleReaderWrapper1_12_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/SkinTools1_12_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/SkinTools1_12_R1.java index e74b954..35524d6 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/tools/SkinTools1_12_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.tools; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_12_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/utils/EntityConstructors1_12_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/utils/EntityConstructors1_12_R1.java index 2039abe..b66060d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/utils/EntityConstructors1_12_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_12_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_12_R1.entity.ArmorStand1_12_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.entity.ArmorStand1_12_R1; public abstract class EntityConstructors1_12_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/wrapper/ConsoleReaderWrapper1_12_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/wrapper/ConsoleReaderWrapper1_12_R1.java new file mode 100644 index 0000000..722fab7 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_12_R1/wrapper/ConsoleReaderWrapper1_12_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_12_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_12_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_12_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_12_R1 INSTANCE = new ConsoleReaderWrapper1_12_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_12_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/BukkitConversion1_13_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/BukkitConversion1_13_R1.java index c49bd09..6d13776 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/BukkitConversion1_13_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; import java.util.Set; import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_13_R1.ItemStack; import net.minecraft.server.v1_13_R1.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_13_R1.NBTTagLongArray; import net.minecraft.server.v1_13_R1.NBTTagShort; import net.minecraft.server.v1_13_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_13_R1 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/EntityProvider1_13_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/EntityProvider1_13_R1.java index 1a8b960..9beb064 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/EntityProvider1_13_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_13_R1.CraftWorld; import net.minecraft.server.v1_13_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.utils.EntityConstructors1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.utils.EntityConstructors1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_13_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/PlayerProvider1_13_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/PlayerProvider1_13_R1.java index 39d6e36..92a3341 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/PlayerProvider1_13_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity.Player1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity.Player1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_13_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/TextureProvider1_13_R1.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/TextureProvider1_13_R1.java index d4c6040..ea5511e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/TextureProvider1_13_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_13_R1.GameProfileSerializer; import net.minecraft.server.v1_13_R1.ItemStack; import net.minecraft.server.v1_13_R1.NBTTagCompound; import net.minecraft.server.v1_13_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_13_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_13_R1(VersionControl1_13_R1 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile(); } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/ToolProvider1_13_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/ToolProvider1_13_R1.java index 84d81c7..1ccbb73 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/ToolProvider1_13_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools.BlockTools1_13_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools.ServerTools1_13_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools.SkinTools1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools.BlockTools1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools.ServerTools1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools.SkinTools1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_13_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/VersionControl1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/VersionControl1_13_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/VersionControl1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/VersionControl1_13_R1.java index 98af121..814999e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/VersionControl1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/VersionControl1_13_R1.java @@ -1,6 +1,6 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_13_R1 extends VersionControl { @@ -12,7 +12,6 @@ public static VersionControl1_13_R1 init() { private final ToolProvider1_13_R1 toolProvider = new ToolProvider1_13_R1(this); private final TextureProvider1_13_R1 textureProvider = new TextureProvider1_13_R1(this); - private final PacketHandler1_13_R1 packetHandler = new PacketHandler1_13_R1(this); private final EntityProvider1_13_R1 entityProvider = new EntityProvider1_13_R1(this); private final PlayerProvider1_13_R1 playerProvider = new PlayerProvider1_13_R1(this); private final BukkitConversion1_13_R1 bukkitConversion = new BukkitConversion1_13_R1(this); @@ -40,12 +39,7 @@ public PlayerProvider1_13_R1 getPlayerProvider() { public TextureProvider1_13_R1 getTextureProvider() { return textureProvider; } - - @Override - public PacketHandler1_13_R1 getPacketHandler() { - return packetHandler; - } - + @Override public BukkitConversion1_13_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/ArmorStand1_13_R1.java similarity index 75% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/ArmorStand1_13_R1.java index a73f3f0..e18f20d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/ArmorStand1_13_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity; import net.minecraft.server.v1_13_R1.EntityArmorStand; import net.minecraft.server.v1_13_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_13_R1 extends EntityLiving1_13_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Entity1_13_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Entity1_13_R1.java index 38653c3..a712aa5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Entity1_13_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -21,8 +21,8 @@ import net.minecraft.server.v1_13_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_13_R1.PlayerConnection; import net.minecraft.server.v1_13_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_13_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/EntityLiving1_13_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/EntityLiving1_13_R1.java index cfc8642..a884037 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/EntityLiving1_13_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity; import net.minecraft.server.v1_13_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_13_R1 extends Entity1_13_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Player1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Player1_13_R1.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Player1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Player1_13_R1.java index 61da9be..d99164d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/entity/Player1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/entity/Player1_13_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -31,17 +31,17 @@ import net.minecraft.server.v1_13_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_13_R1.PacketPlayOutTitle; import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_13_R1.PlayerConnection; import net.minecraft.server.v1_13_R1.WorldServer; @@ -281,7 +281,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/BlockTools1_13_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/BlockTools1_13_R1.java index 014419a..b24b913 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/BlockTools1_13_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_13_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_13_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_13_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/ServerTools1_13_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/ServerTools1_13_R1.java index b44a28b..b8dd087 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/ServerTools1_13_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_13_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.wrapper.ConsoleReaderWrapper1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_13_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_13_R1 getConsole() { + return ConsoleReaderWrapper1_13_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/SkinTools1_13_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/SkinTools1_13_R1.java index 3fdbbdd..79b6e32 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/tools/SkinTools1_13_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.tools; import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_13_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/utils/EntityConstructors1_13_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/utils/EntityConstructors1_13_R1.java index 4fa54ec..1b402c9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/utils/EntityConstructors1_13_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_13_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R1.entity.ArmorStand1_13_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.entity.ArmorStand1_13_R1; public abstract class EntityConstructors1_13_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/wrapper/ConsoleReaderWrapper1_13_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/wrapper/ConsoleReaderWrapper1_13_R1.java new file mode 100644 index 0000000..4849ded --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R1/wrapper/ConsoleReaderWrapper1_13_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_13_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_13_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_13_R1 INSTANCE = new ConsoleReaderWrapper1_13_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_13_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/BukkitConversion1_13_R2.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/BukkitConversion1_13_R2.java index 54dec63..245ec77 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/BukkitConversion1_13_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; import java.util.Set; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_13_R2.ItemStack; import net.minecraft.server.v1_13_R2.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_13_R2.NBTTagLongArray; import net.minecraft.server.v1_13_R2.NBTTagShort; import net.minecraft.server.v1_13_R2.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_13_R2 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/EntityProvider1_13_R2.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/EntityProvider1_13_R2.java index 2fc7d5f..3b0637e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/EntityProvider1_13_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; import net.minecraft.server.v1_13_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.utils.EntityConstructors1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.utils.EntityConstructors1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_13_R2 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/PlayerProvider1_13_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/PlayerProvider1_13_R2.java index 1b5294e..c7bbb65 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/PlayerProvider1_13_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity.Player1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity.Player1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_13_R2 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/TextureProvider1_13_R2.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/TextureProvider1_13_R2.java index 9517867..086f5d3 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/TextureProvider1_13_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_13_R2.GameProfileSerializer; import net.minecraft.server.v1_13_R2.ItemStack; import net.minecraft.server.v1_13_R2.NBTTagCompound; import net.minecraft.server.v1_13_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_13_R2 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R2.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_13_R2.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_13_R2(VersionControl1_13_R2 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile(); } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/ToolProvider1_13_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/ToolProvider1_13_R2.java index 8dff8a0..2b12b9a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/ToolProvider1_13_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools.BlockTools1_13_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools.ServerTools1_13_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools.SkinTools1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools.BlockTools1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools.ServerTools1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools.SkinTools1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_13_R2 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/VersionControl1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/VersionControl1_13_R2.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/VersionControl1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/VersionControl1_13_R2.java index 1818a0c..6f5abd1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/VersionControl1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/VersionControl1_13_R2.java @@ -1,6 +1,6 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_13_R2 extends VersionControl { @@ -12,7 +12,6 @@ public static VersionControl1_13_R2 init() { private final ToolProvider1_13_R2 toolProvider = new ToolProvider1_13_R2(this); private final TextureProvider1_13_R2 textureProvider = new TextureProvider1_13_R2(this); - private final PacketHandler1_13_R2 packetHandler = new PacketHandler1_13_R2(this); private final EntityProvider1_13_R2 entityProvider = new EntityProvider1_13_R2(this); private final PlayerProvider1_13_R2 playerProvider = new PlayerProvider1_13_R2(this); private final BukkitConversion1_13_R2 bukkitConversion = new BukkitConversion1_13_R2(this); @@ -41,11 +40,6 @@ public TextureProvider1_13_R2 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_13_R2 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_13_R2 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/ArmorStand1_13_R2.java similarity index 75% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/ArmorStand1_13_R2.java index 7f8668c..5ceba46 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/ArmorStand1_13_R2.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity; import net.minecraft.server.v1_13_R2.EntityArmorStand; import net.minecraft.server.v1_13_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_13_R2 extends EntityLiving1_13_R2 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Entity1_13_R2.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Entity1_13_R2.java index a839bb1..aa7e80a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Entity1_13_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -21,8 +21,8 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_13_R2.PlayerConnection; import net.minecraft.server.v1_13_R2.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_13_R2 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/EntityLiving1_13_R2.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/EntityLiving1_13_R2.java index 07e7fa6..f8c9dfb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/EntityLiving1_13_R2.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity; import net.minecraft.server.v1_13_R2.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_13_R2 extends Entity1_13_R2 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Player1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Player1_13_R2.java similarity index 90% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Player1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Player1_13_R2.java index ff6c8bd..bb284e1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/entity/Player1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/entity/Player1_13_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -31,17 +31,17 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutRespawn; import net.minecraft.server.v1_13_R2.PacketPlayOutTitle; import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_13_R2.PlayerConnection; import net.minecraft.server.v1_13_R2.WorldServer; @@ -281,7 +281,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/BlockTools1_13_R2.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/BlockTools1_13_R2.java index 1e9a714..e6bddd4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/BlockTools1_13_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_13_R2.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_13_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_13_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/ServerTools1_13_R2.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/ServerTools1_13_R2.java index 728b241..ae4c120 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/ServerTools1_13_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_13_R2.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.wrapper.ConsoleReaderWrapper1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_13_R2 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_13_R2 getConsole() { + return ConsoleReaderWrapper1_13_R2.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/SkinTools1_13_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/SkinTools1_13_R2.java index 83c3c8e..5dab1de 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/tools/SkinTools1_13_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.tools; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_13_R2 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/utils/EntityConstructors1_13_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/utils/EntityConstructors1_13_R2.java index 8e0c2bd..a9449d4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/utils/EntityConstructors1_13_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.utils; import java.util.function.Function; import net.minecraft.server.v1_13_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_13_R2.entity.ArmorStand1_13_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.entity.ArmorStand1_13_R2; public abstract class EntityConstructors1_13_R2 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/wrapper/ConsoleReaderWrapper1_13_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/wrapper/ConsoleReaderWrapper1_13_R2.java new file mode 100644 index 0000000..88e962e --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_13_R2/wrapper/ConsoleReaderWrapper1_13_R2.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_13_R2.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_13_R2.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_13_R2 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_13_R2 INSTANCE = new ConsoleReaderWrapper1_13_R2(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_13_R2() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/BukkitConversion1_14_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/BukkitConversion1_14_R1.java index 6108f80..4154049 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/BukkitConversion1_14_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; import java.util.Set; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_14_R1.NBTTagLongArray; import net.minecraft.server.v1_14_R1.NBTTagShort; import net.minecraft.server.v1_14_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.BukkitContext1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.BukkitType1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.BukkitContext1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.BukkitType1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_14_R1 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new BukkitContext1_14_R1(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new BukkitType1_14_R1<>(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/EntityProvider1_14_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/EntityProvider1_14_R1.java index 480d6ec..4d0555a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/EntityProvider1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import net.minecraft.server.v1_14_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.utils.EntityConstructors1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.utils.EntityConstructors1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_14_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/PlayerProvider1_14_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/PlayerProvider1_14_R1.java index 20e0ab6..772b752 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/PlayerProvider1_14_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity.Player1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity.Player1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_14_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/TextureProvider1_14_R1.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/TextureProvider1_14_R1.java index 2a17d07..4b42cbe 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/TextureProvider1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_14_R1.GameProfileSerializer; import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_14_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_14_R1(VersionControl1_14_R1 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile; } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/ToolProvider1_14_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/ToolProvider1_14_R1.java index 3e3e45a..9efa743 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/ToolProvider1_14_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools.BlockTools1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools.ServerTools1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools.SkinTools1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools.BlockTools1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools.ServerTools1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools.SkinTools1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_14_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/VersionControl1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/VersionControl1_14_R1.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/VersionControl1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/VersionControl1_14_R1.java index a81a340..f097f6c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/VersionControl1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/VersionControl1_14_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.hook.BukkitContainerAdapterHook1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.hook.BukkitContainerAdapterHook1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_14_R1 extends VersionControl { @@ -13,7 +13,6 @@ public static VersionControl1_14_R1 init() { private final ToolProvider1_14_R1 toolProvider = new ToolProvider1_14_R1(this); private final TextureProvider1_14_R1 textureProvider = new TextureProvider1_14_R1(this); - private final PacketHandler1_14_R1 packetHandler = new PacketHandler1_14_R1(this); private final EntityProvider1_14_R1 entityProvider = new EntityProvider1_14_R1(this); private final PlayerProvider1_14_R1 playerProvider = new PlayerProvider1_14_R1(this); private final BukkitConversion1_14_R1 bukkitConversion = new BukkitConversion1_14_R1(this); @@ -42,11 +41,6 @@ public TextureProvider1_14_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_14_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_14_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContainer1_14_R1.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContainer1_14_R1.java index 81f8993..25a915c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContainer1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import java.util.Arrays; import java.util.Optional; @@ -10,12 +10,12 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class BukkitContainer1_14_R1 extends WrappedContainer implements PersistentDataContainer { @@ -70,7 +70,7 @@ public Set getKeys() { @Override public PersistentDataAdapterContext getAdapterContext() { - return getContext(); + return getWrapContext(); } /* @@ -78,8 +78,8 @@ public PersistentDataAdapterContext getAdapterContext() { */ @Override - public BukkitContext1_14_R1 getContext() { - return new BukkitContext1_14_R1(container.getAdapterContext()); + public BukkitContext1_14_R1 getWrapContext() { + return new BukkitContext1_14_R1(container.getContext()); } @Override diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContext1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContext1_14_R1.java new file mode 100644 index 0000000..d5195f4 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitContext1_14_R1.java @@ -0,0 +1,39 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_14_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_14_R1(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_14_R1 newWrapContainer() { + return new BukkitContainer1_14_R1(context.newContainer()); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitKey1_14_R1.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitKey1_14_R1.java index c57165e..a2ca0d8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitKey1_14_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import org.bukkit.NamespacedKey; import org.bukkit.plugin.Plugin; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class BukkitKey1_14_R1 extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitType1_14_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitType1_14_R1.java index 74e4f8c..8ab5c26 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/BukkitType1_14_R1.java @@ -1,24 +1,24 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; -public class BukkitType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> +public class BukkitType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> implements PersistentDataType { - private final DataType type; + private final IDataType type; - public BukkitType1_14_R1(DataType type) { + public BukkitType1_14_R1(IDataType type) { super(type.getPrimitive(), type.getComplex()); this.type = type; } @Override - public DataType getHandle() { + public IDataType getHandle() { return type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SimpleBukkitType1_14_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SimpleBukkitType1_14_R1.java index 1f1e985..ded3c08 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SimpleBukkitType1_14_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public class SimpleBukkitType1_14_R1 implements PersistentDataType { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContainer1_14_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContainer1_14_R1.java index 31759ff..43a2e17 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContainer1_14_R1.java @@ -1,19 +1,21 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class SyntaxContainer1_14_R1 extends WrappedContainer implements IDataContainer { @@ -32,6 +34,11 @@ public PersistentDataContainer getHandle() { public IDataContainer getAsSyntaxContainer() { return new SyntaxContainer1_14_R1(container); } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } /* * @@ -43,22 +50,22 @@ public boolean has(IKey key) { } @Override - public boolean has(String key, DataType type) { + public boolean has(String key, IDataType type) { return has(syntaxKey(key), type); } @Override - public boolean has(IKey key, DataType type) { + public boolean has(IKey key, IDataType type) { return has(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); } @Override - public C get(String key, DataType type) { + public C get(String key, IDataType type) { return get(syntaxKey(key), type); } @Override - public C get(IKey key, DataType type) { + public C get(IKey key, IDataType type) { return get(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); } @@ -73,12 +80,12 @@ public Object get(IKey key) { } @Override - public void set(String key, E value, DataType type) { + public void set(String key, E value, IDataType type) { set(wrappedKey(key), value, WrappedType1_14_R1.wrap(type)); } @Override - public void set(IKey key, E value, DataType type) { + public void set(IKey key, E value, IDataType type) { set(new SyntaxKey(key), value, WrappedType1_14_R1.wrap(type)); } @@ -103,8 +110,8 @@ public Set getKeyspaces() { } @Override - public DataAdapterContext getAdapterContext() { - return getContext(); + public IDataAdapterContext getContext() { + return getWrapContext(); } /* @@ -112,7 +119,7 @@ public DataAdapterContext getAdapterContext() { */ @Override - public SyntaxContext1_14_R1 getContext() { + public SyntaxContext1_14_R1 getWrapContext() { return new SyntaxContext1_14_R1(container.getAdapterContext()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContext1_14_R1.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContext1_14_R1.java index 91cebbc..68d310b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxContext1_14_R1.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class SyntaxContext1_14_R1 extends WrappedContext implements PersistentDataAdapterContext { @@ -26,12 +26,12 @@ public PersistentDataContainer newPersistentDataContainer() { } @Override - public IDataContainer newDataContainer() { + public IDataContainer newContainer() { return newContainer(); } @Override - public SyntaxContainer1_14_R1 newContainer() { + public SyntaxContainer1_14_R1 newWrapContainer() { return new SyntaxContainer1_14_R1(context.newPersistentDataContainer()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxType1_14_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxType1_14_R1.java index 31b24d5..3135a14 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/SyntaxType1_14_R1.java @@ -1,15 +1,15 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SyntaxType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> - implements DataType { + implements IDataType { private final PersistentDataType type; @@ -48,12 +48,12 @@ public Class getPrimitive() { } @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { return wrapToPrimitive(complex, new BukkitContext1_14_R1(context)); } @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { return wrapToComplex(primitive, new BukkitContext1_14_R1(context)); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/WrappedType1_14_R1.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/WrappedType1_14_R1.java index 7540ba7..a0f61a8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/WrappedType1_14_R1.java @@ -1,14 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data; import java.util.Arrays; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public abstract class WrappedType1_14_R1 implements WrapType { @@ -139,7 +139,7 @@ protected static int internalState(Class clazz) { return 0; } - public static BukkitType1_14_R1 wrap(DataType type) { + public static BukkitType1_14_R1 wrap(IDataType type) { return new BukkitType1_14_R1<>(type); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java index acad01a..5541f61 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/data/hook/BukkitContainerAdapterHook1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.hook; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.hook; import java.util.HashMap; import java.util.Map; @@ -10,17 +10,18 @@ import org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_14_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.BukkitContainer1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.SyntaxContainer1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.BukkitContainer1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.SyntaxContainer1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; @SuppressWarnings({ "rawtypes", @@ -30,11 +31,11 @@ public final class BukkitContainerAdapterHook1_14_R1 { private static final BukkitContainerAdapterHook1_14_R1 HOOK = new BukkitContainerAdapterHook1_14_R1(); - private final AbstractReflect registryRef = new Reflect(CraftPersistentDataTypeRegistry.class) + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) .searchField("adapters", "adapters") .searchField("function", "CREATE_ADAPTER"); - private final AbstractReflect entityRef = new Reflect(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); private BukkitContainerAdapterHook1_14_R1() {} @@ -46,7 +47,7 @@ private CraftPersistentDataTypeRegistry getEntityRegistry() { private void uninjectAll() { for (CraftPersistentDataTypeRegistry registry : map.keySet()) { - Map adapters = (Map) registryRef.getFieldValue("adapters", registry); + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); adapters.remove(BukkitContainer1_14_R1.class); adapters.remove(SyntaxContainer1_14_R1.class); registryRef.setFieldValue(registry, "function", map.get(registry)); @@ -58,8 +59,8 @@ private void inject(CraftPersistentDataTypeRegistry registry) { if (map.containsKey(registry)) { return; } - map.put(registry, (Function) registryRef.getFieldValue("function", registry)); - Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").getReturnType(), (Class) clazz); + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); registryRef.setFieldValue(registry, "function", function); } @@ -89,7 +90,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } if (handle instanceof IDataContainer) { if (handle instanceof NbtContainer) { - return (NBTTagCompound) VersionControl.get().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + return (NBTTagCompound) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); } throw new IllegalArgumentException( "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); @@ -98,7 +99,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } private BukkitContainer1_14_R1 fromPrimitiveSyntax(NBTTagCompound data) { - VersionControl control = VersionControl.get(); + VersionControl control = VersionCompatProvider.get().getControl(); NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); container.fromNbt(compound); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/ArmorStand1_14_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/ArmorStand1_14_R1.java index ff6b523..3c7959e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/ArmorStand1_14_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity; import net.minecraft.server.v1_14_R1.EntityArmorStand; import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_14_R1 extends EntityLiving1_14_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Entity1_14_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Entity1_14_R1.java index 9a62cbc..9bcc628 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Entity1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_14_R1.PlayerConnection; import net.minecraft.server.v1_14_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_14_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/EntityLiving1_14_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/EntityLiving1_14_R1.java index cd3db27..886b5b2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/EntityLiving1_14_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity; import net.minecraft.server.v1_14_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_14_R1 extends Entity1_14_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Player1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Player1_14_R1.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Player1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Player1_14_R1.java index 3e26d72..91255bd 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/entity/Player1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/entity/Player1_14_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -31,16 +31,16 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_14_R1.PacketPlayOutTitle; import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.data.SyntaxContainer1_14_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.data.SyntaxContainer1_14_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_14_R1.PlayerConnection; public class Player1_14_R1 extends EntityLiving1_14_R1 implements NmsPlayer { @@ -277,7 +277,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/BlockTools1_14_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/BlockTools1_14_R1.java index 38e97df..3b452bf 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/BlockTools1_14_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_14_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_14_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_14_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.gameProfile.getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/ServerTools1_14_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/ServerTools1_14_R1.java index 2b3345b..4bfa15e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/ServerTools1_14_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_14_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.wrapper.ConsoleReaderWrapper1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_14_R1 extends ServerTools { @@ -18,10 +18,9 @@ public String getMotd() { return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); } - @SuppressWarnings("resource") @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_14_R1 getConsole() { + return ConsoleReaderWrapper1_14_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/SkinTools1_14_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/SkinTools1_14_R1.java index 64e5e34..aec8e00 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/tools/SkinTools1_14_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.tools; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_14_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/utils/EntityConstructors1_14_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/utils/EntityConstructors1_14_R1.java index 54a0d98..ca18482 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/utils/EntityConstructors1_14_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_14_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_14_R1.entity.ArmorStand1_14_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.entity.ArmorStand1_14_R1; public abstract class EntityConstructors1_14_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/wrapper/ConsoleReaderWrapper1_14_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/wrapper/ConsoleReaderWrapper1_14_R1.java new file mode 100644 index 0000000..5ae6514 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_14_R1/wrapper/ConsoleReaderWrapper1_14_R1.java @@ -0,0 +1,49 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_14_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_14_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_14_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_14_R1 INSTANCE = new ConsoleReaderWrapper1_14_R1(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_14_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/BukkitConversion1_15_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/BukkitConversion1_15_R1.java index 0726b39..454cc21 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/BukkitConversion1_15_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; import java.util.Set; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_15_R1.ItemStack; import net.minecraft.server.v1_15_R1.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_15_R1.NBTTagLongArray; import net.minecraft.server.v1_15_R1.NBTTagShort; import net.minecraft.server.v1_15_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.BukkitContext1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.BukkitType1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.BukkitContext1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.BukkitType1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_15_R1 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new BukkitContext1_15_R1(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new BukkitType1_15_R1<>(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/EntityProvider1_15_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/EntityProvider1_15_R1.java index 49e7ed4..05f7b59 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/EntityProvider1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import net.minecraft.server.v1_15_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.utils.EntityConstructors1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.utils.EntityConstructors1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_15_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/PlayerProvider1_15_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/PlayerProvider1_15_R1.java index 4b49a0e..e41e5af 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/PlayerProvider1_15_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity.Player1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity.Player1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_15_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/TextureProvider1_15_R1.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/TextureProvider1_15_R1.java index d9e2cb3..d02bafc 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/TextureProvider1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_15_R1.GameProfileSerializer; import net.minecraft.server.v1_15_R1.ItemStack; import net.minecraft.server.v1_15_R1.NBTTagCompound; import net.minecraft.server.v1_15_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_15_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_15_R1(VersionControl1_15_R1 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile; } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/ToolProvider1_15_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/ToolProvider1_15_R1.java index 14c0f0b..87d30c4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/ToolProvider1_15_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools.BlockTools1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools.ServerTools1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools.SkinTools1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools.BlockTools1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools.ServerTools1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools.SkinTools1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_15_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/VersionControl1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/VersionControl1_15_R1.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/VersionControl1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/VersionControl1_15_R1.java index 5a5106b..60299ae 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/VersionControl1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/VersionControl1_15_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.hook.BukkitContainerAdapterHook1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.hook.BukkitContainerAdapterHook1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_15_R1 extends VersionControl { @@ -13,7 +13,6 @@ public static VersionControl1_15_R1 init() { private final ToolProvider1_15_R1 toolProvider = new ToolProvider1_15_R1(this); private final TextureProvider1_15_R1 textureProvider = new TextureProvider1_15_R1(this); - private final PacketHandler1_15_R1 packetHandler = new PacketHandler1_15_R1(this); private final EntityProvider1_15_R1 entityProvider = new EntityProvider1_15_R1(this); private final PlayerProvider1_15_R1 playerProvider = new PlayerProvider1_15_R1(this); private final BukkitConversion1_15_R1 bukkitConversion = new BukkitConversion1_15_R1(this); @@ -42,11 +41,6 @@ public TextureProvider1_15_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_15_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_15_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContainer1_15_R1.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContainer1_15_R1.java index a4b3817..b06a248 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContainer1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import java.util.Arrays; import java.util.Optional; @@ -10,12 +10,12 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class BukkitContainer1_15_R1 extends WrappedContainer implements PersistentDataContainer { @@ -70,7 +70,7 @@ public Set getKeys() { @Override public PersistentDataAdapterContext getAdapterContext() { - return getContext(); + return getWrapContext(); } /* @@ -78,8 +78,8 @@ public PersistentDataAdapterContext getAdapterContext() { */ @Override - public BukkitContext1_15_R1 getContext() { - return new BukkitContext1_15_R1(container.getAdapterContext()); + public BukkitContext1_15_R1 getWrapContext() { + return new BukkitContext1_15_R1(container.getContext()); } @Override diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContext1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContext1_15_R1.java new file mode 100644 index 0000000..adf112c --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitContext1_15_R1.java @@ -0,0 +1,39 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_15_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_15_R1(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_15_R1 newWrapContainer() { + return new BukkitContainer1_15_R1(context.newContainer()); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitKey1_15_R1.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitKey1_15_R1.java index bf849e4..e05451d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitKey1_15_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import org.bukkit.NamespacedKey; import org.bukkit.plugin.Plugin; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class BukkitKey1_15_R1 extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitType1_15_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitType1_15_R1.java index 2a64e11..f02ddb9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/BukkitType1_15_R1.java @@ -1,24 +1,24 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; -public class BukkitType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> +public class BukkitType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> implements PersistentDataType { - private final DataType type; + private final IDataType type; - public BukkitType1_15_R1(DataType type) { + public BukkitType1_15_R1(IDataType type) { super(type.getPrimitive(), type.getComplex()); this.type = type; } @Override - public DataType getHandle() { + public IDataType getHandle() { return type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SimpleBukkitType1_15_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SimpleBukkitType1_15_R1.java index 6b8bfc1..5067321 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SimpleBukkitType1_15_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public class SimpleBukkitType1_15_R1 implements PersistentDataType { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContainer1_15_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContainer1_15_R1.java index a391fe0..8a43ede 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContainer1_15_R1.java @@ -1,19 +1,21 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class SyntaxContainer1_15_R1 extends WrappedContainer implements IDataContainer { @@ -32,6 +34,11 @@ public PersistentDataContainer getHandle() { public IDataContainer getAsSyntaxContainer() { return new SyntaxContainer1_15_R1(container); } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } /* * @@ -43,22 +50,22 @@ public boolean has(IKey key) { } @Override - public boolean has(String key, DataType type) { + public boolean has(String key, IDataType type) { return has(syntaxKey(key), type); } @Override - public boolean has(IKey key, DataType type) { + public boolean has(IKey key, IDataType type) { return has(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); } @Override - public C get(String key, DataType type) { + public C get(String key, IDataType type) { return get(syntaxKey(key), type); } @Override - public C get(IKey key, DataType type) { + public C get(IKey key, IDataType type) { return get(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); } @@ -73,12 +80,12 @@ public Object get(IKey key) { } @Override - public void set(String key, E value, DataType type) { + public void set(String key, E value, IDataType type) { set(wrappedKey(key), value, WrappedType1_15_R1.wrap(type)); } @Override - public void set(IKey key, E value, DataType type) { + public void set(IKey key, E value, IDataType type) { set(new SyntaxKey(key), value, WrappedType1_15_R1.wrap(type)); } @@ -103,8 +110,8 @@ public Set getKeyspaces() { } @Override - public DataAdapterContext getAdapterContext() { - return getContext(); + public IDataAdapterContext getContext() { + return getWrapContext(); } /* @@ -112,7 +119,7 @@ public DataAdapterContext getAdapterContext() { */ @Override - public SyntaxContext1_15_R1 getContext() { + public SyntaxContext1_15_R1 getWrapContext() { return new SyntaxContext1_15_R1(container.getAdapterContext()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContext1_15_R1.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContext1_15_R1.java index c7cbb1b..9c19bf8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxContext1_15_R1.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class SyntaxContext1_15_R1 extends WrappedContext implements PersistentDataAdapterContext { @@ -26,12 +26,12 @@ public PersistentDataContainer newPersistentDataContainer() { } @Override - public IDataContainer newDataContainer() { + public IDataContainer newContainer() { return newContainer(); } @Override - public SyntaxContainer1_15_R1 newContainer() { + public SyntaxContainer1_15_R1 newWrapContainer() { return new SyntaxContainer1_15_R1(context.newPersistentDataContainer()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxType1_15_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxType1_15_R1.java index d6eaf1d..e8c8624 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/SyntaxType1_15_R1.java @@ -1,15 +1,15 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SyntaxType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> - implements DataType { + implements IDataType { private final PersistentDataType type; @@ -48,12 +48,12 @@ public Class getPrimitive() { } @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { return wrapToPrimitive(complex, new BukkitContext1_15_R1(context)); } @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { return wrapToComplex(primitive, new BukkitContext1_15_R1(context)); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/WrappedType1_15_R1.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/WrappedType1_15_R1.java index 1497921..b73c72c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/WrappedType1_15_R1.java @@ -1,14 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data; import java.util.Arrays; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public abstract class WrappedType1_15_R1 implements WrapType { @@ -139,7 +139,7 @@ protected static int internalState(Class clazz) { return 0; } - public static BukkitType1_15_R1 wrap(DataType type) { + public static BukkitType1_15_R1 wrap(IDataType type) { return new BukkitType1_15_R1<>(type); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java index 2161dba..236deb4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/data/hook/BukkitContainerAdapterHook1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.hook; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.hook; import java.util.HashMap; import java.util.Map; @@ -10,17 +10,18 @@ import org.bukkit.craftbukkit.v1_15_R1.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_15_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.BukkitContainer1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.SyntaxContainer1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.BukkitContainer1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.SyntaxContainer1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; @SuppressWarnings({ "rawtypes", @@ -30,11 +31,11 @@ public final class BukkitContainerAdapterHook1_15_R1 { private static final BukkitContainerAdapterHook1_15_R1 HOOK = new BukkitContainerAdapterHook1_15_R1(); - private final AbstractReflect registryRef = new Reflect(CraftPersistentDataTypeRegistry.class) + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) .searchField("adapters", "adapters") .searchField("function", "CREATE_ADAPTER"); - private final AbstractReflect entityRef = new Reflect(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); private BukkitContainerAdapterHook1_15_R1() {} @@ -46,7 +47,7 @@ private CraftPersistentDataTypeRegistry getEntityRegistry() { private void uninjectAll() { for (CraftPersistentDataTypeRegistry registry : map.keySet()) { - Map adapters = (Map) registryRef.getFieldValue("adapters", registry); + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); adapters.remove(BukkitContainer1_15_R1.class); adapters.remove(SyntaxContainer1_15_R1.class); registryRef.setFieldValue(registry, "function", map.get(registry)); @@ -58,8 +59,8 @@ private void inject(CraftPersistentDataTypeRegistry registry) { if (map.containsKey(registry)) { return; } - map.put(registry, (Function) registryRef.getFieldValue("function", registry)); - Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").getReturnType(), (Class) clazz); + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); registryRef.setFieldValue(registry, "function", function); } @@ -89,7 +90,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } if (handle instanceof IDataContainer) { if (handle instanceof NbtContainer) { - return (NBTTagCompound) VersionControl.get().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + return (NBTTagCompound) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); } throw new IllegalArgumentException( "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); @@ -98,7 +99,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } private BukkitContainer1_15_R1 fromPrimitiveSyntax(NBTTagCompound data) { - VersionControl control = VersionControl.get(); + VersionControl control = VersionCompatProvider.get().getControl(); NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); container.fromNbt(compound); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/ArmorStand1_15_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/ArmorStand1_15_R1.java index 8d4a61c..dc9cf47 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/ArmorStand1_15_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity; import net.minecraft.server.v1_15_R1.EntityArmorStand; import net.minecraft.server.v1_15_R1.EntityTypes; import net.minecraft.server.v1_15_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_15_R1 extends EntityLiving1_15_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Entity1_15_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Entity1_15_R1.java index 7b8d3cd..1ae91da 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Entity1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_15_R1.PlayerConnection; import net.minecraft.server.v1_15_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_15_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/EntityLiving1_15_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/EntityLiving1_15_R1.java index 1fce472..d4c5a6f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/EntityLiving1_15_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity; import net.minecraft.server.v1_15_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_15_R1 extends Entity1_15_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Player1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Player1_15_R1.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Player1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Player1_15_R1.java index 5fd9030..7b9e9f4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/entity/Player1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/entity/Player1_15_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -31,16 +31,16 @@ import net.minecraft.server.v1_15_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_15_R1.PacketPlayOutTitle; import net.minecraft.server.v1_15_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.data.SyntaxContainer1_15_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.data.SyntaxContainer1_15_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_15_R1.PlayerConnection; public class Player1_15_R1 extends EntityLiving1_15_R1 implements NmsPlayer { @@ -277,7 +277,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/BlockTools1_15_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/BlockTools1_15_R1.java index c9c22d5..bfdf2a2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/BlockTools1_15_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_15_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_15_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_15_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.gameProfile.getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/ServerTools1_15_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/ServerTools1_15_R1.java index 6679123..1c9c05e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/ServerTools1_15_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.wrapper.ConsoleReaderWrapper1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_15_R1 extends ServerTools { @@ -18,10 +18,9 @@ public String getMotd() { return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); } - @SuppressWarnings("resource") @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_15_R1 getConsole() { + return ConsoleReaderWrapper1_15_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/SkinTools1_15_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/SkinTools1_15_R1.java index 2cf4e06..c016962 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/tools/SkinTools1_15_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.tools; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_15_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/utils/EntityConstructors1_15_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/utils/EntityConstructors1_15_R1.java index 19a3e0e..377f198 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/utils/EntityConstructors1_15_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_15_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_15_R1.entity.ArmorStand1_15_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.entity.ArmorStand1_15_R1; public abstract class EntityConstructors1_15_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/wrapper/ConsoleReaderWrapper1_15_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/wrapper/ConsoleReaderWrapper1_15_R1.java new file mode 100644 index 0000000..d941580 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_15_R1/wrapper/ConsoleReaderWrapper1_15_R1.java @@ -0,0 +1,49 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_15_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_15_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_15_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_15_R1 INSTANCE = new ConsoleReaderWrapper1_15_R1(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_15_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/BukkitConversion1_16_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/BukkitConversion1_16_R1.java index 600a9ef..65577d0 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/BukkitConversion1_16_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; import java.util.Set; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R1.ItemStack; import net.minecraft.server.v1_16_R1.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_16_R1.NBTTagLongArray; import net.minecraft.server.v1_16_R1.NBTTagShort; import net.minecraft.server.v1_16_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.BukkitContext1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.BukkitType1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.BukkitContext1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.BukkitType1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_16_R1 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new BukkitContext1_16_R1(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new BukkitType1_16_R1<>(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/EntityProvider1_16_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/EntityProvider1_16_R1.java index f8c37ce..a052d49 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/EntityProvider1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; import net.minecraft.server.v1_16_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.utils.EntityConstructors1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.utils.EntityConstructors1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_16_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/PlayerProvider1_16_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/PlayerProvider1_16_R1.java index e51bb5f..f7ca594 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/PlayerProvider1_16_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity.Player1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity.Player1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_16_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/TextureProvider1_16_R1.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/TextureProvider1_16_R1.java index 95055de..91a23c1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/TextureProvider1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R1.GameProfileSerializer; import net.minecraft.server.v1_16_R1.ItemStack; import net.minecraft.server.v1_16_R1.NBTTagCompound; import net.minecraft.server.v1_16_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_16_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_16_R1(VersionControl1_16_R1 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile; } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/ToolProvider1_16_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/ToolProvider1_16_R1.java index 464f2cc..4ec592c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/ToolProvider1_16_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools.BlockTools1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools.ServerTools1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools.SkinTools1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools.BlockTools1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools.ServerTools1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools.SkinTools1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_16_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/VersionControl1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/VersionControl1_16_R1.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/VersionControl1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/VersionControl1_16_R1.java index f154084..f5e434a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/VersionControl1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/VersionControl1_16_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.hook.BukkitContainerAdapterHook1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.hook.BukkitContainerAdapterHook1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_16_R1 extends VersionControl { @@ -13,7 +13,6 @@ public static VersionControl1_16_R1 init() { private final ToolProvider1_16_R1 toolProvider = new ToolProvider1_16_R1(this); private final TextureProvider1_16_R1 textureProvider = new TextureProvider1_16_R1(this); - private final PacketHandler1_16_R1 packetHandler = new PacketHandler1_16_R1(this); private final EntityProvider1_16_R1 entityProvider = new EntityProvider1_16_R1(this); private final PlayerProvider1_16_R1 playerProvider = new PlayerProvider1_16_R1(this); private final BukkitConversion1_16_R1 bukkitConversion = new BukkitConversion1_16_R1(this); @@ -42,11 +41,6 @@ public TextureProvider1_16_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_16_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_16_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContainer1_16_R1.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContainer1_16_R1.java index bd7d1c2..8cd64d0 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContainer1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import java.util.Arrays; import java.util.Optional; @@ -10,12 +10,12 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class BukkitContainer1_16_R1 extends WrappedContainer implements PersistentDataContainer { @@ -71,7 +71,7 @@ public Set getKeys() { @Override public PersistentDataAdapterContext getAdapterContext() { - return getContext(); + return getWrapContext(); } /* @@ -79,8 +79,8 @@ public PersistentDataAdapterContext getAdapterContext() { */ @Override - public BukkitContext1_16_R1 getContext() { - return new BukkitContext1_16_R1(container.getAdapterContext()); + public BukkitContext1_16_R1 getWrapContext() { + return new BukkitContext1_16_R1(container.getContext()); } @Override diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContext1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContext1_16_R1.java new file mode 100644 index 0000000..6289141 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitContext1_16_R1.java @@ -0,0 +1,39 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_16_R1 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_16_R1(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_16_R1 newWrapContainer() { + return new BukkitContainer1_16_R1(context.newContainer()); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitKey1_16_R1.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitKey1_16_R1.java index c965caf..cf8e934 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitKey1_16_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import org.bukkit.NamespacedKey; import org.bukkit.plugin.Plugin; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class BukkitKey1_16_R1 extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitType1_16_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitType1_16_R1.java index c7e397a..53b0a86 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/BukkitType1_16_R1.java @@ -1,24 +1,24 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; -public class BukkitType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> +public class BukkitType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> implements PersistentDataType { - private final DataType type; + private final IDataType type; - public BukkitType1_16_R1(DataType type) { + public BukkitType1_16_R1(IDataType type) { super(type.getPrimitive(), type.getComplex()); this.type = type; } @Override - public DataType getHandle() { + public IDataType getHandle() { return type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SimpleBukkitType1_16_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SimpleBukkitType1_16_R1.java index 10f7b95..0e2fcf2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SimpleBukkitType1_16_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public class SimpleBukkitType1_16_R1 implements PersistentDataType { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContainer1_16_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContainer1_16_R1.java index 162ca03..9af14aa 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContainer1_16_R1.java @@ -1,19 +1,21 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class SyntaxContainer1_16_R1 extends WrappedContainer implements IDataContainer { @@ -32,6 +34,11 @@ public PersistentDataContainer getHandle() { public IDataContainer getAsSyntaxContainer() { return new SyntaxContainer1_16_R1(container); } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } /* * @@ -43,22 +50,22 @@ public boolean has(IKey key) { } @Override - public boolean has(String key, DataType type) { + public boolean has(String key, IDataType type) { return has(syntaxKey(key), type); } @Override - public boolean has(IKey key, DataType type) { + public boolean has(IKey key, IDataType type) { return has(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); } @Override - public C get(String key, DataType type) { + public C get(String key, IDataType type) { return get(syntaxKey(key), type); } @Override - public C get(IKey key, DataType type) { + public C get(IKey key, IDataType type) { return get(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); } @@ -73,12 +80,12 @@ public Object get(IKey key) { } @Override - public void set(String key, E value, DataType type) { + public void set(String key, E value, IDataType type) { set(wrappedKey(key), value, WrappedType1_16_R1.wrap(type)); } @Override - public void set(IKey key, E value, DataType type) { + public void set(IKey key, E value, IDataType type) { set(new SyntaxKey(key), value, WrappedType1_16_R1.wrap(type)); } @@ -103,8 +110,8 @@ public Set getKeyspaces() { } @Override - public DataAdapterContext getAdapterContext() { - return getContext(); + public IDataAdapterContext getContext() { + return getWrapContext(); } /* @@ -112,7 +119,7 @@ public DataAdapterContext getAdapterContext() { */ @Override - public SyntaxContext1_16_R1 getContext() { + public SyntaxContext1_16_R1 getWrapContext() { return new SyntaxContext1_16_R1(container.getAdapterContext()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContext1_16_R1.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContext1_16_R1.java index 8d544d1..e0e13dc 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxContext1_16_R1.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class SyntaxContext1_16_R1 extends WrappedContext implements PersistentDataAdapterContext { @@ -26,12 +26,12 @@ public PersistentDataContainer newPersistentDataContainer() { } @Override - public IDataContainer newDataContainer() { + public IDataContainer newContainer() { return newContainer(); } @Override - public SyntaxContainer1_16_R1 newContainer() { + public SyntaxContainer1_16_R1 newWrapContainer() { return new SyntaxContainer1_16_R1(context.newPersistentDataContainer()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxType1_16_R1.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxType1_16_R1.java index 6a5c2b3..4f0fb07 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/SyntaxType1_16_R1.java @@ -1,15 +1,15 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SyntaxType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> - implements DataType { + implements IDataType { private final PersistentDataType type; @@ -48,12 +48,12 @@ public Class getPrimitive() { } @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { return wrapToPrimitive(complex, new BukkitContext1_16_R1(context)); } @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { return wrapToComplex(primitive, new BukkitContext1_16_R1(context)); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/WrappedType1_16_R1.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/WrappedType1_16_R1.java index 6e8da6a..9c95f97 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/WrappedType1_16_R1.java @@ -1,14 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data; import java.util.Arrays; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public abstract class WrappedType1_16_R1 implements WrapType { @@ -139,7 +139,7 @@ protected static int internalState(Class clazz) { return 0; } - public static BukkitType1_16_R1 wrap(DataType type) { + public static BukkitType1_16_R1 wrap(IDataType type) { return new BukkitType1_16_R1<>(type); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java index e9e404e..26c0bb6 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/data/hook/BukkitContainerAdapterHook1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.hook; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.hook; import java.util.HashMap; import java.util.Map; @@ -10,17 +10,18 @@ import org.bukkit.craftbukkit.v1_16_R1.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.BukkitContainer1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.SyntaxContainer1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.BukkitContainer1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.SyntaxContainer1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; @SuppressWarnings({ "rawtypes", @@ -30,11 +31,11 @@ public final class BukkitContainerAdapterHook1_16_R1 { private static final BukkitContainerAdapterHook1_16_R1 HOOK = new BukkitContainerAdapterHook1_16_R1(); - private final AbstractReflect registryRef = new Reflect(CraftPersistentDataTypeRegistry.class) + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) .searchField("adapters", "adapters") .searchField("function", "CREATE_ADAPTER"); - private final AbstractReflect entityRef = new Reflect(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); private BukkitContainerAdapterHook1_16_R1() {} @@ -46,7 +47,7 @@ private CraftPersistentDataTypeRegistry getEntityRegistry() { private void uninjectAll() { for (CraftPersistentDataTypeRegistry registry : map.keySet()) { - Map adapters = (Map) registryRef.getFieldValue("adapters", registry); + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); adapters.remove(BukkitContainer1_16_R1.class); adapters.remove(SyntaxContainer1_16_R1.class); registryRef.setFieldValue(registry, "function", map.get(registry)); @@ -58,8 +59,8 @@ private void inject(CraftPersistentDataTypeRegistry registry) { if (map.containsKey(registry)) { return; } - map.put(registry, (Function) registryRef.getFieldValue("function", registry)); - Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").getReturnType(), (Class) clazz); + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); registryRef.setFieldValue(registry, "function", function); } @@ -89,7 +90,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } if (handle instanceof IDataContainer) { if (handle instanceof NbtContainer) { - return (NBTTagCompound) VersionControl.get().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + return (NBTTagCompound) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); } throw new IllegalArgumentException( "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); @@ -98,7 +99,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } private BukkitContainer1_16_R1 fromPrimitiveSyntax(NBTTagCompound data) { - VersionControl control = VersionControl.get(); + VersionControl control = VersionCompatProvider.get().getControl(); NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); container.fromNbt(compound); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/ArmorStand1_16_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/ArmorStand1_16_R1.java index 677ca44..36a9ed5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/ArmorStand1_16_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity; import net.minecraft.server.v1_16_R1.EntityArmorStand; import net.minecraft.server.v1_16_R1.EntityTypes; import net.minecraft.server.v1_16_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_16_R1 extends EntityLiving1_16_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Entity1_16_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Entity1_16_R1.java index 0365a06..62159fa 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Entity1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_16_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R1.PlayerConnection; import net.minecraft.server.v1_16_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_16_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/EntityLiving1_16_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/EntityLiving1_16_R1.java index a551056..0e00a74 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/EntityLiving1_16_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity; import net.minecraft.server.v1_16_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_16_R1 extends Entity1_16_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Player1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Player1_16_R1.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Player1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Player1_16_R1.java index 76fb05f..0335c58 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/entity/Player1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/entity/Player1_16_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -34,16 +34,16 @@ import net.minecraft.server.v1_16_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_16_R1.PacketPlayOutTitle; import net.minecraft.server.v1_16_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.data.SyntaxContainer1_16_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.data.SyntaxContainer1_16_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_16_R1.PlayerConnection; import net.minecraft.server.v1_16_R1.WorldServer; @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/BlockTools1_16_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/BlockTools1_16_R1.java index f8a8532..012e4a7 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/BlockTools1_16_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_16_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.gameProfile.getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/ServerTools1_16_R1.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/ServerTools1_16_R1.java index 711dd5f..7238264 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/ServerTools1_16_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_16_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.wrapper.ConsoleReaderWrapper1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_16_R1 extends ServerTools { @@ -18,10 +18,9 @@ public String getMotd() { return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); } - @SuppressWarnings("resource") @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_16_R1 getConsole() { + return ConsoleReaderWrapper1_16_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/SkinTools1_16_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/SkinTools1_16_R1.java index a81ea8a..a47e1fa 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/tools/SkinTools1_16_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.tools; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_16_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/utils/EntityConstructors1_16_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/utils/EntityConstructors1_16_R1.java index 589941c..b9ebf41 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/utils/EntityConstructors1_16_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_16_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R1.entity.ArmorStand1_16_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.entity.ArmorStand1_16_R1; public abstract class EntityConstructors1_16_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/wrapper/ConsoleReaderWrapper1_16_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/wrapper/ConsoleReaderWrapper1_16_R1.java new file mode 100644 index 0000000..3132551 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R1/wrapper/ConsoleReaderWrapper1_16_R1.java @@ -0,0 +1,49 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_16_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_16_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_16_R1 INSTANCE = new ConsoleReaderWrapper1_16_R1(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_16_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/BukkitConversion1_16_R2.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/BukkitConversion1_16_R2.java index 905c0ed..920c01a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/BukkitConversion1_16_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; import java.util.Set; import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R2.ItemStack; import net.minecraft.server.v1_16_R2.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_16_R2.NBTTagLongArray; import net.minecraft.server.v1_16_R2.NBTTagShort; import net.minecraft.server.v1_16_R2.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.BukkitContext1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.BukkitType1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.BukkitContext1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.BukkitType1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_16_R2 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new BukkitContext1_16_R2(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new BukkitType1_16_R2<>(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/EntityProvider1_16_R2.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/EntityProvider1_16_R2.java index 4870db5..01feb08 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/EntityProvider1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; import net.minecraft.server.v1_16_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.utils.EntityConstructors1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.utils.EntityConstructors1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_16_R2 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/PlayerProvider1_16_R2.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/PlayerProvider1_16_R2.java index 726cdb6..10ec0b6 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/PlayerProvider1_16_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity.Player1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity.Player1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_16_R2 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/TextureProvider1_16_R2.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/TextureProvider1_16_R2.java index 6eb514c..cc7d1dc 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/TextureProvider1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R2.GameProfileSerializer; import net.minecraft.server.v1_16_R2.ItemStack; import net.minecraft.server.v1_16_R2.NBTTagCompound; import net.minecraft.server.v1_16_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_16_R2 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_16_R2(VersionControl1_16_R2 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile; } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/ToolProvider1_16_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/ToolProvider1_16_R2.java index 6257519..e8969d9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/ToolProvider1_16_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools.BlockTools1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools.ServerTools1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools.SkinTools1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools.BlockTools1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools.ServerTools1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools.SkinTools1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_16_R2 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/VersionControl1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/VersionControl1_16_R2.java similarity index 77% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/VersionControl1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/VersionControl1_16_R2.java index 143a7dd..c0fab18 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/VersionControl1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/VersionControl1_16_R2.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.hook.BukkitContainerAdapterHook1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.hook.BukkitContainerAdapterHook1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_16_R2 extends VersionControl { @@ -13,7 +13,6 @@ public static VersionControl1_16_R2 init() { private final ToolProvider1_16_R2 toolProvider = new ToolProvider1_16_R2(this); private final TextureProvider1_16_R2 textureProvider = new TextureProvider1_16_R2(this); - private final PacketHandler1_16_R2 packetHandler = new PacketHandler1_16_R2(this); private final EntityProvider1_16_R2 entityProvider = new EntityProvider1_16_R2(this); private final PlayerProvider1_16_R2 playerProvider = new PlayerProvider1_16_R2(this); private final BukkitConversion1_16_R2 bukkitConversion = new BukkitConversion1_16_R2(this); @@ -42,11 +41,6 @@ public TextureProvider1_16_R2 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_16_R2 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_16_R2 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContainer1_16_R2.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContainer1_16_R2.java index 348d61c..6031195 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContainer1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import java.util.Arrays; import java.util.Optional; @@ -10,12 +10,12 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class BukkitContainer1_16_R2 extends WrappedContainer implements PersistentDataContainer { @@ -71,7 +71,7 @@ public Set getKeys() { @Override public PersistentDataAdapterContext getAdapterContext() { - return getContext(); + return getWrapContext(); } /* @@ -79,8 +79,8 @@ public PersistentDataAdapterContext getAdapterContext() { */ @Override - public BukkitContext1_16_R2 getContext() { - return new BukkitContext1_16_R2(container.getAdapterContext()); + public BukkitContext1_16_R2 getWrapContext() { + return new BukkitContext1_16_R2(container.getContext()); } @Override diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContext1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContext1_16_R2.java new file mode 100644 index 0000000..d906b21 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitContext1_16_R2.java @@ -0,0 +1,39 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_16_R2 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_16_R2(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_16_R2 newWrapContainer() { + return new BukkitContainer1_16_R2(context.newContainer()); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitKey1_16_R2.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitKey1_16_R2.java index 0239cdd..ff8a9a4 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitKey1_16_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import org.bukkit.NamespacedKey; import org.bukkit.plugin.Plugin; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class BukkitKey1_16_R2 extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitType1_16_R2.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitType1_16_R2.java index da95a3c..2a4ddff 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/BukkitType1_16_R2.java @@ -1,24 +1,24 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; -public class BukkitType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> +public class BukkitType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> implements PersistentDataType { - private final DataType type; + private final IDataType type; - public BukkitType1_16_R2(DataType type) { + public BukkitType1_16_R2(IDataType type) { super(type.getPrimitive(), type.getComplex()); this.type = type; } @Override - public DataType getHandle() { + public IDataType getHandle() { return type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SimpleBukkitType1_16_R2.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SimpleBukkitType1_16_R2.java index fbc530c..e970778 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SimpleBukkitType1_16_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public class SimpleBukkitType1_16_R2 implements PersistentDataType { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContainer1_16_R2.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContainer1_16_R2.java index f844d9b..da834bf 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContainer1_16_R2.java @@ -1,19 +1,21 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class SyntaxContainer1_16_R2 extends WrappedContainer implements IDataContainer { @@ -32,6 +34,11 @@ public PersistentDataContainer getHandle() { public IDataContainer getAsSyntaxContainer() { return new SyntaxContainer1_16_R2(container); } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } /* * @@ -43,22 +50,22 @@ public boolean has(IKey key) { } @Override - public boolean has(String key, DataType type) { + public boolean has(String key, IDataType type) { return has(syntaxKey(key), type); } @Override - public boolean has(IKey key, DataType type) { + public boolean has(IKey key, IDataType type) { return has(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); } @Override - public C get(String key, DataType type) { + public C get(String key, IDataType type) { return get(syntaxKey(key), type); } @Override - public C get(IKey key, DataType type) { + public C get(IKey key, IDataType type) { return get(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); } @@ -73,12 +80,12 @@ public Object get(IKey key) { } @Override - public void set(String key, E value, DataType type) { + public void set(String key, E value, IDataType type) { set(wrappedKey(key), value, WrappedType1_16_R2.wrap(type)); } @Override - public void set(IKey key, E value, DataType type) { + public void set(IKey key, E value, IDataType type) { set(new SyntaxKey(key), value, WrappedType1_16_R2.wrap(type)); } @@ -103,8 +110,8 @@ public Set getKeyspaces() { } @Override - public DataAdapterContext getAdapterContext() { - return getContext(); + public IDataAdapterContext getContext() { + return getWrapContext(); } /* @@ -112,7 +119,7 @@ public DataAdapterContext getAdapterContext() { */ @Override - public SyntaxContext1_16_R2 getContext() { + public SyntaxContext1_16_R2 getWrapContext() { return new SyntaxContext1_16_R2(container.getAdapterContext()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContext1_16_R2.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContext1_16_R2.java index 25ea05f..a5f00ff 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxContext1_16_R2.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class SyntaxContext1_16_R2 extends WrappedContext implements PersistentDataAdapterContext { @@ -26,12 +26,12 @@ public PersistentDataContainer newPersistentDataContainer() { } @Override - public IDataContainer newDataContainer() { + public IDataContainer newContainer() { return newContainer(); } @Override - public SyntaxContainer1_16_R2 newContainer() { + public SyntaxContainer1_16_R2 newWrapContainer() { return new SyntaxContainer1_16_R2(context.newPersistentDataContainer()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxType1_16_R2.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxType1_16_R2.java index 606d481..898c6b9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/SyntaxType1_16_R2.java @@ -1,15 +1,15 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SyntaxType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> - implements DataType { + implements IDataType { private final PersistentDataType type; @@ -48,12 +48,12 @@ public Class getPrimitive() { } @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { return wrapToPrimitive(complex, new BukkitContext1_16_R2(context)); } @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { return wrapToComplex(primitive, new BukkitContext1_16_R2(context)); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/WrappedType1_16_R2.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/WrappedType1_16_R2.java index f3481af..68b3ceb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/WrappedType1_16_R2.java @@ -1,14 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data; import java.util.Arrays; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public abstract class WrappedType1_16_R2 implements WrapType { @@ -139,7 +139,7 @@ protected static int internalState(Class clazz) { return 0; } - public static BukkitType1_16_R2 wrap(DataType type) { + public static BukkitType1_16_R2 wrap(IDataType type) { return new BukkitType1_16_R2<>(type); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java index 8cf5d64..1e320cb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/data/hook/BukkitContainerAdapterHook1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.hook; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.hook; import java.util.HashMap; import java.util.Map; @@ -10,17 +10,18 @@ import org.bukkit.craftbukkit.v1_16_R2.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R2.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.BukkitContainer1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.SyntaxContainer1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.BukkitContainer1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.SyntaxContainer1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; @SuppressWarnings({ "rawtypes", @@ -30,11 +31,11 @@ public final class BukkitContainerAdapterHook1_16_R2 { private static final BukkitContainerAdapterHook1_16_R2 HOOK = new BukkitContainerAdapterHook1_16_R2(); - private final AbstractReflect registryRef = new Reflect(CraftPersistentDataTypeRegistry.class) + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) .searchField("adapters", "adapters") .searchField("function", "CREATE_ADAPTER"); - private final AbstractReflect entityRef = new Reflect(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); private BukkitContainerAdapterHook1_16_R2() {} @@ -46,7 +47,7 @@ private CraftPersistentDataTypeRegistry getEntityRegistry() { private void uninjectAll() { for (CraftPersistentDataTypeRegistry registry : map.keySet()) { - Map adapters = (Map) registryRef.getFieldValue("adapters", registry); + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); adapters.remove(BukkitContainer1_16_R2.class); adapters.remove(SyntaxContainer1_16_R2.class); registryRef.setFieldValue(registry, "function", map.get(registry)); @@ -58,8 +59,8 @@ private void inject(CraftPersistentDataTypeRegistry registry) { if (map.containsKey(registry)) { return; } - map.put(registry, (Function) registryRef.getFieldValue("function", registry)); - Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").getReturnType(), (Class) clazz); + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); registryRef.setFieldValue(registry, "function", function); } @@ -89,7 +90,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } if (handle instanceof IDataContainer) { if (handle instanceof NbtContainer) { - return (NBTTagCompound) VersionControl.get().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + return (NBTTagCompound) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); } throw new IllegalArgumentException( "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); @@ -98,7 +99,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } private BukkitContainer1_16_R2 fromPrimitiveSyntax(NBTTagCompound data) { - VersionControl control = VersionControl.get(); + VersionControl control = VersionCompatProvider.get().getControl(); NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); container.fromNbt(compound); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/ArmorStand1_16_R2.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/ArmorStand1_16_R2.java index a39a732..42635fc 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/ArmorStand1_16_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity; import net.minecraft.server.v1_16_R2.EntityArmorStand; import net.minecraft.server.v1_16_R2.EntityTypes; import net.minecraft.server.v1_16_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_16_R2 extends EntityLiving1_16_R2 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Entity1_16_R2.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Entity1_16_R2.java index e65fbe7..241386e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Entity1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_16_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R2.PlayerConnection; import net.minecraft.server.v1_16_R2.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_16_R2 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/EntityLiving1_16_R2.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/EntityLiving1_16_R2.java index 5c62ab8..1ffa94a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/EntityLiving1_16_R2.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity; import net.minecraft.server.v1_16_R2.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_16_R2 extends Entity1_16_R2 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Player1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Player1_16_R2.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Player1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Player1_16_R2.java index 194c6f6..075ab58 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/entity/Player1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/entity/Player1_16_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -34,16 +34,16 @@ import net.minecraft.server.v1_16_R2.PacketPlayOutRespawn; import net.minecraft.server.v1_16_R2.PacketPlayOutTitle; import net.minecraft.server.v1_16_R2.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.data.SyntaxContainer1_16_R2; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.data.SyntaxContainer1_16_R2; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_16_R2.PlayerConnection; import net.minecraft.server.v1_16_R2.WorldServer; @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/BlockTools1_16_R2.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/BlockTools1_16_R2.java index b683151..3804321 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/BlockTools1_16_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R2.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_16_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.gameProfile.getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/ServerTools1_16_R2.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/ServerTools1_16_R2.java index 55aa678..426b042 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/ServerTools1_16_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_16_R2.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.wrapper.ConsoleReaderWrapper1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_16_R2 extends ServerTools { @@ -18,10 +18,9 @@ public String getMotd() { return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); } - @SuppressWarnings("resource") @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_16_R2 getConsole() { + return ConsoleReaderWrapper1_16_R2.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/SkinTools1_16_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/SkinTools1_16_R2.java index 9b9f797..003ab81 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/tools/SkinTools1_16_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.tools; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_16_R2 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/utils/EntityConstructors1_16_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/utils/EntityConstructors1_16_R2.java index 3603889..999875e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/utils/EntityConstructors1_16_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.utils; import java.util.function.Function; import net.minecraft.server.v1_16_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R2.entity.ArmorStand1_16_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.entity.ArmorStand1_16_R2; public abstract class EntityConstructors1_16_R2 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/wrapper/ConsoleReaderWrapper1_16_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/wrapper/ConsoleReaderWrapper1_16_R2.java new file mode 100644 index 0000000..edbd08f --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R2/wrapper/ConsoleReaderWrapper1_16_R2.java @@ -0,0 +1,49 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R2.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_16_R2.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_16_R2 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_16_R2 INSTANCE = new ConsoleReaderWrapper1_16_R2(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_16_R2() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/BukkitConversion1_16_R3.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/BukkitConversion1_16_R3.java index 74b3168..d07346f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/BukkitConversion1_16_R3.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; import java.util.Set; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R3.ItemStack; import net.minecraft.server.v1_16_R3.NBTBase; @@ -39,12 +39,12 @@ import net.minecraft.server.v1_16_R3.NBTTagLongArray; import net.minecraft.server.v1_16_R3.NBTTagShort; import net.minecraft.server.v1_16_R3.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.BukkitContext1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.BukkitType1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.BukkitContext1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.BukkitType1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_16_R3 extends BukkitConversion { @@ -206,12 +206,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new BukkitContext1_16_R3(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new BukkitType1_16_R3<>(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/EntityProvider1_16_R3.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/EntityProvider1_16_R3.java index a732afe..bdbcdc3 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/EntityProvider1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import net.minecraft.server.v1_16_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.utils.EntityConstructors1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.utils.EntityConstructors1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_16_R3 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/PlayerProvider1_16_R3.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/PlayerProvider1_16_R3.java index bafd66d..95cf279 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/PlayerProvider1_16_R3.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity.Player1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity.Player1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_16_R3 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/TextureProvider1_16_R3.java similarity index 80% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/TextureProvider1_16_R3.java index d94a2d1..4a2f7a7 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/TextureProvider1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,20 +9,20 @@ import org.bukkit.inventory.meta.SkullMeta; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R3.GameProfileSerializer; import net.minecraft.server.v1_16_R3.ItemStack; import net.minecraft.server.v1_16_R3.NBTTagCompound; import net.minecraft.server.v1_16_R3.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; public class TextureProvider1_16_R3 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMetaSkull") + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); protected TextureProvider1_16_R3(VersionControl1_16_R3 versionControl) { @@ -34,7 +34,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile; } @@ -44,13 +44,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -94,7 +94,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); entitySkull.setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/ToolProvider1_16_R3.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/ToolProvider1_16_R3.java index fe893a4..2e9b1a8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/ToolProvider1_16_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools.BlockTools1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools.ServerTools1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools.SkinTools1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools.BlockTools1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools.ServerTools1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools.SkinTools1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_16_R3 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/VersionControl1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/VersionControl1_16_R3.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/VersionControl1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/VersionControl1_16_R3.java index d1055de..8c5ac69 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/VersionControl1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/VersionControl1_16_R3.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.hook.BukkitContainerAdapterHook1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.hook.BukkitContainerAdapterHook1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_16_R3 extends VersionControl { @@ -13,7 +13,6 @@ public static VersionControl1_16_R3 init() { private final ToolProvider1_16_R3 toolProvider = new ToolProvider1_16_R3(this); private final TextureProvider1_16_R3 textureProvider = new TextureProvider1_16_R3(this); - private final PacketHandler1_16_R3 packetHandler = new PacketHandler1_16_R3(this); private final EntityProvider1_16_R3 entityProvider = new EntityProvider1_16_R3(this); private final PlayerProvider1_16_R3 playerProvider = new PlayerProvider1_16_R3(this); private final BukkitConversion1_16_R3 bukkitConversion = new BukkitConversion1_16_R3(this); @@ -42,11 +41,6 @@ public TextureProvider1_16_R3 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_16_R3 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_16_R3 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContainer1_16_R3.java similarity index 86% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContainer1_16_R3.java index a95aeee..fcde11c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContainer1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import java.util.Arrays; import java.util.Optional; @@ -10,12 +10,12 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class BukkitContainer1_16_R3 extends WrappedContainer implements PersistentDataContainer { @@ -71,7 +71,7 @@ public Set getKeys() { @Override public PersistentDataAdapterContext getAdapterContext() { - return getContext(); + return getWrapContext(); } /* @@ -79,8 +79,8 @@ public PersistentDataAdapterContext getAdapterContext() { */ @Override - public BukkitContext1_16_R3 getContext() { - return new BukkitContext1_16_R3(container.getAdapterContext()); + public BukkitContext1_16_R3 getWrapContext() { + return new BukkitContext1_16_R3(container.getContext()); } @Override diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContext1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContext1_16_R3.java new file mode 100644 index 0000000..ae36749 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitContext1_16_R3.java @@ -0,0 +1,39 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; + +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; + +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; + +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; + +public final class BukkitContext1_16_R3 extends WrappedContext implements PersistentDataAdapterContext { + + private final IDataAdapterContext context; + + public BukkitContext1_16_R3(IDataAdapterContext context) { + this.context = context; + } + + @Override + public IDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newWrapContainer(); + } + + @Override + public IDataContainer newContainer() { + return context.newContainer(); + } + + @Override + public BukkitContainer1_16_R3 newWrapContainer() { + return new BukkitContainer1_16_R3(context.newContainer()); + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitKey1_16_R3.java similarity index 88% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitKey1_16_R3.java index 6f4451d..be4dcc2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitKey1_16_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import org.bukkit.NamespacedKey; import org.bukkit.plugin.Plugin; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; public final class BukkitKey1_16_R3 extends WrappedKey { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitType1_16_R3.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitType1_16_R3.java index 8dce2d2..9bd3f77 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/BukkitType1_16_R3.java @@ -1,24 +1,24 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; -public class BukkitType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> +public class BukkitType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> implements PersistentDataType { - private final DataType type; + private final IDataType type; - public BukkitType1_16_R3(DataType type) { + public BukkitType1_16_R3(IDataType type) { super(type.getPrimitive(), type.getComplex()); this.type = type; } @Override - public DataType getHandle() { + public IDataType getHandle() { return type; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SimpleBukkitType1_16_R3.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SimpleBukkitType1_16_R3.java index bad048e..fd48aac 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SimpleBukkitType1_16_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public class SimpleBukkitType1_16_R3 implements PersistentDataType { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContainer1_16_R3.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContainer1_16_R3.java index ce5e07e..829729a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContainer1_16_R3.java @@ -1,19 +1,21 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterRegistry; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.utils.key.IKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedKey; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SyntaxKey; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedKey; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SyntaxKey; public final class SyntaxContainer1_16_R3 extends WrappedContainer implements IDataContainer { @@ -32,6 +34,11 @@ public PersistentDataContainer getHandle() { public IDataContainer getAsSyntaxContainer() { return new SyntaxContainer1_16_R3(container); } + + @Override + public IDataAdapterRegistry getRegistry() { + return VersionCompatProvider.get().getControl().getDataProvider().getRegistry(); + } /* * @@ -43,22 +50,22 @@ public boolean has(IKey key) { } @Override - public boolean has(String key, DataType type) { + public boolean has(String key, IDataType type) { return has(syntaxKey(key), type); } @Override - public boolean has(IKey key, DataType type) { + public boolean has(IKey key, IDataType type) { return has(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); } @Override - public C get(String key, DataType type) { + public C get(String key, IDataType type) { return get(syntaxKey(key), type); } @Override - public C get(IKey key, DataType type) { + public C get(IKey key, IDataType type) { return get(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); } @@ -73,12 +80,12 @@ public Object get(IKey key) { } @Override - public void set(String key, E value, DataType type) { + public void set(String key, E value, IDataType type) { set(wrappedKey(key), value, WrappedType1_16_R3.wrap(type)); } @Override - public void set(IKey key, E value, DataType type) { + public void set(IKey key, E value, IDataType type) { set(new SyntaxKey(key), value, WrappedType1_16_R3.wrap(type)); } @@ -103,8 +110,8 @@ public Set getKeyspaces() { } @Override - public DataAdapterContext getAdapterContext() { - return getContext(); + public IDataAdapterContext getContext() { + return getWrapContext(); } /* @@ -112,7 +119,7 @@ public DataAdapterContext getAdapterContext() { */ @Override - public SyntaxContext1_16_R3 getContext() { + public SyntaxContext1_16_R3 getWrapContext() { return new SyntaxContext1_16_R3(container.getAdapterContext()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContext1_16_R3.java similarity index 72% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContext1_16_R3.java index 7960bfa..a75b06d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxContext1_16_R3.java @@ -1,11 +1,11 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public final class SyntaxContext1_16_R3 extends WrappedContext implements PersistentDataAdapterContext { @@ -26,12 +26,12 @@ public PersistentDataContainer newPersistentDataContainer() { } @Override - public IDataContainer newDataContainer() { + public IDataContainer newContainer() { return newContainer(); } @Override - public SyntaxContainer1_16_R3 newContainer() { + public SyntaxContainer1_16_R3 newWrapContainer() { return new SyntaxContainer1_16_R3(context.newPersistentDataContainer()); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxType1_16_R3.java similarity index 79% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxType1_16_R3.java index 57cd421..51881f6 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/SyntaxType1_16_R3.java @@ -1,15 +1,15 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; public class SyntaxType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> - implements DataType { + implements IDataType { private final PersistentDataType type; @@ -48,12 +48,12 @@ public Class getPrimitive() { } @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { + public P0 toPrimitive(IDataAdapterContext context, C0 complex) { return wrapToPrimitive(complex, new BukkitContext1_16_R3(context)); } @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + public C0 fromPrimitive(IDataAdapterContext context, P0 primitive) { return wrapToComplex(primitive, new BukkitContext1_16_R3(context)); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/WrappedType1_16_R3.java similarity index 94% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/WrappedType1_16_R3.java index 6ca30a8..7074c5f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/WrappedType1_16_R3.java @@ -1,14 +1,14 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data; import java.util.Arrays; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; public abstract class WrappedType1_16_R3 implements WrapType { @@ -139,7 +139,7 @@ protected static int internalState(Class clazz) { return 0; } - public static BukkitType1_16_R3 wrap(DataType type) { + public static BukkitType1_16_R3 wrap(IDataType type) { return new BukkitType1_16_R3<>(type); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java similarity index 76% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java index c1bca14..bceb96f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/data/hook/BukkitContainerAdapterHook1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.hook; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.hook; import java.util.HashMap; import java.util.Map; @@ -10,17 +10,18 @@ import org.bukkit.craftbukkit.v1_16_R3.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.persistence.PersistentDataContainer; -import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.data.container.nbt.NbtContainer; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataContainer; +import net.sourcewriters.minecraft.vcompat.data.nbt.NbtContainer; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R3.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.BukkitContainer1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.SyntaxContainer1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.BukkitContainer1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.SyntaxContainer1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; @SuppressWarnings({ "rawtypes", @@ -30,11 +31,11 @@ public final class BukkitContainerAdapterHook1_16_R3 { private static final BukkitContainerAdapterHook1_16_R3 HOOK = new BukkitContainerAdapterHook1_16_R3(); - private final AbstractReflect registryRef = new Reflect(CraftPersistentDataTypeRegistry.class) + private final ClassLookup registryRef = ClassLookup.of(CraftPersistentDataTypeRegistry.class) .searchMethod("create", "createAdapter", Class.class, Class.class, Function.class, Function.class) .searchField("adapters", "adapters") .searchField("function", "CREATE_ADAPTER"); - private final AbstractReflect entityRef = new Reflect(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); + private final ClassLookup entityRef = ClassLookup.of(CraftEntity.class).searchField("registry", "DATA_TYPE_REGISTRY"); private BukkitContainerAdapterHook1_16_R3() {} @@ -46,7 +47,7 @@ private CraftPersistentDataTypeRegistry getEntityRegistry() { private void uninjectAll() { for (CraftPersistentDataTypeRegistry registry : map.keySet()) { - Map adapters = (Map) registryRef.getFieldValue("adapters", registry); + Map adapters = (Map) registryRef.getFieldValue(registry, "adapters"); adapters.remove(BukkitContainer1_16_R3.class); adapters.remove(SyntaxContainer1_16_R3.class); registryRef.setFieldValue(registry, "function", map.get(registry)); @@ -58,8 +59,8 @@ private void inject(CraftPersistentDataTypeRegistry registry) { if (map.containsKey(registry)) { return; } - map.put(registry, (Function) registryRef.getFieldValue("function", registry)); - Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").getReturnType(), (Class) clazz); + map.put(registry, (Function) registryRef.getFieldValue(registry, "function")); + Function function = clazz -> createAdapter(registry, registryRef.getMethod("create").type().returnType(), (Class) clazz); registryRef.setFieldValue(registry, "function", function); } @@ -89,7 +90,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } if (handle instanceof IDataContainer) { if (handle instanceof NbtContainer) { - return (NBTTagCompound) VersionControl.get().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); + return (NBTTagCompound) VersionCompatProvider.get().getControl().getBukkitConversion().toMinecraftCompound(((NbtContainer) handle).asNbt()); } throw new IllegalArgumentException( "Expected 'CraftPersistentDataContainer' got '" + handle.getClass().getSimpleName() + " instead'!"); @@ -98,7 +99,7 @@ private NBTTagCompound toPrimitive(WrappedContainer input) { } private BukkitContainer1_16_R3 fromPrimitiveSyntax(NBTTagCompound data) { - VersionControl control = VersionControl.get(); + VersionControl control = VersionCompatProvider.get().getControl(); NbtContainer container = new NbtContainer(control.getDataProvider().getRegistry()); NbtCompound compound = control.getBukkitConversion().fromMinecraftCompound(data); container.fromNbt(compound); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/ArmorStand1_16_R3.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/ArmorStand1_16_R3.java index 4553418..a0ba43f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/ArmorStand1_16_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity; import net.minecraft.server.v1_16_R3.EntityArmorStand; import net.minecraft.server.v1_16_R3.EntityTypes; import net.minecraft.server.v1_16_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_16_R3 extends EntityLiving1_16_R3 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Entity1_16_R3.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Entity1_16_R3.java index 01d37be..199e019 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Entity1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R3.PlayerConnection; import net.minecraft.server.v1_16_R3.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_16_R3 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/EntityLiving1_16_R3.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/EntityLiving1_16_R3.java index 26d6638..204f165 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/EntityLiving1_16_R3.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity; import net.minecraft.server.v1_16_R3.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_16_R3 extends Entity1_16_R3 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Player1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Player1_16_R3.java similarity index 91% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Player1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Player1_16_R3.java index 10834fa..8398bf1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/entity/Player1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/entity/Player1_16_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity; import java.util.ArrayList; import java.util.Collections; @@ -34,16 +34,16 @@ import net.minecraft.server.v1_16_R3.PacketPlayOutRespawn; import net.minecraft.server.v1_16_R3.PacketPlayOutTitle; import net.minecraft.server.v1_16_R3.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.data.SyntaxContainer1_16_R3; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.data.SyntaxContainer1_16_R3; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_16_R3.PlayerConnection; import net.minecraft.server.v1_16_R3.WorldServer; @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/BlockTools1_16_R3.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/BlockTools1_16_R3.java index 9c730fc..2d5378d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/BlockTools1_16_R3.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R3.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_16_R3.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_16_R3 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.gameProfile.getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/ServerTools1_16_R3.java similarity index 53% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/ServerTools1_16_R3.java index 1aa976f..230707f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/ServerTools1_16_R3.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_16_R3.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.wrapper.ConsoleReaderWrapper1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_16_R3 extends ServerTools { @@ -18,10 +18,9 @@ public String getMotd() { return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); } - @SuppressWarnings("resource") @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_16_R3 getConsole() { + return ConsoleReaderWrapper1_16_R3.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/SkinTools1_16_R3.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/SkinTools1_16_R3.java index 4c1ef08..e84e806 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/tools/SkinTools1_16_R3.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.tools; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_16_R3 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/utils/EntityConstructors1_16_R3.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/utils/EntityConstructors1_16_R3.java index a8581db..780e0b7 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/utils/EntityConstructors1_16_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.utils; import java.util.function.Function; import net.minecraft.server.v1_16_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_16_R3.entity.ArmorStand1_16_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.entity.ArmorStand1_16_R3; public abstract class EntityConstructors1_16_R3 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/wrapper/ConsoleReaderWrapper1_16_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/wrapper/ConsoleReaderWrapper1_16_R3.java new file mode 100644 index 0000000..d3ad010 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_16_R3/wrapper/ConsoleReaderWrapper1_16_R3.java @@ -0,0 +1,49 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_16_R3.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_16_R3.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_16_R3 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_16_R3 INSTANCE = new ConsoleReaderWrapper1_16_R3(); + + private final ConsoleReader reader; + + @SuppressWarnings("resource") + private ConsoleReaderWrapper1_16_R3() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/BukkitConversion1_8_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/BukkitConversion1_8_R1.java index 53082bb..97c70da 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/BukkitConversion1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R1.ItemStack; import net.minecraft.server.v1_8_R1.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_8_R1.NBTTagLong; import net.minecraft.server.v1_8_R1.NBTTagShort; import net.minecraft.server.v1_8_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_8_R1 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -220,12 +220,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/EntityProvider1_8_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/EntityProvider1_8_R1.java index f190b67..5e3ef22 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/EntityProvider1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; import net.minecraft.server.v1_8_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.utils.EntityConstructors1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.utils.EntityConstructors1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_8_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/PlayerProvider1_8_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/PlayerProvider1_8_R1.java index 0020d6d..1d8e6ad 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/PlayerProvider1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity.Player1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity.Player1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_8_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/TextureProvider1_8_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/TextureProvider1_8_R1.java index 825d00f..a115c63 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/TextureProvider1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,22 +9,22 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R1.GameProfileSerializer; import net.minecraft.server.v1_8_R1.ItemStack; import net.minecraft.server.v1_8_R1.NBTTagCompound; import net.minecraft.server.v1_8_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_8_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final AbstractReflect craftSkullRef = new Reflect(CraftSkull.class).searchField("tileEntity", "skull"); + private final ClassLookup craftSkullRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "skull"); private final Material skullMaterial = Material.valueOf("SKULL"); protected TextureProvider1_8_R1(VersionControl1_8_R1 versionControl) { @@ -36,7 +36,7 @@ public GameProfile profileFromBlock(Block block) { if (!(block instanceof CraftSkull)) { return null; } - return ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).getGameProfile(); + return ((TileEntitySkull) craftSkullRef.getFieldValue(block, "tileEntity")).getGameProfile(); } @Override @@ -45,13 +45,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); @@ -100,7 +100,7 @@ public boolean applyBlock(Block block, GameProfile profile) { if (!(block instanceof CraftSkull)) { return false; } - ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).setGameProfile(profile); + ((TileEntitySkull) craftSkullRef.getFieldValue(block, "tileEntity")).setGameProfile(profile); return true; } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/ToolProvider1_8_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/ToolProvider1_8_R1.java index d94d998..1bbf70b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/ToolProvider1_8_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools.BlockTools1_8_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools.ServerTools1_8_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools.SkinTools1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools.BlockTools1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools.ServerTools1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools.SkinTools1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_8_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/VersionControl1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/VersionControl1_8_R1.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/VersionControl1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/VersionControl1_8_R1.java index b60fc83..56e2eed 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/VersionControl1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/VersionControl1_8_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.reflection.NmsReflection1_8_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.reflection.NmsReflection1_8_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_8_R1 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_8_R1 init() { private final ToolProvider1_8_R1 toolProvider = new ToolProvider1_8_R1(this); private final TextureProvider1_8_R1 textureProvider = new TextureProvider1_8_R1(this); - private final PacketHandler1_8_R1 packetHandler = new PacketHandler1_8_R1(this); private final EntityProvider1_8_R1 entityProvider = new EntityProvider1_8_R1(this); private final PlayerProvider1_8_R1 playerProvider = new PlayerProvider1_8_R1(this); private final BukkitConversion1_8_R1 bukkitConversion = new BukkitConversion1_8_R1(this); private VersionControl1_8_R1() { - NmsReflection1_8_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_8_R1.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_8_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_8_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_8_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/ArmorStand1_8_R1.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/ArmorStand1_8_R1.java index 9a2247f..895e35a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/ArmorStand1_8_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity; import net.minecraft.server.v1_8_R1.EntityArmorStand; import net.minecraft.server.v1_8_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_8_R1 extends EntityLiving1_8_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Entity1_8_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Entity1_8_R1.java index 3bb5277..e8078dd 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Entity1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R1.PlayerConnection; import net.minecraft.server.v1_8_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_8_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/EntityLiving1_8_R1.java similarity index 66% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/EntityLiving1_8_R1.java index 0e40af9..3f61638 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/EntityLiving1_8_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity; import net.minecraft.server.v1_8_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_8_R1 extends Entity1_8_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Player1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Player1_8_R1.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Player1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Player1_8_R1.java index 5740f90..a2a11bb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/entity/Player1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/entity/Player1_8_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R1.EntityPlayer; import net.minecraft.server.v1_8_R1.EnumClientCommand; @@ -34,17 +34,17 @@ import net.minecraft.server.v1_8_R1.PacketPlayOutTitle; import net.minecraft.server.v1_8_R1.PlayerConnection; import net.minecraft.server.v1_8_R1.WorldServer; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; public class Player1_8_R1 extends EntityLiving1_8_R1 implements NmsPlayer { @@ -151,7 +151,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/reflection/NmsReflection1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/reflection/NmsReflection1_8_R1.java new file mode 100644 index 0000000..7300b0b --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/reflection/NmsReflection1_8_R1.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.reflection; + +import net.minecraft.server.v1_8_R1.NBTTagEnd; +import net.minecraft.server.v1_8_R1.NBTTagList; +import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_8_R1 extends ClassLookups { + + public static NmsReflection1_8_R1 INSTANCE = new NmsReflection1_8_R1(); + + private NmsReflection1_8_R1() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/BlockTools1_8_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/BlockTools1_8_R1.java index 82ec379..2354abb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/BlockTools1_8_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_8_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/ServerTools1_8_R1.java similarity index 54% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/ServerTools1_8_R1.java index 918333a..898c39e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/ServerTools1_8_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_8_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.wrapper.ConsoleReaderWrapper1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_8_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_8_R1 getConsole() { + return ConsoleReaderWrapper1_8_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/SkinTools1_8_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/SkinTools1_8_R1.java index 69e057f..e2a0b8d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/tools/SkinTools1_8_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.tools; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_8_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/utils/EntityConstructors1_8_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/utils/EntityConstructors1_8_R1.java index 87044df..e4c2efe 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/utils/EntityConstructors1_8_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_8_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R1.entity.ArmorStand1_8_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.entity.ArmorStand1_8_R1; public abstract class EntityConstructors1_8_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/wrapper/ConsoleReaderWrapper1_8_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/wrapper/ConsoleReaderWrapper1_8_R1.java new file mode 100644 index 0000000..3937a59 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R1/wrapper/ConsoleReaderWrapper1_8_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_8_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_8_R1 INSTANCE = new ConsoleReaderWrapper1_8_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_8_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/BukkitConversion1_8_R2.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/BukkitConversion1_8_R2.java index 328dbc5..89395a9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/BukkitConversion1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_8_R2.NBTTagLong; import net.minecraft.server.v1_8_R2.NBTTagShort; import net.minecraft.server.v1_8_R2.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_8_R2 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -219,12 +219,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/EntityProvider1_8_R2.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/EntityProvider1_8_R2.java index 53cdb4f..1d9ff33 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/EntityProvider1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; import net.minecraft.server.v1_8_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.utils.EntityConstructors1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.utils.EntityConstructors1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_8_R2 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/PlayerProvider1_8_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/PlayerProvider1_8_R2.java index 92edb33..db0facb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/PlayerProvider1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity.Player1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity.Player1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_8_R2 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/TextureProvider1_8_R2.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/TextureProvider1_8_R2.java index bd6d55a..a03b96b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/TextureProvider1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R2.GameProfileSerializer; import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_8_R2 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R2.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_8_R2.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/ToolProvider1_8_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/ToolProvider1_8_R2.java index 03650f7..9300d3c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/ToolProvider1_8_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools.BlockTools1_8_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools.ServerTools1_8_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools.SkinTools1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools.BlockTools1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools.ServerTools1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools.SkinTools1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_8_R2 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/VersionControl1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/VersionControl1_8_R2.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/VersionControl1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/VersionControl1_8_R2.java index 8cd546f..b677820 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/VersionControl1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/VersionControl1_8_R2.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.reflection.NmsReflection1_8_R2; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.reflection.NmsReflection1_8_R2; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_8_R2 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_8_R2 init() { private final ToolProvider1_8_R2 toolProvider = new ToolProvider1_8_R2(this); private final TextureProvider1_8_R2 textureProvider = new TextureProvider1_8_R2(this); - private final PacketHandler1_8_R2 packetHandler = new PacketHandler1_8_R2(this); private final EntityProvider1_8_R2 entityProvider = new EntityProvider1_8_R2(this); private final PlayerProvider1_8_R2 playerProvider = new PlayerProvider1_8_R2(this); private final BukkitConversion1_8_R2 bukkitConversion = new BukkitConversion1_8_R2(this); private VersionControl1_8_R2() { - NmsReflection1_8_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_8_R2.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_8_R2 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_8_R2 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_8_R2 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/ArmorStand1_8_R2.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/ArmorStand1_8_R2.java index c80721f..206fa21 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/ArmorStand1_8_R2.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity; import net.minecraft.server.v1_8_R2.EntityArmorStand; import net.minecraft.server.v1_8_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_8_R2 extends EntityLiving1_8_R2 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Entity1_8_R2.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Entity1_8_R2.java index 7ab61b4..1afdb3d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Entity1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R2.PlayerConnection; import net.minecraft.server.v1_8_R2.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_8_R2 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/EntityLiving1_8_R2.java similarity index 66% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/EntityLiving1_8_R2.java index dd7d3c8..d8fd14b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/EntityLiving1_8_R2.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity; import net.minecraft.server.v1_8_R2.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_8_R2 extends Entity1_8_R2 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Player1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Player1_8_R2.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Player1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Player1_8_R2.java index 620c217..6534c7f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/entity/Player1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/entity/Player1_8_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_8_R2.IChatBaseComponent; @@ -32,17 +32,17 @@ import net.minecraft.server.v1_8_R2.PacketPlayOutRespawn; import net.minecraft.server.v1_8_R2.PacketPlayOutTitle; import net.minecraft.server.v1_8_R2.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_8_R2.PlayerConnection; import net.minecraft.server.v1_8_R2.WorldServer; @@ -151,7 +151,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/reflection/NmsReflection1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/reflection/NmsReflection1_8_R2.java new file mode 100644 index 0000000..8d972c3 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/reflection/NmsReflection1_8_R2.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.reflection; + +import net.minecraft.server.v1_8_R2.NBTTagEnd; +import net.minecraft.server.v1_8_R2.NBTTagList; +import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_8_R2 extends ClassLookups { + + public static NmsReflection1_8_R2 INSTANCE = new NmsReflection1_8_R2(); + + private NmsReflection1_8_R2() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/BlockTools1_8_R2.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/BlockTools1_8_R2.java index f1e7215..a8fce17 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/BlockTools1_8_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R2.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_8_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/ServerTools1_8_R2.java similarity index 54% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/ServerTools1_8_R2.java index 0c3cb70..da32424 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/ServerTools1_8_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.wrapper.ConsoleReaderWrapper1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_8_R2 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_8_R2 getConsole() { + return ConsoleReaderWrapper1_8_R2.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/SkinTools1_8_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/SkinTools1_8_R2.java index 10037a3..8a4518d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/tools/SkinTools1_8_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.tools; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_8_R2 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/utils/EntityConstructors1_8_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/utils/EntityConstructors1_8_R2.java index dc2ce01..ef8be73 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/utils/EntityConstructors1_8_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.utils; import java.util.function.Function; import net.minecraft.server.v1_8_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R2.entity.ArmorStand1_8_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.entity.ArmorStand1_8_R2; public abstract class EntityConstructors1_8_R2 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/wrapper/ConsoleReaderWrapper1_8_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/wrapper/ConsoleReaderWrapper1_8_R2.java new file mode 100644 index 0000000..31be001 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R2/wrapper/ConsoleReaderWrapper1_8_R2.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R2.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_8_R2 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_8_R2 INSTANCE = new ConsoleReaderWrapper1_8_R2(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_8_R2() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/BukkitConversion1_8_R3.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/BukkitConversion1_8_R3.java index ca77c4b..e657adf 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/BukkitConversion1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_8_R3.NBTTagLong; import net.minecraft.server.v1_8_R3.NBTTagShort; import net.minecraft.server.v1_8_R3.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_8_R3 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -219,12 +219,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/EntityProvider1_8_R3.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/EntityProvider1_8_R3.java index 4399e8d..c6a86e1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/EntityProvider1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import net.minecraft.server.v1_8_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.utils.EntityConstructors1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.utils.EntityConstructors1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_8_R3 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/PlayerProvider1_8_R3.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/PlayerProvider1_8_R3.java index 4615e4f..9fb94ad 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/PlayerProvider1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity.Player1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity.Player1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_8_R3 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/TextureProvider1_8_R3.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/TextureProvider1_8_R3.java index 72d093b..2d625de 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/TextureProvider1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R3.GameProfileSerializer; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_8_R3 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/ToolProvider1_8_R3.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/ToolProvider1_8_R3.java index 786de5a..e98d054 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/ToolProvider1_8_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools.BlockTools1_8_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools.ServerTools1_8_R3; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools.SkinTools1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools.BlockTools1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools.ServerTools1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools.SkinTools1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_8_R3 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/VersionControl1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/VersionControl1_8_R3.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/VersionControl1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/VersionControl1_8_R3.java index 14ce3d6..0b179b9 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/VersionControl1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/VersionControl1_8_R3.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.reflection.NmsReflection1_8_R3; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.reflection.NmsReflection1_8_R3; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_8_R3 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_8_R3 init() { private final ToolProvider1_8_R3 toolProvider = new ToolProvider1_8_R3(this); private final TextureProvider1_8_R3 textureProvider = new TextureProvider1_8_R3(this); - private final PacketHandler1_8_R3 packetHandler = new PacketHandler1_8_R3(this); private final EntityProvider1_8_R3 entityProvider = new EntityProvider1_8_R3(this); private final PlayerProvider1_8_R3 playerProvider = new PlayerProvider1_8_R3(this); private final BukkitConversion1_8_R3 bukkitConversion = new BukkitConversion1_8_R3(this); private VersionControl1_8_R3() { - NmsReflection1_8_R3.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_8_R3.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_8_R3 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_8_R3 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_8_R3 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/ArmorStand1_8_R3.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/ArmorStand1_8_R3.java index a60a7ee..f8ecda7 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/ArmorStand1_8_R3.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity; import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_8_R3 extends EntityLiving1_8_R3 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Entity1_8_R3.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Entity1_8_R3.java index cfe965d..56ce8fb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Entity1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R3.PlayerConnection; import net.minecraft.server.v1_8_R3.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_8_R3 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/EntityLiving1_8_R3.java similarity index 66% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/EntityLiving1_8_R3.java index 8940326..1b650ce 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/EntityLiving1_8_R3.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity; import net.minecraft.server.v1_8_R3.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_8_R3 extends Entity1_8_R3 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Player1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Player1_8_R3.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Player1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Player1_8_R3.java index 6527c08..f27c9f5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/entity/Player1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/entity/Player1_8_R3.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.IChatBaseComponent; @@ -32,17 +32,17 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutRespawn; import net.minecraft.server.v1_8_R3.PacketPlayOutTitle; import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_8_R3.PlayerConnection; import net.minecraft.server.v1_8_R3.WorldServer; @@ -151,7 +151,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -283,7 +283,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/reflection/NmsReflection1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/reflection/NmsReflection1_8_R3.java new file mode 100644 index 0000000..7921409 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/reflection/NmsReflection1_8_R3.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.reflection; + +import net.minecraft.server.v1_8_R3.NBTTagEnd; +import net.minecraft.server.v1_8_R3.NBTTagList; +import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_8_R3 extends ClassLookups { + + public static NmsReflection1_8_R3 INSTANCE = new NmsReflection1_8_R3(); + + private NmsReflection1_8_R3() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/BlockTools1_8_R3.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/BlockTools1_8_R3.java index 91983d8..b64af2d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/BlockTools1_8_R3.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_8_R3.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_8_R3 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/ServerTools1_8_R3.java similarity index 54% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/ServerTools1_8_R3.java index 4a37618..15e19bf 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/ServerTools1_8_R3.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.wrapper.ConsoleReaderWrapper1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_8_R3 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_8_R3 getConsole() { + return ConsoleReaderWrapper1_8_R3.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/SkinTools1_8_R3.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/SkinTools1_8_R3.java index aa350c7..d6e29b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/tools/SkinTools1_8_R3.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.tools; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_8_R3 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/utils/EntityConstructors1_8_R3.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/utils/EntityConstructors1_8_R3.java index 24bcead..078ed2c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/utils/EntityConstructors1_8_R3.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.utils; import java.util.function.Function; import net.minecraft.server.v1_8_R3.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_8_R3.entity.ArmorStand1_8_R3; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.entity.ArmorStand1_8_R3; public abstract class EntityConstructors1_8_R3 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/wrapper/ConsoleReaderWrapper1_8_R3.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/wrapper/ConsoleReaderWrapper1_8_R3.java new file mode 100644 index 0000000..3e5d899 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_8_R3/wrapper/ConsoleReaderWrapper1_8_R3.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_8_R3.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_8_R3 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_8_R3 INSTANCE = new ConsoleReaderWrapper1_8_R3(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_8_R3() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/BukkitConversion1_9_R1.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/BukkitConversion1_9_R1.java index ad61638..c2be451 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/BukkitConversion1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_9_R1.ItemStack; import net.minecraft.server.v1_9_R1.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_9_R1.NBTTagLong; import net.minecraft.server.v1_9_R1.NBTTagShort; import net.minecraft.server.v1_9_R1.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_9_R1 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -219,12 +219,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/EntityProvider1_9_R1.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/EntityProvider1_9_R1.java index 5671a86..debcece 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/EntityProvider1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; import net.minecraft.server.v1_9_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.utils.EntityConstructors1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.utils.EntityConstructors1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_9_R1 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/PlayerProvider1_9_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/PlayerProvider1_9_R1.java index 20bbaed..5b7f881 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/PlayerProvider1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity.Player1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity.Player1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_9_R1 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/TextureProvider1_9_R1.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/TextureProvider1_9_R1.java index c9b3a0a..37203b8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/TextureProvider1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R1.GameProfileSerializer; import net.minecraft.server.v1_9_R1.ItemStack; import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_9_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R1.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_9_R1.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/ToolProvider1_9_R1.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/ToolProvider1_9_R1.java index c8f1937..a53241a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/ToolProvider1_9_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools.BlockTools1_9_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools.ServerTools1_9_R1; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools.SkinTools1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools.BlockTools1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools.ServerTools1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools.SkinTools1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_9_R1 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/VersionControl1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/VersionControl1_9_R1.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/VersionControl1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/VersionControl1_9_R1.java index 839cc75..d72952a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/VersionControl1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/VersionControl1_9_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.reflection.NmsReflection1_9_R1; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.reflection.NmsReflection1_9_R1; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_9_R1 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_9_R1 init() { private final ToolProvider1_9_R1 toolProvider = new ToolProvider1_9_R1(this); private final TextureProvider1_9_R1 textureProvider = new TextureProvider1_9_R1(this); - private final PacketHandler1_9_R1 packetHandler = new PacketHandler1_9_R1(this); private final EntityProvider1_9_R1 entityProvider = new EntityProvider1_9_R1(this); private final PlayerProvider1_9_R1 playerProvider = new PlayerProvider1_9_R1(this); private final BukkitConversion1_9_R1 bukkitConversion = new BukkitConversion1_9_R1(this); private VersionControl1_9_R1() { - NmsReflection1_9_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_9_R1.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_9_R1 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_9_R1 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_9_R1 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/ArmorStand1_9_R1.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/ArmorStand1_9_R1.java index a71cd39..6483dae 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/ArmorStand1_9_R1.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity; import net.minecraft.server.v1_9_R1.EntityArmorStand; import net.minecraft.server.v1_9_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_9_R1 extends EntityLiving1_9_R1 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Entity1_9_R1.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Entity1_9_R1.java index 10eb5a4..885e2f2 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Entity1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_9_R1.PlayerConnection; import net.minecraft.server.v1_9_R1.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_9_R1 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/EntityLiving1_9_R1.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/EntityLiving1_9_R1.java index be3e212..a87019e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/EntityLiving1_9_R1.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity; import net.minecraft.server.v1_9_R1.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_9_R1 extends Entity1_9_R1 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Player1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Player1_9_R1.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Player1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Player1_9_R1.java index 62647c8..bde2d13 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/entity/Player1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/entity/Player1_9_R1.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R1.EntityPlayer; import net.minecraft.server.v1_9_R1.EnumItemSlot; @@ -33,17 +33,17 @@ import net.minecraft.server.v1_9_R1.PacketPlayOutRespawn; import net.minecraft.server.v1_9_R1.PacketPlayOutTitle; import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_9_R1.PlayerConnection; import net.minecraft.server.v1_9_R1.WorldServer; @@ -152,7 +152,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -284,7 +284,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/reflection/NmsReflection1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/reflection/NmsReflection1_9_R1.java new file mode 100644 index 0000000..ba8c1ab --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/reflection/NmsReflection1_9_R1.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.reflection; + +import net.minecraft.server.v1_9_R1.NBTTagEnd; +import net.minecraft.server.v1_9_R1.NBTTagList; +import net.minecraft.server.v1_9_R1.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_9_R1 extends ClassLookups { + + public static NmsReflection1_9_R1 INSTANCE = new NmsReflection1_9_R1(); + + private NmsReflection1_9_R1() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/BlockTools1_9_R1.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/BlockTools1_9_R1.java index b58f8be..2a46bd8 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/BlockTools1_9_R1.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_9_R1.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R1.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_9_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/ServerTools1_9_R1.java similarity index 54% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/ServerTools1_9_R1.java index 9ffa15c..e474e39 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/ServerTools1_9_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_9_R1.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.wrapper.ConsoleReaderWrapper1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_9_R1 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_9_R1 getConsole() { + return ConsoleReaderWrapper1_9_R1.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/SkinTools1_9_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/SkinTools1_9_R1.java index 89b55cb..aac029b 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/tools/SkinTools1_9_R1.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.tools; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_9_R1 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/utils/EntityConstructors1_9_R1.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/utils/EntityConstructors1_9_R1.java index 2a37191..b66892c 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/utils/EntityConstructors1_9_R1.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.utils; import java.util.function.Function; import net.minecraft.server.v1_9_R1.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R1.entity.ArmorStand1_9_R1; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.entity.ArmorStand1_9_R1; public abstract class EntityConstructors1_9_R1 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/wrapper/ConsoleReaderWrapper1_9_R1.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/wrapper/ConsoleReaderWrapper1_9_R1.java new file mode 100644 index 0000000..dcfef31 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R1/wrapper/ConsoleReaderWrapper1_9_R1.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R1.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_9_R1.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_9_R1 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_9_R1 INSTANCE = new ConsoleReaderWrapper1_9_R1(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_9_R1() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +} diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/BukkitConversion1_9_R2.java similarity index 74% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/BukkitConversion1_9_R2.java index 6c1c9f0..5207510 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/BukkitConversion1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; import java.util.List; import java.util.Set; @@ -6,23 +6,24 @@ import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; import org.bukkit.entity.EntityType; -import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.data.DataType; -import com.syntaxphoenix.syntaxapi.nbt.NbtByte; -import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; -import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; -import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; -import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; -import com.syntaxphoenix.syntaxapi.nbt.NbtInt; -import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtList; -import com.syntaxphoenix.syntaxapi.nbt.NbtLong; -import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; -import com.syntaxphoenix.syntaxapi.nbt.NbtShort; -import com.syntaxphoenix.syntaxapi.nbt.NbtString; -import com.syntaxphoenix.syntaxapi.nbt.NbtTag; -import com.syntaxphoenix.syntaxapi.nbt.NbtType; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.data.api.IDataAdapterContext; +import net.sourcewriters.minecraft.vcompat.data.api.IDataType; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByte; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtByteArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtCompound; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtDouble; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtEnd; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtFloat; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtInt; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtIntArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtList; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLong; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtLongArray; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtShort; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtString; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtTag; +import net.sourcewriters.minecraft.vcompat.shaded.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_9_R2.ItemStack; import net.minecraft.server.v1_9_R2.NBTBase; @@ -38,13 +39,12 @@ import net.minecraft.server.v1_9_R2.NBTTagLong; import net.minecraft.server.v1_9_R2.NBTTagShort; import net.minecraft.server.v1_9_R2.NBTTagString; -import net.sourcewriters.minecraft.vcompat.reflection.BukkitConversion; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContext; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleWrapType; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.BukkitConversion; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContext; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleWrapType; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class BukkitConversion1_9_R2 extends BukkitConversion { @@ -102,7 +102,7 @@ public NBTBase toMinecraftTag(NbtTag tag) { case COMPOUND: return toMinecraftCompound((NbtCompound) tag); case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + return (NBTTagEnd) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagEnd").init(); default: return null; } @@ -163,7 +163,7 @@ public NbtList fromMinecraftList(Object raw) { return null; } NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + List content = (List) VersionCompatProvider.get().getLookupProvider().getLookup("nmsNBTTagList").getFieldValue(list, "value"); NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); for (NBTBase base : content) { output.add(fromMinecraftTag(base)); @@ -219,12 +219,12 @@ public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { } @Override - public WrappedContext createContext(DataAdapterContext context) { + public WrappedContext createContext(IDataAdapterContext context) { return new SimpleSyntaxContext(context); } @Override - public WrapType wrap(DataType dataType) { + public WrapType wrap(IDataType dataType) { return new SimpleWrapType(dataType); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/EntityProvider1_9_R2.java similarity index 78% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/EntityProvider1_9_R2.java index f39370b..43bd86a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/EntityProvider1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; import java.util.EnumMap; import java.util.function.Function; @@ -6,10 +6,10 @@ import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; import net.minecraft.server.v1_9_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.EntityProvider; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityType; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.utils.EntityConstructors1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.utils.EntityConstructors1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.EntityProvider; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityType; public class EntityProvider1_9_R2 extends EntityProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/PlayerProvider1_9_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/PlayerProvider1_9_R2.java index 63e7c8b..f694240 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/PlayerProvider1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; import java.io.File; import java.util.UUID; @@ -6,11 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.DataProvider; -import net.sourcewriters.minecraft.vcompat.reflection.PlayerProvider; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.DataDistributor; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity.Player1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity.Player1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.DataProvider; +import net.sourcewriters.minecraft.vcompat.provider.PlayerProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.DataDistributor; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; public class PlayerProvider1_9_R2 extends PlayerProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/TextureProvider1_9_R2.java similarity index 85% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/TextureProvider1_9_R2.java index 4802206..4292f91 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/TextureProvider1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,19 +9,19 @@ import org.bukkit.material.MaterialData; import com.mojang.authlib.GameProfile; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R2.GameProfileSerializer; import net.minecraft.server.v1_9_R2.ItemStack; import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.sourcewriters.minecraft.vcompat.reflection.TextureProvider; +import net.sourcewriters.minecraft.vcompat.provider.TextureProvider; @SuppressWarnings("deprecation") public class TextureProvider1_9_R2 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R2.inventory.CraftMetaSkull") + private final ClassLookup craftItemStackRef = ClassLookup.of(CraftItemStack.class).searchField("handle", "handle"); + private final ClassLookup craftMetaSkullRef = ClassLookup.of("org.bukkit.craftbukkit.v1_9_R2.inventory.CraftMetaSkull") .searchField("serialized", "serializedProfile").searchField("profile", "profile"); private final Material skullMaterial = Material.valueOf("SKULL"); @@ -43,13 +43,13 @@ public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { return null; } SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue(meta, "profile"); if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue(meta, "serialized"); if (compound == null) { ItemStack stack = null; if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + stack = (ItemStack) craftItemStackRef.getFieldValue(itemStack, "handle"); } if (stack == null) { stack = CraftItemStack.asNMSCopy(itemStack); diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/ToolProvider1_9_R2.java similarity index 61% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/ToolProvider1_9_R2.java index ab2945f..026d98e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/ToolProvider1_9_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; -import net.sourcewriters.minecraft.vcompat.reflection.ToolProvider; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools.BlockTools1_9_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools.ServerTools1_9_R2; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools.SkinTools1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools.BlockTools1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools.ServerTools1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools.SkinTools1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.ToolProvider; public class ToolProvider1_9_R2 extends ToolProvider { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/VersionControl1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/VersionControl1_9_R2.java similarity index 68% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/VersionControl1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/VersionControl1_9_R2.java index 9441d2a..3c3e64e 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/VersionControl1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/VersionControl1_9_R2.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2; -import net.sourcewriters.minecraft.vcompat.reflection.VersionControl; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.reflection.NmsReflection1_9_R2; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.reflection.NmsReflection1_9_R2; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.VersionControl; public class VersionControl1_9_R2 extends VersionControl { @@ -14,13 +14,12 @@ public static VersionControl1_9_R2 init() { private final ToolProvider1_9_R2 toolProvider = new ToolProvider1_9_R2(this); private final TextureProvider1_9_R2 textureProvider = new TextureProvider1_9_R2(this); - private final PacketHandler1_9_R2 packetHandler = new PacketHandler1_9_R2(this); private final EntityProvider1_9_R2 entityProvider = new EntityProvider1_9_R2(this); private final PlayerProvider1_9_R2 playerProvider = new PlayerProvider1_9_R2(this); private final BukkitConversion1_9_R2 bukkitConversion = new BukkitConversion1_9_R2(this); private VersionControl1_9_R2() { - NmsReflection1_9_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); + NmsReflection1_9_R2.INSTANCE.setup(VersionCompatProvider.get().getLookupProvider()); } @Override @@ -43,11 +42,6 @@ public TextureProvider1_9_R2 getTextureProvider() { return textureProvider; } - @Override - public PacketHandler1_9_R2 getPacketHandler() { - return packetHandler; - } - @Override public BukkitConversion1_9_R2 getBukkitConversion() { return bukkitConversion; diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/ArmorStand1_9_R2.java similarity index 81% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/ArmorStand1_9_R2.java index b67b339..adf88c3 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/ArmorStand1_9_R2.java @@ -1,8 +1,8 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity; import net.minecraft.server.v1_9_R2.EntityArmorStand; import net.minecraft.server.v1_9_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsArmorStand; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsArmorStand; public class ArmorStand1_9_R2 extends EntityLiving1_9_R2 implements NmsArmorStand { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Entity1_9_R2.java similarity index 96% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Entity1_9_R2.java index 0deb812..af5332f 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Entity1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -20,8 +20,8 @@ import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_9_R2.PlayerConnection; import net.minecraft.server.v1_9_R2.Vec3D; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntity; -import net.sourcewriters.minecraft.vcompat.reflection.utils.NmsBoundingBox; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntity; +import net.sourcewriters.minecraft.vcompat.provider.utils.NmsBoundingBox; public abstract class Entity1_9_R2 implements NmsEntity { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/EntityLiving1_9_R2.java similarity index 69% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/EntityLiving1_9_R2.java index 06d038e..e1c2164 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/EntityLiving1_9_R2.java @@ -1,7 +1,7 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity; import net.minecraft.server.v1_9_R2.EntityLiving; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsEntityLiving; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsEntityLiving; public abstract class EntityLiving1_9_R2 extends Entity1_9_R2 implements NmsEntityLiving { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Player1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Player1_9_R2.java similarity index 89% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Player1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Player1_9_R2.java index 9847e96..8a13933 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/entity/Player1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/entity/Player1_9_R2.java @@ -1,4 +1,4 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +10,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R2.EntityPlayer; import net.minecraft.server.v1_9_R2.EnumItemSlot; @@ -33,17 +33,17 @@ import net.minecraft.server.v1_9_R2.PacketPlayOutRespawn; import net.minecraft.server.v1_9_R2.PacketPlayOutTitle; import net.minecraft.server.v1_9_R2.PacketPlayOutTitle.EnumTitleAction; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrapType; -import net.sourcewriters.minecraft.vcompat.reflection.data.WrappedContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.persistence.PersistentContainer; -import net.sourcewriters.minecraft.vcompat.reflection.data.type.SkinDataType; -import net.sourcewriters.minecraft.vcompat.reflection.data.wrap.SimpleSyntaxContainer; -import net.sourcewriters.minecraft.vcompat.reflection.entity.NmsPlayer; -import net.sourcewriters.minecraft.vcompat.reflection.reflect.ReflectionProvider; -import net.sourcewriters.minecraft.vcompat.utils.bukkit.Players; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.MojangProfileServer; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; -import net.sourcewriters.minecraft.vcompat.utils.thread.PostAsync; +import net.sourcewriters.minecraft.vcompat.VersionCompatProvider; +import net.sourcewriters.minecraft.vcompat.provider.data.WrapType; +import net.sourcewriters.minecraft.vcompat.provider.data.WrappedContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.persistence.PersistentContainer; +import net.sourcewriters.minecraft.vcompat.provider.data.type.SkinDataType; +import net.sourcewriters.minecraft.vcompat.provider.data.wrap.SimpleSyntaxContainer; +import net.sourcewriters.minecraft.vcompat.provider.entity.NmsPlayer; +import net.sourcewriters.minecraft.vcompat.util.bukkit.Players; +import net.sourcewriters.minecraft.vcompat.util.minecraft.MojangProfileServer; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.util.thread.PostAsync; import net.minecraft.server.v1_9_R2.PlayerConnection; import net.minecraft.server.v1_9_R2.WorldServer; @@ -152,7 +152,7 @@ private final void sendPlayerListInfo(String header, String footer) { PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + ClassLookup reflect = VersionCompatProvider.get().getLookupProvider().getLookup("nmsPacketPlayOutPlayerListHeaderFooter"); reflect.setFieldValue(packet, "header", headerComponent); reflect.setFieldValue(packet, "footer", footerComponent); @@ -284,7 +284,7 @@ private final void update(boolean flag) { String name = getName(); if (name != null) { - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", name); + VersionCompatProvider.get().getLookupProvider().getLookup("mjGameProfile").setFieldValue(profile, "name", name); } if (!(name == null && skin == null)) { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/reflection/NmsReflection1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/reflection/NmsReflection1_9_R2.java new file mode 100644 index 0000000..5ad9a82 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/reflection/NmsReflection1_9_R2.java @@ -0,0 +1,34 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.reflection; + +import net.minecraft.server.v1_9_R2.NBTTagEnd; +import net.minecraft.server.v1_9_R2.NBTTagList; +import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerListHeaderFooter; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookupProvider; +import net.sourcewriters.minecraft.vcompat.provider.lookup.ClassLookups; + +public class NmsReflection1_9_R2 extends ClassLookups { + + public static NmsReflection1_9_R2 INSTANCE = new NmsReflection1_9_R2(); + + private NmsReflection1_9_R2() {} + + @Override + public void setup(ClassLookupProvider provider) { + + // + // + // Create Reflects + // + + // + // Minecraft + + provider.createLookup("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); + + provider.createLookup("nmsNBTTagEnd", NBTTagEnd.class); + provider.createLookup("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } + +} \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/BlockTools1_9_R2.java similarity index 64% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/BlockTools1_9_R2.java index cd0bb32..2a27a5a 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/BlockTools1_9_R2.java @@ -1,27 +1,27 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_9_R2.block.CraftSkull; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import com.syntaxphoenix.syntaxapi.reflection.AbstractReflect; -import com.syntaxphoenix.syntaxapi.reflection.Reflect; + +import net.sourcewriters.minecraft.vcompat.provider.lookup.handle.ClassLookup; import net.minecraft.server.v1_9_R2.TileEntitySkull; -import net.sourcewriters.minecraft.vcompat.reflection.tools.BlockTools; -import net.sourcewriters.minecraft.vcompat.utils.constants.MinecraftConstants; +import net.sourcewriters.minecraft.vcompat.provider.tools.BlockTools; +import net.sourcewriters.minecraft.vcompat.util.constants.MinecraftConstants; public class BlockTools1_9_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + private final ClassLookup craftEntityStateRef = ClassLookup.of(CraftSkull.class).searchField("tileEntity", "tileEntity"); @Override public void setHeadTexture(Block block, String texture) { if (!(block instanceof CraftSkull)) { return; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); PropertyMap map = entitySkull.getGameProfile().getProperties(); map.removeAll("textures"); map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); @@ -32,7 +32,7 @@ public String getHeadTexture(Block block) { if (!(block instanceof CraftSkull)) { return null; } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue(block, "tileEntity"); return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); } diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/ServerTools1_9_R2.java similarity index 54% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/ServerTools1_9_R2.java index 10bed0f..b0a32f1 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/ServerTools1_9_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; import org.bukkit.craftbukkit.v1_9_R2.CraftServer; -import net.sourcewriters.minecraft.vcompat.reflection.tools.ServerTools; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.wrapper.ConsoleReaderWrapper1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.tools.ServerTools; public class ServerTools1_9_R2 extends ServerTools { @@ -19,8 +19,8 @@ public String getMotd() { } @Override - public ConsoleReader getConsole() { - return ((CraftServer) Bukkit.getServer()).getServer().reader; + public ConsoleReaderWrapper1_9_R2 getConsole() { + return ConsoleReaderWrapper1_9_R2.INSTANCE; } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/SkinTools1_9_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/SkinTools1_9_R2.java index 26046bd..aa92c0d 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/tools/SkinTools1_9_R2.java @@ -1,10 +1,10 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.tools; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.tools; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import net.sourcewriters.minecraft.vcompat.reflection.tools.SkinTools; -import net.sourcewriters.minecraft.vcompat.utils.minecraft.Skin; +import net.sourcewriters.minecraft.vcompat.provider.tools.SkinTools; +import net.sourcewriters.minecraft.vcompat.util.minecraft.Skin; public class SkinTools1_9_R2 extends SkinTools { diff --git a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/utils/EntityConstructors1_9_R2.java similarity index 58% rename from src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java rename to vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/utils/EntityConstructors1_9_R2.java index 4735565..90328cb 100644 --- a/src/main/java/net/sourcewriters/minecraft/vcompat/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/utils/EntityConstructors1_9_R2.java @@ -1,9 +1,9 @@ -package net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.utils; +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.utils; import java.util.function.Function; import net.minecraft.server.v1_9_R2.World; -import net.sourcewriters.minecraft.vcompat.reflection.provider.v1_9_R2.entity.ArmorStand1_9_R2; +import net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.entity.ArmorStand1_9_R2; public abstract class EntityConstructors1_9_R2 { diff --git a/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/wrapper/ConsoleReaderWrapper1_9_R2.java b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/wrapper/ConsoleReaderWrapper1_9_R2.java new file mode 100644 index 0000000..ecca520 --- /dev/null +++ b/vcompat-legacy/src/main/java/net/sourcewriters/minecraft/vcompat/provider/impl/v1_9_R2/wrapper/ConsoleReaderWrapper1_9_R2.java @@ -0,0 +1,48 @@ +package net.sourcewriters.minecraft.vcompat.provider.impl.v1_9_R2.wrapper; + +import java.io.IOException; +import java.io.Writer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_9_R2.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader; + +import net.sourcewriters.minecraft.vcompat.provider.wrapper.ConsoleReaderWrapper; + +public final class ConsoleReaderWrapper1_9_R2 extends ConsoleReaderWrapper { + + public static final ConsoleReaderWrapper1_9_R2 INSTANCE = new ConsoleReaderWrapper1_9_R2(); + + private final ConsoleReader reader; + + private ConsoleReaderWrapper1_9_R2() { + this.reader = ((CraftServer) Bukkit.getServer()).getServer().reader; + } + + @Override + public Writer getOutput() { + return reader.getOutput(); + } + + @Override + public boolean isAnsiSupported() { + return reader.getTerminal().isAnsiSupported(); + } + + @Override + public void flush() throws IOException { + reader.flush(); + } + + @Override + public void drawLine() throws IOException { + reader.drawLine(); + } + + @Override + public boolean isJLineSupported() { + return Main.useJline; + } + +}