From 13cfe1f044084e133ba3834b897a44753f9a1608 Mon Sep 17 00:00:00 2001 From: Scyu_ Date: Fri, 16 Jul 2021 10:51:22 +0100 Subject: [PATCH 1/5] Add Sync block command Syncs blocks between your current section and the corresponding section in a radius --- build.gradle.kts | 7 +- .../deeperworld/DeeperCommandExecutor.kt | 117 ++++++++++++++++++ .../minecraft/deeperworld/DeeperContext.kt | 1 + src/main/resources/plugin.yml | 2 +- 4 files changed, 124 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a9cc2d2..9066c5b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ repositories { maven("https://repo.mineinabyss.com/releases") maven("https://papermc.io/repo/repository/maven-public/") //Paper maven("https://repo.codemc.org/repository/maven-public/") -// maven("https://mvn.intellectualsites.com/content/repositories/releases/") // FAWE + maven("https://mvn.intellectualsites.com/content/repositories/releases/") // FAWE maven("https://jitpack.io") } @@ -30,7 +30,10 @@ val kotlinVersion: String by project dependencies { compileOnly("com.destroystokyo.paper:paper-api:$serverVersion") -// compileOnly("com.intellectualsites.fawe:FAWE-Bukkit:1.16-637") + + compileOnly("com.fastasyncworldedit:FAWE-Bukkit:1.17-47") { isTransitive = false } + compileOnly("com.fastasyncworldedit:FAWE-Core:1.17-47") + compileOnly(kotlin("stdlib-jdk8")) kotlinSpice("$kotlinVersion+") diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt index 3e6a79b..cc97b84 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt @@ -4,6 +4,12 @@ import com.derongan.minecraft.deeperworld.MinecraftConstants.FULL_DAY_TIME import com.derongan.minecraft.deeperworld.config.DeeperConfig import com.derongan.minecraft.deeperworld.services.WorldManager import com.derongan.minecraft.deeperworld.services.canMoveSections +import com.derongan.minecraft.deeperworld.synchronization.sync +import com.derongan.minecraft.deeperworld.world.section.correspondingSection +import com.derongan.minecraft.deeperworld.world.section.getCorrespondingLocation +import com.derongan.minecraft.deeperworld.world.section.section +import com.fastasyncworldedit.core.FaweAPI +import com.fastasyncworldedit.core.util.EditSessionBuilder import com.mineinabyss.idofront.commands.CommandHolder import com.mineinabyss.idofront.commands.arguments.booleanArg import com.mineinabyss.idofront.commands.arguments.intArg @@ -14,6 +20,16 @@ import com.mineinabyss.idofront.commands.extensions.actions.playerAction import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success +import com.sk89q.worldedit.EditSession +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard +import com.sk89q.worldedit.function.operation.ForwardExtentCopy +import com.sk89q.worldedit.function.operation.Operation +import com.sk89q.worldedit.function.operation.Operations +import com.sk89q.worldedit.math.BlockVector3 +import com.sk89q.worldedit.regions.CuboidRegion +import com.sk89q.worldedit.session.ClipboardHolder +import com.sk89q.worldedit.world.World + @ExperimentalCommandDSL object DeeperCommandExecutor : IdofrontCommandExecutor() { @@ -69,6 +85,107 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { } } } + "sync"(desc = "Sync blocks in range") { + val range by intArg() + playerAction { + val section = WorldManager.getSectionFor(player.location) + if (section == null) + sender.info("${player.name} is not in a managed section") + else { + when { + DeeperContext.isFAWELoaded -> { + try { + val pos1 = BlockVector3.at( + (player.location.x + range), + (player.location.y + range), + (player.location.z + range) + ); + val pos2 = BlockVector3.at( + (player.location.x - range), + (player.location.y - range), + (player.location.z - range) + ); + + val region = CuboidRegion(pos1, pos2) + + val clipboard = BlockArrayClipboard(region) + + val weWorld: World = FaweAPI.getWorld(player.world.name) + + val editSession: EditSession = EditSessionBuilder(weWorld) +// .limitUnlimited() + .build() + + val loc = player.location + + val section = loc.section ?: throw Exception("Section not found") + val linkedSection = loc.correspondingSection ?: throw Exception("Corresponding Section not found") + + val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block ?: throw Exception("Corresponding Location not found") + + var offset = 0 + + if(pos2.y < 0){ + offset = pos2.y + } + + editSession.use { editSession -> + // Copy + val forwardExtentCopy = + ForwardExtentCopy( + editSession, region, clipboard, region.minimumPoint + ) + forwardExtentCopy.isCopyingEntities = false + forwardExtentCopy.isCopyingBiomes = true + Operations.complete(forwardExtentCopy) + + // Paste + val operation: Operation = ClipboardHolder(clipboard) + .createPaste(editSession) + .to(BlockVector3.at(linkedBlock.x - range, linkedBlock.y - range - offset, linkedBlock.z - range)) + .build() + Operations.complete(operation) + + player.success("Blocks syncing...") + + } + } + catch (e: Exception) { + player.error("""An error occurred: ${e.message}""") + } + finally { + player.success("Blocks synced (FAWE)") + } + } + range <= 100 -> { + // Get blocks in range specified + for (x in -range..range) { + for (y in -range..range) { + for (z in -range..range) { + val block = player.world.getBlockAt( + (player.location.x + x).toInt(), + (player.location.y + y).toInt(), + (player.location.z + z).toInt() + ) + + block.sync { original, corr -> + if (original.type != corr.type) { + corr.blockData = original.blockData.clone() + } + } + } + } + } + + player.success("Blocks synced") + } + else -> { + sender.error("Please use a range smaller than 100 blocks, or install FAWE to use a larger range") + } + } + } + } + } } "linfo"{ playerAction{ diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperContext.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperContext.kt index 2971584..0a6e1de 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperContext.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperContext.kt @@ -5,4 +5,5 @@ package com.derongan.minecraft.deeperworld */ object DeeperContext { val isBlockLockerLoaded: Boolean = deeperWorld.server.pluginManager.isPluginEnabled("BlockLocker") + val isFAWELoaded: Boolean = deeperWorld.server.pluginManager.isPluginEnabled("FastAsyncWorldEdit") } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7c7388c..42bfef5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ authors: [Derongan] api-version: '1.16' description: A plugin for letting you create a deeper world. Or at least fake it. -softdepend: [Multiverse-Core, BlockLocker, KotlinSpice, ProtocolLib] +softdepend: [Multiverse-Core, BlockLocker, KotlinSpice, ProtocolLib, FastAsyncWorldEdit] commands: deeperworld: From 08ff72ad0bf96a6051a9da6a87b2cf57aa623b11 Mon Sep 17 00:00:00 2001 From: Scyu_ Date: Fri, 16 Jul 2021 10:56:30 +0100 Subject: [PATCH 2/5] Update --- .../minecraft/deeperworld/DeeperCommandExecutor.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt index cc97b84..6a28999 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt @@ -119,15 +119,13 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { val loc = player.location val section = loc.section ?: throw Exception("Section not found") - val linkedSection = loc.correspondingSection ?: throw Exception("Corresponding Section not found") + val linkedSection = + loc.correspondingSection ?: throw Exception("Corresponding Section not found") - val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block ?: throw Exception("Corresponding Location not found") + val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block + ?: throw Exception("Corresponding Location not found") - var offset = 0 - - if(pos2.y < 0){ - offset = pos2.y - } + var offset = if (pos2.y < 0) pos2.y else 0 editSession.use { editSession -> // Copy From 66a37da9c59a1b043a2fec20431bbf837e6c239d Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 16 Jul 2021 12:40:39 +0200 Subject: [PATCH 3/5] fix /dw info uwu --- .../minecraft/deeperworld/DeeperCommandExecutor.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt index 3e6a79b..1e407ae 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt @@ -26,7 +26,7 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { sender.success("Automatic TP ${if(state) "enabled" else "disabled"} for ${player.name}") } } - ("layerinfo" / "linfo")(desc = "Gets information about a players section") { + ("layerinfo" / "linfo" / "info")(desc = "Gets information about a players section") { playerAction { val section = WorldManager.getSectionFor(player.location) if (section == null) @@ -35,11 +35,6 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { sender.info("${player.name} is in section ${section.key}") } } - "info" { - playerAction { - sender.error("Please use /dw linfo or /deeperworld layerinfo instead") - } - } "time" { val time by intArg() "set"(desc = "Set the time of the main synchronization world and the other worlds with their respective offsets") { From 7d888dead52542ea53f2c9d6d607760201937e98 Mon Sep 17 00:00:00 2001 From: Scyu_ Date: Fri, 16 Jul 2021 12:55:08 +0100 Subject: [PATCH 4/5] Make async --- .../deeperworld/DeeperCommandExecutor.kt | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt index 6a28999..846c901 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt @@ -8,8 +8,8 @@ import com.derongan.minecraft.deeperworld.synchronization.sync import com.derongan.minecraft.deeperworld.world.section.correspondingSection import com.derongan.minecraft.deeperworld.world.section.getCorrespondingLocation import com.derongan.minecraft.deeperworld.world.section.section -import com.fastasyncworldedit.core.FaweAPI import com.fastasyncworldedit.core.util.EditSessionBuilder +import com.fastasyncworldedit.core.util.TaskManager import com.mineinabyss.idofront.commands.CommandHolder import com.mineinabyss.idofront.commands.arguments.booleanArg import com.mineinabyss.idofront.commands.arguments.intArg @@ -21,6 +21,7 @@ import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success import com.sk89q.worldedit.EditSession +import com.sk89q.worldedit.bukkit.WorldEditPlugin import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard import com.sk89q.worldedit.function.operation.ForwardExtentCopy import com.sk89q.worldedit.function.operation.Operation @@ -110,7 +111,9 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { val clipboard = BlockArrayClipboard(region) - val weWorld: World = FaweAPI.getWorld(player.world.name) + val wep = WorldEditPlugin.getInstance().bukkitImplAdapter; + + val weWorld: World = wep.adapt(player.world) val editSession: EditSession = EditSessionBuilder(weWorld) // .limitUnlimited() @@ -126,34 +129,37 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { ?: throw Exception("Corresponding Location not found") var offset = if (pos2.y < 0) pos2.y else 0 - - editSession.use { editSession -> - // Copy - val forwardExtentCopy = - ForwardExtentCopy( - editSession, region, clipboard, region.minimumPoint - ) - forwardExtentCopy.isCopyingEntities = false - forwardExtentCopy.isCopyingBiomes = true - Operations.complete(forwardExtentCopy) - - // Paste - val operation: Operation = ClipboardHolder(clipboard) - .createPaste(editSession) - .to(BlockVector3.at(linkedBlock.x - range, linkedBlock.y - range - offset, linkedBlock.z - range)) - .build() - Operations.complete(operation) - + TaskManager.IMP.taskNowAsync { player.success("Blocks syncing...") - + editSession.use { editSession -> + // Copy + val forwardExtentCopy = + ForwardExtentCopy( + editSession, region, clipboard, region.minimumPoint + ) + forwardExtentCopy.isCopyingEntities = false + forwardExtentCopy.isCopyingBiomes = true + Operations.complete(forwardExtentCopy) + + // Paste + val operation: Operation = ClipboardHolder(clipboard) + .createPaste(editSession) + .to( + BlockVector3.at( + linkedBlock.x - range, + linkedBlock.y - range - offset, + linkedBlock.z - range + ) + ) + .build() + Operations.complete(operation) + } + player.success("Blocks synced (FAWE)") } } catch (e: Exception) { player.error("""An error occurred: ${e.message}""") } - finally { - player.success("Blocks synced (FAWE)") - } } range <= 100 -> { // Get blocks in range specified From 2755b6274d123b02a103ee9f7f8b0282366ee6e1 Mon Sep 17 00:00:00 2001 From: Scyu_ Date: Fri, 16 Jul 2021 18:30:41 +0100 Subject: [PATCH 5/5] CS --- .../deeperworld/DeeperCommandExecutor.kt | 168 +++++++++--------- 1 file changed, 81 insertions(+), 87 deletions(-) diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt index 846c901..d52aca9 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperCommandExecutor.kt @@ -89,103 +89,97 @@ object DeeperCommandExecutor : IdofrontCommandExecutor() { "sync"(desc = "Sync blocks in range") { val range by intArg() playerAction { - val section = WorldManager.getSectionFor(player.location) - if (section == null) - sender.info("${player.name} is not in a managed section") - else { - when { - DeeperContext.isFAWELoaded -> { - try { - val pos1 = BlockVector3.at( - (player.location.x + range), - (player.location.y + range), - (player.location.z + range) - ); - val pos2 = BlockVector3.at( - (player.location.x - range), - (player.location.y - range), - (player.location.z - range) - ); - - val region = CuboidRegion(pos1, pos2) - - val clipboard = BlockArrayClipboard(region) - - val wep = WorldEditPlugin.getInstance().bukkitImplAdapter; - - val weWorld: World = wep.adapt(player.world) - - val editSession: EditSession = EditSessionBuilder(weWorld) -// .limitUnlimited() - .build() - - val loc = player.location - - val section = loc.section ?: throw Exception("Section not found") - val linkedSection = - loc.correspondingSection ?: throw Exception("Corresponding Section not found") - - val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block - ?: throw Exception("Corresponding Location not found") - - var offset = if (pos2.y < 0) pos2.y else 0 - TaskManager.IMP.taskNowAsync { - player.success("Blocks syncing...") - editSession.use { editSession -> - // Copy - val forwardExtentCopy = - ForwardExtentCopy( - editSession, region, clipboard, region.minimumPoint - ) - forwardExtentCopy.isCopyingEntities = false - forwardExtentCopy.isCopyingBiomes = true - Operations.complete(forwardExtentCopy) + val section = + player.location.section ?: run { + sender.error("${player.name} is not in a managed section") + return@playerAction + } - // Paste - val operation: Operation = ClipboardHolder(clipboard) - .createPaste(editSession) - .to( - BlockVector3.at( - linkedBlock.x - range, - linkedBlock.y - range - offset, - linkedBlock.z - range - ) + when { + DeeperContext.isFAWELoaded -> { + try { + val pos1 = BlockVector3.at( + (player.location.x + range), + (player.location.y + range), + (player.location.z + range) + ) + val pos2 = BlockVector3.at( + (player.location.x - range), + (player.location.y - range), + (player.location.z - range) + ) + + val region = CuboidRegion(pos1, pos2) + val clipboard = BlockArrayClipboard(region) + val wep = WorldEditPlugin.getInstance().bukkitImplAdapter; + val weWorld: World = wep.adapt(player.world) + val editSession: EditSession = EditSessionBuilder(weWorld) + .limitUnlimited() + .build() + + val loc = player.location + val linkedSection = + loc.correspondingSection ?: error("Corresponding Section not found") + + val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block + ?: error("Corresponding Location not found") + + val offset = if (pos2.y < 0) pos2.y else 0 + TaskManager.IMP.taskNowAsync { + player.success("Blocks syncing...") + editSession.use { editSession -> + // Copy + val forwardExtentCopy = + ForwardExtentCopy( + editSession, region, clipboard, region.minimumPoint + ) + forwardExtentCopy.isCopyingEntities = false + forwardExtentCopy.isCopyingBiomes = true + Operations.complete(forwardExtentCopy) + + // Paste + val operation: Operation = ClipboardHolder(clipboard) + .createPaste(editSession) + .to( + BlockVector3.at( + linkedBlock.x - range, + linkedBlock.y - range - offset, + linkedBlock.z - range ) - .build() - Operations.complete(operation) - } - player.success("Blocks synced (FAWE)") + ) + .build() + Operations.complete(operation) } + player.success("Blocks synced (FAWE)") } - catch (e: Exception) { - player.error("""An error occurred: ${e.message}""") - } + } catch (e: Exception) { + player.error("""An error occurred: ${e.message}""") } - range <= 100 -> { - // Get blocks in range specified - for (x in -range..range) { - for (y in -range..range) { - for (z in -range..range) { - val block = player.world.getBlockAt( - (player.location.x + x).toInt(), - (player.location.y + y).toInt(), - (player.location.z + z).toInt() - ) - - block.sync { original, corr -> - if (original.type != corr.type) { - corr.blockData = original.blockData.clone() - } + } + range <= 100 -> { + // Get blocks in range specified + for (x in -range..range) { + for (y in -range..range) { + for (z in -range..range) { + val block = player.world.getBlockAt( + (player.location.x + x).toInt(), + (player.location.y + y).toInt(), + (player.location.z + z).toInt() + ) + + block.sync { original, corr -> + if (original.type != corr.type) { + corr.blockData = original.blockData.clone() } } } } - - player.success("Blocks synced") - } - else -> { - sender.error("Please use a range smaller than 100 blocks, or install FAWE to use a larger range") } + + player.success("Blocks synced") + } + else -> { + sender.error("Please use a range smaller than 100 blocks, or install FAWE to use a larger range") } } }