minesire

ProtocolLibHook Code

Sep 13th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public class ProtocolLibHook extends PacketAdapter {
  2.  
  3.     public ProtocolLibHook(Main plugin) {
  4.         super(plugin, ListenerPriority.NORMAL, new PacketType[] { PacketType.Status.Server.SERVER_INFO });
  5.         this.plugin = plugin;
  6.     }
  7.  
  8.     @SuppressWarnings("deprecation")
  9.     public ProtocolLibHook(Main plugin, boolean b) {
  10.         super(plugin, ListenerPriority.NORMAL, new PacketType[] { PacketType.Status.Server.OUT_SERVER_INFO });
  11.         this.plugin = plugin;
  12.     }
  13.  
  14.     public static void register(Main plugin) {
  15.         try {
  16.             ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibHook(plugin));
  17.         } catch (NoSuchMethodError ex) {
  18.             ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibHook(plugin, true));
  19.         }
  20.     }
  21.  
  22.     public Main plugin = (Main) Bukkit.getPluginManager().getPlugin("Main");
  23.  
  24.     public void onPacketSending (PacketEvent event) {
  25.         try {
  26.             if (Main.plugin.getServer().getPluginManager().getPlugin("ProtocolLib") == null)
  27.                 return;
  28.  
  29.             WrappedServerPing ping = (WrappedServerPing) event.getPacket().getServerPings().read(0);
  30.             Collection<UUID> vanishedPlayers = VanishUtilities.getInstance().listInVanishUUID();
  31.             ping.setPlayersOnline(Bukkit.getOnlinePlayers().size() - VanishUtilities.getInstance().listInVanish().size());
  32.             List<WrappedGameProfile> wrappedGameProfiles = new ArrayList<WrappedGameProfile>(ping.getPlayers());
  33.             Iterator<WrappedGameProfile> iterator = wrappedGameProfiles.iterator();
  34.  
  35.             while (iterator.hasNext()) {
  36.                 if (vanishedPlayers.contains(((WrappedGameProfile) iterator.next()).getUUID())) {
  37.                     iterator.remove();
  38.                 }
  39.             }
  40.             ping.setPlayers(wrappedGameProfiles);
  41.  
  42.         } catch (Exception ex) {
  43.             ex.printStackTrace();
  44.         }
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment