From d0c64ea4c871927e21d349dbdf6ea62844f9033a Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Fri, 2 Dec 2022 19:38:29 -0600 Subject: [PATCH 01/27] Update libraries --- modules/api/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/api/pom.xml b/modules/api/pom.xml index be302e2d7..8dab7d303 100644 --- a/modules/api/pom.xml +++ b/modules/api/pom.xml @@ -7,7 +7,7 @@ UTF-8 - 5.8.2 + 5.9.0 ${junit.jupiter.version} 1.2.0 4.13.2 @@ -80,24 +80,24 @@ org.roaringbitmap RoaringBitmap - 0.9.27 + 0.9.32 compile it.unimi.dsi fastutil - 8.5.8 + 8.5.9 compile net.kyori adventure-api - 4.10.1 + 4.12.0 net.kyori adventure-platform-bukkit - 4.1.0 + 4.1.2 @@ -185,4 +185,4 @@ - \ No newline at end of file + From 7a151c946ade422ee443024c07a9918f5d571735 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Fri, 2 Dec 2022 19:38:58 -0600 Subject: [PATCH 02/27] Clean up redundant libraries and relocate roaringbitmap --- modules/Movecraft/pom.xml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/Movecraft/pom.xml b/modules/Movecraft/pom.xml index 2ee267887..d698b796e 100644 --- a/modules/Movecraft/pom.xml +++ b/modules/Movecraft/pom.xml @@ -83,18 +83,7 @@ org.yaml snakeyaml - 1.32 - - - org.jetbrains - annotations-java5 - 22.0.0 - - - it.unimi.dsi - fastutil - 8.5.8 - compile + 1.33 @@ -188,6 +177,10 @@ net.kyori net.countercraft.movecraft.libs.net.kyori + + org.roaringbitmap + net.countercraft.movecraft.libs.org.roaringbitmap + true false From e563cc1af729bec412d5fc7604d56a9aa63ecdbb Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 17:13:45 -0600 Subject: [PATCH 03/27] Remove 1.17.1 --- modules/v1_17_R1/pom.xml | 94 ------ .../compat/v1_17_R1/IWorldHandler.java | 299 ------------------ .../compat/v1_17_R1/NextTickProvider.java | 30 -- .../support/v1_17_R1/IAsyncChunk.java | 57 ---- pom.xml | 1 - 5 files changed, 481 deletions(-) delete mode 100644 modules/v1_17_R1/pom.xml delete mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java delete mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java delete mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java diff --git a/modules/v1_17_R1/pom.xml b/modules/v1_17_R1/pom.xml deleted file mode 100644 index 9e8517ca3..000000000 --- a/modules/v1_17_R1/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - movecraft-parent - net.countercraft - ${revision} - ../../pom.xml - - 4.0.0 - - movecraft-v1_17_r1 - Movecraft-v1_17_R1 - jar - - - org.spigotmc - spigot - 1.17.1-R0.1-SNAPSHOT - remapped-mojang - provided - - - net.countercraft - movecraft-api - ${revision} - jar - - - - src/main/java - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - net/countercraft/movecraft/compat/v1_17_R1/** - net/countercraft/movecraft/support/v1_17_R1/** - - 13 - 13 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - net/countercraft/movecraft/compat/v1_17_R1/** - net/countercraft/movecraft/support/v1_17_R1/** - - - - - net.md-5 - specialsource-maven-plugin - 1.2.2 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.17.1-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:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - \ No newline at end of file diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java deleted file mode 100644 index c4d624824..000000000 --- a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java +++ /dev/null @@ -1,299 +0,0 @@ -package net.countercraft.movecraft.compat.v1_17_R1; - -import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.MovecraftRotation; -import net.countercraft.movecraft.WorldHandler; -import net.countercraft.movecraft.craft.Craft; -import net.countercraft.movecraft.util.CollectionUtils; -import net.countercraft.movecraft.util.MathUtils; -import net.countercraft.movecraft.util.UnsafeUtils; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.TickNextTickData; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.level.chunk.LevelChunkSection; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@SuppressWarnings("unused") -public class IWorldHandler extends WorldHandler { - private static final Rotation ROTATION[]; - - static { - ROTATION = new Rotation[3]; - ROTATION[MovecraftRotation.NONE.ordinal()] = Rotation.NONE; - ROTATION[MovecraftRotation.CLOCKWISE.ordinal()] = Rotation.CLOCKWISE_90; - ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = Rotation.COUNTERCLOCKWISE_90; - } - - private final NextTickProvider tickProvider = new NextTickProvider(); - - public IWorldHandler() { - String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); - if (!mappings.equals("f0e3dfc7390de285a4693518dd5bd126")) - throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.17: " + mappings); - } - - @Override - public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { - //******************************************* - //* Step one: Convert to Positions * - //******************************************* - HashMap rotatedPositions = new HashMap<>(); - MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE; - for (MovecraftLocation newLocation : craft.getHitBox()) { - rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation)); - } - //******************************************* - //* Step two: Get the tiles * - //******************************************* - ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); - List tiles = new ArrayList<>(); - //get the tiles - for (BlockPos position : rotatedPositions.keySet()) { - //BlockEntity tile = nativeWorld.removeBlockEntity(position); - BlockEntity tile = removeBlockEntity(nativeWorld, position); - if (tile == null) - continue; -// tile.a(ROTATION[rotation.ordinal()]); - //get the nextTick to move with the tile - tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position)); - } - - //******************************************* - //* Step three: Translate all the blocks * - //******************************************* - // blockedByWater=false means an ocean-going vessel - //TODO: Simplify - //TODO: go by chunks - //TODO: Don't move unnecessary blocks - //get the blocks and rotate them - HashMap blockData = new HashMap<>(); - for (BlockPos position : rotatedPositions.keySet()) { - blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()])); - } - //create the new block - for (Map.Entry entry : blockData.entrySet()) { - setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue()); - } - - - //******************************************* - //* Step four: replace all the tiles * - //******************************************* - //TODO: go by chunks - for (TileHolder tileHolder : tiles) { - moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile()); - if (tileHolder.getNextTick() == null) - continue; - final long currentTime = nativeWorld.E.getGameTime(); - nativeWorld.getBlockTickList().scheduleTick(rotatedPositions.get(tileHolder.getNextTick().pos), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority); - } - - //******************************************* - //* Step five: Destroy the leftovers * - //******************************************* - //TODO: add support for pass-through - Collection deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values()); - for (BlockPos position : deletePositions) { - setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState()); - } - } - - @Override - public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) { - //TODO: Add support for rotations - //A craftTranslateCommand should only occur if the craft is moving to a valid position - //******************************************* - //* Step one: Convert to Positions * - //******************************************* - BlockPos translateVector = locationToPosition(displacement); - List positions = new ArrayList<>(craft.getHitBox().size()); - craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).e(translateVector))); - ServerLevel oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); - ServerLevel nativeWorld = ((CraftWorld) world).getHandle(); - //******************************************* - //* Step two: Get the tiles * - //******************************************* - List tiles = new ArrayList<>(); - //get the tiles - for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { - BlockPos position = positions.get(i); - if (oldNativeWorld.getBlockState(position) == Blocks.AIR.defaultBlockState()) - continue; - //BlockEntity tile = nativeWorld.removeBlockEntity(position); - BlockEntity tile = removeBlockEntity(oldNativeWorld, position); - if (tile == null) - continue; - //get the nextTick to move with the tile - - //nativeWorld.capturedTileEntities.remove(position); - //nativeWorld.getChunkAtWorldCoords(position).getTileEntities().remove(position); - tiles.add(new TileHolder(tile, tickProvider.getNextTick(oldNativeWorld, position), position)); - - } - //******************************************* - //* Step three: Translate all the blocks * - //******************************************* - // blockedByWater=false means an ocean-going vessel - //TODO: Simplify - //TODO: go by chunks - //TODO: Don't move unnecessary blocks - //get the blocks and translate the positions - List blockData = new ArrayList<>(); - List newPositions = new ArrayList<>(); - for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { - BlockPos position = positions.get(i); - blockData.add(oldNativeWorld.getBlockState(position)); - newPositions.add(position.f(translateVector)); - } - //create the new block - for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) { - setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i)); - } - //******************************************* - //* Step four: replace all the tiles * - //******************************************* - //TODO: go by chunks - for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) { - TileHolder tileHolder = tiles.get(i); - moveBlockEntity(nativeWorld, tileHolder.getTilePosition().f(translateVector), tileHolder.getTile()); - if (tileHolder.getNextTick() == null) - continue; - final long currentTime = nativeWorld.E.getGameTime(); - nativeWorld.getBlockTickList().scheduleTick(tileHolder.getNextTick().pos.f(translateVector), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority); - } - //******************************************* - //* Step five: Destroy the leftovers * - //******************************************* - List deletePositions = positions; - if (oldNativeWorld == nativeWorld) - deletePositions = CollectionUtils.filter(positions, newPositions); - for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) { - BlockPos position = deletePositions.get(i); - setBlockFast(oldNativeWorld, position, Blocks.AIR.defaultBlockState()); - } - } - - @Nullable - private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) { - return world.getChunkAt(position).blockEntities.remove(position); - } - - @NotNull - private BlockPos locationToPosition(@NotNull MovecraftLocation loc) { - return new BlockPos(loc.getX(), loc.getY(), loc.getZ()); - } - - private void setBlockFast(@NotNull Level world, @NotNull BlockPos position, @NotNull BlockState data) { - LevelChunk chunk = world.getChunkAt(position); - int chunkSection = (position.getY() >> 4) - chunk.getMinSection(); - LevelChunkSection section = chunk.getSections()[chunkSection]; - if (section == null) { - // Put a GLASS block to initialize the section. It will be replaced next with the real block. - chunk.setBlockState(position, Blocks.GLASS.defaultBlockState(), false); - section = chunk.getSections()[chunkSection]; - } - if (section.getBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) { - //Block is already of correct type and data, don't overwrite - return; - } - section.setBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data); - world.sendBlockUpdated(position, data, data, 3); - world.getLightEngine().checkBlock(position); // boolean corresponds to if chunk section empty - chunk.markUnsaved(); - } - - @Override - public void setBlockFast(@NotNull Location location, @NotNull BlockData data) { - setBlockFast(location, MovecraftRotation.NONE, data); - } - - @Override - public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) { - BlockState blockData; - if (data instanceof CraftBlockData) { - blockData = ((CraftBlockData) data).getState(); - } - else { - blockData = (BlockState) data; - } - blockData = blockData.rotate(ROTATION[rotation.ordinal()]); - Level world = ((CraftWorld) (location.getWorld())).getHandle(); - BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location)); - setBlockFast(world, BlockPos, blockData); - } - - @Override - public void disableShadow(@NotNull Material type) { - // Disabled - } - - private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { - LevelChunk chunk = nativeWorld.getChunkAt(newPosition); - try { - var positionField = BlockEntity.class.getDeclaredField("o"); // o is obfuscated worldPosition - UnsafeUtils.setField(positionField, tile, newPosition); - } - catch (NoSuchFieldException e) { - e.printStackTrace(); - } - tile.setLevel(nativeWorld); - tile.clearRemoved(); - if (nativeWorld.captureBlockStates) { - nativeWorld.capturedTileEntities.put(newPosition, tile); - return; - } - chunk.setBlockEntity(tile); - chunk.blockEntities.put(newPosition, tile); - } - - private static class TileHolder { - @NotNull - private final BlockEntity tile; - @Nullable - private final TickNextTickData nextTick; - @NotNull - private final BlockPos tilePosition; - - public TileHolder(@NotNull BlockEntity tile, @Nullable TickNextTickData nextTick, @NotNull BlockPos tilePosition) { - this.tile = tile; - this.nextTick = nextTick; - this.tilePosition = tilePosition; - } - - - @NotNull - public BlockEntity getTile() { - return tile; - } - - @Nullable - public TickNextTickData getNextTick() { - return nextTick; - } - - @NotNull - public BlockPos getTilePosition() { - return tilePosition; - } - } -} \ No newline at end of file diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java deleted file mode 100644 index 3b574d476..000000000 --- a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.countercraft.movecraft.compat.v1_17_R1; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.ServerTickList; -import net.minecraft.world.level.TickNextTickData; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.levelgen.structure.BoundingBox; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.logging.Logger; - -public class NextTickProvider { - - @Nullable - public TickNextTickData getNextTick(@NotNull ServerLevel world, @NotNull BlockPos position){ - ServerTickList tickList = world.getBlockTickList(); - var box = BoundingBox.encapsulatingPositions(List.of(position)); - if(box.isEmpty()){ - return null; - } - for(var tick : tickList.fetchTicksInArea(box.get(), false, false)){ - Logger.getAnonymousLogger().info("" + tick); - return tick; - } - return null; - } -} diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java deleted file mode 100644 index aac0c7749..000000000 --- a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java +++ /dev/null @@ -1,57 +0,0 @@ -package net.countercraft.movecraft.support.v1_17_R1; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.processing.WorldManager; -import net.countercraft.movecraft.support.AsyncChunk; -import net.minecraft.core.BlockPos; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.block.BlockState; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_17_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings("unused") -public class IAsyncChunk extends AsyncChunk { - - private final @NotNull LoadingCache stateCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<>() { - @Override - public BlockState load(@NotNull MovecraftLocation movecraftLocation) { - var block = chunk.getBlock(movecraftLocation.getX(), movecraftLocation.getY(), movecraftLocation.getZ()); - return WorldManager.INSTANCE.executeMain(block::getState); - } - }); - - public IAsyncChunk(@NotNull Chunk chunk) { - super(chunk); - } - - @NotNull - @Override - protected CraftChunk adapt(@NotNull org.bukkit.Chunk chunk) { - return (CraftChunk) chunk; - } - - @NotNull - @Override - public BlockState getState(@NotNull MovecraftLocation location) { - return stateCache.getUnchecked(location); - } - - @Override - @NotNull - public Material getType(@NotNull MovecraftLocation location){ - return this.getData(location).getMaterial(); - } - - @Override - @NotNull - public BlockData getData(@NotNull MovecraftLocation location){ - return CraftBlockData.fromData(chunk.getHandle().getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))); - } - -} diff --git a/pom.xml b/pom.xml index 64b7236ed..04b399504 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,6 @@ modules/api modules/v1_14_R1 modules/v1_16_R3 - modules/v1_17_R1 modules/v1_18_R2 modules/v1_19_R1 modules/datapack From e26591526d8d5acf50c37211ecd1422d4e01c9e3 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 17:17:36 -0600 Subject: [PATCH 04/27] Initial stab at 1.19.3 worldhandler This is a copy of 1.19.2's worldhandler --- modules/v1_19_R2/pom.xml | 94 ++++++ .../compat/v1_19_R2/IWorldHandler.java | 305 ++++++++++++++++++ .../compat/v1_19_R2/NextTickProvider.java | 44 +++ .../support/v1_19_R2/IAsyncChunk.java | 57 ++++ pom.xml | 1 + 5 files changed, 501 insertions(+) create mode 100644 modules/v1_19_R2/pom.xml create mode 100644 modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java create mode 100644 modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/NextTickProvider.java create mode 100644 modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/IAsyncChunk.java diff --git a/modules/v1_19_R2/pom.xml b/modules/v1_19_R2/pom.xml new file mode 100644 index 000000000..ffd3ede5d --- /dev/null +++ b/modules/v1_19_R2/pom.xml @@ -0,0 +1,94 @@ + + + + movecraft-parent + net.countercraft + ${revision} + ../../pom.xml + + 4.0.0 + + movecraft-v1_19_r2 + Movecraft-v1_19_R2 + jar + + + org.spigotmc + spigot + 1.19.3-R0.1-SNAPSHOT + remapped-mojang + provided + + + net.countercraft + movecraft-api + ${revision} + jar + + + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + net/countercraft/movecraft/compat/v1_19_R2/** + net/countercraft/movecraft/support/v1_19_R2/** + + 13 + 13 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + net/countercraft/movecraft/compat/v1_19_R2/** + net/countercraft/movecraft/support/v1_19_R2/** + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.19.3-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:1.19.3-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java new file mode 100644 index 000000000..a5f254575 --- /dev/null +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java @@ -0,0 +1,305 @@ +package net.countercraft.movecraft.compat.v1_19_R2; + +import net.countercraft.movecraft.MovecraftLocation; +import net.countercraft.movecraft.MovecraftRotation; +import net.countercraft.movecraft.WorldHandler; +import net.countercraft.movecraft.craft.Craft; +import net.countercraft.movecraft.util.CollectionUtils; +import net.countercraft.movecraft.util.MathUtils; +import net.countercraft.movecraft.util.UnsafeUtils; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.ticks.ScheduledTick; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_19_R2.util.CraftMagicNumbers; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("unused") +public class IWorldHandler extends WorldHandler { + private static final Rotation ROTATION[]; + + static { + ROTATION = new Rotation[3]; + ROTATION[MovecraftRotation.NONE.ordinal()] = Rotation.NONE; + ROTATION[MovecraftRotation.CLOCKWISE.ordinal()] = Rotation.CLOCKWISE_90; + ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = Rotation.COUNTERCLOCKWISE_90; + } + + private final NextTickProvider tickProvider = new NextTickProvider(); + + public IWorldHandler() { + String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); + if (!mappings.equals("69c84c88aeb92ce9fa9525438b93f4fe")) + throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.19: " + mappings); + } + +// @Override +// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){ +// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle(); +// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class)); +// } + + @Override + public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { + //******************************************* + //* Step one: Convert to Positions * + //******************************************* + HashMap rotatedPositions = new HashMap<>(); + MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE; + for (MovecraftLocation newLocation : craft.getHitBox()) { + rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation)); + } + //******************************************* + //* Step two: Get the tiles * + //******************************************* + ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); + List tiles = new ArrayList<>(); + //get the tiles + for (BlockPos position : rotatedPositions.keySet()) { + //BlockEntity tile = nativeWorld.removeBlockEntity(position); + BlockEntity tile = removeBlockEntity(nativeWorld, position); + if (tile == null) + continue; +// tile.a(ROTATION[rotation.ordinal()]); + //get the nextTick to move with the tile + tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position)); + } + + //******************************************* + //* Step three: Translate all the blocks * + //******************************************* + // blockedByWater=false means an ocean-going vessel + //TODO: Simplify + //TODO: go by chunks + //TODO: Don't move unnecessary blocks + //get the blocks and rotate them + HashMap blockData = new HashMap<>(); + for (BlockPos position : rotatedPositions.keySet()) { + blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()])); + } + //create the new block + for (Map.Entry entry : blockData.entrySet()) { + setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue()); + } + + + //******************************************* + //* Step four: replace all the tiles * + //******************************************* + //TODO: go by chunks + for (TileHolder tileHolder : tiles) { + moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile()); + if (tileHolder.getNextTick() == null) + continue; + final long currentTime = nativeWorld.N.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())); + } + + //******************************************* + //* Step five: Destroy the leftovers * + //******************************************* + //TODO: add support for pass-through + Collection deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values()); + for (BlockPos position : deletePositions) { + setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState()); + } + } + + @Override + public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) { + //TODO: Add support for rotations + //A craftTranslateCommand should only occur if the craft is moving to a valid position + //******************************************* + //* Step one: Convert to Positions * + //******************************************* + BlockPos translateVector = locationToPosition(displacement); + List positions = new ArrayList<>(craft.getHitBox().size()); + craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).subtract(translateVector))); + ServerLevel oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); + ServerLevel nativeWorld = ((CraftWorld) world).getHandle(); + //******************************************* + //* Step two: Get the tiles * + //******************************************* + List tiles = new ArrayList<>(); + //get the tiles + for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { + BlockPos position = positions.get(i); + if (oldNativeWorld.getBlockState(position) == Blocks.AIR.defaultBlockState()) + continue; + //BlockEntity tile = nativeWorld.removeBlockEntity(position); + BlockEntity tile = removeBlockEntity(oldNativeWorld, position); + if (tile == null) + continue; + //get the nextTick to move with the tile + + //nativeWorld.capturedTileEntities.remove(position); + //nativeWorld.getChunkAtWorldCoords(position).getTileEntities().remove(position); + tiles.add(new TileHolder(tile, tickProvider.getNextTick(oldNativeWorld, position), position)); + + } + //******************************************* + //* Step three: Translate all the blocks * + //******************************************* + // blockedByWater=false means an ocean-going vessel + //TODO: Simplify + //TODO: go by chunks + //TODO: Don't move unnecessary blocks + //get the blocks and translate the positions + List blockData = new ArrayList<>(); + List newPositions = new ArrayList<>(); + for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { + BlockPos position = positions.get(i); + blockData.add(oldNativeWorld.getBlockState(position)); + newPositions.add(position.offset(translateVector)); + } + //create the new block + for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) { + setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i)); + } + //******************************************* + //* Step four: replace all the tiles * + //******************************************* + //TODO: go by chunks + for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) { + TileHolder tileHolder = tiles.get(i); + moveBlockEntity(nativeWorld, tileHolder.getTilePosition().offset(translateVector), tileHolder.getTile()); + if (tileHolder.getNextTick() == null) + continue; + final long currentTime = nativeWorld.getGameTime(); + nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), tileHolder.getTilePosition().offset(translateVector), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder())); + } + //******************************************* + //* Step five: Destroy the leftovers * + //******************************************* + List deletePositions = positions; + if (oldNativeWorld == nativeWorld) + deletePositions = CollectionUtils.filter(positions, newPositions); + for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) { + BlockPos position = deletePositions.get(i); + setBlockFast(oldNativeWorld, position, Blocks.AIR.defaultBlockState()); + } + } + + @Nullable + private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) { + return world.getChunkAt(position).blockEntities.remove(position); + } + + @NotNull + private BlockPos locationToPosition(@NotNull MovecraftLocation loc) { + return new BlockPos(loc.getX(), loc.getY(), loc.getZ()); + } + + private void setBlockFast(@NotNull Level world, @NotNull BlockPos position, @NotNull BlockState data) { + LevelChunk chunk = world.getChunkAt(position); + int chunkSection = (position.getY() >> 4) - chunk.getMinSection(); + LevelChunkSection section = chunk.getSections()[chunkSection]; + if (section == null) { + // Put a GLASS block to initialize the section. It will be replaced next with the real block. + chunk.setBlockState(position, Blocks.GLASS.defaultBlockState(), false); + section = chunk.getSections()[chunkSection]; + } + if (section.getBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) { + //Block is already of correct type and data, don't overwrite + return; + } + section.setBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data); + world.sendBlockUpdated(position, data, data, 3); + world.getLightEngine().checkBlock(position); // boolean corresponds to if chunk section empty + chunk.setUnsaved(true); + } + + @Override + public void setBlockFast(@NotNull Location location, @NotNull BlockData data) { + setBlockFast(location, MovecraftRotation.NONE, data); + } + + @Override + public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) { + BlockState blockData; + if (data instanceof CraftBlockData) { + blockData = ((CraftBlockData) data).getState(); + } + else { + blockData = (BlockState) data; + } + blockData = blockData.rotate(ROTATION[rotation.ordinal()]); + Level world = ((CraftWorld) (location.getWorld())).getHandle(); + BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location)); + setBlockFast(world, BlockPos, blockData); + } + + @Override + public void disableShadow(@NotNull Material type) { + // Disabled + } + + private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { + LevelChunk chunk = nativeWorld.getChunkAt(newPosition); + try { + var positionField = BlockEntity.class.getDeclaredField("o"); // o is obfuscated worldPosition + UnsafeUtils.setField(positionField, tile, newPosition); + } + catch (NoSuchFieldException e) { + e.printStackTrace(); + } + tile.setLevel(nativeWorld); + tile.clearRemoved(); + if (nativeWorld.captureBlockStates) { + nativeWorld.capturedTileEntities.put(newPosition, tile); + return; + } + chunk.setBlockEntity(tile); + chunk.blockEntities.put(newPosition, tile); + } + + private static class TileHolder { + @NotNull + private final BlockEntity tile; + @Nullable + private final ScheduledTick nextTick; + @NotNull + private final BlockPos tilePosition; + + public TileHolder(@NotNull BlockEntity tile, @Nullable ScheduledTick nextTick, @NotNull BlockPos tilePosition) { + this.tile = tile; + this.nextTick = nextTick; + this.tilePosition = tilePosition; + } + + + @NotNull + public BlockEntity getTile() { + return tile; + } + + @Nullable + public ScheduledTick getNextTick() { + return nextTick; + } + + @NotNull + public BlockPos getTilePosition() { + return tilePosition; + } + } +} \ No newline at end of file diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/NextTickProvider.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/NextTickProvider.java new file mode 100644 index 000000000..06f40c453 --- /dev/null +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/NextTickProvider.java @@ -0,0 +1,44 @@ +package net.countercraft.movecraft.compat.v1_19_R2; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.ticks.LevelTicks; +import net.minecraft.world.ticks.ScheduledTick; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Queue; + +public class NextTickProvider { + + @Nullable + public ScheduledTick getNextTick(@NotNull ServerLevel world, @NotNull BlockPos position){ + LevelTicks tickList = world.getBlockTicks(); + var box = BoundingBox.encapsulatingPositions(List.of(position)); + if(box.isEmpty()){ + return null; + } + Queue> toRunThisTick; + try { + Field toRunThisTickField = LevelTicks.class.getDeclaredField("g"); + toRunThisTickField.setAccessible(true); + toRunThisTick = (Queue>) toRunThisTickField.get(tickList); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + return null; + } + for (var iter = toRunThisTick.iterator(); iter.hasNext(); ) { + var next = iter.next(); + if (!next.pos().equals(position)) { + continue; + } + iter.remove(); + return next; + } + return null; + } +} diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/IAsyncChunk.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/IAsyncChunk.java new file mode 100644 index 000000000..d6cc3a737 --- /dev/null +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/IAsyncChunk.java @@ -0,0 +1,57 @@ +package net.countercraft.movecraft.support.v1_19_R2; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import net.countercraft.movecraft.MovecraftLocation; +import net.countercraft.movecraft.processing.WorldManager; +import net.countercraft.movecraft.support.AsyncChunk; +import net.minecraft.core.BlockPos; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_19_R2.CraftChunk; +import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("unused") +public class IAsyncChunk extends AsyncChunk { + + private final @NotNull LoadingCache stateCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<>() { + @Override + public BlockState load(@NotNull MovecraftLocation movecraftLocation) { + var block = chunk.getBlock(movecraftLocation.getX(), movecraftLocation.getY(), movecraftLocation.getZ()); + return WorldManager.INSTANCE.executeMain(block::getState); + } + }); + + public IAsyncChunk(@NotNull Chunk chunk) { + super(chunk); + } + + @NotNull + @Override + protected CraftChunk adapt(@NotNull org.bukkit.Chunk chunk) { + return (CraftChunk) chunk; + } + + @NotNull + @Override + public BlockState getState(@NotNull MovecraftLocation location) { + return stateCache.getUnchecked(location); + } + + @Override + @NotNull + public Material getType(@NotNull MovecraftLocation location){ + return this.getData(location).getMaterial(); + } + + @Override + @NotNull + public BlockData getData(@NotNull MovecraftLocation location){ + return CraftBlockData.fromData(chunk.getHandle().getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))); + } + +} diff --git a/pom.xml b/pom.xml index 04b399504..d8a87d5cb 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ modules/v1_16_R3 modules/v1_18_R2 modules/v1_19_R1 + modules/v1_19_R2 modules/datapack modules/Movecraft From 00440e323e152524926307cb1eb0fb7b7289a916 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 18:50:31 -0600 Subject: [PATCH 05/27] Change magic number, add mappings links The 1.19.3 and 1.19.2 mappings seem to be identical --- modules/v1_18_R2/pom.xml | 1 + modules/v1_19_R1/pom.xml | 1 + modules/v1_19_R2/pom.xml | 1 + .../countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/v1_18_R2/pom.xml b/modules/v1_18_R2/pom.xml index d896c8c11..ce1947274 100644 --- a/modules/v1_18_R2/pom.xml +++ b/modules/v1_18_R2/pom.xml @@ -20,6 +20,7 @@ 1.18.2-R0.1-SNAPSHOT remapped-mojang provided + net.countercraft diff --git a/modules/v1_19_R1/pom.xml b/modules/v1_19_R1/pom.xml index 2bc1384a7..faea18a95 100644 --- a/modules/v1_19_R1/pom.xml +++ b/modules/v1_19_R1/pom.xml @@ -20,6 +20,7 @@ 1.19.2-R0.1-SNAPSHOT remapped-mojang provided + net.countercraft diff --git a/modules/v1_19_R2/pom.xml b/modules/v1_19_R2/pom.xml index ffd3ede5d..10bd81f4e 100644 --- a/modules/v1_19_R2/pom.xml +++ b/modules/v1_19_R2/pom.xml @@ -20,6 +20,7 @@ 1.19.3-R0.1-SNAPSHOT remapped-mojang provided + net.countercraft diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java index a5f254575..91a82a546 100644 --- a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java @@ -48,7 +48,7 @@ public class IWorldHandler extends WorldHandler { public IWorldHandler() { String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); - if (!mappings.equals("69c84c88aeb92ce9fa9525438b93f4fe")) + if (!mappings.equals("1afe2ffe8a9d7fc510442a168b3d4338")) throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.19: " + 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.N.getGameTime(); + final long currentTime = nativeWorld.N.getGameTime(); // N is obfuscated serverLevelData nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), rotatedPositions.get(tileHolder.getNextTick().pos()), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder())); } From adfe09d62f9d6aab28731648b56bdac669b8dd9a Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 19:09:00 -0600 Subject: [PATCH 06/27] Update CI? --- .github/workflows/maven.yml | 233 ++++++++++++++++++---------------- .github/workflows/publish.yml | 99 ++++++++------- 2 files changed, 177 insertions(+), 155 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 99dc37247..543c6d064 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -69,48 +69,6 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit - # Build 1.17.1 NMS - goats_1_17: - runs-on: ubuntu-latest - steps: - - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache 1.17.1 Maven package - id: cacheGoats - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.17.1-all - restore-keys: ${{ runner.os }}-spigot-1.17.1-all - - name: Cache Maven packages - id: cacheMain - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2_1.17.1 - restore-keys: ${{ runner.os }}-m2_1.17.1 - - - 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.17.1 Spigot - id: goats - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Mojang) - id: goatsMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Obf) - id: goatsObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Build 1.17.1 - if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped - # Build 1.18.2 NMS caves_1_18: runs-on: ubuntu-latest @@ -154,7 +112,7 @@ jobs: run: cd BuildTools && java -jar BuildTools.jar --rev 1.18.2 --remapped # Build 1.19.2 NMS - wild_1_19: + wild_1_19_2: runs-on: ubuntu-latest steps: - name: Set up JDK 17 # 1.19.2 can only be built with Java 17 @@ -195,78 +153,131 @@ 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.2 --remapped + + # Build 1.19.3 NMS + wild_1_19_3: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.19.3 can only be built with Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.19.3 Maven package + id: cacheWild + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.19.3-all + restore-keys: ${{ runner.os }}-spigot-1.19.3-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.19.3 + restore-keys: ${{ runner.os }}-m2_1.19.3 + + - 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.19.3 Spigot + id: wild + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.19.3 Spigot (Mojang) + id: wildMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.19.3 Spigot (Obf) + id: wildObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.19.3 + 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.3 --remapped + # Build Movecraft build: runs-on: ubuntu-latest - needs: [pillage_1_14, nether_1_16, goats_1_17, caves_1_18, wild_1_19] + needs: [pillage_1_14, nether_1_16, goats_1_17, caves_1_18, wild_1_19_2, wild_1_19_3] steps: - - name: Checkout Movecraft - uses: actions/checkout@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache Maven packages - id: cacheMain - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2 - restore-keys: ${{ runner.os }}-m2 - - name: Cache 1.14.4 Maven package - id: cachePillage - uses: actions/cache@v2 - with: - path: ~/.m2/repository/org/bukkit/craftbukkit/1.14.4-R0.1-SNAPSHOT/ - key: ${{ runner.os }}-1.14.4 - restore-keys: ${{ runner.os }}-1.14.4 - - name: Cache 1.16.5 Maven package - id: cacheNether - uses: actions/cache@v2 - with: - path: ~/.m2/repository/org/bukkit/craftbukkit/1.16.5-R0.1-SNAPSHOT/ - key: ${{ runner.os }}-1.16.5 - restore-keys: ${{ runner.os }}-1.16.5 - - name: Cache 1.17.1 Maven package - id: cacheGoats - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.17.1-all - restore-keys: ${{ runner.os }}-spigot-1.17.1-all - - name: Cache 1.18.2 Maven package - id: cacheCaves - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.18.2-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.18.2-all - restore-keys: ${{ runner.os }}-spigot-1.18.2-all - - name: Cache 1.19.2 Maven package - id: cacheWild - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.19.2-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.19.2-all - restore-keys: ${{ runner.os }}-spigot-1.19.2-all + - name: Checkout Movecraft + uses: actions/checkout@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2 + restore-keys: ${{ runner.os }}-m2 + - name: Cache 1.14.4 Maven package + id: cachePillage + uses: actions/cache@v2 + with: + path: ~/.m2/repository/org/bukkit/craftbukkit/1.14.4-R0.1-SNAPSHOT/ + key: ${{ runner.os }}-1.14.4 + restore-keys: ${{ runner.os }}-1.14.4 + - name: Cache 1.16.5 Maven package + id: cacheNether + uses: actions/cache@v2 + with: + path: ~/.m2/repository/org/bukkit/craftbukkit/1.16.5-R0.1-SNAPSHOT/ + key: ${{ runner.os }}-1.16.5 + restore-keys: ${{ runner.os }}-1.16.5 + - name: Cache 1.17.1 Maven package + id: cacheGoats + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.17.1-all + restore-keys: ${{ runner.os }}-spigot-1.17.1-all + - name: Cache 1.18.2 Maven package + id: cacheCaves + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.18.2-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.18.2-all + restore-keys: ${{ runner.os }}-spigot-1.18.2-all + - name: Cache 1.19.2 Maven package + id: cacheWild + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.19.2-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.19.2-all + restore-keys: ${{ runner.os }}-spigot-1.19.2-all + - name: Cache 1.19.3 Maven package + id: cacheWild + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.19.3-all + restore-keys: ${{ runner.os }}-spigot-1.19.3-all - - name: Build with Maven - run: mvn -T 1C -B package --file pom.xml + - name: Build with Maven + run: mvn -T 1C -B package --file pom.xml - - name: Stage jar - run: mkdir staging && cp target/Movecraft.jar staging && mv staging/Movecraft.jar staging/Movecraft_$GITHUB_SHA.jar - - name: Upload jar - uses: actions/upload-artifact@v2 - with: - name: Movecraft_Dev-Build - path: staging/Movecraft_*.jar + - name: Stage jar + run: mkdir staging && cp target/Movecraft.jar staging && mv staging/Movecraft.jar staging/Movecraft_$GITHUB_SHA.jar + - name: Upload jar + uses: actions/upload-artifact@v2 + with: + name: Movecraft_Dev-Build + path: staging/Movecraft_*.jar diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0fc825ace..a4b113f54 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -72,48 +72,6 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit - # Build 1.17.1 NMS - goats_1_17: - runs-on: ubuntu-latest - steps: - - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache 1.17.1 Maven package - id: cacheGoats - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.17.1-all - restore-keys: ${{ runner.os }}-spigot-1.17.1-all - - name: Cache Maven packages - id: cacheMain - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2_1.17.1 - restore-keys: ${{ runner.os }}-m2_1.17.1 - - - 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.17.1 Spigot - id: goats - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Mojang) - id: goatsMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Obf) - id: goatsObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Build 1.17.1 - if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped - # Build 1.18.2 NMS caves_1_18: runs-on: ubuntu-latest @@ -157,7 +115,7 @@ jobs: run: cd BuildTools && java -jar BuildTools.jar --rev 1.18.2 --remapped # Build 1.19.2 NMS - wild_1_19: + wild_1_19_2: runs-on: ubuntu-latest steps: - name: Set up JDK 17 # 1.19.2 can only be built with Java 17 @@ -198,10 +156,53 @@ 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.2 --remapped + + # Build 1.19.3 NMS + wild_1_19_3: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.19.3 can only be built with Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.19.3 Maven package + id: cacheWild + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.19.3-all + restore-keys: ${{ runner.os }}-spigot-1.19.3-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.19.3 + restore-keys: ${{ runner.os }}-m2_1.19.3 + + - 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.19.3 Spigot + id: wild + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.19.3 Spigot (Mojang) + id: wildMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.19.3 Spigot (Obf) + id: wildObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.19.3 + 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.3 --remapped + # Build Movecraft publish: runs-on: ubuntu-latest - needs: [pillage_1_14, nether_1_16, goats_1_17, caves_1_18, wild_1_19] + needs: [pillage_1_14, nether_1_16, goats_1_17, caves_1_18, wild_1_19_2, wild_1_19_3] permissions: contents: read packages: write @@ -265,6 +266,16 @@ jobs: ~/.m2/repository/org/spigotmc/minecraft-server/ key: ${{ runner.os }}-spigot-1.19.2-all restore-keys: ${{ runner.os }}-spigot-1.19.2-all + - name: Cache 1.19.3 Maven package + id: cacheWild + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.19.3-all + restore-keys: ${{ runner.os }}-spigot-1.19.3-all - name: Build with Maven run: mvn -T 1C -B package --file pom.xml From 2f1d0c20050573710773ae64b0de3eb6312fe768 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 19:47:04 -0600 Subject: [PATCH 07/27] Update pom to include 1.19.3 worldhandler --- modules/Movecraft/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/Movecraft/pom.xml b/modules/Movecraft/pom.xml index d698b796e..e2832b0d3 100644 --- a/modules/Movecraft/pom.xml +++ b/modules/Movecraft/pom.xml @@ -52,19 +52,19 @@ net.countercraft - movecraft-v1_17_r1 + movecraft-v1_18_r2 ${revision} jar net.countercraft - movecraft-v1_18_r2 + movecraft-v1_19_r1 ${revision} jar net.countercraft - movecraft-v1_19_r1 + movecraft-v1_19_r2 ${revision} jar @@ -198,19 +198,19 @@ - net.countercraft:movecraft-v1_17_r1 + net.countercraft:movecraft-v1_18_r2 ** - net.countercraft:movecraft-v1_18_r2 + net.countercraft:movecraft-v1_19_r1 ** - net.countercraft:movecraft-v1_19_r1 + net.countercraft:movecraft-v1_19_r2 ** From 2289089ebb88e82647522fa6d088a1a98c4127dd Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Thu, 8 Dec 2022 19:47:18 -0600 Subject: [PATCH 08/27] Update setup for 1.19.3 --- setup.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index 327b4c1e5..e48ff073f 100755 --- a/setup.sh +++ b/setup.sh @@ -40,13 +40,6 @@ else /usr/lib/jvm/temurin-11-jdk-amd64/bin/java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit fi -# Build 1.17.1 -if [ -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar ]; then - echo "1.17.1 already exists, skipping build" -else - java -jar BuildTools.jar --rev 1.17.1 --remapped -fi - # Build 1.18.2 if [ -f ~/.m2/repository/org/spigotmc/spigot/1.18.2-R0.1-SNAPSHOT/spigot-1.18.2-R0.1-SNAPSHOT.jar ]; then echo "1.18.2 already exists, skipping build" @@ -54,13 +47,20 @@ else java -jar BuildTools.jar --rev 1.18.2 --remapped fi -# Build 1.19.1 +# Build 1.19.2 if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19-R0.1-SNAPSHOT/spigot-1.19.2-R0.1-SNAPSHOT.jar ]; then echo "1.19.2 already exists, skipping build" else java -jar BuildTools.jar --rev 1.19.2 --remapped fi +# Build 1.19.3 +if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT.jar ]; then + echo "1.19.3 already exists, skipping build" +else + java -jar BuildTools.jar --rev 1.19.3 --remapped +fi + # Restore git information git config --global user.name "$git_name" git config --global user.email "$git_email" From 6b3f888275fdc92a02305a4f6ab0a52ed00f6eb4 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:31:03 -0600 Subject: [PATCH 09/27] Move TeleportUtils --- .../util/teleport/TeleportUtils.java | 101 ------------------ .../movecraft/util/ReflectUtils.java | 36 +++++++ 2 files changed, 36 insertions(+), 101 deletions(-) delete mode 100644 modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/TeleportUtils.java create mode 100644 modules/api/src/main/java/net/countercraft/movecraft/util/ReflectUtils.java diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/TeleportUtils.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/TeleportUtils.java deleted file mode 100644 index 877715084..000000000 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/TeleportUtils.java +++ /dev/null @@ -1,101 +0,0 @@ -package net.countercraft.movecraft.util.teleport; - -import net.countercraft.movecraft.Movecraft; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * Code taken with permission from MicleBrick - * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ - */ -public class TeleportUtils { - protected static @Nullable Object getHandle(Entity entity) { - try { - Method entity_getHandle = entity.getClass().getMethod("getHandle"); - return entity_getHandle.invoke(entity); - } - catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - protected static @NotNull Field getField(@NotNull Class clazz, String name) throws NoSuchFieldException { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field; - } - - protected static @NotNull String getVersion() { - return Bukkit.getServer().getClass().getPackage().getName().substring(23); - } - - - private enum Mode { - UNINITIALIZED, - FALLBACK, - SPIGOT_MAPPED, - V1_17, - V1_18, - V1_19 - } - - private static Mode mode = Mode.UNINITIALIZED; - - private static void initialize() { - int version = Integer.parseInt(getVersion().split("_")[1]); - if (version < 17 && SpigotMappedTeleport.initialize()) { - mode = Mode.SPIGOT_MAPPED; - } - else if (version <= 17 && V1_17Teleport.initialize()) { - mode = Mode.V1_17; - } - else if (version <= 18 && V1_18Teleport.initialize()) { - mode = Mode.V1_18; - } - else if (version <= 19 && V1_19Teleport.initialize()) { - mode = Mode.V1_19; - } - else { - Bukkit.getLogger().warning("Failed to access internal teleportation handle, switching to fallback"); - mode = Mode.FALLBACK; - } - } - - public static void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { - if (mode == Mode.UNINITIALIZED) - initialize(); - - switch (mode) { - case SPIGOT_MAPPED: - SpigotMappedTeleport.teleport(player, location, yawChange, pitchChange); - break; - case V1_17: - V1_17Teleport.teleport(player, location, yawChange, pitchChange); - break; - case V1_18: - V1_18Teleport.teleport(player, location, yawChange, pitchChange); - break; - case V1_19: - V1_19Teleport.teleport(player, location, yawChange, pitchChange); - break; - case FALLBACK: - Movecraft.getInstance().getWorldHandler().addPlayerLocation(player, - location.getX() - player.getLocation().getX(), - location.getY() - player.getLocation().getY(), - location.getZ() - player.getLocation().getZ(), - yawChange, pitchChange - ); - break; - default: - throw new IllegalStateException("Unknown mode: " + mode); - } - } -} diff --git a/modules/api/src/main/java/net/countercraft/movecraft/util/ReflectUtils.java b/modules/api/src/main/java/net/countercraft/movecraft/util/ReflectUtils.java new file mode 100644 index 000000000..e3c519a07 --- /dev/null +++ b/modules/api/src/main/java/net/countercraft/movecraft/util/ReflectUtils.java @@ -0,0 +1,36 @@ +package net.countercraft.movecraft.util; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * Code taken with permission from MicleBrick + * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ + */ +public class ReflectUtils { + public static @Nullable Object getHandle(Entity entity) { + try { + Method entity_getHandle = entity.getClass().getMethod("getHandle"); + return entity_getHandle.invoke(entity); + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static @NotNull Field getField(@NotNull Class clazz, String name) throws NoSuchFieldException { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } + + public static @NotNull String getVersion() { + return Bukkit.getServer().getClass().getPackage().getName().substring(23); + } +} From 9b75c813ac61285a383c5038ceb6b8556257f6a1 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:36:54 -0600 Subject: [PATCH 10/27] Create smooth teleport base class and bukkit implementation --- .../movecraft/SmoothTeleport.java | 11 ++ .../movecraft/util/BukkitTeleport.java | 20 +++ .../support/v1_16_R3/ISmoothTeleport.java | 121 ++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java create mode 100644 modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java create mode 100644 modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java diff --git a/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java b/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java new file mode 100644 index 000000000..716f39ea7 --- /dev/null +++ b/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java @@ -0,0 +1,11 @@ +package net.countercraft.movecraft; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public abstract class SmoothTeleport { + public abstract boolean initialize(); + + public abstract void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange); +} diff --git a/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java b/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java new file mode 100644 index 000000000..f2e36c057 --- /dev/null +++ b/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java @@ -0,0 +1,20 @@ +package net.countercraft.movecraft.util; + +import net.countercraft.movecraft.SmoothTeleport; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class BukkitTeleport extends SmoothTeleport { + @Override + public boolean initialize() { + return true; + } + + @Override + public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { + location.setYaw(player.getLocation().getYaw() + yawChange); + location.setPitch(player.getLocation().getPitch() + pitchChange); + player.teleport(location); + } +} diff --git a/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java new file mode 100644 index 000000000..9e03c7467 --- /dev/null +++ b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java @@ -0,0 +1,121 @@ +package net.countercraft.movecraft.support.v1_16_R3; + +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 taken with permission from MicleBrick + * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ + * Used for 1.14.4 to 1.16.5 + */ +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; + + private Constructor packetConstructor; + private Constructor vec3D; + + private Method position; + private Method sendMethod; + + private Field connectionField; + private Field justTeleportedField; + private Field teleportPosField; + private Field lastPosXField; + private Field lastPosYField; + private Field lastPosZField; + private Field teleportAwaitField; + private Field AField; + private Field eField; + private Field yaw; + private Field pitch; + + private static @NotNull Class getNmsClass(String name) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + ReflectUtils.getVersion() + "." + 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 boolean initialize() { + boolean success = false; + try { + Class packet = getNmsClass("Packet"); + Class entity = getNmsClass("Entity"); + Class entityPlayer = getNmsClass("EntityPlayer"); + Class connectionClass = getNmsClass("PlayerConnection"); + Class packetClass = getNmsClass("PacketPlayOutPosition"); + Class vecClass = getNmsClass("Vec3D"); + sendMethod = connectionClass.getMethod("sendPacket", packet); + + position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); + + yaw = ReflectUtils.getField(entity, "yaw"); + pitch = ReflectUtils.getField(entity, "pitch"); + connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); + + packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); + vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); + + Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); + teleportFlags = Set.of(enumObjects[4], enumObjects[3]); + + justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); + teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); + lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); + lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); + lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); + teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); + AField = ReflectUtils.getField(connectionClass, "A"); + eField = ReflectUtils.getField(connectionClass, "e"); + success = true; + } + catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return success; + } + + 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 { + position.invoke(handle, x, y, z, yaw.get(handle), pitch.get(handle)); + Object connection = connectionField.get(handle); + justTeleportedField.set(connection, true); + teleportPosField.set(connection, vec3D.newInstance(x, y, z)); + lastPosXField.set(connection, x); + lastPosYField.set(connection, y); + lastPosZField.set(connection, z); + int teleportAwait = teleportAwaitField.getInt(connection) + 1; + if (teleportAwait == Integer.MAX_VALUE) + teleportAwait = 0; + teleportAwaitField.set(connection, teleportAwait); + AField.set(connection, eField.get(connection)); + + Object packet = packetConstructor.newInstance(x, y, z, yawChange, pitchChange, teleportFlags, teleportAwait); + sendPacket(packet, player); + } + catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} From 2f8c69df8b0f9f28a96868f90cefd92204bb2a10 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:39:30 -0600 Subject: [PATCH 11/27] Remove smooth teleport from worldhandlers --- .../util/teleport/SpigotMappedTeleport.java | 119 ------------------ .../countercraft/movecraft/WorldHandler.java | 4 - .../compat/v1_14_R1/IWorldHandler.java | 29 ----- .../compat/v1_16_R3/IWorldHandler.java | 30 ----- .../compat/v1_18_R2/IWorldHandler.java | 6 - .../compat/v1_19_R1/IWorldHandler.java | 6 - .../compat/v1_19_R2/IWorldHandler.java | 6 - 7 files changed, 200 deletions(-) delete mode 100644 modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/SpigotMappedTeleport.java diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/SpigotMappedTeleport.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/SpigotMappedTeleport.java deleted file mode 100644 index 855a62cee..000000000 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/SpigotMappedTeleport.java +++ /dev/null @@ -1,119 +0,0 @@ -package net.countercraft.movecraft.util.teleport; - -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 taken with permission from MicleBrick - * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ - * Used for 1.14.4 to 1.16.5 - */ -public class SpigotMappedTeleport extends AbstractTeleport { - private static Set teleportFlags; - - private static Constructor packetConstructor; - private static Constructor vec3D; - - private static Method position; - private static Method sendMethod; - - private static Field connectionField; - private static Field justTeleportedField; - private static Field teleportPosField; - private static Field lastPosXField; - private static Field lastPosYField; - private static Field lastPosZField; - private static Field teleportAwaitField; - private static Field AField; - private static Field eField; - private static Field yaw; - private static Field pitch; - - private static @NotNull Class getNmsClass(String name) throws ClassNotFoundException { - return Class.forName("net.minecraft.server." + TeleportUtils.getVersion() + "." + name); - } - - private static void sendPacket(Object packet, Player p) { - try { - Object handle = TeleportUtils.getHandle(p); - Object pConnection = connectionField.get(handle); - sendMethod.invoke(pConnection, packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public static boolean initialize() { - boolean success = false; - try { - Class packet = getNmsClass("Packet"); - Class entity = getNmsClass("Entity"); - Class entityPlayer = getNmsClass("EntityPlayer"); - Class connectionClass = getNmsClass("PlayerConnection"); - Class packetClass = getNmsClass("PacketPlayOutPosition"); - Class vecClass = getNmsClass("Vec3D"); - sendMethod = connectionClass.getMethod("sendPacket", packet); - - position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); - - yaw = TeleportUtils.getField(entity, "yaw"); - pitch = TeleportUtils.getField(entity, "pitch"); - connectionField = TeleportUtils.getField(entityPlayer, "playerConnection"); - - packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); - vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); - - Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); - teleportFlags = Set.of(enumObjects[4], enumObjects[3]); - - justTeleportedField = TeleportUtils.getField(connectionClass, "justTeleported"); - teleportPosField = TeleportUtils.getField(connectionClass, "teleportPos"); - lastPosXField = TeleportUtils.getField(connectionClass, "lastPosX"); - lastPosYField = TeleportUtils.getField(connectionClass, "lastPosY"); - lastPosZField = TeleportUtils.getField(connectionClass, "lastPosZ"); - teleportAwaitField = TeleportUtils.getField(connectionClass, "teleportAwait"); - AField = TeleportUtils.getField(connectionClass, "A"); - eField = TeleportUtils.getField(connectionClass, "e"); - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - return success; - } - - public static 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 = TeleportUtils.getHandle(player); - try { - position.invoke(handle, x, y, z, yaw.get(handle), pitch.get(handle)); - Object connection = connectionField.get(handle); - justTeleportedField.set(connection, true); - teleportPosField.set(connection, vec3D.newInstance(x, y, z)); - lastPosXField.set(connection, x); - lastPosYField.set(connection, y); - lastPosZField.set(connection, z); - int teleportAwait = teleportAwaitField.getInt(connection) + 1; - if (teleportAwait == Integer.MAX_VALUE) - teleportAwait = 0; - teleportAwaitField.set(connection, teleportAwait); - AField.set(connection, eField.get(connection)); - - Object packet = packetConstructor.newInstance(x, y, z, yawChange, pitchChange, teleportFlags, teleportAwait); - sendPacket(packet, player); - } - catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e) { - e.printStackTrace(); - } - } -} diff --git a/modules/api/src/main/java/net/countercraft/movecraft/WorldHandler.java b/modules/api/src/main/java/net/countercraft/movecraft/WorldHandler.java index e5c110e53..6957f4d35 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/WorldHandler.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/WorldHandler.java @@ -14,8 +14,4 @@ public abstract class WorldHandler { public abstract void setBlockFast(@NotNull Location location, @NotNull BlockData data); public abstract void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data); public abstract void disableShadow(@NotNull Material type); - public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){ - Location playerLoc = player.getLocation(); - player.teleport(new Location(player.getWorld(), x + playerLoc.getX(),y + playerLoc.getY(),z + playerLoc.getZ(),yaw + playerLoc.getYaw(),pitch + playerLoc.getPitch())); - } } diff --git a/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/compat/v1_14_R1/IWorldHandler.java b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/compat/v1_14_R1/IWorldHandler.java index b5aa74d8f..ff64a02d2 100644 --- a/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/compat/v1_14_R1/IWorldHandler.java +++ b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/compat/v1_14_R1/IWorldHandler.java @@ -55,39 +55,10 @@ public class IWorldHandler extends WorldHandler { ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = EnumBlockRotation.COUNTERCLOCKWISE_90; } - private MethodHandle internalTeleportMH; - public IWorldHandler() { String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); if (!mappings.equals("11ae498d9cf909730659b6357e7c2afa")) throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.14: " + mappings); - - MethodHandles.Lookup lookup = MethodHandles.lookup(); - Method teleport; - try { - teleport = PlayerConnection.class.getDeclaredMethod("a", double.class, double.class, double.class, float.class, float.class, Set.class); - teleport.setAccessible(true); - internalTeleportMH = lookup.unreflect(teleport); - } - catch (NoSuchMethodException | IllegalAccessException e) { - e.printStackTrace(); - } - } - - @Override - public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch) { - EntityPlayer ePlayer = ((CraftPlayer) player).getHandle(); - if (internalTeleportMH == null) { - //something went wrong - super.addPlayerLocation(player, x, y, z, yaw, pitch); - return; - } - try { - internalTeleportMH.invoke(ePlayer.playerConnection, x, y, z, yaw, pitch, EnumSet.allOf(PacketPlayOutPosition.EnumPlayerTeleportFlags.class)); - } - catch (Throwable throwable) { - throwable.printStackTrace(); - } } @Override diff --git a/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/compat/v1_16_R3/IWorldHandler.java b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/compat/v1_16_R3/IWorldHandler.java index 3e6d871b9..bc68a831f 100644 --- a/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/compat/v1_16_R3/IWorldHandler.java +++ b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/compat/v1_16_R3/IWorldHandler.java @@ -55,40 +55,10 @@ public class IWorldHandler extends WorldHandler { ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = EnumBlockRotation.COUNTERCLOCKWISE_90; } - private MethodHandle internalTeleportMH; - public IWorldHandler() { String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); if (!mappings.equals("d4b392244df170796f8779ef0fc1f2e9")) throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.16: " + mappings); - - MethodHandles.Lookup lookup = MethodHandles.lookup(); - Method teleport = null; - try { - teleport = PlayerConnection.class.getDeclaredMethod("a", double.class, double.class, double.class, float.class, float.class, Set.class); - teleport.setAccessible(true); - internalTeleportMH = lookup.unreflect(teleport); - - } - catch (NoSuchMethodException | IllegalAccessException e) { - e.printStackTrace(); - } - } - - @Override - public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch) { - EntityPlayer ePlayer = ((CraftPlayer) player).getHandle(); - if (internalTeleportMH == null) { - //something went wrong - super.addPlayerLocation(player, x, y, z, yaw, pitch); - return; - } - try { - internalTeleportMH.invoke(ePlayer.playerConnection, x, y, z, yaw, pitch, EnumSet.allOf(PacketPlayOutPosition.EnumPlayerTeleportFlags.class)); - } - catch (Throwable throwable) { - throwable.printStackTrace(); - } } @Override diff --git a/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/compat/v1_18_R2/IWorldHandler.java b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/compat/v1_18_R2/IWorldHandler.java index 505833525..1d70ba93a 100644 --- a/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/compat/v1_18_R2/IWorldHandler.java +++ b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/compat/v1_18_R2/IWorldHandler.java @@ -52,12 +52,6 @@ public IWorldHandler() { throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.18: " + mappings); } -// @Override -// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){ -// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle(); -// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class)); -// } - @Override public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { //******************************************* diff --git a/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/compat/v1_19_R1/IWorldHandler.java b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/compat/v1_19_R1/IWorldHandler.java index 1530bf7aa..e8dcad3df 100644 --- a/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/compat/v1_19_R1/IWorldHandler.java +++ b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/compat/v1_19_R1/IWorldHandler.java @@ -52,12 +52,6 @@ public IWorldHandler() { throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.19: " + mappings); } -// @Override -// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){ -// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle(); -// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class)); -// } - @Override public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { //******************************************* diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java index 91a82a546..fdaaf94d6 100644 --- a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/compat/v1_19_R2/IWorldHandler.java @@ -52,12 +52,6 @@ public IWorldHandler() { throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.19: " + mappings); } -// @Override -// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){ -// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle(); -// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class)); -// } - @Override public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { //******************************************* From 66bf6583c4e1126388ac5e26ab607d92f1511afa Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:40:35 -0600 Subject: [PATCH 12/27] More work on smooth teleport handlers --- .../util/teleport/AbstractTeleport.java | 14 -- .../support/v1_14_R1/ISmoothTeleport.java | 121 ++++++++++++++++++ 2 files changed, 121 insertions(+), 14 deletions(-) delete mode 100644 modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/AbstractTeleport.java create mode 100644 modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/AbstractTeleport.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/AbstractTeleport.java deleted file mode 100644 index 90c15055f..000000000 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/AbstractTeleport.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.countercraft.movecraft.util.teleport; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public abstract class AbstractTeleport { - - public static boolean initialize() { - return false; - } - - public static void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { } -} diff --git a/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java new file mode 100644 index 000000000..d82d1ace9 --- /dev/null +++ b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java @@ -0,0 +1,121 @@ +package net.countercraft.movecraft.support.v1_14_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 taken with permission from MicleBrick + * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ + * Used for 1.14.4 to 1.16.5 + */ +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; + + private Constructor packetConstructor; + private Constructor vec3D; + + private Method position; + private Method sendMethod; + + private Field connectionField; + private Field justTeleportedField; + private Field teleportPosField; + private Field lastPosXField; + private Field lastPosYField; + private Field lastPosZField; + private Field teleportAwaitField; + private Field AField; + private Field eField; + private Field yaw; + private Field pitch; + + private static @NotNull Class getNmsClass(String name) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + ReflectUtils.getVersion() + "." + 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 boolean initialize() { + boolean success = false; + try { + Class packet = getNmsClass("Packet"); + Class entity = getNmsClass("Entity"); + Class entityPlayer = getNmsClass("EntityPlayer"); + Class connectionClass = getNmsClass("PlayerConnection"); + Class packetClass = getNmsClass("PacketPlayOutPosition"); + Class vecClass = getNmsClass("Vec3D"); + sendMethod = connectionClass.getMethod("sendPacket", packet); + + position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); + + yaw = ReflectUtils.getField(entity, "yaw"); + pitch = ReflectUtils.getField(entity, "pitch"); + connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); + + packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); + vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); + + Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); + teleportFlags = Set.of(enumObjects[4], enumObjects[3]); + + justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); + teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); + lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); + lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); + lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); + teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); + AField = ReflectUtils.getField(connectionClass, "A"); + eField = ReflectUtils.getField(connectionClass, "e"); + success = true; + } + catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return success; + } + + 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 { + position.invoke(handle, x, y, z, yaw.get(handle), pitch.get(handle)); + Object connection = connectionField.get(handle); + justTeleportedField.set(connection, true); + teleportPosField.set(connection, vec3D.newInstance(x, y, z)); + lastPosXField.set(connection, x); + lastPosYField.set(connection, y); + lastPosZField.set(connection, z); + int teleportAwait = teleportAwaitField.getInt(connection) + 1; + if (teleportAwait == Integer.MAX_VALUE) + teleportAwait = 0; + teleportAwaitField.set(connection, teleportAwait); + AField.set(connection, eField.get(connection)); + + Object packet = packetConstructor.newInstance(x, y, z, yawChange, pitchChange, teleportFlags, teleportAwait); + sendPacket(packet, player); + } + catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} From bd3c2d85830349ded4796f80c9d31434676fa612 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:40:44 -0600 Subject: [PATCH 13/27] Revert "Remove 1.17.1" This reverts commit e563cc1af729bec412d5fc7604d56a9aa63ecdbb. --- modules/v1_17_R1/pom.xml | 94 ++++++ .../compat/v1_17_R1/IWorldHandler.java | 299 ++++++++++++++++++ .../compat/v1_17_R1/NextTickProvider.java | 30 ++ .../support/v1_17_R1/IAsyncChunk.java | 57 ++++ pom.xml | 1 + 5 files changed, 481 insertions(+) create mode 100644 modules/v1_17_R1/pom.xml create mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java create mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java create mode 100644 modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java diff --git a/modules/v1_17_R1/pom.xml b/modules/v1_17_R1/pom.xml new file mode 100644 index 000000000..9e8517ca3 --- /dev/null +++ b/modules/v1_17_R1/pom.xml @@ -0,0 +1,94 @@ + + + + movecraft-parent + net.countercraft + ${revision} + ../../pom.xml + + 4.0.0 + + movecraft-v1_17_r1 + Movecraft-v1_17_R1 + jar + + + org.spigotmc + spigot + 1.17.1-R0.1-SNAPSHOT + remapped-mojang + provided + + + net.countercraft + movecraft-api + ${revision} + jar + + + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + net/countercraft/movecraft/compat/v1_17_R1/** + net/countercraft/movecraft/support/v1_17_R1/** + + 13 + 13 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + net/countercraft/movecraft/compat/v1_17_R1/** + net/countercraft/movecraft/support/v1_17_R1/** + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.17.1-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:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java new file mode 100644 index 000000000..c4d624824 --- /dev/null +++ b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/IWorldHandler.java @@ -0,0 +1,299 @@ +package net.countercraft.movecraft.compat.v1_17_R1; + +import net.countercraft.movecraft.MovecraftLocation; +import net.countercraft.movecraft.MovecraftRotation; +import net.countercraft.movecraft.WorldHandler; +import net.countercraft.movecraft.craft.Craft; +import net.countercraft.movecraft.util.CollectionUtils; +import net.countercraft.movecraft.util.MathUtils; +import net.countercraft.movecraft.util.UnsafeUtils; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.TickNextTickData; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("unused") +public class IWorldHandler extends WorldHandler { + private static final Rotation ROTATION[]; + + static { + ROTATION = new Rotation[3]; + ROTATION[MovecraftRotation.NONE.ordinal()] = Rotation.NONE; + ROTATION[MovecraftRotation.CLOCKWISE.ordinal()] = Rotation.CLOCKWISE_90; + ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = Rotation.COUNTERCLOCKWISE_90; + } + + private final NextTickProvider tickProvider = new NextTickProvider(); + + public IWorldHandler() { + String mappings = ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion(); + if (!mappings.equals("f0e3dfc7390de285a4693518dd5bd126")) + throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft 1.17: " + mappings); + } + + @Override + public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { + //******************************************* + //* Step one: Convert to Positions * + //******************************************* + HashMap rotatedPositions = new HashMap<>(); + MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE; + for (MovecraftLocation newLocation : craft.getHitBox()) { + rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation)); + } + //******************************************* + //* Step two: Get the tiles * + //******************************************* + ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); + List tiles = new ArrayList<>(); + //get the tiles + for (BlockPos position : rotatedPositions.keySet()) { + //BlockEntity tile = nativeWorld.removeBlockEntity(position); + BlockEntity tile = removeBlockEntity(nativeWorld, position); + if (tile == null) + continue; +// tile.a(ROTATION[rotation.ordinal()]); + //get the nextTick to move with the tile + tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position)); + } + + //******************************************* + //* Step three: Translate all the blocks * + //******************************************* + // blockedByWater=false means an ocean-going vessel + //TODO: Simplify + //TODO: go by chunks + //TODO: Don't move unnecessary blocks + //get the blocks and rotate them + HashMap blockData = new HashMap<>(); + for (BlockPos position : rotatedPositions.keySet()) { + blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()])); + } + //create the new block + for (Map.Entry entry : blockData.entrySet()) { + setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue()); + } + + + //******************************************* + //* Step four: replace all the tiles * + //******************************************* + //TODO: go by chunks + for (TileHolder tileHolder : tiles) { + moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile()); + if (tileHolder.getNextTick() == null) + continue; + final long currentTime = nativeWorld.E.getGameTime(); + nativeWorld.getBlockTickList().scheduleTick(rotatedPositions.get(tileHolder.getNextTick().pos), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority); + } + + //******************************************* + //* Step five: Destroy the leftovers * + //******************************************* + //TODO: add support for pass-through + Collection deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values()); + for (BlockPos position : deletePositions) { + setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState()); + } + } + + @Override + public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) { + //TODO: Add support for rotations + //A craftTranslateCommand should only occur if the craft is moving to a valid position + //******************************************* + //* Step one: Convert to Positions * + //******************************************* + BlockPos translateVector = locationToPosition(displacement); + List positions = new ArrayList<>(craft.getHitBox().size()); + craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).e(translateVector))); + ServerLevel oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); + ServerLevel nativeWorld = ((CraftWorld) world).getHandle(); + //******************************************* + //* Step two: Get the tiles * + //******************************************* + List tiles = new ArrayList<>(); + //get the tiles + for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { + BlockPos position = positions.get(i); + if (oldNativeWorld.getBlockState(position) == Blocks.AIR.defaultBlockState()) + continue; + //BlockEntity tile = nativeWorld.removeBlockEntity(position); + BlockEntity tile = removeBlockEntity(oldNativeWorld, position); + if (tile == null) + continue; + //get the nextTick to move with the tile + + //nativeWorld.capturedTileEntities.remove(position); + //nativeWorld.getChunkAtWorldCoords(position).getTileEntities().remove(position); + tiles.add(new TileHolder(tile, tickProvider.getNextTick(oldNativeWorld, position), position)); + + } + //******************************************* + //* Step three: Translate all the blocks * + //******************************************* + // blockedByWater=false means an ocean-going vessel + //TODO: Simplify + //TODO: go by chunks + //TODO: Don't move unnecessary blocks + //get the blocks and translate the positions + List blockData = new ArrayList<>(); + List newPositions = new ArrayList<>(); + for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { + BlockPos position = positions.get(i); + blockData.add(oldNativeWorld.getBlockState(position)); + newPositions.add(position.f(translateVector)); + } + //create the new block + for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) { + setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i)); + } + //******************************************* + //* Step four: replace all the tiles * + //******************************************* + //TODO: go by chunks + for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) { + TileHolder tileHolder = tiles.get(i); + moveBlockEntity(nativeWorld, tileHolder.getTilePosition().f(translateVector), tileHolder.getTile()); + if (tileHolder.getNextTick() == null) + continue; + final long currentTime = nativeWorld.E.getGameTime(); + nativeWorld.getBlockTickList().scheduleTick(tileHolder.getNextTick().pos.f(translateVector), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority); + } + //******************************************* + //* Step five: Destroy the leftovers * + //******************************************* + List deletePositions = positions; + if (oldNativeWorld == nativeWorld) + deletePositions = CollectionUtils.filter(positions, newPositions); + for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) { + BlockPos position = deletePositions.get(i); + setBlockFast(oldNativeWorld, position, Blocks.AIR.defaultBlockState()); + } + } + + @Nullable + private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) { + return world.getChunkAt(position).blockEntities.remove(position); + } + + @NotNull + private BlockPos locationToPosition(@NotNull MovecraftLocation loc) { + return new BlockPos(loc.getX(), loc.getY(), loc.getZ()); + } + + private void setBlockFast(@NotNull Level world, @NotNull BlockPos position, @NotNull BlockState data) { + LevelChunk chunk = world.getChunkAt(position); + int chunkSection = (position.getY() >> 4) - chunk.getMinSection(); + LevelChunkSection section = chunk.getSections()[chunkSection]; + if (section == null) { + // Put a GLASS block to initialize the section. It will be replaced next with the real block. + chunk.setBlockState(position, Blocks.GLASS.defaultBlockState(), false); + section = chunk.getSections()[chunkSection]; + } + if (section.getBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) { + //Block is already of correct type and data, don't overwrite + return; + } + section.setBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data); + world.sendBlockUpdated(position, data, data, 3); + world.getLightEngine().checkBlock(position); // boolean corresponds to if chunk section empty + chunk.markUnsaved(); + } + + @Override + public void setBlockFast(@NotNull Location location, @NotNull BlockData data) { + setBlockFast(location, MovecraftRotation.NONE, data); + } + + @Override + public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) { + BlockState blockData; + if (data instanceof CraftBlockData) { + blockData = ((CraftBlockData) data).getState(); + } + else { + blockData = (BlockState) data; + } + blockData = blockData.rotate(ROTATION[rotation.ordinal()]); + Level world = ((CraftWorld) (location.getWorld())).getHandle(); + BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location)); + setBlockFast(world, BlockPos, blockData); + } + + @Override + public void disableShadow(@NotNull Material type) { + // Disabled + } + + private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { + LevelChunk chunk = nativeWorld.getChunkAt(newPosition); + try { + var positionField = BlockEntity.class.getDeclaredField("o"); // o is obfuscated worldPosition + UnsafeUtils.setField(positionField, tile, newPosition); + } + catch (NoSuchFieldException e) { + e.printStackTrace(); + } + tile.setLevel(nativeWorld); + tile.clearRemoved(); + if (nativeWorld.captureBlockStates) { + nativeWorld.capturedTileEntities.put(newPosition, tile); + return; + } + chunk.setBlockEntity(tile); + chunk.blockEntities.put(newPosition, tile); + } + + private static class TileHolder { + @NotNull + private final BlockEntity tile; + @Nullable + private final TickNextTickData nextTick; + @NotNull + private final BlockPos tilePosition; + + public TileHolder(@NotNull BlockEntity tile, @Nullable TickNextTickData nextTick, @NotNull BlockPos tilePosition) { + this.tile = tile; + this.nextTick = nextTick; + this.tilePosition = tilePosition; + } + + + @NotNull + public BlockEntity getTile() { + return tile; + } + + @Nullable + public TickNextTickData getNextTick() { + return nextTick; + } + + @NotNull + public BlockPos getTilePosition() { + return tilePosition; + } + } +} \ No newline at end of file diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java new file mode 100644 index 000000000..3b574d476 --- /dev/null +++ b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/compat/v1_17_R1/NextTickProvider.java @@ -0,0 +1,30 @@ +package net.countercraft.movecraft.compat.v1_17_R1; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.ServerTickList; +import net.minecraft.world.level.TickNextTickData; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.logging.Logger; + +public class NextTickProvider { + + @Nullable + public TickNextTickData getNextTick(@NotNull ServerLevel world, @NotNull BlockPos position){ + ServerTickList tickList = world.getBlockTickList(); + var box = BoundingBox.encapsulatingPositions(List.of(position)); + if(box.isEmpty()){ + return null; + } + for(var tick : tickList.fetchTicksInArea(box.get(), false, false)){ + Logger.getAnonymousLogger().info("" + tick); + return tick; + } + return null; + } +} diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java new file mode 100644 index 000000000..aac0c7749 --- /dev/null +++ b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/IAsyncChunk.java @@ -0,0 +1,57 @@ +package net.countercraft.movecraft.support.v1_17_R1; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import net.countercraft.movecraft.MovecraftLocation; +import net.countercraft.movecraft.processing.WorldManager; +import net.countercraft.movecraft.support.AsyncChunk; +import net.minecraft.core.BlockPos; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_17_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("unused") +public class IAsyncChunk extends AsyncChunk { + + private final @NotNull LoadingCache stateCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<>() { + @Override + public BlockState load(@NotNull MovecraftLocation movecraftLocation) { + var block = chunk.getBlock(movecraftLocation.getX(), movecraftLocation.getY(), movecraftLocation.getZ()); + return WorldManager.INSTANCE.executeMain(block::getState); + } + }); + + public IAsyncChunk(@NotNull Chunk chunk) { + super(chunk); + } + + @NotNull + @Override + protected CraftChunk adapt(@NotNull org.bukkit.Chunk chunk) { + return (CraftChunk) chunk; + } + + @NotNull + @Override + public BlockState getState(@NotNull MovecraftLocation location) { + return stateCache.getUnchecked(location); + } + + @Override + @NotNull + public Material getType(@NotNull MovecraftLocation location){ + return this.getData(location).getMaterial(); + } + + @Override + @NotNull + public BlockData getData(@NotNull MovecraftLocation location){ + return CraftBlockData.fromData(chunk.getHandle().getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))); + } + +} diff --git a/pom.xml b/pom.xml index d8a87d5cb..6ef0a27a7 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ modules/api modules/v1_14_R1 modules/v1_16_R3 + modules/v1_17_R1 modules/v1_18_R2 modules/v1_19_R1 modules/v1_19_R2 From d688dce894edb742079bd70a076957dd3e792c31 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:42:43 -0600 Subject: [PATCH 14/27] Restore 1.17 CI --- .github/workflows/maven.yml | 43 ++++++++++++++++++++++++++++++++++- .github/workflows/publish.yml | 43 ++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 543c6d064..0bdc3235a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -69,6 +69,48 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit + # Build 1.17.1 NMS + goats_1_17: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.17.1 Maven package + id: cacheGoats + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.17.1-all + restore-keys: ${{ runner.os }}-spigot-1.17.1-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.17.1 + restore-keys: ${{ runner.os }}-m2_1.17.1 + + - 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.17.1 Spigot + id: goats + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Mojang) + id: goatsMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Obf) + id: goatsObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.17.1 + if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' + run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped + # Build 1.18.2 NMS caves_1_18: runs-on: ubuntu-latest @@ -153,7 +195,6 @@ 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.2 --remapped - # Build 1.19.3 NMS wild_1_19_3: runs-on: ubuntu-latest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a4b113f54..5de90f649 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -72,6 +72,48 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit + # Build 1.17.1 NMS + goats_1_17: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.17.1 Maven package + id: cacheGoats + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.17.1-all + restore-keys: ${{ runner.os }}-spigot-1.17.1-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.17.1 + restore-keys: ${{ runner.os }}-m2_1.17.1 + + - 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.17.1 Spigot + id: goats + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Mojang) + id: goatsMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Obf) + id: goatsObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.17.1 + if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' + run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped + # Build 1.18.2 NMS caves_1_18: runs-on: ubuntu-latest @@ -156,7 +198,6 @@ 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.2 --remapped - # Build 1.19.3 NMS wild_1_19_3: runs-on: ubuntu-latest From ce2e392e74fc50027135d413f0f45f50ae841e1e Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:44:02 -0600 Subject: [PATCH 15/27] Update ISmoothTeleport.java --- .../support/v1_17_R1/ISmoothTeleport.java} | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) rename modules/{Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_17Teleport.java => v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java} (59%) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_17Teleport.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java similarity index 59% rename from modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_17Teleport.java rename to modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java index 0900c1c1d..fe79a4592 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_17Teleport.java +++ b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java @@ -1,5 +1,7 @@ -package net.countercraft.movecraft.util.teleport; +package net.countercraft.movecraft.support.v1_17_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; @@ -15,34 +17,30 @@ * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ * Used for 1.17.1 */ -public class V1_17Teleport extends AbstractTeleport { - private static Set teleportFlags; +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; - private static Method positionMethod; - private static Method sendMethod; + private Method positionMethod; + private Method sendMethod; - private static Constructor vec3Constructor; - private static Constructor packetConstructor; + private Constructor vec3Constructor; + private Constructor packetConstructor; - private static Field connectionField; - //private static Field justTeleportedField; - private static Field teleportPosField; - //private static Field lastPosXField; - //private static Field lastPosYField; - //private static Field lastPosZField; - private static Field teleportAwaitField; - private static Field awaitingTeleportTimeField; - private static Field tickCountField; - private static Field yawField; - private static Field pitchField; + private Field connectionField; + private Field teleportPosField; + private Field teleportAwaitField; + private Field awaitingTeleportTimeField; + private Field tickCountField; + private Field yawField; + private Field pitchField; private static @NotNull Class getNmClass(String name) throws ClassNotFoundException { return Class.forName("net.minecraft." + name); } - private static void sendPacket(Object packet, Player p) { + private void sendPacket(Object packet, Player p) { try { - Object handle = TeleportUtils.getHandle(p); + Object handle = ReflectUtils.getHandle(p); Object pConnection = connectionField.get(handle); sendMethod.invoke(pConnection, packet); } @@ -51,7 +49,7 @@ private static void sendPacket(Object packet, Player p) { } } - public static boolean initialize() { + public boolean initialize() { boolean success = false; try { Class packetClass = getNmClass("network.protocol.Packet"); @@ -70,17 +68,13 @@ public static boolean initialize() { 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, Boolean.TYPE); - connectionField = TeleportUtils.getField(playerClass, "b"); // connection - //justTeleportedField = TeleportUtils.getField(connectionClass, "justTeleported"); - teleportPosField = TeleportUtils.getField(connectionClass, "y"); // awaitingPositionFromClient - //lastPosXField = TeleportUtils.getField(connectionClass, "lastPosX"); - //lastPosYField = TeleportUtils.getField(connectionClass, "lastPosY"); - //lastPosZField = TeleportUtils.getField(connectionClass, "lastPosZ"); - teleportAwaitField = TeleportUtils.getField(connectionClass, "z"); // awaitingTeleport - awaitingTeleportTimeField = TeleportUtils.getField(connectionClass, "A"); // awaitingTeleportTime - tickCountField = TeleportUtils.getField(connectionClass, "f"); // tickCount - yawField = TeleportUtils.getField(entityClass, "az"); // xRot - pitchField = TeleportUtils.getField(entityClass, "ay"); // yRot + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount + yawField = ReflectUtils.getField(entityClass, "az"); // xRot + pitchField = ReflectUtils.getField(entityClass, "ay"); // yRot success = true; } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { @@ -89,19 +83,15 @@ public static boolean initialize() { return success; } - public static void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { + 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 = TeleportUtils.getHandle(player); + Object handle = ReflectUtils.getHandle(player); try { positionMethod.invoke(handle, x, y, z, yawField.get(handle), pitchField.get(handle)); Object connection = connectionField.get(handle); - //justTeleportedField.set(connection, true); teleportPosField.set(connection, vec3Constructor.newInstance(x, y, z)); - //lastPosXField.set(connection, x); - //lastPosYField.set(connection, y); - //lastPosZField.set(connection, z); int teleportAwait = teleportAwaitField.getInt(connection) + 1; if (teleportAwait == Integer.MAX_VALUE) teleportAwait = 0; From 5f6ac734af03f9bf3b8686597f0e54b180c253fd Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:45:19 -0600 Subject: [PATCH 16/27] Update ISmoothTeleport.java --- .../support/v1_18_R2/ISmoothTeleport.java} | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) rename modules/{Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_18Teleport.java => v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java} (58%) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_18Teleport.java b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java similarity index 58% rename from modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_18Teleport.java rename to modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java index 5255d6eea..5c655e897 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_18Teleport.java +++ b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java @@ -1,5 +1,7 @@ -package net.countercraft.movecraft.util.teleport; +package net.countercraft.movecraft.support.v1_18_R2; +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; @@ -15,34 +17,30 @@ * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ * Used for 1.18.2 */ -public class V1_18Teleport extends AbstractTeleport { - private static Set teleportFlags; +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; - private static Method positionMethod; - private static Method sendMethod; + private Method positionMethod; + private Method sendMethod; - private static Constructor vec3Constructor; - private static Constructor packetConstructor; + private Constructor vec3Constructor; + private Constructor packetConstructor; - private static Field connectionField; - //private static Field justTeleportedField; - private static Field teleportPosField; - //private static Field lastPosXField; - //private static Field lastPosYField; - //private static Field lastPosZField; - private static Field teleportAwaitField; - private static Field awaitingTeleportTimeField; - private static Field tickCountField; - private static Field yawField; - private static Field pitchField; + private Field connectionField; + private Field teleportPosField; + private Field teleportAwaitField; + private Field awaitingTeleportTimeField; + private Field tickCountField; + private Field yawField; + private Field pitchField; private static @NotNull Class getNmClass(String name) throws ClassNotFoundException { return Class.forName("net.minecraft." + name); } - private static void sendPacket(Object packet, Player p) { + private void sendPacket(Object packet, Player p) { try { - Object handle = TeleportUtils.getHandle(p); + Object handle = ReflectUtils.getHandle(p); Object pConnection = connectionField.get(handle); sendMethod.invoke(pConnection, packet); } @@ -51,7 +49,7 @@ private static void sendPacket(Object packet, Player p) { } } - public static boolean initialize() { + public boolean initialize() { boolean success = false; try { Class packetClass = getNmClass("network.protocol.Packet"); @@ -70,17 +68,13 @@ public static boolean initialize() { 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, Boolean.TYPE); - connectionField = TeleportUtils.getField(playerClass, "b"); // connection - //justTeleportedField = TeleportUtils.getField(connectionClass, "justTeleported"); // justTeleported - teleportPosField = TeleportUtils.getField(connectionClass, "y"); // awaitingPositionFromClient - //lastPosXField = TeleportUtils.getField(connectionClass, "lastPosX"); // lastPosX - //lastPosYField = TeleportUtils.getField(connectionClass, "lastPosY"); // lastPosY - //lastPosZField = TeleportUtils.getField(connectionClass, "lastPosZ"); // lastPosZ - teleportAwaitField = TeleportUtils.getField(connectionClass, "z"); // awaitingTeleport - awaitingTeleportTimeField = TeleportUtils.getField(connectionClass, "A"); // awaitingTeleportTime - tickCountField = TeleportUtils.getField(connectionClass, "f"); // tickCount - yawField = TeleportUtils.getField(entityClass, "aB"); // xRot - pitchField = TeleportUtils.getField(entityClass, "aA"); // yRot + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount + yawField = ReflectUtils.getField(entityClass, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot success = true; } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { @@ -89,19 +83,15 @@ public static boolean initialize() { return success; } - public static void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { + 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 = TeleportUtils.getHandle(player); + Object handle = ReflectUtils.getHandle(player); try { positionMethod.invoke(handle, x, y, z, yawField.get(handle), pitchField.get(handle)); Object connection = connectionField.get(handle); - //justTeleportedField.set(connection, true); teleportPosField.set(connection, vec3Constructor.newInstance(x, y, z)); - //lastPosXField.set(connection, x); - //lastPosYField.set(connection, y); - //lastPosZField.set(connection, z); int teleportAwait = teleportAwaitField.getInt(connection) + 1; if (teleportAwait == Integer.MAX_VALUE) teleportAwait = 0; From 489b3af7665815332385210ce129ac935ef58fd1 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:46:21 -0600 Subject: [PATCH 17/27] Update ISmoothTeleport.java --- .../support/v1_19_R1/ISmoothTeleport.java} | 68 ++++++++----------- 1 file changed, 29 insertions(+), 39 deletions(-) rename modules/{Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_19Teleport.java => v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java} (58%) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_19Teleport.java b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java similarity index 58% rename from modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_19Teleport.java rename to modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java index 67e3eabd5..ec431b640 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/util/teleport/V1_19Teleport.java +++ b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java @@ -1,5 +1,7 @@ -package net.countercraft.movecraft.util.teleport; +package net.countercraft.movecraft.support.v1_19_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; @@ -13,36 +15,32 @@ /** * Code derived from code taken with permission from MicleBrick * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ - * Used for 1.19.1 + * Used for 1.19.2 */ -public class V1_19Teleport extends AbstractTeleport { - private static Set teleportFlags; +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; - private static Method positionMethod; - private static Method sendMethod; + private Method positionMethod; + private Method sendMethod; - private static Constructor vec3Constructor; - private static Constructor packetConstructor; + private Constructor vec3Constructor; + private Constructor packetConstructor; - private static Field connectionField; - //private static Field justTeleportedField; - private static Field teleportPosField; - //private static Field lastPosXField; - //private static Field lastPosYField; - //private static Field lastPosZField; - private static Field teleportAwaitField; - private static Field awaitingTeleportTimeField; - private static Field tickCountField; - private static Field yawField; - private static Field pitchField; + private Field connectionField; + private Field teleportPosField; + private Field teleportAwaitField; + private Field awaitingTeleportTimeField; + private Field tickCountField; + private Field yawField; + private Field pitchField; private static @NotNull Class getNmClass(String name) throws ClassNotFoundException { return Class.forName("net.minecraft." + name); } - private static void sendPacket(Object packet, Player p) { + private void sendPacket(Object packet, Player p) { try { - Object handle = TeleportUtils.getHandle(p); + Object handle = ReflectUtils.getHandle(p); Object pConnection = connectionField.get(handle); sendMethod.invoke(pConnection, packet); } @@ -51,7 +49,7 @@ private static void sendPacket(Object packet, Player p) { } } - public static boolean initialize() { + public boolean initialize() { boolean success = false; try { Class packetClass = getNmClass("network.protocol.Packet"); @@ -70,17 +68,13 @@ public static boolean initialize() { 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, Boolean.TYPE); - connectionField = TeleportUtils.getField(playerClass, "b"); // connection - //justTeleportedField = TeleportUtils.getField(connectionClass, "justTeleported"); // justTeleported - teleportPosField = TeleportUtils.getField(connectionClass, "C"); // awaitingPositionFromClient - //lastPosXField = TeleportUtils.getField(connectionClass, "lastPosX"); // lastPosX - //lastPosYField = TeleportUtils.getField(connectionClass, "lastPosY"); // lastPosY - //lastPosZField = TeleportUtils.getField(connectionClass, "lastPosZ"); // lastPosZ - teleportAwaitField = TeleportUtils.getField(connectionClass, "D"); // awaitingTeleport - awaitingTeleportTimeField = TeleportUtils.getField(connectionClass, "E"); // awaitingTeleportTime - tickCountField = TeleportUtils.getField(connectionClass, "i"); // tickCount - yawField = TeleportUtils.getField(entityClass, "aB"); // xRot - pitchField = TeleportUtils.getField(entityClass, "aA"); // yRot + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "C"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "D"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "E"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "i"); // tickCount + yawField = ReflectUtils.getField(entityClass, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot success = true; } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { @@ -89,19 +83,15 @@ public static boolean initialize() { return success; } - public static void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { + 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 = TeleportUtils.getHandle(player); + Object handle = ReflectUtils.getHandle(player); try { positionMethod.invoke(handle, x, y, z, yawField.get(handle), pitchField.get(handle)); Object connection = connectionField.get(handle); - //justTeleportedField.set(connection, true); teleportPosField.set(connection, vec3Constructor.newInstance(x, y, z)); - //lastPosXField.set(connection, x); - //lastPosYField.set(connection, y); - //lastPosZField.set(connection, z); int teleportAwait = teleportAwaitField.getInt(connection) + 1; if (teleportAwait == Integer.MAX_VALUE) teleportAwait = 0; From 881dc382f40c61ae731e33ad3afc7590a45dc9d2 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:58:03 -0600 Subject: [PATCH 18/27] Fix compile issues --- .../net/countercraft/movecraft/Movecraft.java | 63 ++++++++++++------- .../commands/ManOverboardCommand.java | 6 +- .../update/EntityUpdateCommand.java | 5 +- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index 9e2407397..03ad90252 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -55,6 +55,8 @@ import net.countercraft.movecraft.sign.StatusSign; import net.countercraft.movecraft.sign.SubcraftRotateSign; import net.countercraft.movecraft.sign.TeleportSign; +import net.countercraft.movecraft.util.BukkitTeleport; +import net.countercraft.movecraft.util.Tags; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -67,6 +69,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.logging.Logger; public class Movecraft extends JavaPlugin { @@ -76,6 +79,7 @@ public class Movecraft extends JavaPlugin { private Logger logger; private boolean shuttingDown; private WorldHandler worldHandler; + private SmoothTeleport smoothTeleport; private AsyncManager asyncManager; public static synchronized Movecraft getInstance() { @@ -84,7 +88,7 @@ public static synchronized Movecraft getInstance() { @NotNull public static BukkitAudiences getAdventure() { - if(adventure == null) + if (adventure == null) throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); return adventure; @@ -93,7 +97,7 @@ public static BukkitAudiences getAdventure() { @Override public void onDisable() { shuttingDown = true; - if(adventure != null) { + if (adventure != null) { adventure.close(); adventure = null; } @@ -108,39 +112,51 @@ public void onEnable() { Settings.DisableIceForm = getConfig().getBoolean("DisableIceForm", true); String[] localisations = {"en", "cz", "nl", "fr"}; - for(String s : localisations) { - if(!new File(getDataFolder() + for (String s : localisations) { + if (!new File(getDataFolder() + "/localisation/movecraftlang_" + s + ".properties").exists()) { saveResource("localisation/movecraftlang_" + s + ".properties", false); } } I18nSupport.init(); - - + + // if the PilotTool is specified in the config.yml file, use it String pilotTool = getConfig().getString("PilotTool"); - if(pilotTool != null) { + if (pilotTool != null) { Material material = Material.getMaterial(pilotTool); - if(material != null) { + if (material != null) { logger.info(I18nSupport.getInternationalisedString("Startup - Recognized Pilot Tool") + pilotTool); Settings.PilotTool = material; } - else + else { logger.info(I18nSupport.getInternationalisedString("Startup - No Pilot Tool")); + } } - else + else { logger.info(I18nSupport.getInternationalisedString("Startup - No Pilot Tool")); + } String packageName = getServer().getClass().getPackage().getName(); String version = packageName.substring(packageName.lastIndexOf('.') + 1); try { - final Class clazz = Class.forName("net.countercraft.movecraft.compat." + version + ".IWorldHandler"); + final Class worldHandlerClazz = Class.forName("net.countercraft.movecraft.compat." + version + ".IWorldHandler"); // Check if we have a NMSHandler class at that location. - if (WorldHandler.class.isAssignableFrom(clazz)) // Make sure it actually implements NMS - worldHandler = (WorldHandler) clazz.getConstructor().newInstance(); // Set our handler + if (WorldHandler.class.isAssignableFrom(worldHandlerClazz)) { // Make sure it actually implements NMS + worldHandler = (WorldHandler) worldHandlerClazz.getConstructor().newInstance(); // Set our handler + + // Try to setup the smooth teleport handler + final Class smoothTeleportClazz = Class.forName("net.countercraft.movecraft.support." + version + ".ISmoothTeleport"); + if (SmoothTeleport.class.isAssignableFrom(smoothTeleportClazz)) { + smoothTeleport = (SmoothTeleport) smoothTeleportClazz.getConstructor().newInstance(); + } + else { + smoothTeleport = new BukkitTeleport(); // Fall back to bukkit teleportation + } + } } - catch(final Exception e) { + catch (final Exception e) { e.printStackTrace(); getLogger().severe(I18nSupport.getInternationalisedString("Startup - Version Not Supported")); setEnabled(false); @@ -162,17 +178,13 @@ public void onEnable() { Settings.FadeWrecksAfter = getConfig().getInt("FadeWrecksAfter", 0); Settings.FadeTickCooldown = getConfig().getInt("FadeTickCooldown", 20); Settings.FadePercentageOfWreckPerCycle = getConfig().getDouble("FadePercentageOfWreckPerCycle", 10.0); - if(getConfig().contains("ExtraFadeTimePerBlock")) { + if (getConfig().contains("ExtraFadeTimePerBlock")) { Map temp = getConfig().getConfigurationSection("ExtraFadeTimePerBlock").getValues(false); - for(String str : temp.keySet()) { - Material type; - try { - type = Material.getMaterial(str); - } - catch(NumberFormatException e) { - type = Material.getMaterial(str); + for (String str : temp.keySet()) { + Set materials = Tags.parseMaterials(str); + for (Material m : materials) { + Settings.ExtraFadeTimePerBlock.put(m, (Integer) temp.get(str)); } - Settings.ExtraFadeTimePerBlock.put(type, (Integer) temp.get(str)); } } @@ -331,6 +343,9 @@ public WorldHandler getWorldHandler(){ return worldHandler; } + public SmoothTeleport getSmoothTeleport() { + return smoothTeleport; + } + public AsyncManager getAsyncManager(){return asyncManager;} } - diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/commands/ManOverboardCommand.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/commands/ManOverboardCommand.java index b06e93dcd..e3118c255 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/commands/ManOverboardCommand.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/commands/ManOverboardCommand.java @@ -1,14 +1,14 @@ package net.countercraft.movecraft.commands; +import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.craft.CraftManager; -import net.countercraft.movecraft.craft.PilotedCraft; import net.countercraft.movecraft.craft.SinkingCraft; import net.countercraft.movecraft.events.ManOverboardEvent; import net.countercraft.movecraft.localisation.I18nSupport; import net.countercraft.movecraft.util.MathUtils; -import net.countercraft.movecraft.util.teleport.TeleportUtils; +import net.countercraft.movecraft.util.ReflectUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.Command; @@ -73,7 +73,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s, player.setVelocity(new Vector(0, 0, 0)); player.setFallDistance(0); - TeleportUtils.teleport(player, telPoint, 0, 0); + Movecraft.getInstance().getSmoothTeleport().teleport(player, telPoint, 0, 0); return true; } diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/EntityUpdateCommand.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/EntityUpdateCommand.java index 853fde2f1..c334f4e5b 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/EntityUpdateCommand.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/EntityUpdateCommand.java @@ -17,7 +17,8 @@ package net.countercraft.movecraft.mapUpdater.update; -import net.countercraft.movecraft.util.teleport.TeleportUtils; +import net.countercraft.movecraft.Movecraft; +import net.countercraft.movecraft.util.ReflectUtils; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.World; @@ -89,7 +90,7 @@ public void doUpdate() { return; } Location location = new Location(world, playerLoc.getX() + x, playerLoc.getY() + y, playerLoc.getZ() + z); - TeleportUtils.teleport((Player) entity, location, yaw, pitch); + Movecraft.getInstance().getSmoothTeleport().teleport((Player) entity, location, yaw, pitch); if (sound != null) { ((Player) entity).playSound(location, sound, volume, 1.0f); } From 92e9429e8a4a915692d0b82f0d2c9093a300c922 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 19:58:08 -0600 Subject: [PATCH 19/27] Delete ConfigManager.java --- .../movecraft/config/ConfigManager.java | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 modules/api/src/main/java/net/countercraft/movecraft/config/ConfigManager.java diff --git a/modules/api/src/main/java/net/countercraft/movecraft/config/ConfigManager.java b/modules/api/src/main/java/net/countercraft/movecraft/config/ConfigManager.java deleted file mode 100644 index d920db274..000000000 --- a/modules/api/src/main/java/net/countercraft/movecraft/config/ConfigManager.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Movecraft. - * - * Movecraft is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Movecraft is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Movecraft. If not, see . - */ - -package net.countercraft.movecraft.config; - -import org.bukkit.configuration.file.FileConfiguration; - -import java.util.ArrayList; -import java.util.List; - -class ConfigManager { - private final FileConfiguration configFile; - - public ConfigManager(FileConfiguration configFile) { - this.configFile = configFile; - } - - public void loadConfig() { - setupDefaults(); - Settings.DATA_BLOCKS = configFile.getIntegerList("dataBlocks"); - Settings.THREAD_POOL_SIZE = configFile.getInt("ThreadPoolSize"); - Settings.IGNORE_RESET = configFile.getBoolean("safeReload"); - - } - - private void setupDefaults() { - configFile.addDefault("ThreadPoolSize", 5); - configFile.addDefault("safeReload", false); - List dataBlockList = new ArrayList<>(); - dataBlockList.add(23); - dataBlockList.add(25); - dataBlockList.add(33); - dataBlockList.add(44); - dataBlockList.add(50); - dataBlockList.add(53); - dataBlockList.add(54); - dataBlockList.add(55); - dataBlockList.add(61); - dataBlockList.add(62); - dataBlockList.add(63); - dataBlockList.add(64); - dataBlockList.add(65); - configFile.addDefault("dataBlocks", dataBlockList); - configFile.options().copyDefaults(true); - //Movecraft.getInstance().saveConfig(); - } -} From e44a4b8479e8b47d0903460026b9c73a53e3d139 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 20:00:23 -0600 Subject: [PATCH 20/27] Attempt to fix CI --- .github/workflows/maven.yml | 80 +++++++++++++++++------------------ .github/workflows/publish.yml | 80 +++++++++++++++++------------------ 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0bdc3235a..6f0f687c3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -69,47 +69,47 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit - # Build 1.17.1 NMS - goats_1_17: - runs-on: ubuntu-latest - steps: - - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache 1.17.1 Maven package - id: cacheGoats - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.17.1-all - restore-keys: ${{ runner.os }}-spigot-1.17.1-all - - name: Cache Maven packages - id: cacheMain - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2_1.17.1 - restore-keys: ${{ runner.os }}-m2_1.17.1 + # Build 1.17.1 NMS + goats_1_17: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.17.1 Maven package + id: cacheGoats + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.17.1-all + restore-keys: ${{ runner.os }}-spigot-1.17.1-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.17.1 + restore-keys: ${{ runner.os }}-m2_1.17.1 - - 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.17.1 Spigot - id: goats - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Mojang) - id: goatsMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Obf) - id: goatsObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Build 1.17.1 - if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped + - 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.17.1 Spigot + id: goats + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Mojang) + id: goatsMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Obf) + id: goatsObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.17.1 + if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' + run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped # Build 1.18.2 NMS caves_1_18: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5de90f649..5fa5def8d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -72,47 +72,47 @@ jobs: if: steps.nether.outputs.sucess != 'true' run: cd BuildTools && java -jar BuildTools.jar --rev 1.16.5 --compile craftbukkit - # Build 1.17.1 NMS - goats_1_17: - runs-on: ubuntu-latest - steps: - - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '17' - - name: Cache 1.17.1 Maven package - id: cacheGoats - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ - ~/.m2/repository/org/spigotmc/spigot-parent/ - ~/.m2/repository/org/spigotmc/minecraft-server/ - key: ${{ runner.os }}-spigot-1.17.1-all - restore-keys: ${{ runner.os }}-spigot-1.17.1-all - - name: Cache Maven packages - id: cacheMain - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2_1.17.1 - restore-keys: ${{ runner.os }}-m2_1.17.1 + # Build 1.17.1 NMS + goats_1_17: + runs-on: ubuntu-latest + steps: + - name: Set up JDK 17 # 1.17.1 can be built with Java 16 to Java 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache 1.17.1 Maven package + id: cacheGoats + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/ + ~/.m2/repository/org/spigotmc/spigot-parent/ + ~/.m2/repository/org/spigotmc/minecraft-server/ + key: ${{ runner.os }}-spigot-1.17.1-all + restore-keys: ${{ runner.os }}-spigot-1.17.1-all + - name: Cache Maven packages + id: cacheMain + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2_1.17.1 + restore-keys: ${{ runner.os }}-m2_1.17.1 - - 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.17.1 Spigot - id: goats - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Mojang) - id: goatsMojang - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Check 1.17.1 Spigot (Obf) - id: goatsObf - run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" - - name: Build 1.17.1 - if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' - run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped + - 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.17.1 Spigot + id: goats + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Mojang) + id: goatsMojang + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-mojang.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Check 1.17.1 Spigot (Obf) + id: goatsObf + run: test -f ~/.m2/repository/org/spigotmc/spigot/1.17.1-R0.1-SNAPSHOT/spigot-1.17.1-R0.1-SNAPSHOT-remapped-obf.jar && echo "::set-output name=sucess::true" || echo "::set-output name=sucess::false" + - name: Build 1.17.1 + if: steps.goats.outputs.sucess != 'true' || steps.goatsMojang.outputs.sucess != 'true' || steps.goatsObf.outputs.sucess != 'true' + run: cd BuildTools && java -jar BuildTools.jar --rev 1.17.1 --remapped # Build 1.18.2 NMS caves_1_18: From eeb094c097f0479e209bfcd9e4e2d09f8c0f5e3d Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 11 Dec 2022 20:01:43 -0600 Subject: [PATCH 21/27] Attempt to fix CI --- .github/workflows/maven.yml | 8 ++++---- .github/workflows/publish.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6f0f687c3..e827c664c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -163,7 +163,7 @@ jobs: distribution: 'temurin' java-version: '17' - name: Cache 1.19.2 Maven package - id: cacheWild + id: cacheWild_r1 uses: actions/cache@v2 with: path: | @@ -205,7 +205,7 @@ jobs: distribution: 'temurin' java-version: '17' - name: Cache 1.19.3 Maven package - id: cacheWild + id: cacheWild_r2 uses: actions/cache@v2 with: path: | @@ -292,7 +292,7 @@ jobs: key: ${{ runner.os }}-spigot-1.18.2-all restore-keys: ${{ runner.os }}-spigot-1.18.2-all - name: Cache 1.19.2 Maven package - id: cacheWild + id: cacheWild_r1 uses: actions/cache@v2 with: path: | @@ -302,7 +302,7 @@ jobs: key: ${{ runner.os }}-spigot-1.19.2-all restore-keys: ${{ runner.os }}-spigot-1.19.2-all - name: Cache 1.19.3 Maven package - id: cacheWild + id: cacheWild_r2 uses: actions/cache@v2 with: path: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5fa5def8d..1e39add12 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -166,7 +166,7 @@ jobs: distribution: 'temurin' java-version: '17' - name: Cache 1.19.2 Maven package - id: cacheWild + id: cacheWild_r1 uses: actions/cache@v2 with: path: | @@ -208,7 +208,7 @@ jobs: distribution: 'temurin' java-version: '17' - name: Cache 1.19.3 Maven package - id: cacheWild + id: cacheWild_r2 uses: actions/cache@v2 with: path: | @@ -298,7 +298,7 @@ jobs: key: ${{ runner.os }}-spigot-1.18.2-all restore-keys: ${{ runner.os }}-spigot-1.18.2-all - name: Cache 1.19.2 Maven package - id: cacheWild + id: cacheWild_r1 uses: actions/cache@v2 with: path: | @@ -308,7 +308,7 @@ jobs: key: ${{ runner.os }}-spigot-1.19.2-all restore-keys: ${{ runner.os }}-spigot-1.19.2-all - name: Cache 1.19.3 Maven package - id: cacheWild + id: cacheWild_r2 uses: actions/cache@v2 with: path: | From ed80528c3b28e3de6ae4a4f70b0dc65e135adbb9 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 09:13:31 -0600 Subject: [PATCH 22/27] Catch exception and warn on fallback --- .../net/countercraft/movecraft/Movecraft.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index 03ad90252..6ab4c3f03 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -147,12 +147,19 @@ public void onEnable() { worldHandler = (WorldHandler) worldHandlerClazz.getConstructor().newInstance(); // Set our handler // Try to setup the smooth teleport handler - final Class smoothTeleportClazz = Class.forName("net.countercraft.movecraft.support." + version + ".ISmoothTeleport"); - if (SmoothTeleport.class.isAssignableFrom(smoothTeleportClazz)) { - smoothTeleport = (SmoothTeleport) smoothTeleportClazz.getConstructor().newInstance(); + try { + final Class smoothTeleportClazz = Class.forName("net.countercraft.movecraft.support." + version + ".ISmoothTeleport"); + if (SmoothTeleport.class.isAssignableFrom(smoothTeleportClazz)) { + smoothTeleport = (SmoothTeleport) smoothTeleportClazz.getConstructor().newInstance(); + } + else { + smoothTeleport = new BukkitTeleport(); // Fall back to bukkit teleportation + getLogger().warning("Falling back to bukkit teleportation provider."); + } } - else { + catch (ClassNotFoundException ignored) { smoothTeleport = new BukkitTeleport(); // Fall back to bukkit teleportation + getLogger().warning("Falling back to bukkit teleportation provider."); } } } From ec15f689df170d82fc938e385aafdd33319e8aba Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 09:28:06 -0600 Subject: [PATCH 23/27] Create ISmoothTeleport.java --- .../support/v1_19_R2/ISmoothTeleport.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java new file mode 100644 index 000000000..088144fde --- /dev/null +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java @@ -0,0 +1,108 @@ +package net.countercraft.movecraft.support.v1_19_R2; + +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.19.3 + */ +public class ISmoothTeleport extends SmoothTeleport { + private Set teleportFlags; + + private Method positionMethod; + private Method sendMethod; + + private Constructor vec3Constructor; + private Constructor packetConstructor; + + private Field connectionField; + private Field teleportPosField; + private Field teleportAwaitField; + private Field awaitingTeleportTimeField; + private Field tickCountField; + private Field yawField; + private 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 boolean initialize() { + boolean success = false; + try { + 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("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument + 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, Boolean.TYPE); + + connectionField = ReflectUtils.getField(playerClass, "b"); // 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, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot + success = true; + } + catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { + e.printStackTrace(); + } + return success; + } + + 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, false); + sendPacket(packet, player); + } + catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { + e.printStackTrace(); + } + } +} From 8994a02d8649d2cabcac3409aa0c99b3ba324b9b Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 09:52:30 -0600 Subject: [PATCH 24/27] Refactor initialize method --- .../net/countercraft/movecraft/Movecraft.java | 2 +- .../movecraft/SmoothTeleport.java | 2 - .../movecraft/util/BukkitTeleport.java | 5 - .../support/v1_14_R1/ISmoothTeleport.java | 104 ++++++++---------- .../support/v1_16_R3/ISmoothTeleport.java | 104 ++++++++---------- .../support/v1_17_R1/ISmoothTeleport.java | 72 ++++++------ .../support/v1_18_R2/ISmoothTeleport.java | 72 ++++++------ .../support/v1_19_R1/ISmoothTeleport.java | 72 ++++++------ .../support/v1_19_R2/ISmoothTeleport.java | 72 ++++++------ 9 files changed, 225 insertions(+), 280 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index 6ab4c3f03..0a911405f 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -157,7 +157,7 @@ public void onEnable() { getLogger().warning("Falling back to bukkit teleportation provider."); } } - catch (ClassNotFoundException ignored) { + catch (ReflectiveOperationException ignored) { smoothTeleport = new BukkitTeleport(); // Fall back to bukkit teleportation getLogger().warning("Falling back to bukkit teleportation provider."); } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java b/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java index 716f39ea7..f6e9e898c 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/SmoothTeleport.java @@ -5,7 +5,5 @@ import org.jetbrains.annotations.NotNull; public abstract class SmoothTeleport { - public abstract boolean initialize(); - public abstract void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange); } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java b/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java index f2e36c057..7bc69dc9e 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/util/BukkitTeleport.java @@ -6,11 +6,6 @@ import org.jetbrains.annotations.NotNull; public class BukkitTeleport extends SmoothTeleport { - @Override - public boolean initialize() { - return true; - } - @Override public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { location.setYaw(player.getLocation().getYaw() + yawChange); diff --git a/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java index d82d1ace9..f69e195e3 100644 --- a/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java +++ b/modules/v1_14_R1/src/main/java/net/countercraft/movecraft/support/v1_14_R1/ISmoothTeleport.java @@ -18,25 +18,25 @@ * Used for 1.14.4 to 1.16.5 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; - - private Constructor packetConstructor; - private Constructor vec3D; - - private Method position; - private Method sendMethod; - - private Field connectionField; - private Field justTeleportedField; - private Field teleportPosField; - private Field lastPosXField; - private Field lastPosYField; - private Field lastPosZField; - private Field teleportAwaitField; - private Field AField; - private Field eField; - private Field yaw; - private Field pitch; + private final Set teleportFlags; + + private final Constructor packetConstructor; + private final Constructor vec3D; + + private final Method position; + private final Method sendMethod; + + private final Field connectionField; + private final Field justTeleportedField; + private final Field teleportPosField; + private final Field lastPosXField; + private final Field lastPosYField; + private final Field lastPosZField; + private final Field teleportAwaitField; + private final Field AField; + private final Field eField; + private final Field yaw; + private final Field pitch; private static @NotNull Class getNmsClass(String name) throws ClassNotFoundException { return Class.forName("net.minecraft.server." + ReflectUtils.getVersion() + "." + name); @@ -53,43 +53,35 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - Class packet = getNmsClass("Packet"); - Class entity = getNmsClass("Entity"); - Class entityPlayer = getNmsClass("EntityPlayer"); - Class connectionClass = getNmsClass("PlayerConnection"); - Class packetClass = getNmsClass("PacketPlayOutPosition"); - Class vecClass = getNmsClass("Vec3D"); - sendMethod = connectionClass.getMethod("sendPacket", packet); - - position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); - - yaw = ReflectUtils.getField(entity, "yaw"); - pitch = ReflectUtils.getField(entity, "pitch"); - connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); - - packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); - vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); - - Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); - teleportFlags = Set.of(enumObjects[4], enumObjects[3]); - - justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); - teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); - lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); - lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); - lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); - teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); - AField = ReflectUtils.getField(connectionClass, "A"); - eField = ReflectUtils.getField(connectionClass, "e"); - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - return success; + public ISmoothTeleport() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { + Class packet = getNmsClass("Packet"); + Class entity = getNmsClass("Entity"); + Class entityPlayer = getNmsClass("EntityPlayer"); + Class connectionClass = getNmsClass("PlayerConnection"); + Class packetClass = getNmsClass("PacketPlayOutPosition"); + Class vecClass = getNmsClass("Vec3D"); + sendMethod = connectionClass.getMethod("sendPacket", packet); + + position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); + + yaw = ReflectUtils.getField(entity, "yaw"); + pitch = ReflectUtils.getField(entity, "pitch"); + connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); + + packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); + vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); + + Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); + teleportFlags = Set.of(enumObjects[4], enumObjects[3]); + + justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); + teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); + lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); + lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); + lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); + teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); + AField = ReflectUtils.getField(connectionClass, "A"); + eField = ReflectUtils.getField(connectionClass, "e"); } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { diff --git a/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java index 9e03c7467..ef6e4d848 100644 --- a/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java +++ b/modules/v1_16_R3/src/main/java/net/countercraft/movecraft/support/v1_16_R3/ISmoothTeleport.java @@ -18,25 +18,25 @@ * Used for 1.14.4 to 1.16.5 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; - - private Constructor packetConstructor; - private Constructor vec3D; - - private Method position; - private Method sendMethod; - - private Field connectionField; - private Field justTeleportedField; - private Field teleportPosField; - private Field lastPosXField; - private Field lastPosYField; - private Field lastPosZField; - private Field teleportAwaitField; - private Field AField; - private Field eField; - private Field yaw; - private Field pitch; + private final Set teleportFlags; + + private final Constructor packetConstructor; + private final Constructor vec3D; + + private final Method position; + private final Method sendMethod; + + private final Field connectionField; + private final Field justTeleportedField; + private final Field teleportPosField; + private final Field lastPosXField; + private final Field lastPosYField; + private final Field lastPosZField; + private final Field teleportAwaitField; + private final Field AField; + private final Field eField; + private final Field yaw; + private final Field pitch; private static @NotNull Class getNmsClass(String name) throws ClassNotFoundException { return Class.forName("net.minecraft.server." + ReflectUtils.getVersion() + "." + name); @@ -53,43 +53,35 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - Class packet = getNmsClass("Packet"); - Class entity = getNmsClass("Entity"); - Class entityPlayer = getNmsClass("EntityPlayer"); - Class connectionClass = getNmsClass("PlayerConnection"); - Class packetClass = getNmsClass("PacketPlayOutPosition"); - Class vecClass = getNmsClass("Vec3D"); - sendMethod = connectionClass.getMethod("sendPacket", packet); - - position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); - - yaw = ReflectUtils.getField(entity, "yaw"); - pitch = ReflectUtils.getField(entity, "pitch"); - connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); - - packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); - vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); - - Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); - teleportFlags = Set.of(enumObjects[4], enumObjects[3]); - - justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); - teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); - lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); - lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); - lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); - teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); - AField = ReflectUtils.getField(connectionClass, "A"); - eField = ReflectUtils.getField(connectionClass, "e"); - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - return success; + public ISmoothTeleport() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { + Class packet = getNmsClass("Packet"); + Class entity = getNmsClass("Entity"); + Class entityPlayer = getNmsClass("EntityPlayer"); + Class connectionClass = getNmsClass("PlayerConnection"); + Class packetClass = getNmsClass("PacketPlayOutPosition"); + Class vecClass = getNmsClass("Vec3D"); + sendMethod = connectionClass.getMethod("sendPacket", packet); + + position = entity.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); + + yaw = ReflectUtils.getField(entity, "yaw"); + pitch = ReflectUtils.getField(entity, "pitch"); + connectionField = ReflectUtils.getField(entityPlayer, "playerConnection"); + + packetConstructor = packetClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE); + vec3D = vecClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); + + Object[] enumObjects = getNmsClass("PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); + teleportFlags = Set.of(enumObjects[4], enumObjects[3]); + + justTeleportedField = ReflectUtils.getField(connectionClass, "justTeleported"); + teleportPosField = ReflectUtils.getField(connectionClass, "teleportPos"); + lastPosXField = ReflectUtils.getField(connectionClass, "lastPosX"); + lastPosYField = ReflectUtils.getField(connectionClass, "lastPosY"); + lastPosZField = ReflectUtils.getField(connectionClass, "lastPosZ"); + teleportAwaitField = ReflectUtils.getField(connectionClass, "teleportAwait"); + AField = ReflectUtils.getField(connectionClass, "A"); + eField = ReflectUtils.getField(connectionClass, "e"); } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { diff --git a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java index fe79a4592..5b0903668 100644 --- a/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java +++ b/modules/v1_17_R1/src/main/java/net/countercraft/movecraft/support/v1_17_R1/ISmoothTeleport.java @@ -18,21 +18,21 @@ * Used for 1.17.1 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; + private final Set teleportFlags; - private Method positionMethod; - private Method sendMethod; + private final Method positionMethod; + private final Method sendMethod; - private Constructor vec3Constructor; - private Constructor packetConstructor; + private final Constructor vec3Constructor; + private final Constructor packetConstructor; - private Field connectionField; - private Field teleportPosField; - private Field teleportAwaitField; - private Field awaitingTeleportTimeField; - private Field tickCountField; - private Field yawField; - private Field pitchField; + 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); @@ -49,38 +49,30 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - 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 + 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("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT + Object[] flags = getNmClass("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument + teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT - positionMethod = entityClass.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); // absMoveTo - sendMethod = connectionClass.getMethod("sendPacket", packetClass); // send + positionMethod = entityClass.getDeclaredMethod("setLocation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); // absMoveTo + sendMethod = connectionClass.getMethod("sendPacket", 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, Boolean.TYPE); + 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, Boolean.TYPE); - connectionField = ReflectUtils.getField(playerClass, "b"); // connection - teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient - teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport - awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime - tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount - yawField = ReflectUtils.getField(entityClass, "az"); // xRot - pitchField = ReflectUtils.getField(entityClass, "ay"); // yRot - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } - return success; + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount + yawField = ReflectUtils.getField(entityClass, "az"); // xRot + pitchField = ReflectUtils.getField(entityClass, "ay"); // yRot } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { diff --git a/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java index 5c655e897..3f123aec3 100644 --- a/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java +++ b/modules/v1_18_R2/src/main/java/net/countercraft/movecraft/support/v1_18_R2/ISmoothTeleport.java @@ -18,21 +18,21 @@ * Used for 1.18.2 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; + private final Set teleportFlags; - private Method positionMethod; - private Method sendMethod; + private final Method positionMethod; + private final Method sendMethod; - private Constructor vec3Constructor; - private Constructor packetConstructor; + private final Constructor vec3Constructor; + private final Constructor packetConstructor; - private Field connectionField; - private Field teleportPosField; - private Field teleportAwaitField; - private Field awaitingTeleportTimeField; - private Field tickCountField; - private Field yawField; - private Field pitchField; + 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); @@ -49,38 +49,30 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - 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 + public ISmoothTeleport() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { + 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("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT + Object[] flags = getNmClass("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument + 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 + 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, Boolean.TYPE); + 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, Boolean.TYPE); - connectionField = ReflectUtils.getField(playerClass, "b"); // connection - teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient - teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport - awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime - tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount - yawField = ReflectUtils.getField(entityClass, "aB"); // xRot - pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } - return success; + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount + yawField = ReflectUtils.getField(entityClass, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { diff --git a/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java index ec431b640..20345a457 100644 --- a/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java +++ b/modules/v1_19_R1/src/main/java/net/countercraft/movecraft/support/v1_19_R1/ISmoothTeleport.java @@ -18,21 +18,21 @@ * Used for 1.19.2 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; + private final Set teleportFlags; - private Method positionMethod; - private Method sendMethod; + private final Method positionMethod; + private final Method sendMethod; - private Constructor vec3Constructor; - private Constructor packetConstructor; + private final Constructor vec3Constructor; + private final Constructor packetConstructor; - private Field connectionField; - private Field teleportPosField; - private Field teleportAwaitField; - private Field awaitingTeleportTimeField; - private Field tickCountField; - private Field yawField; - private Field pitchField; + 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); @@ -49,38 +49,30 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - 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 + public ISmoothTeleport() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { + 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("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT + Object[] flags = getNmClass("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument + 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 + 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, Boolean.TYPE); + 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, Boolean.TYPE); - connectionField = ReflectUtils.getField(playerClass, "b"); // connection - teleportPosField = ReflectUtils.getField(connectionClass, "C"); // awaitingPositionFromClient - teleportAwaitField = ReflectUtils.getField(connectionClass, "D"); // awaitingTeleport - awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "E"); // awaitingTeleportTime - tickCountField = ReflectUtils.getField(connectionClass, "i"); // tickCount - yawField = ReflectUtils.getField(entityClass, "aB"); // xRot - pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } - return success; + connectionField = ReflectUtils.getField(playerClass, "b"); // connection + teleportPosField = ReflectUtils.getField(connectionClass, "C"); // awaitingPositionFromClient + teleportAwaitField = ReflectUtils.getField(connectionClass, "D"); // awaitingTeleport + awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "E"); // awaitingTeleportTime + tickCountField = ReflectUtils.getField(connectionClass, "i"); // tickCount + yawField = ReflectUtils.getField(entityClass, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { diff --git a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java index 088144fde..9b82d8ec8 100644 --- a/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java +++ b/modules/v1_19_R2/src/main/java/net/countercraft/movecraft/support/v1_19_R2/ISmoothTeleport.java @@ -18,21 +18,21 @@ * Used for 1.19.3 */ public class ISmoothTeleport extends SmoothTeleport { - private Set teleportFlags; + private final Set teleportFlags; - private Method positionMethod; - private Method sendMethod; + private final Method positionMethod; + private final Method sendMethod; - private Constructor vec3Constructor; - private Constructor packetConstructor; + private final Constructor vec3Constructor; + private final Constructor packetConstructor; - private Field connectionField; - private Field teleportPosField; - private Field teleportAwaitField; - private Field awaitingTeleportTimeField; - private Field tickCountField; - private Field yawField; - private Field pitchField; + 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); @@ -49,38 +49,30 @@ private void sendPacket(Object packet, Player p) { } } - public boolean initialize() { - boolean success = false; - try { - 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 + 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("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT + Object[] flags = getNmClass("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument + 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 + 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, Boolean.TYPE); + 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, Boolean.TYPE); - connectionField = ReflectUtils.getField(playerClass, "b"); // 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, "aB"); // xRot - pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot - success = true; - } - catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - e.printStackTrace(); - } - return success; + connectionField = ReflectUtils.getField(playerClass, "b"); // 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, "aB"); // xRot + pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot } public void teleport(Player player, @NotNull Location location, float yawChange, float pitchChange) { From c6536f49e00fd80c35ffa174fb66538d890bd802 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 10:03:42 -0600 Subject: [PATCH 25/27] Update version and setup script --- pom.xml | 2 +- setup.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 6ef0a27a7..a0fdb4a8c 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ http://github.com/apdevteam/Movecraft UTF-8 - 8.0.0-a.9 + 8.0.0-a.10-dev diff --git a/setup.sh b/setup.sh index e48ff073f..63f69f1a3 100755 --- a/setup.sh +++ b/setup.sh @@ -48,14 +48,14 @@ else fi # Build 1.19.2 -if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19-R0.1-SNAPSHOT/spigot-1.19.2-R0.1-SNAPSHOT.jar ]; then +if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19.2-R0.1-SNAPSHOT/spigot-1.19.2-R0.1-SNAPSHOT.jar ]; then echo "1.19.2 already exists, skipping build" else java -jar BuildTools.jar --rev 1.19.2 --remapped fi # Build 1.19.3 -if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT.jar ]; then +if [ -f ~/.m2/repository/org/spigotmc/spigot/1.19.3-R0.1-SNAPSHOT/spigot-1.19.3-R0.1-SNAPSHOT.jar ]; then echo "1.19.3 already exists, skipping build" else java -jar BuildTools.jar --rev 1.19.3 --remapped From ab2779a79b20a548462c98eeffaaa12e8c9d90d8 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 10:07:50 -0600 Subject: [PATCH 26/27] Re-add 1.17.1 worldhandler --- modules/Movecraft/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/Movecraft/pom.xml b/modules/Movecraft/pom.xml index e2832b0d3..a2fcac0d3 100644 --- a/modules/Movecraft/pom.xml +++ b/modules/Movecraft/pom.xml @@ -50,6 +50,12 @@ ${revision} jar + + net.countercraft + movecraft-v1_17_r1 + ${revision} + jar + net.countercraft movecraft-v1_18_r2 From c3af06abfd20dfde7caf092517f8554e1c342dd4 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sat, 17 Dec 2022 10:10:43 -0600 Subject: [PATCH 27/27] Do it correctly now... --- modules/Movecraft/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/Movecraft/pom.xml b/modules/Movecraft/pom.xml index a2fcac0d3..af49fdd1e 100644 --- a/modules/Movecraft/pom.xml +++ b/modules/Movecraft/pom.xml @@ -203,6 +203,12 @@ ** + + net.countercraft:movecraft-v1_17_r1 + + ** + + net.countercraft:movecraft-v1_18_r2