Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void register() {
- ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
- protocolManager.addPacketListener(new PacketAdapter(Main.getMain(), ListenerPriority.LOWEST,
- PacketType.Play.Server.BLOCK_CHANGE, PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
- @Override
- public void onPacketSending(PacketEvent event) {
- // Item packets (id: 0x29)
- PacketContainer clone = event.getPacket().shallowClone();
- Player p = event.getPlayer();
- if (joinHidePlayer.contains(p.getUniqueId())) {
- return;
- }
- PacketContainer packets = event.getPacket();
- if (event.getPacketType() == PacketType.Play.Server.BLOCK_CHANGE) {
- BlockPosition pos = packets.getBlockPositionModifier().getValues().get(0);
- List<String> apllRegions = regions
- .getApplicableRegionsIDs(BlockVector3.at(pos.getX(), pos.getY(), pos.getZ()));
- WrappedBlockData data = packets.getBlockData().getValues().get(0);
- if (materials.contains(data.getType())) {
- if (apllRegions.contains("south")) {
- if (Main.aWdlWhitelist.contains(p.getName()) || Main.teamSmembers.contains(p.getName())) {
- event.setPacket(packets);
- } else {
- data.setType(Material.END_STONE);
- clone.getBlockData().write(0, data);
- event.setPacket(clone);
- }
- } else if (apllRegions.contains("north")) {
- if (Main.aWdlWhitelist.contains(p.getName()) || Main.teamNmembers.contains(p.getName())) {
- event.setPacket(packets);
- } else {
- data.setType(Material.END_STONE);
- clone.getBlockData().write(0, data);
- event.setPacket(clone);
- }
- }
- }
- } else if (event.getPacketType() == PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
- int packets_size = packets.getMultiBlockChangeInfoArrays().size();
- for (int j = 0; j < packets_size; j++) {
- MultiBlockChangeInfo[] info = packets.getMultiBlockChangeInfoArrays().getValues().get(j);
- int size = info.length;
- for (int i = 0; i < size; i++) {
- Location loc = info[i].getLocation(p.getWorld());
- List<String> apllRegions = regions
- .getApplicableRegionsIDs(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()));
- if (materials.contains(info[i].getData().getType())) {
- if (apllRegions.contains("south")) {
- if (Main.aWdlWhitelist.contains(p.getName())
- || Main.teamSmembers.contains(p.getName())) {
- // event.setCancelled(true);
- event.setPacket(packets);
- } else {
- WrappedBlockData data = info[i].getData();
- data.setType(Material.END_STONE);
- info[i].setData(data);
- clone.getMultiBlockChangeInfoArrays().write(j, info);
- event.setPacket(clone);
- }
- } else if (apllRegions.contains("north")) {
- if (Main.aWdlWhitelist.contains(p.getName())
- || Main.teamNmembers.contains(p.getName())) {
- event.setPacket(packets);
- } else {
- WrappedBlockData data = info[i].getData();
- data.setType(Material.END_STONE);
- clone.getMultiBlockChangeInfoArrays().write(j, info);
- event.setPacket(clone);
- }
- }
- }
- }
- }
- }
- }
- });
- protocolManager.addPacketListener(
- new PacketAdapter(Main.getMain(), ListenerPriority.HIGHEST, PacketType.Play.Server.MAP_CHUNK) {
- @Override
- public void onPacketSending(PacketEvent event) {
- Player p = event.getPlayer();
- if (joinHidePlayer.contains(p.getUniqueId())) {
- return;
- }
- if (event.getPacketType().equals(PacketType.Play.Server.MAP_CHUNK)) {
- PacketContainer packet = event.getPacket();
- PacketContainer clone = packet.shallowClone();
- List<NbtBase<?>> listout = new ArrayList<>();
- List<NbtBase<?>> listNBT = packet.getListNbtModifier().read(0);
- for (NbtBase<?> base : listNBT) {
- NbtCompound nbt = NbtFactory.asCompound(base);
- int x = nbt.getInteger("x");
- int y = nbt.getInteger("y");
- int z = nbt.getInteger("z");
- List<String> apllRegions = regions
- .getApplicableRegionsIDs(BlockVector3.at(x, y, z));
- Material m = Material
- .getMaterial(nbt.getString("id").replace("minecraft:", "").toUpperCase());
- if (materials.contains(m)) {
- if (apllRegions.contains("south")) {
- if (Main.aWdlWhitelist.contains(p.getName())
- || Main.teamSmembers.contains(p.getName())) {
- event.setPacket(packet);
- return;
- } else {
- listout.add(getEndStoneNBT(x, y, z));
- System.out.println( x + " " + y + " " + z + " to endstone");
- }
- // norden?
- } else if (apllRegions.contains("north")) {
- if (Main.aWdlWhitelist.contains(p.getName())
- || Main.teamSmembers.contains(p.getName())) {
- event.setPacket(packet);
- return;
- } else {
- listout.add(getEndStoneNBT(x, y, z));
- System.out.println( x + " " + y + " " + z + " to endstone");
- }
- }
- }
- }
- clone.getListNbtModifier().write(0, listout);
- event.setPacket(clone);
- }
- }
- });
- }
- private static NbtBase<?> getEndStoneNBT(int x, int y, int z) {
- NbtCompound out = NbtFactory.ofCompound(null);
- out.put("x", x);
- out.put("y", y);
- out.put("z", z);
- out.put("id", "minecraft:end_stone");
- System.out.println(out.toString());
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement