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.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.Vector3F; 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.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
public class DisguiseUtilities public class DisguiseUtilities
{ {
@ -1266,18 +1267,23 @@ public class DisguiseUtilities
return; return;
} }
// Code to stop player pushing in 1.9 // Code to stop player pushing
Scoreboard scoreboard = player.getScoreboard(); Scoreboard scoreboard = player.getScoreboard();
Team t; Team t;
if ((t = scoreboard.getTeam("LDPushing")) == null) if ((t = scoreboard.getTeam("LDPushing")) == null)
{ {
t = scoreboard.registerNewTeam("LDPushing"); 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 // Add himself to his own entity tracker
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") 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. * 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 try
{ {
if (packets == null) if (transformed.isUnhandled())
{ transformed.addPacket(packet);
packets = new PacketContainer[]
{
packet
};
}
for (PacketContainer p : packets) transformed.setPacketType(packet.getType());
for (PacketContainer p : transformed.getPackets())
{ {
p = p.deepClone(); p = p.deepClone();
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false); ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
} }
if (delayed != null && delayed.length > 0) transformed.sendDelayed(player);
{
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();
}
}
});
}
} }
catch (InvocationTargetException e) 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.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.MinecraftKey; 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.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
public class PacketListenerMain extends PacketAdapter public class PacketListenerMain extends PacketAdapter
{ {
private LibsDisguises libsDisguises;
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen) public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
{ {
super(plugin, ListenerPriority.HIGH, packetsToListen); super(plugin, ListenerPriority.HIGH, packetsToListen);
libsDisguises = plugin;
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(final PacketEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
return;
final Player observer = event.getPlayer(); 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 // First get the entity, the one sending this packet
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
@ -51,11 +49,16 @@ public class PacketListenerMain extends PacketAdapter
if (entity == observer) if (entity == observer)
return; return;
PacketContainer[][] packets; final Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null)
return;
LibsPackets packets;
try try
{ {
packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity); packets = PacketsManager.transformPacket(event.getPacket(), disguise, observer, entity);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -64,44 +67,23 @@ public class PacketListenerMain extends PacketAdapter
return; return;
} }
if (packets == null) if (packets.isUnhandled())
{ {
return; return;
} }
packets.setPacketType(event.getPacketType());
event.setCancelled(true); event.setCancelled(true);
try try
{ {
for (PacketContainer packet : packets[0]) for (PacketContainer packet : packets.getPackets())
{ {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} }
final PacketContainer[] delayed = packets[1]; packets.sendDelayed(observer);
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);
} }
catch (InvocationTargetException ex) catch (InvocationTargetException ex)
{ {

View File

@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType.Play.Server; 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.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerViewDisguises extends PacketAdapter public class PacketListenerViewDisguises extends PacketAdapter
{ {
private LibsDisguises libsDisguises;
public PacketListenerViewDisguises(LibsDisguises plugin) public PacketListenerViewDisguises(LibsDisguises plugin)
{ {
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, 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.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_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS); Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
libsDisguises = plugin;
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(final PacketEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled())
return; return;
@ -59,22 +55,22 @@ public class PacketListenerViewDisguises extends PacketAdapter
return; 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. // 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]; if (transformed.isUnhandled())
final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1];
if (packets == null)
{ {
packets = new PacketContainer[] transformed.getPackets().add(event.getPacket());
{
event.getPacket()
};
} }
for (PacketContainer packet : packets) transformed.setPacketType(event.getPacketType());
for (PacketContainer packet : transformed.getPackets())
{ {
if (packet.getType() != Server.PLAYER_INFO) if (packet.getType() != Server.PLAYER_INFO)
{ {
@ -96,26 +92,7 @@ public class PacketListenerViewDisguises extends PacketAdapter
} }
} }
if (delayedPackets != null && delayedPackets.length > 0) transformed.sendDelayed(observer);
{
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);
}
if (event.getPacketType() == Server.ENTITY_METADATA) if (event.getPacketType() == Server.ENTITY_METADATA)
{ {
@ -182,8 +159,6 @@ public class PacketListenerViewDisguises extends PacketAdapter
} }
else if (event.getPacketType() == Server.ENTITY_STATUS) else if (event.getPacketType() == Server.ENTITY_STATUS)
{ {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
&& event.getPacket().getBytes().read(0) == 2) && event.getPacket().getBytes().read(0) == 2)
{ {