Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix packet leak bug #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/de/myzelyam/supervanish/SuperVanish.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import de.myzelyam.supervanish.net.UpdateNotifier;
import de.myzelyam.supervanish.utils.ExceptionLogger;
import de.myzelyam.supervanish.utils.VersionUtil;
import de.myzelyam.supervanish.visibility.ActionBarMgr;
import de.myzelyam.supervanish.visibility.FileVanishStateMgr;
import de.myzelyam.supervanish.visibility.ServerListPacketListener;
import de.myzelyam.supervanish.visibility.VisibilityChanger;
import de.myzelyam.supervanish.visibility.*;
import de.myzelyam.supervanish.visibility.hiders.PreventionHider;
import lombok.Getter;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -100,6 +97,8 @@ public void onEnable() {
actionBarMgr = new ActionBarMgr(this);
if (useProtocolLib && ServerListPacketListener.isEnabled(this))
ServerListPacketListener.register(this);
if (useProtocolLib)
PlayerSpawnPacketListener.register(this);
registerEvents();
new PluginHookMgr(this);
featureMgr = new FeatureMgr(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.myzelyam.supervanish.visibility;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import de.myzelyam.supervanish.SuperVanish;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import static com.comphenix.protocol.PacketType.Play.Server.*;

public class PlayerSpawnPacketListener extends PacketAdapter {

private final SuperVanish plugin;

public PlayerSpawnPacketListener(SuperVanish plugin) {
super(plugin, ListenerPriority.NORMAL, NAMED_ENTITY_SPAWN);
this.plugin = plugin;
}

public static void register(SuperVanish plugin) {
if (plugin.getVersionUtil().isOneDotXOrHigher(17)) {
ProtocolLibrary.getProtocolManager().addPacketListener(new PlayerSpawnPacketListener(plugin));
}

}

@Override
public void onPacketSending(PacketEvent event) {
// This prevents packet leaking vanished players around a non-admin player when he logs in
try {
if (event.getPacketType() == NAMED_ENTITY_SPAWN) {
Player p = event.getPlayer();
Entity entity = event.getPacket().getEntityModifier(p.getWorld()).read(0);
if (entity instanceof Player) {
Player target = (Player) entity;
if (plugin.getVanishStateMgr().isVanished(target.getUniqueId()) && plugin.getLayeredPermissionChecker().hasPermissionToSee(p, target)) {
event.setCancelled(true);
}
}
}
} catch (Exception er) {
plugin.logException(er);
}
}
}