Cleanup, fix skins not appearing by increasing tablist delay

This commit is contained in:
libraryaddict 2016-10-05 02:11:50 +13:00
parent 2af792bbf1
commit b19bb87e53
6 changed files with 593 additions and 504 deletions

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.Vector3F;

View File

@ -56,6 +56,7 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
public class DisguiseUtilities
{
@ -1266,18 +1267,23 @@ public class DisguiseUtilities
return;
}
// Code to stop player pushing in 1.9
// Code to stop player pushing
Scoreboard scoreboard = player.getScoreboard();
Team t;
if ((t = scoreboard.getTeam("LDPushing")) == null)
{
t = scoreboard.registerNewTeam("LDPushing");
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
}
t.addEntry(player.getName());
if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER)
{
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
t.setCanSeeFriendlyInvisibles(false);
}
if (!t.hasEntry(player.getName()))
t.addEntry(player.getName());
// Add himself to his own entity tracker
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
@ -1411,52 +1417,33 @@ public class DisguiseUtilities
/**
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
*/
private static void sendSelfPacket(final Player player, PacketContainer packet)
private static void sendSelfPacket(final Player player, final PacketContainer packet)
{
PacketContainer[][] transformed = PacketsManager.transformPacket(packet, player, player);
final Disguise disguise = DisguiseAPI.getDisguise(player, player);
PacketContainer[] packets = transformed == null ? null : transformed[0];
// If disguised.
if (disguise == null)
{
return;
}
final PacketContainer[] delayed = transformed == null ? null : transformed[1];
LibsPackets transformed = PacketsManager.transformPacket(packet, disguise, player, player);
try
{
if (packets == null)
{
packets = new PacketContainer[]
{
packet
};
}
if (transformed.isUnhandled())
transformed.addPacket(packet);
for (PacketContainer p : packets)
transformed.setPacketType(packet.getType());
for (PacketContainer p : transformed.getPackets())
{
p = p.deepClone();
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
}
if (delayed != null && delayed.length > 0)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
{
@Override
public void run()
{
try
{
for (PacketContainer packet : delayed)
{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
});
}
transformed.sendDelayed(player);
}
catch (InvocationTargetException e)
{

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.MinecraftKey;

View File

@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities.packetlisteners;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -16,31 +15,30 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
public class PacketListenerMain extends PacketAdapter
{
private LibsDisguises libsDisguises;
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
{
super(plugin, ListenerPriority.HIGH, packetsToListen);
libsDisguises = plugin;
}
@Override
public void onPacketSending(PacketEvent event)
public void onPacketSending(final PacketEvent event)
{
if (event.isCancelled())
return;
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
return;
final Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return;
// First get the entity, the one sending this packet
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
@ -51,11 +49,16 @@ public class PacketListenerMain extends PacketAdapter
if (entity == observer)
return;
PacketContainer[][] packets;
final Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null)
return;
LibsPackets packets;
try
{
packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity);
packets = PacketsManager.transformPacket(event.getPacket(), disguise, observer, entity);
}
catch (Exception ex)
{
@ -64,44 +67,23 @@ public class PacketListenerMain extends PacketAdapter
return;
}
if (packets == null)
if (packets.isUnhandled())
{
return;
}
packets.setPacketType(event.getPacketType());
event.setCancelled(true);
try
{
for (PacketContainer packet : packets[0])
for (PacketContainer packet : packets.getPackets())
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
final PacketContainer[] delayed = packets[1];
if (delayed.length == 0)
{
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
{
public void run()
{
try
{
for (PacketContainer packet : delayed)
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
}, 2);
packets.sendDelayed(observer);
}
catch (InvocationTargetException ex)
{

View File

@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType.Play.Server;
@ -20,24 +19,21 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerViewDisguises extends PacketAdapter
{
private LibsDisguises libsDisguises;
public PacketListenerViewDisguises(LibsDisguises plugin)
{
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
libsDisguises = plugin;
}
@Override
public void onPacketSending(PacketEvent event)
public void onPacketSending(final PacketEvent event)
{
if (event.isCancelled())
return;
@ -59,22 +55,22 @@ public class PacketListenerViewDisguises extends PacketAdapter
return;
}
final Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
if (disguise == null)
return;
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
PacketContainer[][] transformed = PacketsManager.transformPacket(event.getPacket(), observer, observer);
LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer);
PacketContainer[] packets = transformed == null ? null : transformed[0];
final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1];
if (packets == null)
if (transformed.isUnhandled())
{
packets = new PacketContainer[]
{
event.getPacket()
};
transformed.getPackets().add(event.getPacket());
}
for (PacketContainer packet : packets)
transformed.setPacketType(event.getPacketType());
for (PacketContainer packet : transformed.getPackets())
{
if (packet.getType() != Server.PLAYER_INFO)
{
@ -96,26 +92,7 @@ public class PacketListenerViewDisguises extends PacketAdapter
}
}
if (delayedPackets != null && delayedPackets.length > 0)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
{
public void run()
{
try
{
for (PacketContainer packet : delayedPackets)
{
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
}, 2);
}
transformed.sendDelayed(observer);
if (event.getPacketType() == Server.ENTITY_METADATA)
{
@ -182,8 +159,6 @@ public class PacketListenerViewDisguises extends PacketAdapter
}
else if (event.getPacketType() == Server.ENTITY_STATUS)
{
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
&& event.getPacket().getBytes().read(0) == 2)
{