diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java index f88367f..12c6cc8 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java @@ -20,7 +20,12 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import net.minecraft.server.v1_12_R1.BlockPosition; +import net.minecraft.server.v1_12_R1.PacketPlayOutOpenSignEditor; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; class RegionListener_12 { private RegionListener_12(){} @@ -33,4 +38,9 @@ class RegionListener_12 { return ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")).getWorldEdit().getPlatformManager() .getCommandManager().getDispatcher().get(command) != null; } + + static void openSignEditor(Player player, Location location) { + PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } } diff --git a/BauSystem_15/pom.xml b/BauSystem_15/pom.xml index cd2adb4..bcebe1e 100644 --- a/BauSystem_15/pom.xml +++ b/BauSystem_15/pom.xml @@ -50,5 +50,12 @@ BauSystem_API 1.0 + + steamwar + ProtocolLib + 4.5.0 + system + ${main.basedir}/lib/ProtocolLib.jar + diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java index 14a810e..fd22589 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java @@ -19,7 +19,17 @@ package de.steamwar.bausystem.world; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.BlockPosition; import com.sk89q.worldedit.WorldEdit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; class RegionListener_15 { private RegionListener_15(){} @@ -31,4 +41,14 @@ class RegionListener_15 { command = command.toLowerCase(); return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command); } + + static 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); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 3019aad..47d49c0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -20,18 +20,30 @@ package de.steamwar.bausystem.world; +import com.comphenix.protocol.PacketType; +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 de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; +import de.steamwar.core.VersionedRunnable; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import com.comphenix.protocol.ProtocolLibrary; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; public class RegionListener implements Listener { @@ -98,4 +110,48 @@ public class RegionListener implements Listener { event.setLine(i, line); } } + + @EventHandler + public void editSign(PlayerInteractEvent event) { + if(event.getAction() != Action.RIGHT_CLICK_BLOCK || + !event.getClickedBlock().getType().name().contains("SIGN") || + !event.getPlayer().isSneaking()) + return; + + Player player = event.getPlayer(); + Sign sign = (Sign) event.getClickedBlock().getState(); + String[] lines = sign.getLines(); + for (int i = 0; i < lines.length; i++) { + sign.setLine(i, lines[i].replace('ยง', '&')); + } + sign.update(); + + VersionedRunnable.call(new VersionedRunnable(() -> RegionListener_12.openSignEditor(player, event.getClickedBlock().getLocation()), 12), + new VersionedRunnable(() -> RegionListener_15.openSignEditor(player, event.getClickedBlock().getLocation()), 15)); + + 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); + }); + } + }); + } } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 4d17a57..74b9ef6 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,7 +1,7 @@ name: BauSystem author: [Lixfel, YoyoNow, Chaoscaot] version: "1.0" -depend: [WorldEdit, SpigotCore] +depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13"