Advertisement
FREE2WIN

Untitled

Apr 9th, 2020
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1.     public static void register() {
  2.         ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
  3.         protocolManager.addPacketListener(new PacketAdapter(Main.getMain(), ListenerPriority.LOWEST,
  4.                 PacketType.Play.Server.BLOCK_CHANGE, PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
  5.             @Override
  6.             public void onPacketSending(PacketEvent event) {
  7.                 // Item packets (id: 0x29)
  8.                 PacketContainer clone = event.getPacket().shallowClone();
  9.                 Player p = event.getPlayer();
  10.                 if (joinHidePlayer.contains(p.getUniqueId())) {
  11.                     return;
  12.                 }
  13.                 PacketContainer packets = event.getPacket();
  14.                 if (event.getPacketType() == PacketType.Play.Server.BLOCK_CHANGE) {
  15.  
  16.                     BlockPosition pos = packets.getBlockPositionModifier().getValues().get(0);
  17.                     List<String> apllRegions = regions
  18.                             .getApplicableRegionsIDs(BlockVector3.at(pos.getX(), pos.getY(), pos.getZ()));
  19.                     WrappedBlockData data = packets.getBlockData().getValues().get(0);
  20.                     if (materials.contains(data.getType())) {
  21.                         if (apllRegions.contains("south")) {
  22.                             if (Main.aWdlWhitelist.contains(p.getName()) || Main.teamSmembers.contains(p.getName())) {
  23.                                 event.setPacket(packets);
  24.                             } else {
  25.                                 data.setType(Material.END_STONE);
  26.                                 clone.getBlockData().write(0, data);
  27.                                 event.setPacket(clone);
  28.                             }
  29.                         } else if (apllRegions.contains("north")) {
  30.                             if (Main.aWdlWhitelist.contains(p.getName()) || Main.teamNmembers.contains(p.getName())) {
  31.                                 event.setPacket(packets);
  32.                             } else {
  33.                                 data.setType(Material.END_STONE);
  34.                                 clone.getBlockData().write(0, data);
  35.                                 event.setPacket(clone);
  36.                             }
  37.                         }
  38.                     }
  39.  
  40.                 } else if (event.getPacketType() == PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
  41.                     int packets_size = packets.getMultiBlockChangeInfoArrays().size();
  42.                     for (int j = 0; j < packets_size; j++) {
  43.                         MultiBlockChangeInfo[] info = packets.getMultiBlockChangeInfoArrays().getValues().get(j);
  44.                         int size = info.length;
  45.                         for (int i = 0; i < size; i++) {
  46.                             Location loc = info[i].getLocation(p.getWorld());
  47.                             List<String> apllRegions = regions
  48.                                     .getApplicableRegionsIDs(BlockVector3.at(loc.getX(), loc.getY(), loc.getZ()));
  49.                             if (materials.contains(info[i].getData().getType())) {
  50.                                 if (apllRegions.contains("south")) {
  51.                                     if (Main.aWdlWhitelist.contains(p.getName())
  52.                                             || Main.teamSmembers.contains(p.getName())) {
  53.                                         // event.setCancelled(true);
  54.                                         event.setPacket(packets);
  55.                                     } else {
  56.                                         WrappedBlockData data = info[i].getData();
  57.                                         data.setType(Material.END_STONE);
  58.                                         info[i].setData(data);
  59.                                         clone.getMultiBlockChangeInfoArrays().write(j, info);
  60.                                         event.setPacket(clone);
  61.                                     }
  62.                                 } else if (apllRegions.contains("north")) {
  63.                                     if (Main.aWdlWhitelist.contains(p.getName())
  64.                                             || Main.teamNmembers.contains(p.getName())) {
  65.                                         event.setPacket(packets);
  66.                                     } else {
  67.                                         WrappedBlockData data = info[i].getData();
  68.                                         data.setType(Material.END_STONE);
  69.                                         clone.getMultiBlockChangeInfoArrays().write(j, info);
  70.                                         event.setPacket(clone);
  71.                                     }
  72.                                 }
  73.                             }
  74.                         }
  75.  
  76.                     }
  77.                 }
  78.  
  79.             }
  80.         });
  81.         protocolManager.addPacketListener(
  82.                 new PacketAdapter(Main.getMain(), ListenerPriority.HIGHEST, PacketType.Play.Server.MAP_CHUNK) {
  83.                     @Override
  84.                     public void onPacketSending(PacketEvent event) {
  85.                         Player p = event.getPlayer();
  86.                         if (joinHidePlayer.contains(p.getUniqueId())) {
  87.                             return;
  88.                         }
  89.                         if (event.getPacketType().equals(PacketType.Play.Server.MAP_CHUNK)) {
  90.                             PacketContainer packet = event.getPacket();
  91.                             PacketContainer clone = packet.shallowClone();
  92.                             List<NbtBase<?>> listout = new ArrayList<>();
  93.                             List<NbtBase<?>> listNBT = packet.getListNbtModifier().read(0);
  94.                                 for (NbtBase<?> base : listNBT) {
  95.                                     NbtCompound nbt = NbtFactory.asCompound(base);
  96.                                     int x = nbt.getInteger("x");
  97.                                     int y = nbt.getInteger("y");
  98.                                     int z = nbt.getInteger("z");
  99.                                     List<String> apllRegions = regions
  100.                                             .getApplicableRegionsIDs(BlockVector3.at(x, y, z));
  101.                                     Material m = Material
  102.                                             .getMaterial(nbt.getString("id").replace("minecraft:", "").toUpperCase());
  103.                                     if (materials.contains(m)) {
  104.                                         if (apllRegions.contains("south")) {
  105.                                             if (Main.aWdlWhitelist.contains(p.getName())
  106.                                                     || Main.teamSmembers.contains(p.getName())) {
  107.                                                 event.setPacket(packet);
  108.                                                 return;
  109.                                             } else {
  110.                                                 listout.add(getEndStoneNBT(x, y, z));
  111.                                                 System.out.println( x + " " + y + " " + z + " to endstone");
  112.                                             }
  113.  
  114.                                             // norden?
  115.                                         } else if (apllRegions.contains("north")) {
  116.                                             if (Main.aWdlWhitelist.contains(p.getName())
  117.                                                     || Main.teamSmembers.contains(p.getName())) {
  118.                                                 event.setPacket(packet);
  119.                                                 return;
  120.                                             } else {
  121.                                                 listout.add(getEndStoneNBT(x, y, z));
  122.                                                 System.out.println( x + " " + y + " " + z + " to endstone");
  123.                                             }
  124.                                         }
  125.  
  126.                                     }
  127.                                 }
  128.                                 clone.getListNbtModifier().write(0, listout);
  129.                                 event.setPacket(clone);
  130.                             }
  131.                         }
  132.                 });
  133.     }
  134.  
  135.  
  136.     private static NbtBase<?> getEndStoneNBT(int x, int y, int z) {
  137.         NbtCompound out = NbtFactory.ofCompound(null);
  138.         out.put("x", x);
  139.         out.put("y", y);
  140.         out.put("z", z);
  141.         out.put("id", "minecraft:end_stone");
  142.         System.out.println(out.toString());
  143.         return out;
  144.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement