From 671dc29c94085f65a1d38516ce5341632746b99f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 13 Sep 2017 18:18:14 +1000 Subject: [PATCH] * --- .../fawe/bukkit/util/cui/CUIListener.java | 2 +- .../fawe/bukkit/util/cui/StructureCUI.java | 126 +++++++++--------- 2 files changed, 67 insertions(+), 61 deletions(-) diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/CUIListener.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/CUIListener.java index 76651b3b..2101d64b 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/CUIListener.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/CUIListener.java @@ -19,7 +19,7 @@ public class CUIListener implements Listener { public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); - if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2) { + if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2 || (int) from.getY() >> 2 != (int) to.getY() >> 2) { FawePlayer player = FawePlayer.wrap(event.getPlayer()); CUI cui = player.getMeta("CUI"); if (cui instanceof StructureCUI) { diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java index 5d33da40..14bf7abf 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java @@ -9,6 +9,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.sk89q.worldedit.Vector; @@ -17,6 +18,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent; import com.sk89q.worldedit.internal.cui.SelectionShapeEvent; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -31,6 +33,7 @@ public class StructureCUI extends CUI { private Vector pos2; private Vector remove; + private NbtCompound removeTag; private int combined; public StructureCUI(FawePlayer player) { @@ -74,51 +77,7 @@ public class StructureCUI extends CUI { update(); } - public synchronized void update() { - Player player = this.getPlayer().parent; - Location playerLoc = player.getLocation(); - if (remove != null) { - int cx = playerLoc.getBlockX() >> 4; - int cz = playerLoc.getBlockZ() >> 4; - int viewDistance = viewDistance(); - if (Math.abs(cx - (remove.getBlockX() >> 4)) <= viewDistance && Math.abs(cz - (remove.getBlockZ() >> 4)) <= viewDistance) { - Location removeLoc = new Location(player.getWorld(), remove.getX(), remove.getY(), remove.getZ()); - player.sendBlockChange(removeLoc, FaweCache.getId(combined), (byte) FaweCache.getData(combined)); - } - remove = null; - } - if (pos1 == null || pos2 == null) return; - Vector min = Vector.getMinimum(pos1, pos2); - Vector max = Vector.getMaximum(pos1, pos2); - - // Position - double rotX = playerLoc.getYaw(); - double rotY = playerLoc.getPitch(); - double xz = Math.cos(Math.toRadians(rotY)); - int x = (int) (playerLoc.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 3); - int z = (int) (playerLoc.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 3); - int y = Math.min(Math.min(255, max.getBlockY() + 32), playerLoc.getBlockY() + 3); - - int minX = Math.max(Math.min(32, min.getBlockX() - x), -32); - int maxX = Math.max(Math.min(32, max.getBlockX() - x + 1), -32); - - int minY = Math.max(Math.min(32, min.getBlockY() - y), -32); - int maxY = Math.max(Math.min(32, max.getBlockY() - y + 1), -32); - - int minZ = Math.max(Math.min(32, min.getBlockZ() - z), -32); - int maxZ = Math.max(Math.min(32, max.getBlockZ() - z + 1), -32); - - int sizeX = Math.min(32, maxX - minX); - int sizeY = Math.min(32, maxY - minY); - int sizeZ = Math.min(32, maxZ - minZ); - if (sizeX == 0 || sizeY == 0 || sizeZ == 0) return; - - int posX = Math.max(minX, maxX - 48); - int posY = Math.max(minY, maxY - 48); - int posZ = Math.max(minZ, maxZ - 48); - - - // NBT + private NbtCompound constructStructureNbt(int x, int y, int z, int posX, int posY, int posZ, int sizeX, int sizeY, int sizeZ) { HashMap tag = new HashMap<>(); tag.put("name", UUID.randomUUID().toString()); tag.put("author", "Empire92"); // :D @@ -143,29 +102,76 @@ public class StructureCUI extends CUI { tag.put("seed", 0); tag.put("id", "minecraft:structure_block"); Object nmsTag = BukkitQueue_0.fromNative(FaweCache.asTag(tag)); - NbtCompound compound = NbtFactory.fromNMSCompound(nmsTag); + return NbtFactory.fromNMSCompound(nmsTag); + } - // Type - int type = 7; - - // Packet + private void sendNbt(Vector pos, NbtCompound compound) { + ProtocolManager manager = ProtocolLibrary.getProtocolManager(); PacketContainer containter = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA); - containter.getBlockPositionModifier().write(0, new BlockPosition(x, y, z)); - containter.getIntegers().write(0, type); + containter.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ())); + containter.getIntegers().write(0, 7); containter.getNbtModifier().write(0, compound); - ProtocolManager manager = ProtocolLibrary.getProtocolManager(); + Player player = this.getPlayer().parent; try { - - Block block = player.getWorld().getBlockAt(x, y, z); - remove = new Vector(x, y, z); - combined = FaweCache.getCombined(block.getTypeId(), block.getData()); - - Location blockLoc = new Location(player.getWorld(), x, y, z); - player.sendBlockChange(blockLoc, Material.STRUCTURE_BLOCK, (byte) 0); manager.sendServerPacket(player, containter); } catch (InvocationTargetException e) { e.printStackTrace(); } } + + public synchronized void update() { + Player player = this.getPlayer().parent; + Location playerLoc = player.getLocation(); + if (remove != null) { + int cx = playerLoc.getBlockX() >> 4; + int cz = playerLoc.getBlockZ() >> 4; + int viewDistance = viewDistance(); + if (Math.abs(cx - (remove.getBlockX() >> 4)) <= viewDistance && Math.abs(cz - (remove.getBlockZ() >> 4)) <= viewDistance) { + Map> map = removeTag.getValue(); + map.put("sizeX", NbtFactory.of("sizeX", 0)); + sendNbt(remove, removeTag); + Location removeLoc = new Location(player.getWorld(), remove.getX(), remove.getY(), remove.getZ()); + player.sendBlockChange(removeLoc, FaweCache.getId(combined), (byte) FaweCache.getData(combined)); + } + remove = null; + } + if (pos1 == null || pos2 == null) return; + Vector min = Vector.getMinimum(pos1, pos2); + Vector max = Vector.getMaximum(pos1, pos2); + + // Position + double rotX = playerLoc.getYaw(); + double rotY = playerLoc.getPitch(); + double xz = Math.cos(Math.toRadians(rotY)); + int x = (int) (playerLoc.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 3); + int z = (int) (playerLoc.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 3); + int y = Math.min(Math.min(255, max.getBlockY() + 32), playerLoc.getBlockY() + 3); + int minX = Math.max(Math.min(32, min.getBlockX() - x), -32); + int maxX = Math.max(Math.min(32, max.getBlockX() - x + 1), -32); + int minY = Math.max(Math.min(32, min.getBlockY() - y), -32); + int maxY = Math.max(Math.min(32, max.getBlockY() - y + 1), -32); + int minZ = Math.max(Math.min(32, min.getBlockZ() - z), -32); + int maxZ = Math.max(Math.min(32, max.getBlockZ() - z + 1), -32); + int sizeX = Math.min(32, maxX - minX); + int sizeY = Math.min(32, maxY - minY); + int sizeZ = Math.min(32, maxZ - minZ); + if (sizeX == 0 || sizeY == 0 || sizeZ == 0) return; + // maxX - 32; + int posX = Math.max(minX, Math.min(16, maxX) - 32); + int posY = Math.max(minY, Math.min(16, maxY) - 32); + int posZ = Math.max(minZ, Math.min(16, maxZ) - 32); + + // NBT + NbtCompound compound = constructStructureNbt(x, y, z, posX, posY, posZ, sizeX, sizeY, sizeZ); + + Block block = player.getWorld().getBlockAt(x, y, z); + remove = new Vector(x, y, z); + combined = FaweCache.getCombined(block.getTypeId(), block.getData()); + removeTag = compound; + + Location blockLoc = new Location(player.getWorld(), x, y, z); + player.sendBlockChange(blockLoc, Material.STRUCTURE_BLOCK, (byte) 0); + sendNbt(remove, compound); + } }