Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProtocolLibHook extends PacketAdapter {
- public ProtocolLibHook(Main plugin) {
- super(plugin, ListenerPriority.NORMAL, new PacketType[] { PacketType.Status.Server.SERVER_INFO });
- this.plugin = plugin;
- }
- @SuppressWarnings("deprecation")
- public ProtocolLibHook(Main plugin, boolean b) {
- super(plugin, ListenerPriority.NORMAL, new PacketType[] { PacketType.Status.Server.OUT_SERVER_INFO });
- this.plugin = plugin;
- }
- public static void register(Main plugin) {
- try {
- ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibHook(plugin));
- } catch (NoSuchMethodError ex) {
- ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibHook(plugin, true));
- }
- }
- public Main plugin = (Main) Bukkit.getPluginManager().getPlugin("Main");
- public void onPacketSending (PacketEvent event) {
- try {
- if (Main.plugin.getServer().getPluginManager().getPlugin("ProtocolLib") == null)
- return;
- WrappedServerPing ping = (WrappedServerPing) event.getPacket().getServerPings().read(0);
- Collection<UUID> vanishedPlayers = VanishUtilities.getInstance().listInVanishUUID();
- ping.setPlayersOnline(Bukkit.getOnlinePlayers().size() - VanishUtilities.getInstance().listInVanish().size());
- List<WrappedGameProfile> wrappedGameProfiles = new ArrayList<WrappedGameProfile>(ping.getPlayers());
- Iterator<WrappedGameProfile> iterator = wrappedGameProfiles.iterator();
- while (iterator.hasNext()) {
- if (vanishedPlayers.contains(((WrappedGameProfile) iterator.next()).getUUID())) {
- iterator.remove();
- }
- }
- ping.setPlayers(wrappedGameProfiles);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment