mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-14 15:26:54 +01:00
Push player skin fix may need good testing
This commit is contained in:
parent
02171b60b6
commit
166658b99b
@ -20,6 +20,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.listeners.DisguiseListener;
|
||||
import me.libraryaddict.disguise.utilities.listeners.PaperDisguiseListener;
|
||||
import me.libraryaddict.disguise.utilities.listeners.PlayerSkinHandler;
|
||||
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
||||
@ -50,6 +51,8 @@ public class LibsDisguises extends JavaPlugin {
|
||||
private boolean reloaded;
|
||||
@Getter
|
||||
private final UpdateChecker updateChecker = new UpdateChecker();
|
||||
@Getter
|
||||
private final PlayerSkinHandler skinHandler = new PlayerSkinHandler();
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -139,10 +142,8 @@ public class LibsDisguises extends JavaPlugin {
|
||||
getLogger().severe("!! May I have your attention please !!");
|
||||
getLogger().severe("Update your ProtocolLib! You are running " + version +
|
||||
" but the minimum version you should be on is " + requiredProtocolLib + "!");
|
||||
getLogger()
|
||||
.severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" +
|
||||
"/ProtocolLib" +
|
||||
".jar");
|
||||
getLogger().severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" +
|
||||
"/ProtocolLib" + ".jar");
|
||||
getLogger().severe("Or! Use /ld updateprotocollib - To update to the latest development build");
|
||||
getLogger()
|
||||
.severe("This message is on repeat due to the sheer number of people who don't see this.");
|
||||
@ -178,6 +179,8 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
listener = new DisguiseListener(this);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(getSkinHandler(), LibsDisguises.getInstance());
|
||||
|
||||
if (DisguiseUtilities.isRunningPaper()) {
|
||||
Bukkit.getPluginManager().registerEvents(new PaperDisguiseListener(), this);
|
||||
}
|
||||
|
@ -242,7 +242,8 @@ public class DisguiseUtilities {
|
||||
|
||||
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(playerName);
|
||||
|
||||
if (team != null && (team.getColor() != ChatColor.RESET || !StringUtils.isEmpty(team.getPrefix()) || !StringUtils.isEmpty(team.getSuffix()))) {
|
||||
if (team != null && (team.getColor() != ChatColor.RESET || !StringUtils.isEmpty(team.getPrefix()) ||
|
||||
!StringUtils.isEmpty(team.getSuffix()))) {
|
||||
return team.getPrefix() + team.getColor() + playerName + team.getSuffix();
|
||||
}
|
||||
|
||||
@ -254,7 +255,8 @@ public class DisguiseUtilities {
|
||||
|
||||
team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(player.getUniqueId().toString());
|
||||
|
||||
if (team == null || (team.getColor() != ChatColor.RESET || StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) {
|
||||
if (team == null || (team.getColor() != ChatColor.RESET ||
|
||||
StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) {
|
||||
String name = player.getDisplayName();
|
||||
|
||||
if (name.equals(playerName)) {
|
||||
@ -2568,13 +2570,35 @@ public class DisguiseUtilities {
|
||||
transformed.addPacket(packet);
|
||||
}
|
||||
|
||||
LibsPackets newPackets = new LibsPackets(disguise);
|
||||
|
||||
for (PacketContainer p : transformed.getPackets()) {
|
||||
p = p.deepClone();
|
||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
newPackets.addPacket(p);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : transformed.getDelayedPacketsMap().entrySet()) {
|
||||
for (PacketContainer newPacket : entry.getValue()) {
|
||||
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
|
||||
newPacket.getIntegers().read(0) == player.getEntityId()) {
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
newPackets.addDelayedPacket(newPacket, entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
LibsDisguises.getInstance().getSkinHandler()
|
||||
.handlePackets(player, (PlayerDisguise) disguise, newPackets);
|
||||
}
|
||||
|
||||
for (PacketContainer p : newPackets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||
}
|
||||
|
||||
transformed.sendDelayed(player);
|
||||
newPackets.sendDelayed(player);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.libraryaddict.disguise.utilities.listeners;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
@ -8,20 +10,26 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.RemovalCause;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -29,13 +37,22 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class PlayerSkinHandler implements Listener {
|
||||
@RequiredArgsConstructor
|
||||
private static class PlayerSkin {
|
||||
public static class PlayerSkin {
|
||||
private final long firstPacketSent = System.currentTimeMillis();
|
||||
@Getter
|
||||
private final WeakReference<PlayerDisguise> disguise;
|
||||
@Getter
|
||||
private final HashMap<Integer, ArrayList<PacketContainer>> sleptPackets = new HashMap<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean doTabList = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean sleepPackets;
|
||||
|
||||
public boolean canRemove() {
|
||||
return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) < System.currentTimeMillis();
|
||||
public boolean canRemove(boolean onMoved) {
|
||||
return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) +
|
||||
(onMoved ? 0 : TimeUnit.SECONDS.toMillis(5)) < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,20 +78,14 @@ public class PlayerSkinHandler implements Listener {
|
||||
List<PlayerSkin> skins = (List<PlayerSkin>) event.getValue();
|
||||
|
||||
for (PlayerSkin skin : skins) {
|
||||
PlayerDisguise disguise = skin.disguise.get();
|
||||
|
||||
if (disguise == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
doPacketRemoval((Player) event.getKey(), disguise);
|
||||
doPacketRemoval((Player) event.getKey(), skin);
|
||||
}
|
||||
|
||||
skins.clear();
|
||||
}).build();
|
||||
|
||||
public void addPlayerSkin(Player player, PlayerDisguise disguise) {
|
||||
tryProcess(player);
|
||||
public PlayerSkin addPlayerSkin(Player player, PlayerDisguise disguise) {
|
||||
tryProcess(player, false);
|
||||
|
||||
List<PlayerSkin> skins = getCache().getIfPresent(player);
|
||||
|
||||
@ -82,8 +93,49 @@ public class PlayerSkinHandler implements Listener {
|
||||
skins = new ArrayList<>();
|
||||
}
|
||||
|
||||
skins.add(new PlayerSkin(new WeakReference<>(disguise)));
|
||||
PlayerSkin toReturn = new PlayerSkin(new WeakReference<>(disguise));
|
||||
|
||||
skins.add(toReturn);
|
||||
getCache().put(player, skins);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public void handlePackets(Player player, PlayerDisguise disguise, LibsPackets packets) {
|
||||
List<PlayerSkin> skins = getCache().getIfPresent(player);
|
||||
|
||||
if (skins == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerSkin skin = skins.stream().filter(s -> s.getDisguise().get() == disguise).findAny().orElse(null);
|
||||
|
||||
if (skin == null || !skin.isSleepPackets()) {
|
||||
return;
|
||||
}
|
||||
|
||||
packets.getPackets().removeIf(packet -> isRemove(skin, packet));
|
||||
|
||||
packets.getDelayedPacketsMap().entrySet().removeIf(entry -> {
|
||||
entry.getValue().removeIf(packet -> isRemove(skin, packet));
|
||||
|
||||
return entry.getValue().isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isRemove(PlayerSkin skin, PacketContainer packetContainer) {
|
||||
PacketType type = packetContainer.getType();
|
||||
|
||||
if (type != Server.ENTITY_EQUIPMENT && type != Server.ENTITY_METADATA) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only do equip atm
|
||||
if (type == Server.ENTITY_EQUIPMENT) {
|
||||
skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()).add(packetContainer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR,
|
||||
@ -108,7 +160,7 @@ public class PlayerSkinHandler implements Listener {
|
||||
continue;
|
||||
}
|
||||
|
||||
doPacketRemoval(player, disguise);
|
||||
doPacketRemoval(player, skin);
|
||||
|
||||
if (skins.size() == 1) {
|
||||
getCache().invalidate(player);
|
||||
@ -118,40 +170,69 @@ public class PlayerSkinHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void doPacketRemoval(Player player, PlayerDisguise disguise) {
|
||||
private void doPacketRemoval(Player player, PlayerSkin skin) {
|
||||
PlayerDisguise disguise = skin.getDisguise().get();
|
||||
|
||||
if (disguise == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PacketContainer packetContainer =
|
||||
DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : skin.getSleptPackets().entrySet()) {
|
||||
if (entry.getKey() == 0) {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} else {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!disguise.isDisguiseInUse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(LibsDisguises.getInstance(), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (skin.isDoTabList()) {
|
||||
PacketContainer packetContainer =
|
||||
DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void tryProcess(Player player) {
|
||||
private void tryProcess(Player player, boolean onMove) {
|
||||
List<PlayerSkin> skins = getCache().getIfPresent(player);
|
||||
|
||||
if (skins == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<PlayerDisguise> removed = new ArrayList<>();
|
||||
ArrayList<PlayerSkin> removed = new ArrayList<>();
|
||||
|
||||
skins.removeIf(skin -> {
|
||||
if (!skin.canRemove()) {
|
||||
if (!skin.canRemove(onMove)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
removed.add(skin.getDisguise().get());
|
||||
removed.add(skin);
|
||||
return true;
|
||||
});
|
||||
|
||||
removed.forEach(disguise -> doPacketRemoval(player, disguise));
|
||||
removed.forEach(skin -> doPacketRemoval(player, skin));
|
||||
|
||||
if (!skins.isEmpty()) {
|
||||
return;
|
||||
@ -162,6 +243,6 @@ public class PlayerSkinHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
tryProcess(event.getPlayer());
|
||||
tryProcess(event.getPlayer(), true);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
@ -21,23 +24,14 @@ import java.util.*;
|
||||
/**
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class LibsPackets {
|
||||
private ArrayList<PacketContainer> packets = new ArrayList<>();
|
||||
private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>();
|
||||
private Disguise disguise;
|
||||
private boolean doNothing;
|
||||
|
||||
public LibsPackets(Disguise disguise) {
|
||||
this.disguise = disguise;
|
||||
}
|
||||
|
||||
public void setUnhandled() {
|
||||
doNothing = true;
|
||||
}
|
||||
|
||||
public boolean isUnhandled() {
|
||||
return doNothing;
|
||||
}
|
||||
private final ArrayList<PacketContainer> packets = new ArrayList<>();
|
||||
private final HashMap<Integer, ArrayList<PacketContainer>> delayedPacketsMap = new HashMap<>();
|
||||
private final Disguise disguise;
|
||||
@Setter
|
||||
private boolean unhandled;
|
||||
|
||||
public Disguise getDisguise() {
|
||||
return disguise;
|
||||
@ -56,24 +50,21 @@ public class LibsPackets {
|
||||
}
|
||||
|
||||
public void addDelayedPacket(PacketContainer packet, int ticksDelayed) {
|
||||
if (!delayedPackets.containsKey(ticksDelayed))
|
||||
delayedPackets.put(ticksDelayed, new ArrayList<>());
|
||||
if (!delayedPacketsMap.containsKey(ticksDelayed)) {
|
||||
delayedPacketsMap.put(ticksDelayed, new ArrayList<>());
|
||||
}
|
||||
|
||||
delayedPackets.get(ticksDelayed).add(packet);
|
||||
delayedPacketsMap.get(ticksDelayed).add(packet);
|
||||
}
|
||||
|
||||
public ArrayList<PacketContainer> getPackets() {
|
||||
return packets;
|
||||
}
|
||||
|
||||
public Collection<ArrayList<PacketContainer>> getDelayedPackets() {
|
||||
return delayedPackets.values();
|
||||
}
|
||||
|
||||
public void sendDelayed(final Player observer) {
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) {
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : getDelayedPacketsMap().entrySet()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
if (!disguise.isDisguiseInUse()) {
|
||||
if (!getDisguise().isDisguiseInUse()) {
|
||||
ArrayList<PacketContainer> packets = entry.getValue();
|
||||
|
||||
if (packets.stream().noneMatch(p -> p.getType() == PacketType.Play.Server.PLAYER_INFO)) {
|
||||
@ -87,8 +78,7 @@ public class LibsPackets {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, entry.getKey());
|
||||
@ -97,11 +87,11 @@ public class LibsPackets {
|
||||
|
||||
private PacketContainer createPacket(EquipmentSlot slot) {
|
||||
// Get what the disguise wants to show for its armor
|
||||
ItemStack itemToSend = disguise.getWatcher().getItemStack(slot);
|
||||
ItemStack itemToSend = getDisguise().getWatcher().getItemStack(slot);
|
||||
|
||||
// If the disguise armor isn't visible
|
||||
if (itemToSend == null) {
|
||||
itemToSend = ReflectionManager.getEquipment(slot, disguise.getEntity());
|
||||
itemToSend = ReflectionManager.getEquipment(slot, getDisguise().getEntity());
|
||||
|
||||
// If natural armor isn't sent either
|
||||
if (itemToSend == null || itemToSend.getType() == Material.AIR) {
|
||||
@ -115,7 +105,7 @@ public class LibsPackets {
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, disguise.getEntity().getEntityId());
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
|
||||
if (NmsVersion.v1_16.isSupported()) {
|
||||
List<Pair<Object, Object>> list = new ArrayList<>();
|
||||
|
@ -72,7 +72,7 @@ public class PacketsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
packets.setUnhandled();
|
||||
packets.setUnhandled(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
@ -24,7 +23,6 @@ import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -46,15 +44,9 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketHandlerSpawn implements IPacketHandler {
|
||||
private PacketsHandler packetsHandler;
|
||||
@Getter
|
||||
private PlayerSkinHandler skinHandler;
|
||||
|
||||
public PacketHandlerSpawn(PacketsHandler packetsHandler) {
|
||||
this.packetsHandler = packetsHandler;
|
||||
|
||||
skinHandler = new PlayerSkinHandler();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(skinHandler, LibsDisguises.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,6 +173,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
playerDisguise.getGameProfile());
|
||||
|
||||
int entityId = disguisedEntity.getEntityId();
|
||||
PlayerSkinHandler.PlayerSkin skin;
|
||||
|
||||
if (!playerDisguise.isDisplayedInTab() || !playerDisguise.isNameVisible()) {
|
||||
// Send player info along with the disguise
|
||||
@ -199,10 +192,16 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
PacketContainer deleteTab = sendTab.shallowClone();
|
||||
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||
|
||||
if (LibsPremium.getPaidInformation() == null ||
|
||||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
getSkinHandler().addPlayerSkin(observer, playerDisguise);
|
||||
skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise);
|
||||
|
||||
if (LibsPremium.getPaidInformation() != null &&
|
||||
!LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>())
|
||||
.add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT));
|
||||
}
|
||||
} else {
|
||||
skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise);
|
||||
skin.setDoTabList(false);
|
||||
}
|
||||
|
||||
// Spawn the player
|
||||
@ -211,9 +210,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
spawnPlayer.getIntegers().write(0, entityId); // Id
|
||||
spawnPlayer.getModifier().write(1, spawnProfile.getUUID());
|
||||
|
||||
Location spawnAt = disguisedEntity.getLocation();
|
||||
boolean spawnFarAway = observer == disguisedEntity ||
|
||||
observer.getLocation().distanceSquared(disguisedEntity.getLocation()) >
|
||||
observer.getLocation().add(observer.getLocation().getDirection())
|
||||
.distanceSquared(disguisedEntity.getLocation());
|
||||
|
||||
boolean selfDisguise = observer == disguisedEntity;
|
||||
skin.setSleepPackets(!spawnFarAway);
|
||||
|
||||
Location spawnAt = spawnFarAway ? disguisedEntity.getLocation() :
|
||||
observer.getLocation().add(observer.getLocation().getDirection().normalize().multiply(50));
|
||||
|
||||
// Spawn him in front of the observer
|
||||
StructureModifier<Double> doubles = spawnPlayer.getDoubles();
|
||||
@ -227,18 +232,49 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
|
||||
packets.addPacket(spawnPlayer);
|
||||
|
||||
WrappedDataWatcher newWatcher = DisguiseUtilities
|
||||
WrappedDataWatcher dataWatcher = DisguiseUtilities
|
||||
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
|
||||
disguise.getWatcher());
|
||||
|
||||
WrappedDataWatcher toSend = dataWatcher;
|
||||
|
||||
if (!spawnFarAway) {
|
||||
toSend = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
||||
ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32);
|
||||
|
||||
// Set invis
|
||||
toSend.setObject(obj, (byte) 32);
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true)
|
||||
.createPacket(entityId, newWatcher, true);
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true)
|
||||
.createPacket(entityId, toSend, true);
|
||||
|
||||
packets.addPacket(metaPacket);
|
||||
} else {
|
||||
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
|
||||
spawnPlayer.getDataWatcherModifier().write(0, toSend);
|
||||
}
|
||||
|
||||
if (!spawnFarAway) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, dataWatcher, true)
|
||||
.createPacket(entityId, dataWatcher, true);
|
||||
|
||||
PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
|
||||
StructureModifier<Object> mods = teleport.getModifier();
|
||||
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, loc.getX());
|
||||
mods.write(2, loc.getY());
|
||||
mods.write(3, loc.getZ());
|
||||
mods.write(4, yaw);
|
||||
mods.write(5, pitch);
|
||||
|
||||
skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()).add(teleport);
|
||||
skin.getSleptPackets().computeIfAbsent(2, (a) -> new ArrayList<>()).add(metaPacket);
|
||||
}
|
||||
} else if (disguise.isMobDisguise() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||
Vector vec = disguisedEntity.getVelocity();
|
||||
|
@ -9,6 +9,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
@ -50,6 +51,11 @@ public class PacketListenerMain extends PacketAdapter {
|
||||
try {
|
||||
packets = PacketsManager.getPacketsHandler()
|
||||
.transformPacket(event.getPacket(), disguise, observer, disguise.getEntity());
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
LibsDisguises.getInstance().getSkinHandler()
|
||||
.handlePackets(observer, (PlayerDisguise) disguise, packets);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -13,16 +13,19 @@ import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
public PacketListenerViewSelfDisguise(LibsDisguises plugin) {
|
||||
@ -53,14 +56,6 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
}
|
||||
|
||||
if (!DisguiseAPI.isSelfDisguised(observer)) {
|
||||
if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
|
||||
|
||||
if (disguise != null && DisguiseUtilities.getSelfDisguised().contains(observer.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,38 +73,45 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
transformed.addPacket(packet);
|
||||
}
|
||||
|
||||
LibsPackets selfTransformed = new LibsPackets(disguise);
|
||||
|
||||
for (PacketContainer newPacket : transformed.getPackets()) {
|
||||
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
|
||||
newPacket.getIntegers().read(0) == observer.getEntityId()) {
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
selfTransformed.addPacket(newPacket);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : transformed.getDelayedPacketsMap().entrySet()) {
|
||||
for (PacketContainer newPacket : entry.getValue()) {
|
||||
if (newPacket == packet) {
|
||||
newPacket = newPacket.shallowClone();
|
||||
}
|
||||
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY) {
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
try {
|
||||
selfTransformed.addDelayedPacket(newPacket, entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
LibsDisguises.getInstance().getSkinHandler()
|
||||
.handlePackets(observer, (PlayerDisguise) disguise, selfTransformed);
|
||||
}
|
||||
|
||||
try {
|
||||
for (PacketContainer newPacket : selfTransformed.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) {
|
||||
for (PacketContainer newPacket : packets) {
|
||||
if (newPacket.getType() == Server.PLAYER_INFO || newPacket.getType() == Server.ENTITY_DESTROY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (newPacket.equals(packet)) {
|
||||
newPacket = newPacket.shallowClone();
|
||||
}
|
||||
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
}
|
||||
|
||||
transformed.sendDelayed(observer);
|
||||
selfTransformed.sendDelayed(observer);
|
||||
|
||||
if (event.getPacketType() == Server.ENTITY_METADATA) {
|
||||
if (!LibsPremium.getPluginInformation().isPremium() || LibsPremium.getPaidInformation() != null ||
|
||||
@ -118,14 +120,16 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
}
|
||||
|
||||
for (WrappedWatchableObject watch : packet.getWatchableCollectionModifier().read(0)) {
|
||||
if (watch.getIndex() == 0) {
|
||||
byte b = (byte) watch.getValue();
|
||||
|
||||
// Add invisibility, remove glowing
|
||||
byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
|
||||
|
||||
watch.setValue(a);
|
||||
if (watch.getIndex() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte b = (byte) watch.getValue();
|
||||
|
||||
// Add invisibility, remove glowing
|
||||
byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
|
||||
|
||||
watch.setValue(a);
|
||||
}
|
||||
} else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
|
||||
event.setCancelled(true);
|
||||
|
Loading…
Reference in New Issue
Block a user