diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ffdc23aba..8b015105c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -125,52 +125,52 @@ jobs: if: steps.wild.outputs.sucess != 'true' || steps.wildMojang.outputs.sucess != 'true' || steps.wildObf.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.19.4 --remapped - # Build 1.20.1 NMS - v1_20_R1: + # Build 1.20.2 NMS + v1_20_R2: runs-on: ubuntu-latest steps: - - name: Set up JDK 17 # 1.20.1 can only be built with Java 17 + - name: Set up JDK 17 # 1.20.2 can only be built with Java 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: '17' - - name: Cache 1.20.1 Maven package + - name: Cache 1.20.2 Maven package id: cacheWild_r2 uses: actions/cache@v3 with: path: | - ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/ ~/.m2/repository/org/spigotmc/spigot-parent/ ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-v1_20_R1 - restore-keys: ${{ runner.os }}-v1_20_R1 + key: ${{ runner.os }}-v1_20_R2 + restore-keys: ${{ runner.os }}-v1_20_R2 - name: Cache Maven packages id: cacheMain uses: actions/cache@v3 with: path: ~/.m2 - key: ${{ runner.os }}-m2-v1_20_R1 - restore-keys: ${{ runner.os }}-m2-v1_20_R1 + key: ${{ runner.os }}-m2-v1_20_R2 + restore-keys: ${{ runner.os }}-m2-v1_20_R2 - name: Setup BuildTools run: mkdir BuildTools && wget -O BuildTools/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar - - name: Check 1.20.1 Spigot + - name: Check 1.20.2 Spigot id: wild - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Check 1.20.1 Spigot (Mojang) + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Check 1.20.2 Spigot (Mojang) id: wildMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Check 1.20.1 Spigot (Obf) + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT-remapped-mojang.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Check 1.20.2 Spigot (Obf) id: wildObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Build 1.20.1 + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT-remapped-obf.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Build 1.20.2 if: steps.wild.outputs.sucess != 'true' || steps.wildMojang.outputs.sucess != 'true' || steps.wildObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.20.1 --remapped + run: cd BuildTools && java -jar BuildTools.jar --rev 1.20.2 --remapped # Build Movecraft build: runs-on: ubuntu-latest - needs: [v1_16_R3, v1_18_R2, v1_19_R3, v1_20_R1] + needs: [v1_16_R3, v1_18_R2, v1_19_R3, v1_20_R2] steps: - name: Checkout Movecraft @@ -210,15 +210,15 @@ jobs: ~/.m2/repository/org/spigotmc/minecraft-server/ key: ${{ runner.os }}-v1_19_R3 restore-keys: ${{ runner.os }}-v1_19_R3 - - name: Cache 1.20.1 Maven package + - name: Cache 1.20.2 Maven package uses: actions/cache@v3 with: path: | - ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/ ~/.m2/repository/org/spigotmc/spigot-parent/ ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-v1_20_R1 - restore-keys: ${{ runner.os }}-v1_20_R1 + key: ${{ runner.os }}-v1_20_R2 + restore-keys: ${{ runner.os }}-v1_20_R2 - name: Build with Maven run: mvn -T 1C -B package --file pom.xml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fadb71241..267953d27 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -123,52 +123,52 @@ jobs: if: steps.wild.outputs.sucess != 'true' || steps.wildMojang.outputs.sucess != 'true' || steps.wildObf.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.19.4 --remapped - # Build 1.20.1 NMS - v1_20_R1: + # Build 1.20.2 NMS + v1_20_R2: runs-on: ubuntu-latest steps: - - name: Set up JDK 17 # 1.20.1 can only be built with Java 17 + - name: Set up JDK 17 # 1.20.2 can only be built with Java 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: '17' - - name: Cache 1.20.1 Maven package + - name: Cache 1.20.2 Maven package id: cacheWild_r2 uses: actions/cache@v3 with: path: | - ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/ ~/.m2/repository/org/spigotmc/spigot-parent/ ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-v1_20_R1 - restore-keys: ${{ runner.os }}-v1_20_R1 + key: ${{ runner.os }}-v1_20_R2 + restore-keys: ${{ runner.os }}-v1_20_R2 - name: Cache Maven packages id: cacheMain uses: actions/cache@v3 with: path: ~/.m2 - key: ${{ runner.os }}-m2-v1_20_R1 - restore-keys: ${{ runner.os }}-m2-v1_20_R1 + key: ${{ runner.os }}-m2-v1_20_R2 + restore-keys: ${{ runner.os }}-m2-v1_20_R2 - name: Setup BuildTools run: mkdir BuildTools && wget -O BuildTools/BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar - - name: Check 1.20.1 Spigot + - name: Check 1.20.2 Spigot id: wild - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Check 1.20.1 Spigot (Mojang) + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Check 1.20.2 Spigot (Mojang) id: wildMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Check 1.20.1 Spigot (Obf) + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT-remapped-mojang.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Check 1.20.2 Spigot (Obf) id: wildObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT - - name: Build 1.20.1 + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT-remapped-obf.jar && echo "sucess=true" >> $GITHUB_OUTPUT || echo "sucess=false" >> $GITHUB_OUTPUT + - name: Build 1.20.2 if: steps.wild.outputs.sucess != 'true' || steps.wildMojang.outputs.sucess != 'true' || steps.wildObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.20.1 --remapped + run: cd BuildTools && java -jar BuildTools.jar --rev 1.20.2 --remapped # Build Movecraft build: runs-on: ubuntu-latest - needs: [v1_16_R3, v1_18_R2, v1_19_R3, v1_20_R1] + needs: [v1_16_R3, v1_18_R2, v1_19_R3, v1_20_R2] steps: - name: Checkout Movecraft @@ -208,15 +208,15 @@ jobs: ~/.m2/repository/org/spigotmc/minecraft-server/ key: ${{ runner.os }}-v1_19_R3 restore-keys: ${{ runner.os }}-v1_19_R3 - - name: Cache 1.20.1 Maven package + - name: Cache 1.20.2 Maven package uses: actions/cache@v3 with: path: | - ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/ ~/.m2/repository/org/spigotmc/spigot-parent/ ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-v1_20_R1 - restore-keys: ${{ runner.os }}-v1_20_R1 + key: ${{ runner.os }}-v1_20_R2 + restore-keys: ${{ runner.os }}-v1_20_R2 - name: Build with Maven run: mvn -T 1C -B package --file pom.xml diff --git a/README.md b/README.md index 57e3592be..2ce5fbf0b 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ Please check the [Wiki](https://github.com/APDevTeam/Movecraft/wiki) and [FAQ](h [Discord](http://bit.ly/JoinAP-Dev) ## Development Environment -Movecraft uses multiple versions of the Spigot server software for legacy support. As such, you need to run [BuildTools](https://www.spigotmc.org/wiki/buildtools/) for several versions before building the plugin. It doesn't matter where you do this, but inside the Movecraft directory is probably a bad place. We recommend building Spigot 1.16.5 with Java 13 and Java 17 to build 1.18.2, 1.19.4 & 1.20.1. Alternatively, you can use GitHub codespaces and run the `setup.sh` script to build all the needed versions automatically. +Movecraft uses multiple versions of the Spigot server software for legacy support. As such, you need to run [BuildTools](https://www.spigotmc.org/wiki/buildtools/) for several versions before building the plugin. It doesn't matter where you do this, but inside the Movecraft directory is probably a bad place. We recommend building Spigot 1.16.5 with Java 13 and Java 17 to build 1.18.2, 1.19.4 & 1.20.2. Alternatively, you can use GitHub codespaces and run the `setup.sh` script to build all the needed versions automatically. ``` java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit java -jar BuildTools.jar --rev 1.18.2 --remapped java -jar BuildTools.jar --rev 1.19.4 --remapped -java -jar BuildTools.jar --rev 1.20.1 --remapped +java -jar BuildTools.jar --rev 1.20.2 --remapped ``` Once you have compiled CraftBukkit, it should continue to exist in your local maven repository, and thus you should need to compile each version at most one time. Once complete, run the following to build Movecraft through `maven`. diff --git a/modules/Movecraft/pom.xml b/modules/Movecraft/pom.xml index 3cee2145d..68fb1dcc5 100644 --- a/modules/Movecraft/pom.xml +++ b/modules/Movecraft/pom.xml @@ -50,7 +50,7 @@ net.countercraft - movecraft-v1_20_r1 + movecraft-v1_20_r2 ${revision} jar @@ -190,7 +190,7 @@ - net.countercraft:movecraft-v1_20_r1 + net.countercraft:movecraft-v1_20_r2 ** diff --git a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/ISmoothTeleport.java b/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/ISmoothTeleport.java deleted file mode 100644 index e3c120f23..000000000 --- a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/ISmoothTeleport.java +++ /dev/null @@ -1,100 +0,0 @@ -package net.countercraft.movecraft.support.v1_20_R1; - -import net.countercraft.movecraft.SmoothTeleport; -import net.countercraft.movecraft.util.ReflectUtils; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Set; - -/** - * Code derived from code taken with permission from MicleBrick - * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ - * Used for 1.20.1 - */ -public class ISmoothTeleport extends SmoothTeleport { - private final Set teleportFlags; - - private final Method positionMethod; - private final Method sendMethod; - - private final Constructor vec3Constructor; - private final Constructor packetConstructor; - - private final Field connectionField; - private final Field teleportPosField; - private final Field teleportAwaitField; - private final Field awaitingTeleportTimeField; - private final Field tickCountField; - private final Field yawField; - private final Field pitchField; - - private static @NotNull Class getNmClass(String name) throws ClassNotFoundException { - return Class.forName("net.minecraft." + name); - } - - private void sendPacket(Object packet, Player p) { - try { - Object handle = ReflectUtils.getHandle(p); - Object pConnection = connectionField.get(handle); - sendMethod.invoke(pConnection, packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public ISmoothTeleport() throws NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { - Class packetClass = getNmClass("network.protocol.Packet"); - Class positionPacketClass = getNmClass("network.protocol.game.PacketPlayOutPosition"); // ClientboundPlayerPositionPacket - Class entityClass = getNmClass("world.entity.Entity"); - Class playerClass = getNmClass("server.level.EntityPlayer"); // ServerPlayer - Class connectionClass = getNmClass("server.network.PlayerConnection"); // ServerGamePacketListenerImpl - Class vectorClass = getNmClass("world.phys.Vec3D"); // Vec3 - - Object[] flags = getNmClass("world.entity.RelativeMovement").getEnumConstants(); - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT - - positionMethod = entityClass.getDeclaredMethod("a", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); // absMoveTo - sendMethod = connectionClass.getMethod("a", packetClass); // send - - vec3Constructor = vectorClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); - packetConstructor = positionPacketClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); - - connectionField = ReflectUtils.getField(playerClass, "c"); // connection - teleportPosField = ReflectUtils.getField(connectionClass, "D"); // awaitingPositionFromClient - teleportAwaitField = ReflectUtils.getField(connectionClass, "E"); // awaitingTeleport - awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "F"); // awaitingTeleportTime - tickCountField = ReflectUtils.getField(connectionClass, "j"); // tickCount - yawField = ReflectUtils.getField(entityClass, "aH"); // xRot - pitchField = ReflectUtils.getField(entityClass, "aG"); // yRot - } - - public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - Object handle = ReflectUtils.getHandle(player); - try { - positionMethod.invoke(handle, x, y, z, yawField.get(handle), pitchField.get(handle)); - Object connection = connectionField.get(handle); - teleportPosField.set(connection, vec3Constructor.newInstance(x, y, z)); - int teleportAwait = teleportAwaitField.getInt(connection) + 1; - if (teleportAwait == Integer.MAX_VALUE) - teleportAwait = 0; - teleportAwaitField.setInt(connection, teleportAwait); - awaitingTeleportTimeField.set(connection, tickCountField.get(connection)); - - Object packet = packetConstructor.newInstance(x, y, z, yawChange, pitchChange, teleportFlags, teleportAwait); - sendPacket(packet, player); - } - catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { - e.printStackTrace(); - } - } -} diff --git a/modules/v1_20_R1/pom.xml b/modules/v1_20_R2/pom.xml similarity index 87% rename from modules/v1_20_R1/pom.xml rename to modules/v1_20_R2/pom.xml index 9fa32a465..8f18b0c84 100644 --- a/modules/v1_20_R1/pom.xml +++ b/modules/v1_20_R2/pom.xml @@ -10,17 +10,17 @@ 4.0.0 - movecraft-v1_20_r1 - Movecraft-v1_20_R1 + movecraft-v1_20_r2 + Movecraft-v1_20_R2 jar org.spigotmc spigot - 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT remapped-mojang provided - + net.countercraft @@ -38,8 +38,8 @@ 3.8.1 - net/countercraft/movecraft/compat/v1_20_R1/** - net/countercraft/movecraft/support/v1_20_R1/** + net/countercraft/movecraft/compat/v1_20_R2/** + net/countercraft/movecraft/support/v1_20_R2/** 13 13 @@ -51,8 +51,8 @@ 2.4 - net/countercraft/movecraft/compat/v1_20_R1/** - net/countercraft/movecraft/support/v1_20_R1/** + net/countercraft/movecraft/compat/v1_20_R2/** + net/countercraft/movecraft/support/v1_20_R2/** @@ -68,9 +68,9 @@ remap-obf - org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:txt:maps-mojang + org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:txt:maps-mojang true - org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-mojang + org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-mojang true remapped-obf @@ -83,8 +83,8 @@ remap-spigot ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-obf + org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-obf diff --git a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/IWorldHandler.java b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/IWorldHandler.java similarity index 97% rename from modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/IWorldHandler.java rename to modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/IWorldHandler.java index c870ffa06..cada2608e 100644 --- a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/IWorldHandler.java +++ b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/IWorldHandler.java @@ -1,4 +1,4 @@ -package net.countercraft.movecraft.compat.v1_20_R1; +package net.countercraft.movecraft.compat.v1_20_R2; import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; @@ -24,10 +24,10 @@ import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers; import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +54,7 @@ public class IWorldHandler extends WorldHandler { public IWorldHandler() { String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); - if (!mappings.equals("bcf3dcb22ad42792794079f9443df2c0")) + if (!mappings.equals("3478a65bfd04b15b431fe107b3617dfc")) throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.20: " + mappings); } @@ -110,7 +110,7 @@ public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originP moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile()); if (tileHolder.getNextTick() == null) continue; - final long currentTime = nativeWorld.K.getGameTime(); // K is obfuscated serverLevelData + final long currentTime = nativeWorld.K.getGameTime(); nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), rotatedPositions.get(tileHolder.getNextTick().pos()), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder())); } diff --git a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/NextTickProvider.java b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/NextTickProvider.java similarity index 96% rename from modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/NextTickProvider.java rename to modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/NextTickProvider.java index 62a3b7ddf..a9c5f07a2 100644 --- a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/compat/v1_20_R1/NextTickProvider.java +++ b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/compat/v1_20_R2/NextTickProvider.java @@ -1,4 +1,4 @@ -package net.countercraft.movecraft.compat.v1_20_R1; +package net.countercraft.movecraft.compat.v1_20_R2; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; diff --git a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/IAsyncChunk.java b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/IAsyncChunk.java similarity index 92% rename from modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/IAsyncChunk.java rename to modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/IAsyncChunk.java index 9723dcbda..38e57da0b 100644 --- a/modules/v1_20_R1/src/main/java/net/countercraft/movecraft/support/v1_20_R1/IAsyncChunk.java +++ b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/IAsyncChunk.java @@ -1,4 +1,4 @@ -package net.countercraft.movecraft.support.v1_20_R1; +package net.countercraft.movecraft.support.v1_20_R2; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -13,8 +13,8 @@ import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_20_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R2.CraftChunk; +import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; import org.jetbrains.annotations.NotNull; @SuppressWarnings("unused") diff --git a/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/ISmoothTeleport.java b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/ISmoothTeleport.java new file mode 100644 index 000000000..578b016e9 --- /dev/null +++ b/modules/v1_20_R2/src/main/java/net/countercraft/movecraft/support/v1_20_R2/ISmoothTeleport.java @@ -0,0 +1,57 @@ +package net.countercraft.movecraft.support.v1_20_R2; + +import net.countercraft.movecraft.SmoothTeleport; +import net.countercraft.movecraft.util.ReflectUtils; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.RelativeMovement; +import net.minecraft.world.phys.Vec3; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Field; +import java.util.Set; + +/** + * Code derived from code taken with permission from MicleBrick + * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ + * Used for 1.20.2 + */ +public class ISmoothTeleport extends SmoothTeleport { + private final Field teleportPosField; + private final Field teleportAwaitField; + private final Field awaitingTeleportTimeField; + private final Field tickCountField; + + public ISmoothTeleport() throws NoSuchFieldException, ClassNotFoundException { + teleportPosField = ReflectUtils.getField(ServerGamePacketListenerImpl.class, "B"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(ServerGamePacketListenerImpl.class, "C"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(ServerGamePacketListenerImpl.class, "D"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(ServerGamePacketListenerImpl.class, "k"); // tickCount + } + + public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + ServerPlayer handle = (ServerPlayer) ReflectUtils.getHandle(player); + + try { + handle.absMoveTo(x, y, z, handle.getXRot(), handle.getYRot()); + ServerGamePacketListenerImpl connection = handle.connection; + teleportPosField.set(connection, new Vec3(x, y, z)); + int teleportAwait = teleportAwaitField.getInt(connection) + 1; + if (teleportAwait == Integer.MAX_VALUE) + teleportAwait = 0; + teleportAwaitField.setInt(connection, teleportAwait); + awaitingTeleportTimeField.set(connection, tickCountField.get(connection)); + + ClientboundPlayerPositionPacket packet = new ClientboundPlayerPositionPacket(x, y, z, yawChange, pitchChange, Set.of(RelativeMovement.X_ROT, RelativeMovement.Y_ROT), teleportAwait); + connection.send(packet); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/pom.xml b/pom.xml index f8af38e5c..8fd68bd4f 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ modules/v1_16_R3 modules/v1_18_R2 modules/v1_19_R3 - modules/v1_20_R1 + modules/v1_20_R2 modules/datapack modules/Movecraft diff --git a/setup.sh b/setup.sh index b58878ee2..219d722d0 100755 --- a/setup.sh +++ b/setup.sh @@ -47,11 +47,11 @@ else java -jar BuildTools.jar --rev 1.19.4 --remapped fi -# Build 1.20.1 -if [ -f ~/.m2/repository/org/spigotmc/spigot/1.20.1-R0.1-SNAPSHOT/spigot-1.20.1-R0.1-SNAPSHOT.jar ]; then - echo "1.20.1 already exists, skipping build" +# Build 1.20.2 +if [ -f ~/.m2/repository/org/spigotmc/spigot/1.20.2-R0.1-SNAPSHOT/spigot-1.20.2-R0.1-SNAPSHOT.jar ]; then + echo "1.20.2 already exists, skipping build" else - java -jar BuildTools.jar --rev 1.20.1 --remapped + java -jar BuildTools.jar --rev 1.20.2 --remapped fi # Restore git information