place building preview 1.21.4

This commit is contained in:
ruby
2025-01-02 18:23:38 +13:00
parent 3e8731eb1c
commit c082691845
3 changed files with 50 additions and 30 deletions

View File

@ -25,9 +25,9 @@ repositories {
dependencies { dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0") // compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
// implementation(files("libs/ProtocolLib.jar")) compileOnly(files("libs/ProtocolLib.jar"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(platform("com.intellectualsites.bom:bom-newest:1.51")) // Ref: https://github.com/IntellectualSites/bom implementation(platform("com.intellectualsites.bom:bom-newest:1.51")) // Ref: https://github.com/IntellectualSites/bom
// implementation("de.nilsdruyen.gradle-ftp-upload-plugin:de.nilsdruyen.gradle-ftp-upload-plugin.gradle.plugin:0.5.0") // implementation("de.nilsdruyen.gradle-ftp-upload-plugin:de.nilsdruyen.gradle-ftp-upload-plugin.gradle.plugin:0.5.0")

View File

@ -5,13 +5,14 @@ import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.events.PacketContainer import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.wrappers.* import com.comphenix.protocol.wrappers.*
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry
import com.destroystokyo.paper.MaterialSetTag
import com.pobnellion.aoe.Aoe import com.pobnellion.aoe.Aoe
import com.sk89q.worldedit.bukkit.BukkitAdapter import com.sk89q.worldedit.bukkit.BukkitAdapter
import com.sk89q.worldedit.extent.clipboard.Clipboard import com.sk89q.worldedit.extent.clipboard.Clipboard
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats
import org.bukkit.Bukkit
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.block.data.BlockData
import org.bukkit.entity.EntityType import org.bukkit.entity.EntityType
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
@ -74,6 +75,10 @@ class PlaceHint {
playerHints.clear() playerHints.clear()
} }
fun contains(player: Player): Boolean {
return playerHints.containsKey(player.uniqueId)
}
private fun createOutlineTeam(player: Player) { private fun createOutlineTeam(player: Player) {
val packet = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM) val packet = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM)
packet.strings.write(0, "placeValid") packet.strings.write(0, "placeValid")
@ -88,15 +93,20 @@ class PlaceHint {
if (!playerHints.containsKey(event.player.uniqueId)) if (!playerHints.containsKey(event.player.uniqueId))
return return
val block = event.player.getTargetBlockExact(MAX_TARGET_DISTANCE); val target = event.player.getTargetBlockExact(MAX_TARGET_DISTANCE);
val block = if (target == null) null else event.player.getTargetBlock(MaterialSetTag.REPLACEABLE.values, MAX_TARGET_DISTANCE);
playerHints[event.player.uniqueId]!!.moveTo(block?.location) playerHints[event.player.uniqueId]!!.moveTo(block?.location)
} }
@EventHandler @EventHandler
fun onLeftClick(event: PlayerInteractEvent) { fun onClick(event: PlayerInteractEvent) {
if (!playerHints.containsKey(event.player.uniqueId) || (event.action != Action.LEFT_CLICK_BLOCK && event.action != Action.LEFT_CLICK_AIR)) if (!playerHints.containsKey(event.player.uniqueId))
return return
event.isCancelled = true
// left click - place
if (event.action == Action.LEFT_CLICK_BLOCK || event.action == Action.LEFT_CLICK_AIR) {
if (!playerHints[event.player.uniqueId]!!.isValid) if (!playerHints[event.player.uniqueId]!!.isValid)
return return
@ -105,6 +115,12 @@ class PlaceHint {
remove(event.player) remove(event.player)
} }
// right click - cancel
if (event.action == Action.RIGHT_CLICK_BLOCK || event.action == Action.RIGHT_CLICK_AIR) {
remove(event.player)
}
}
private val teamParamsTemplate: WrappedTeamParameters = WrappedTeamParameters.newBuilder() private val teamParamsTemplate: WrappedTeamParameters = WrappedTeamParameters.newBuilder()
.displayName(WrappedChatComponent.fromText("")) .displayName(WrappedChatComponent.fromText(""))
.collisionRule("never") .collisionRule("never")
@ -153,16 +169,17 @@ class PlaceHint {
val format = ClipboardFormats.findByFile(file) val format = ClipboardFormats.findByFile(file)
val reader = format?.getReader(FileInputStream(file)) val reader = format?.getReader(FileInputStream(file))
val clipboard = reader?.read() val clipboard = reader?.read() ?: throw NullPointerException("Could not load schematic ${file.path}. Is it present?")
this.schematic = clipboard this.schematic = clipboard
this.sizeX = clipboard!!.dimensions.x().toFloat() this.sizeX = clipboard.dimensions.x().toFloat()
this.sizeY = clipboard.dimensions.y().toFloat() this.sizeY = clipboard.dimensions.y().toFloat()
this.sizeZ = clipboard.dimensions.z().toFloat() this.sizeZ = clipboard.dimensions.z().toFloat()
} }
private fun show(initialLocation: Location) { private fun show(initialLocation: Location) {
initialLocation.add(-floor(sizeX / 2.0), 1.0, -floor(sizeZ / 2.0)) initialLocation.add(-floor(sizeX / 2.0), 1.0, -floor(sizeZ / 2.0))
currentLocation = initialLocation;
val spawnMarkerPacket = PacketContainer(PacketType.Play.Server.SPAWN_ENTITY) val spawnMarkerPacket = PacketContainer(PacketType.Play.Server.SPAWN_ENTITY)
spawnMarkerPacket.integers.write(0, marker.first) spawnMarkerPacket.integers.write(0, marker.first)
@ -173,17 +190,19 @@ class PlaceHint {
.write(1, initialLocation.y) .write(1, initialLocation.y)
.write(2, initialLocation.z) .write(2, initialLocation.z)
base = spawnBlockDisplay(initialLocation, Material.GRAY_STAINED_GLASS, scale = Vector3f(sizeX + 0.05f, 0.2f, sizeZ + 0.05f)) base = spawnBlockDisplay(initialLocation, Material.GRAY_STAINED_GLASS.createBlockData(),
scale = Vector3f(sizeX + 0.1f, 0.2f, sizeZ + 0.1f), offset = Vector3f(-0.05f, -0.05f, -0.05f))
schematic?.iterator()?.forEach { schematic?.iterator()?.forEach { blockPosition ->
val material = BukkitAdapter.adapt(schematic.getBlock(it)).material val block = BukkitAdapter.adapt(schematic.getBlock(blockPosition))
val x = (it.x() - schematic.minimumPoint.x()).toFloat() if (!block.material.isAir && !block.material.isEmpty) {
val y = (it.y() - schematic.minimumPoint.y()).toFloat() val x = (blockPosition.x() - schematic.minimumPoint.x()).toFloat()
val z = (it.z() - schematic.minimumPoint.z()).toFloat() val y = (blockPosition.y() - schematic.minimumPoint.y()).toFloat()
val z = (blockPosition.z() - schematic.minimumPoint.z()).toFloat()
if (!material.isAir && !material.isEmpty) displayIds.add(spawnBlockDisplay(initialLocation, block, offset = Vector3f(x, y, z), options = 0b01000000))
displayIds.add(spawnBlockDisplay(initialLocation, material, offset = Vector3f(x, y, z), options = 0b01000000)) }
} }
val outlineTeamPacket = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM) val outlineTeamPacket = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM)
@ -204,8 +223,6 @@ class PlaceHint {
isValid = validate(initialLocation, sizeX, sizeY, sizeZ) isValid = validate(initialLocation, sizeX, sizeY, sizeZ)
updateColour() updateColour()
currentLocation = initialLocation;
} }
private fun hide() { private fun hide() {
@ -234,10 +251,10 @@ class PlaceHint {
newLocation.add(-floor(sizeX / 2.0), 1.0, -floor(sizeZ / 2.0)) newLocation.add(-floor(sizeX / 2.0), 1.0, -floor(sizeZ / 2.0))
val basePacket = PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT) val basePacket = PacketContainer(PacketType.Play.Server.ENTITY_POSITION_SYNC)
basePacket.integers.write(0, marker.first) basePacket.integers.write(0, marker.first)
basePacket.doubles basePacket.structures.values[0].structures.values[0].doubles
.write(0, newLocation.x) .write(0, newLocation.x)
.write(1, newLocation.y) .write(1, newLocation.y)
.write(2, newLocation.z) .write(2, newLocation.z)
@ -261,7 +278,7 @@ class PlaceHint {
private fun spawnBlockDisplay( private fun spawnBlockDisplay(
location: Location, location: Location,
material: Material, block: BlockData,
scale: Vector3f = Vector3f(1f, 1f, 1f), scale: Vector3f = Vector3f(1f, 1f, 1f),
offset: Vector3f = Vector3f(0f, 0f, 0f), offset: Vector3f = Vector3f(0f, 0f, 0f),
options: Byte = 0b00000000 options: Byte = 0b00000000
@ -282,14 +299,14 @@ class PlaceHint {
dataPacket.integers.write(0, id) dataPacket.integers.write(0, id)
// woated // woated
val blockData = BukkitConverters val blockData = BukkitConverters.getWrappedBlockDataConverter()
.getWrappedBlockDataConverter() .getGeneric(WrappedBlockData.createData(block))
.getGeneric(WrappedBlockData.createData(material))
val watcher = WrappedDataWatcher() val watcher = WrappedDataWatcher()
watcher.setObject(0, Registry.get(Byte::class.javaObjectType), options) watcher.setObject(0, Registry.get(Byte::class.javaObjectType), options)
watcher.setObject(11, Registry.get(Vector3f::class.javaObjectType), offset) watcher.setObject(11, Registry.get(Vector3f::class.javaObjectType), offset)
watcher.setObject(12, Registry.get(Vector3f::class.javaObjectType), scale) watcher.setObject(12, Registry.get(Vector3f::class.javaObjectType), scale)
watcher.setObject(16, Registry.get(Int::class.javaObjectType), 200)
watcher.setObject(23, Registry.getBlockDataSerializer(false), blockData) watcher.setObject(23, Registry.getBlockDataSerializer(false), blockData)
dataPacket.dataValueCollectionModifier.write(0, watcher.watchableObjects dataPacket.dataValueCollectionModifier.write(0, watcher.watchableObjects

View File

@ -14,6 +14,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent
import org.bukkit.event.inventory.InventoryDragEvent import org.bukkit.event.inventory.InventoryDragEvent
import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import java.util.*
class PlaceItem : Listener { class PlaceItem : Listener {
@ -26,7 +27,9 @@ class PlaceItem : Listener {
@EventHandler @EventHandler
fun onRightClickItem(event: PlayerInteractEvent) { fun onRightClickItem(event: PlayerInteractEvent) {
if (event.material != Material.BRICKS || (event.action != Action.RIGHT_CLICK_AIR && event.action != Action.RIGHT_CLICK_BLOCK)) if (event.material != Material.BRICKS
|| (event.action != Action.RIGHT_CLICK_AIR && event.action != Action.RIGHT_CLICK_BLOCK)
|| PlaceHint.contains(event.player))
return return
event.isCancelled = true event.isCancelled = true