diff --git a/BauSystem_15/pom.xml b/BauSystem_15/pom.xml deleted file mode 100644 index 08be638..0000000 --- a/BauSystem_15/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - 4.0.0 - - - steamwar - BauSystem - 1.0 - - - - ${project.basedir}/.. - - - BauSystem_15 - 1.0 - - - - steamwar - BauSystem_Core - 1.0 - - - steamwar - WorldEdit - 1.0 - system - ${main.basedir}/lib/WorldEdit-1.15.jar - - - steamwar - Spigot - 1.15 - system - ${main.basedir}/lib/Spigot-1.15.jar - - - \ No newline at end of file diff --git a/BauSystem_15/src/de/steamwar/bausystem/CraftbukkitWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/CraftbukkitWrapper15.java deleted file mode 100644 index 8603d2e..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/CraftbukkitWrapper15.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.BlockPosition; -import de.steamwar.bausystem.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.world.TPSUtils; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.util.Vector; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper { - - private final List> packets = new ArrayList<>(); - - @Override - public void initTPS() { - SystemUtils.a = () -> System.nanoTime() + TPSUtils.getNanoOffset(); - } - - @Override - public void createTickCache(World world) { - packets.clear(); - world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> { - packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), Vec3D.a)); - packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle())); - - if (entity instanceof TNTPrimed) { - net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); - packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true)); - } - }); - } - - @Override - public void sendTickPackets() { - Bukkit.getOnlinePlayers().forEach(player -> { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - for (Packet p : packets) { - connection.sendPacket(p); - } - }); - } - - @Override - public void openSignEditor(Player player, Location location) { - PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); - signOpen.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - } - } - - @Override - public AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) { - return new TraceEntity15(world, tntPosition, tnt); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/FlatteningWrapper15.java deleted file mode 100644 index cbeadb6..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/FlatteningWrapper15.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem; - -import de.steamwar.bausystem.world.Detoloader; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Openable; -import org.bukkit.block.data.Powerable; -import org.bukkit.block.data.Waterlogged; -import org.bukkit.block.data.type.Switch; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class FlatteningWrapper15 implements FlatteningWrapper.IFlatteningWrapper { - - @Override - public boolean tntPlaceActionPerform(Location location) { - Material m = location.getBlock().getType(); - if (m != Material.AIR && m != Material.WATER) - return false; - - location.getBlock().setType(Material.TNT); - return true; - } - - @Override - public boolean setRedstone(Location location, boolean active) { - Block block = location.getBlock(); - BlockData data = block.getBlockData(); - if (!(data instanceof Powerable)) - return false; - - - Powerable powerable = (Powerable) data; - powerable.setPowered(active); - block.setBlockData(powerable); - - if (data instanceof Openable) { - Openable openable = (Openable) data; - openable.setOpen(active); - block.setBlockData(openable); - } - - if (data instanceof Switch) { - Switch swtch = (Switch) data; - Block relative; - switch (swtch.getFace()) { - case FLOOR: - relative = block.getRelative(BlockFace.DOWN); - break; - case CEILING: - relative = block.getRelative(BlockFace.UP); - break; - default: - relative = block.getRelative(swtch.getFacing().getOppositeFace()); - break; - } - updateBlock(relative); - } else if (block.getType() == Material.TRIPWIRE) { - updateBlock(block); - } - return true; - } - - private void updateBlock(Block block) { - BlockData data = block.getBlockData(); - block.setType(Material.BARRIER, true); - block.setBlockData(data, true); - } - - @Override - public Detoloader onPlayerInteractLoader(PlayerInteractEvent event) { - Block block = event.getClickedBlock(); - assert block != null; - BlockData data = block.getBlockData(); - if (!(data instanceof Powerable)) - return new Detoloader("§eUnbekannter Block betätigt (nicht aufgenommen)", -1).setAddBack(false); - Powerable powerable = (Powerable) data; - Material material = block.getType(); - - if (material == Material.LEVER) { - return new Detoloader("Hebel", 0).setActive(!powerable.isPowered()); - } else if (material == Material.STONE_BUTTON) { - return new Detoloader("Knopf", Detoloader.STONE_BUTTON); - } else if (material.name().contains("PRESSURE_PLATE")) { - return new Detoloader("Druckplatte", Detoloader.PRESSURE_PLATE); - } else if (material.name().contains("BUTTON")) { - return new Detoloader("Knopf", Detoloader.WOODEN_BUTTON); - } else if (material == Material.NOTE_BLOCK) { - return new Detoloader("Noteblock", Detoloader.NOTE_BLOCK); - } else if (material.name().equals("TRIPWIRE")) { - return new Detoloader("Tripwire", Detoloader.TRIPWIRE); - } else { - return new Detoloader("§eUnbekannter Block betätigt (aufgenommen)", 0).setAddBack(false); - } - } - - @Override - public boolean getLever(Block block) { - if (!(block.getBlockData() instanceof Powerable)) - return false; - return ((Powerable) block.getBlockData()).isPowered(); - } - - @Override - public boolean isNoBook(ItemStack item) { - return item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK; - } - - @Override - public boolean inWater(World world, Vector tntPosition) { - Block block = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ()); - if (block.getType() == Material.WATER) - return true; - - BlockData data = block.getBlockData(); - if (!(data instanceof Waterlogged)) - return false; - - return ((Waterlogged) data).isWaterlogged(); - } - - @Override - public Material getTraceShowMaterial() { - return Material.LIME_CONCRETE; - } - - @Override - public Material getTraceHideMaterial() { - return Material.RED_CONCRETE; - } - - @Override - public Material getTraceXZMaterial() { - return Material.QUARTZ_SLAB; - } - - @Override - public void giveStick(Player player) { - SWUtils.giveItemToPlayer(player, new ItemStack(Material.DEBUG_STICK)); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/TraceEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/TraceEntity15.java deleted file mode 100644 index eb1db0b..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/TraceEntity15.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem; - -import de.steamwar.bausystem.tracer.AbstractTraceEntity; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -class TraceEntity15 extends EntityFallingBlock implements AbstractTraceEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private final Vector position; - private final boolean tnt; - - private boolean exploded = false; - private int references = 0; - - public TraceEntity15(World world, Vector position, boolean tnt) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData()); - this.position = position; - this.tnt = tnt; - - this.setNoGravity(true); - this.ticksLived = -12000; - } - - @Override - public void display(Player player, boolean exploded) { - if (!this.exploded && exploded) { - this.setCustomNameVisible(true); - this.setCustomName(new ChatComponentText("Bumm")); - this.exploded = true; - if (references++ > 0) - sendDestroy(player); - } else if (references++ > 0) - return; - - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && --references > 0) - return false; - - sendDestroy(player); - die(); - return true; - } - - private void sendDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/WorldeditWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/WorldeditWrapper15.java deleted file mode 100644 index b1bc702..0000000 --- a/BauSystem_15/src/de/steamwar/bausystem/WorldeditWrapper15.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; -import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.transform.AffineTransform; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; -import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.world.World; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.world.Color; -import de.steamwar.bausystem.world.regions.PasteOptions; -import de.steamwar.bausystem.world.regions.Point; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Objects; - -public class WorldeditWrapper15 implements WorldeditWrapper.IWorldeditWrapper { - - private final WorldEditPlugin WORLDEDIT_PLUGIN = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); - private final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); - - @Override - public void setSelection(Player p, Point minPoint, Point maxPoint) { - WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint))); - } - - @Override - public EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { - Clipboard clipboard; - try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { - clipboard = reader.read(); - } catch (NullPointerException | IOException e) { - throw new SecurityException("Bausystem schematic not found", e); - } - - return paste(clipboard, x, y, z, pasteOptions); - } - - @Override - public EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) { - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - changeColor(clipboard, pasteOptions.getColor()); - - ClipboardHolder ch = new ClipboardHolder(clipboard); - BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v = BlockVector3.at(x, y, z); - BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - if (pasteOptions.isRotate()) { - ch.setTransform(new AffineTransform().rotateY(180)); - v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); - } else { - v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); - } - - if (pasteOptions.isReset()) { - e.setBlocks(new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), BlockTypes.AIR.getDefaultState().toBaseBlock()); - if (pasteOptions.getWaterLevel() != 0) { - e.setBlocks(new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), BlockTypes.WATER.getDefaultState().toBaseBlock()); - } - } - Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build()); - return e; - } catch (WorldEditException e) { - throw new SecurityException(e.getMessage(), e); - } - } - - @Override - public boolean isWorldEditCommand(String command) { - if (command.startsWith("/")) { - command = command.replaceFirst("/", ""); - } - command = command.toLowerCase(); - return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command); - } - - private BlockVector3 toBlockVector3(Point point) { - return BlockVector3.at(point.getX(), point.getY(), point.getZ()); - } - - private void changeColor(Clipboard clipboard, Color color) throws WorldEditException { - for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getY(); y++) { - for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { - BlockVector3 blockPointer = clipboard.getMinimumPoint().add(x, y, z); - BaseBlock baseBlock = clipboard.getFullBlock(blockPointer); - BlockType blockType = baseBlock.getBlockType(); - if (blockType != BlockTypes.YELLOW_CONCRETE && blockType != BlockTypes.YELLOW_STAINED_GLASS) { - continue; - } - clipboard.setBlock(blockPointer, mapColor(blockType, color).getDefaultState().toBaseBlock()); - } - } - } - } - - private BlockType mapColor(BlockType original, Color color) { - switch (color) { - case WHITE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.WHITE_CONCRETE; - } else { - return BlockTypes.WHITE_STAINED_GLASS; - } - case ORANGE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.ORANGE_CONCRETE; - } else { - return BlockTypes.ORANGE_STAINED_GLASS; - } - case MAGENTA: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.MAGENTA_CONCRETE; - } else { - return BlockTypes.MAGENTA_STAINED_GLASS; - } - case LIGHT_BLUE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIGHT_BLUE_CONCRETE; - } else { - return BlockTypes.LIGHT_BLUE_STAINED_GLASS; - } - case LIME: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIME_CONCRETE; - } else { - return BlockTypes.LIME_STAINED_GLASS; - } - case PINK: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.PINK_CONCRETE; - } else { - return BlockTypes.PINK_STAINED_GLASS; - } - case GRAY: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.GRAY_CONCRETE; - } else { - return BlockTypes.GRAY_STAINED_GLASS; - } - case LIGHT_GRAY: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIGHT_GRAY_CONCRETE; - } else { - return BlockTypes.LIGHT_GRAY_STAINED_GLASS; - } - case CYAN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.CYAN_CONCRETE; - } else { - return BlockTypes.CYAN_STAINED_GLASS; - } - case PURPLE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.PURPLE_CONCRETE; - } else { - return BlockTypes.PURPLE_STAINED_GLASS; - } - case BLUE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BLUE_CONCRETE; - } else { - return BlockTypes.BLUE_STAINED_GLASS; - } - case BROWN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BROWN_CONCRETE; - } else { - return BlockTypes.BROWN_STAINED_GLASS; - } - case GREEN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.GREEN_CONCRETE; - } else { - return BlockTypes.GREEN_STAINED_GLASS; - } - case RED: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.RED_CONCRETE; - } else { - return BlockTypes.RED_STAINED_GLASS; - } - case BLACK: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BLACK_CONCRETE; - } else { - return BlockTypes.BLACK_STAINED_GLASS; - } - case YELLOW: - default: - return original; - } - } -} diff --git a/BauSystem_Core/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Core/src/de/steamwar/bausystem/world/RegionListener.java index 2440629..a59e1c0 100644 --- a/BauSystem_Core/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Core/src/de/steamwar/bausystem/world/RegionListener.java @@ -19,18 +19,15 @@ package de.steamwar.bausystem.world; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.CraftbukkitWrapper; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.WorldeditWrapper; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -43,8 +40,47 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; +import java.util.ArrayList; +import java.util.List; + public class RegionListener implements Listener { + private final List signEditing = new ArrayList<>(); + + private static final Class updateSign = Reflection.getClass("{nms}.PacketPlayInUpdateSign"); + private static final Class blockPosition = Reflection.getClass("{nms}.BlockPosition"); + private static final Reflection.FieldAccessor blockPos = Reflection.getField(updateSign, blockPosition, 0); + private static final Reflection.FieldAccessor signText = Reflection.getField(updateSign, String[].class, 0); + private static final Class baseBlockPosition = Reflection.getClass("{nms}.BaseBlockPosition"); + private static final Reflection.FieldAccessor blockPosX = Reflection.getField(baseBlockPosition, int.class, 0); + private static final Reflection.FieldAccessor blockPosY = Reflection.getField(baseBlockPosition, int.class, 1); + private static final Reflection.FieldAccessor blockPosZ = Reflection.getField(baseBlockPosition, int.class, 2); + public RegionListener() { + TinyProtocol.instance.setInFilter((player, channel, packet) -> { + if(!signEditing.contains(player) || !updateSign.isInstance(packet)) + return packet; + + String[] lines = signText.get(packet); + Object pos = blockPos.get(packet); + + Bukkit.getScheduler().runTask(BauSystem.getPlugin(), () -> { + Block signLoc = new Location(player.getWorld(), blockPosX.get(pos), blockPosY.get(pos), blockPosZ.get(pos)).getBlock(); + if (!signLoc.getType().name().contains("SIGN")) + return; + + Sign sign = ((Sign) signLoc.getState()); + for (int i = 0; i < lines.length; i++) { + sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); + } + sign.update(); + + signEditing.remove(player); + }); + + return packet; + }); + } + @EventHandler(priority = EventPriority.LOWEST) public void playerCommandHandler(PlayerCommandPreprocessEvent e) { if (!isWorldEditCommand(e.getMessage().split(" ")[0])) @@ -96,30 +132,6 @@ public class RegionListener implements Listener { sign.update(); CraftbukkitWrapper.impl.openSignEditor(player, event.getClickedBlock().getLocation()); - - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Client.UPDATE_SIGN) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (!event.getPlayer().equals(player)) - return; - Bukkit.getScheduler().runTask(BauSystem.getPlugin(), () -> { - PacketContainer packetContainer = event.getPacket(); - BlockPosition position = packetContainer.getBlockPositionModifier().read(0); - String[] lines = packetContainer.getStringArrays().read(0); - - Block signLoc = position.toLocation(player.getWorld()).getBlock(); - if (!signLoc.getType().name().contains("SIGN")) - return; - - Sign sign = ((Sign) signLoc.getState()); - for (int i = 0; i < lines.length; i++) { - sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); - } - sign.update(); - - ProtocolLibrary.getProtocolManager().removePacketListener(this); - }); - } - }); + signEditing.add(player); } } diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index 13bd790..7020d76 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -62,12 +62,6 @@ 1.0 compile - - steamwar - BauSystem_15 - 1.0 - compile - steamwar BauSystem_Core diff --git a/pom.xml b/pom.xml index d139b8c..29c4b9c 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,6 @@ BauSystem_12 - BauSystem_15 BauSystem_Core BauSystem_Main @@ -84,13 +83,6 @@ system ${main.basedir}/lib/SpigotCore.jar - - steamwar - ProtocolLib - 1.0 - system - ${main.basedir}/lib/ProtocolLib.jar -