|
1 | | -package org.maxgamer.quickshop.util.hack.packet; |
2 | | - |
3 | | -import com.bergerkiller.bukkit.common.nbt.CommonTagCompound; |
4 | | -import com.bergerkiller.bukkit.common.protocol.CommonPacket; |
5 | | -import com.bergerkiller.bukkit.common.protocol.PacketType; |
6 | | -import com.bergerkiller.bukkit.common.utils.BlockUtil; |
7 | | -import com.bergerkiller.bukkit.common.utils.PacketUtil; |
8 | | -import net.md_5.bungee.chat.ComponentSerializer; |
9 | | -import org.apache.commons.lang.Validate; |
10 | | -import org.bukkit.Bukkit; |
11 | | -import org.bukkit.block.Sign; |
12 | | -import org.bukkit.entity.Player; |
13 | | -import org.jetbrains.annotations.NotNull; |
14 | | -import org.maxgamer.quickshop.QuickShop; |
15 | | -import org.maxgamer.quickshop.api.chat.ComponentPackage; |
16 | | - |
17 | | -import java.util.List; |
18 | | - |
19 | | -/** |
20 | | - * Little treat, we modify the sign component to translatable component if possible... |
21 | | - */ |
22 | | -public class SignPacketHack { |
23 | | - |
24 | | - private final QuickShop plugin; |
25 | | - |
26 | | - public SignPacketHack(QuickShop plugin) { |
27 | | - this.plugin = plugin; |
28 | | - Validate.isTrue(Bukkit.getPluginManager().isPluginEnabled("BKCommonLib"), "Require BKCommonLib installed!"); |
29 | | - } |
30 | | - |
31 | | - public void sendLines(@NotNull Sign sign, @NotNull List<ComponentPackage> lines, Player player) { |
32 | | - if (player != null) { |
33 | | - CommonPacket updatePacket = BlockUtil.getUpdatePacket(sign); |
34 | | - if (updatePacket != null) { |
35 | | - applyToSign(updatePacket, lines); |
36 | | - PacketUtil.sendPacket(player, updatePacket); |
37 | | - } |
38 | | - } |
39 | | - } |
40 | | - |
41 | | - public void applyToSign(@NotNull CommonPacket updatePacket, @NotNull List<ComponentPackage> lines) { |
42 | | - if (updatePacket.getType() == PacketType.OUT_TILE_ENTITY_DATA) { |
43 | | - // >= MC 1.10.2 |
44 | | - |
45 | | - CommonTagCompound compound = updatePacket.read(PacketType.OUT_TILE_ENTITY_DATA.data); |
46 | | - // ==================================================================== |
47 | | - |
48 | | - for (int i = 0; i < lines.size(); i++) { |
49 | | - String key = "Text" + (i + 1); |
50 | | - String text = ComponentSerializer.toString(lines.get(i).getComponents()); |
51 | | - compound.putValue(key, text); |
52 | | - } |
53 | | - |
54 | | - // ==================================================================== |
55 | | - updatePacket.write(PacketType.OUT_TILE_ENTITY_DATA.data, compound); |
56 | | - } |
57 | | - } |
58 | | - |
59 | | -} |
| 1 | +//package org.maxgamer.quickshop.util.hack.packet; |
| 2 | +// |
| 3 | +//import com.bergerkiller.bukkit.common.nbt.CommonTagCompound; |
| 4 | +//import com.bergerkiller.bukkit.common.protocol.CommonPacket; |
| 5 | +//import com.bergerkiller.bukkit.common.protocol.PacketType; |
| 6 | +//import com.bergerkiller.bukkit.common.utils.BlockUtil; |
| 7 | +//import com.bergerkiller.bukkit.common.utils.PacketUtil; |
| 8 | +//import net.md_5.bungee.chat.ComponentSerializer; |
| 9 | +//import org.apache.commons.lang.Validate; |
| 10 | +//import org.bukkit.Bukkit; |
| 11 | +//import org.bukkit.block.Sign; |
| 12 | +//import org.bukkit.entity.Player; |
| 13 | +//import org.jetbrains.annotations.NotNull; |
| 14 | +//import org.maxgamer.quickshop.QuickShop; |
| 15 | +//import org.maxgamer.quickshop.api.chat.ComponentPackage; |
| 16 | +// |
| 17 | +//import java.util.List; |
| 18 | +// |
| 19 | +///** |
| 20 | +// * Little treat, we modify the sign component to translatable component if possible... |
| 21 | +// */ |
| 22 | +//public class SignPacketHack { |
| 23 | +// |
| 24 | +// private final QuickShop plugin; |
| 25 | +// |
| 26 | +// public SignPacketHack(QuickShop plugin) { |
| 27 | +// this.plugin = plugin; |
| 28 | +// Validate.isTrue(Bukkit.getPluginManager().isPluginEnabled("BKCommonLib"), "Require BKCommonLib installed!"); |
| 29 | +// } |
| 30 | +// |
| 31 | +// public void sendLines(@NotNull Sign sign, @NotNull List<ComponentPackage> lines, Player player) { |
| 32 | +// if (player != null) { |
| 33 | +// CommonPacket updatePacket = BlockUtil.getUpdatePacket(sign); |
| 34 | +// if (updatePacket != null) { |
| 35 | +// applyToSign(updatePacket, lines); |
| 36 | +// PacketUtil.sendPacket(player, updatePacket); |
| 37 | +// } |
| 38 | +// } |
| 39 | +// } |
| 40 | +// |
| 41 | +// public void applyToSign(@NotNull CommonPacket updatePacket, @NotNull List<ComponentPackage> lines) { |
| 42 | +// if (updatePacket.getType() == PacketType.OUT_TILE_ENTITY_DATA) { |
| 43 | +// // >= MC 1.10.2 |
| 44 | +// |
| 45 | +// CommonTagCompound compound = updatePacket.read(PacketType.OUT_TILE_ENTITY_DATA.data); |
| 46 | +// // ==================================================================== |
| 47 | +// |
| 48 | +// for (int i = 0; i < lines.size(); i++) { |
| 49 | +// String key = "Text" + (i + 1); |
| 50 | +// String text = ComponentSerializer.toString(lines.get(i).getComponents()); |
| 51 | +// compound.putValue(key, text); |
| 52 | +// } |
| 53 | +// |
| 54 | +// // ==================================================================== |
| 55 | +// updatePacket.write(PacketType.OUT_TILE_ENTITY_DATA.data, compound); |
| 56 | +// } |
| 57 | +// } |
| 58 | +// |
| 59 | +//} |
0 commit comments