Player disguises no longer hang around in tab

Fix setSkin not working on active disguises
Fixed tab names not displaying
This commit is contained in:
libraryaddict 2020-04-07 16:14:17 +12:00
parent 2c5301eb6c
commit fb97dd4857
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
14 changed files with 112 additions and 206 deletions

View File

@ -415,7 +415,7 @@ public class DisguiseConfig {
setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement"));
setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible"));
setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises"));
setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpires"));
setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpiry"));
setPlayerHideArmor(config.getBoolean("PlayerHideArmor"));
setRetaliationCombat(config.getBoolean("RetaliationCombat"));
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));

View File

@ -420,14 +420,8 @@ public class DisguiseListener implements Listener {
if (disguise.isDisplayedInTab()) {
try {
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL,
WrappedChatComponent.fromText(disguise.getGameProfile().getName()))));
ProtocolLibrary.getProtocolManager().sendServerPacket(p, addTab);
ProtocolLibrary.getProtocolManager().sendServerPacket(p,
DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER));
}
catch (InvocationTargetException e) {
e.printStackTrace();

View File

@ -155,6 +155,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
else
disguise = DisguiseAPI.getDisguise(entity);
if (disguise == null) {
continue;
}
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
if (!permissions.isAllowedDisguise(disguisePerm)) {

View File

@ -962,11 +962,7 @@ public abstract class Disguise {
PlayerDisguise disguise = (PlayerDisguise) this;
if (disguise.isDisplayedInTab()) {
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL,
WrappedChatComponent.fromText(disguise.getProfileName()))));
PacketContainer addTab = DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER);
try {
for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -10,6 +10,7 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
@ -98,6 +99,10 @@ public class PlayerDisguise extends TargetedDisguise {
return scoreboardName;
}
private void setScoreboardName(String[] split) {
getScoreboardName().setSplit(split);
}
private boolean isStaticName(String name) {
return name != null && (name.equalsIgnoreCase("Dinnerbone") || name.equalsIgnoreCase("Grumm"));
}
@ -229,7 +234,7 @@ public class PlayerDisguise extends TargetedDisguise {
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
resendDisguise = !split[1].equals(team.getPlayer());
team.setSplit(split);
setScoreboardName(split);
}
resendDisguise =
@ -268,12 +273,28 @@ public class PlayerDisguise extends TargetedDisguise {
playerName = name;
}
if (isDisplayedInTab()) {
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME);
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!canSee(player))
continue;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
}
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
} else {
if (scoreboardName != null) {
DisguiseUtilities.DScoreTeam team = getScoreboardName();
String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name);
team.setSplit(split);
setScoreboardName(split);
}
if (name.isEmpty()) {
@ -308,6 +329,7 @@ public class PlayerDisguise extends TargetedDisguise {
}
}
String oldSkin = skinToUse;
skinToUse = newSkin;
if (newSkin == null) {
@ -317,6 +339,31 @@ public class PlayerDisguise extends TargetedDisguise {
if (newSkin.length() > 16) {
skinToUse = newSkin.substring(0, 16);
}
if (newSkin.equals(oldSkin)) {
return this;
}
if (isDisguiseInUse()) {
currentLookup = new LibsProfileLookup() {
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty())
return;
setSkin(gameProfile);
currentLookup = null;
}
};
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup,
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
if (gameProfile != null) {
setSkin(gameProfile);
}
}
}
return this;
@ -342,13 +389,15 @@ public class PlayerDisguise extends TargetedDisguise {
this.skinToUse = gameProfile.getName();
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), gameProfile);
refreshDisguise();
return this;
}
private void refreshDisguise() {
if (DisguiseUtilities.isDisguiseInUse(this)) {
if (isDisplayedInTab()) {
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
addTab.getPlayerInfoDataLists().write(0, Arrays.asList(
new PlayerInfoData(getGameProfile(), 0, NativeGameMode.SURVIVAL,
WrappedChatComponent.fromText(getProfileName()))));
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.ADD_PLAYER);
PacketContainer deleteTab = addTab.shallowClone();
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
@ -369,8 +418,6 @@ public class PlayerDisguise extends TargetedDisguise {
DisguiseUtilities.refreshTrackers(this);
}
return this;
}
@Override

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
@ -35,7 +36,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.logging.log4j.util.Strings;
import org.bukkit.*;
import org.bukkit.boss.BossBar;
import org.bukkit.boss.KeyedBossBar;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
@ -1943,8 +1943,6 @@ public class DisguiseUtilities {
if (transformed.isUnhandled())
transformed.addPacket(packet);
transformed.setSpawnPacketCheck(packet.getType());
for (PacketContainer p : transformed.getPackets()) {
p = p.deepClone();
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
@ -1958,6 +1956,17 @@ public class DisguiseUtilities {
}
}
public static PacketContainer getTabPacket(PlayerDisguise disguise, EnumWrappers.PlayerInfoAction action) {
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
addTab.getPlayerInfoAction().write(0, action);
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
new PlayerInfoData(disguise.getGameProfile(), 0, EnumWrappers.NativeGameMode.SURVIVAL,
WrappedChatComponent.fromText(disguise.getName()))));
return addTab;
}
/**
* Setup it so he can see himself when disguised
*

View File

@ -24,13 +24,8 @@ import java.util.*;
public class LibsPackets {
private ArrayList<PacketContainer> packets = new ArrayList<>();
private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>();
private boolean isSpawnPacket;
private Disguise disguise;
private boolean doNothing;
private int removeMetaAt = -1;
@Getter
@Setter
private boolean sendArmor;
public LibsPackets(Disguise disguise) {
this.disguise = disguise;
@ -40,10 +35,6 @@ public class LibsPackets {
doNothing = true;
}
public void setRemoveMetaAt(int tick) {
removeMetaAt = tick;
}
public boolean isUnhandled() {
return doNothing;
}
@ -52,10 +43,6 @@ public class LibsPackets {
return disguise;
}
public void setSpawnPacketCheck(PacketType type) {
isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY");
}
public void addPacket(PacketContainer packet) {
packets.add(packet);
}
@ -84,19 +71,8 @@ public class LibsPackets {
}
public void sendDelayed(final Player observer) {
Iterator<Map.Entry<Integer, ArrayList<PacketContainer>>> itel = delayedPackets.entrySet().iterator();
while (itel.hasNext()) {
Map.Entry<Integer, ArrayList<PacketContainer>> entry = itel.next();
// If this is the last delayed packet
final boolean isRemoveCancel = isSpawnPacket && entry.getKey() >= removeMetaAt && removeMetaAt >= 0;
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
if (isRemoveCancel && "%%__USER__%%".equals("%%__USER__%%") && !"%%__USER__%%".equals("12345")) {
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
}
if (!disguise.isDisguiseInUse()) {
ArrayList<PacketContainer> packets = entry.getValue();
@ -107,25 +83,6 @@ public class LibsPackets {
packets.removeIf(p -> p.getType() != PacketType.Play.Server.PLAYER_INFO);
}
if (isRemoveCancel) {
if (isSendArmor()) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
PacketContainer packet = createPacket(slot);
if (packet == null) {
continue;
}
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
try {
for (PacketContainer packet : entry.getValue()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);

View File

@ -19,7 +19,6 @@ import java.util.UUID;
* Created by libraryaddict on 3/01/2019.
*/
public class PacketsHandler {
private HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<>();
private Collection<IPacketHandler> packetHandlers;
public PacketsHandler() {
@ -38,7 +37,8 @@ public class PacketsHandler {
packetHandlers.add(new PacketHandlerHeadRotation());
// If not prem, if build is from jenkins, else its a custom and needs paid info
if (!LibsPremium.isPremium() || LibsDisguises.getInstance().getBuildNo().matches("[0-9]+") || LibsPremium.getPaidInformation() != null) {
if (!LibsPremium.isPremium() || LibsDisguises.getInstance().getBuildNo().matches("[0-9]+") ||
LibsPremium.getPaidInformation() != null) {
packetHandlers.add(new PacketHandlerMetadata(this));
}
@ -47,32 +47,6 @@ public class PacketsHandler {
packetHandlers.add(new PacketHandlerVelocity());
}
public boolean isCancelMeta(Disguise disguise, Player observer) {
return cancelMeta.containsKey(disguise) && cancelMeta.get(disguise).contains(observer.getUniqueId());
}
public void addCancel(Disguise disguise, Player observer) {
if (!cancelMeta.containsKey(disguise)) {
cancelMeta.put(disguise, new ArrayList<UUID>());
}
cancelMeta.get(disguise).add(observer.getUniqueId());
}
public void removeCancel(Disguise disguise, Player observer) {
ArrayList<UUID> cancel;
if ((cancel = cancelMeta.get(disguise)) == null)
return;
cancel.remove(observer.getUniqueId());
if (!cancel.isEmpty())
return;
cancelMeta.remove(disguise);
}
/**
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if
* its not

View File

@ -38,17 +38,6 @@ public class PacketHandlerEquipment implements IPacketHandler {
@Override
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
if (DisguiseConfig.isPlayerHideArmor() && packetsHandler.isCancelMeta(disguise, observer)) {
packets.clear();
PacketContainer equipPacket = sentPacket.shallowClone();
packets.addPacket(equipPacket);
equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(new ItemStack(Material.AIR)));
return;
}
// Else if the disguise is updating equipment
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));

View File

@ -35,19 +35,22 @@ public class PacketHandlerMetadata implements IPacketHandler {
packets.clear();
if (DisguiseConfig.isMetaPacketsEnabled() && !packetsHandler.isCancelMeta(disguise, observer)) {
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
.convert(sentPacket.getWatchableCollectionModifier().read(0));
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packets.addPacket(metaPacket);
StructureModifier<Object> newMods = metaPacket.getModifier();
newMods.write(0, entity.getEntityId());
metaPacket.getWatchableCollectionModifier().write(0, watchableObjects);
if (!DisguiseConfig.isMetaPacketsEnabled()) {
return;
}
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
.convert(sentPacket.getWatchableCollectionModifier().read(0));
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packets.addPacket(metaPacket);
StructureModifier<Object> newMods = metaPacket.getModifier();
newMods.write(0, entity.getEntityId());
metaPacket.getWatchableCollectionModifier().write(0, watchableObjects);
}
}

View File

@ -159,7 +159,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager
.getGameProfileWithThisSkin(UUID.randomUUID(),
visibleOrNewCompat ? playerDisguise.getProfileName() : "", playerDisguise.getGameProfile());
visibleOrNewCompat ? playerDisguise.getName() : "", playerDisguise.getGameProfile());
int entityId = disguisedEntity.getEntityId();
@ -182,7 +182,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (LibsPremium.getPaidInformation() == null ||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
packets.addDelayedPacket(deleteTab, DisguiseConfig.getPlayerDisguisesTablistExpires());
packets.addDelayedPacket(deleteTab, 2);
}
}
@ -196,18 +196,9 @@ public class PacketHandlerSpawn implements IPacketHandler {
boolean selfDisguise = observer == disguisedEntity;
WrappedDataWatcher newWatcher;
if (selfDisguise) {
newWatcher = DisguiseUtilities
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher());
} else {
newWatcher = new WrappedDataWatcher();
spawnAt = observer.getLocation();
spawnAt.add(spawnAt.getDirection().normalize().multiply(20));
}
WrappedDataWatcher newWatcher = DisguiseUtilities
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher());
// Spawn him in front of the observer
StructureModifier<Double> doubles = spawnPlayer.getDoubles();
@ -219,10 +210,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
bytes.write(0, yaw);
bytes.write(1, pitch);
// Make him invisible
newWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(),
WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32);
packets.addPacket(spawnPlayer);
if (NmsVersion.v1_15.isSupported()) {
@ -234,41 +221,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
} else {
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
}
if (!selfDisguise) {
// Teleport the player back to where he's supposed to be
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
doubles = teleportPacket.getDoubles();
teleportPacket.getIntegers().write(0, entityId); // Id
doubles.write(0, loc.getX());
doubles.write(1, loc.getY());
doubles.write(2, loc.getZ());
bytes = teleportPacket.getBytes();
bytes.write(0, yaw);
bytes.write(1, pitch);
packets.addDelayedPacket(teleportPacket, 3);
// Send a metadata packet
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
newWatcher = DisguiseUtilities
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher());
metaPacket.getIntegers().write(0, entityId); // Id
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
packetsHandler.addCancel(disguise, observer);
// Add a delay to remove the entry from 'cancelMeta'
packets.addDelayedPacket(metaPacket, 7);
packets.setRemoveMetaAt(7);
}
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
Vector vec = disguisedEntity.getVelocity();
@ -420,37 +372,24 @@ public class PacketHandlerSpawn implements IPacketHandler {
}
// If armor must be sent because its currently not displayed and would've been sent normally
boolean delayedArmor =
DisguiseConfig.isPlayerHideArmor() && (disguise.isPlayerDisguise() && disguisedEntity != observer) &&
disguisedEntity instanceof LivingEntity;
if (delayedArmor) {
packets.setSendArmor(true);
packets.setRemoveMetaAt(7);
}
// This sends the armor packets so that the player isn't naked.
if (DisguiseConfig.isEquipmentPacketsEnabled() || delayedArmor) {
if (DisguiseConfig.isEquipmentPacketsEnabled()) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
// Get what the disguise wants to show for its armor
ItemStack itemToSend;
ItemStack itemToSend = disguise.getWatcher().getItemStack(slot);
if (delayedArmor) {
itemToSend = new ItemStack(Material.AIR);
} else {
itemToSend = disguise.getWatcher().getItemStack(slot);
// If the disguise armor isn't visible
if (itemToSend == null) {
itemToSend = ReflectionManager.getEquipment(slot, disguisedEntity);
// If the disguise armor isn't visible
if (itemToSend == null) {
itemToSend = ReflectionManager.getEquipment(slot, disguisedEntity);
// If natural armor isn't sent either
if (itemToSend == null || itemToSend.getType() == Material.AIR) {
continue;
}
} else if (itemToSend.getType() == Material.AIR) {
// Its air which shouldn't be sent
// If natural armor isn't sent either
if (itemToSend == null || itemToSend.getType() == Material.AIR) {
continue;
}
} else if (itemToSend.getType() == Material.AIR) {
// Its air which shouldn't be sent
continue;
}
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);

View File

@ -61,8 +61,6 @@ public class PacketListenerMain extends PacketAdapter {
return;
}
packets.setSpawnPacketCheck(event.getPacketType());
event.setCancelled(true);
try {

View File

@ -77,8 +77,6 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
transformed.getPackets().add(packet);
}
transformed.setSpawnPacketCheck(event.getPacketType());
for (PacketContainer newPacket : transformed.getPackets()) {
if (newPacket.getType() != Server.PLAYER_INFO) {
if (newPacket == packet) {

View File

@ -253,11 +253,9 @@ HideDisguisedPlayersFromTab: false
ShowPlayerDisguisesInTab: false
# On player disguise, a fake player is added to tablist so the skin can load properly.
# If the viewer sees the player disguise but there's no tablist name, they won't see a skin.
# 3 seconds is normally long enough to load the skin properly, but sometimes the server needs longer
# This is in ticks, there are 20 ticks in every second. 60 ticks = 3 seconds. 200 ticks = 10 seconds.
# This option is ignored if 'ShowPlayerDisguisesInTab' is enabled.
PlayerDisguisesTablistExpires: 60
# 2 ticks should easily be enough.
PlayerDisguisesTablistExpires: 2
# Don't like players able to set themselves invisible when using the disguise commands? Toggle this to true and no one can use setInvisible! Plugins can still use this however.
DisableInvisibility: false