Fix up self disguises flicking and Evoker Fangs

This commit is contained in:
libraryaddict 2016-11-29 13:07:33 +13:00
parent ce134af4fa
commit eb1733262f
3 changed files with 59 additions and 51 deletions

View File

@ -209,7 +209,7 @@ public abstract class Disguise {
if (getType() == DisguiseType.FIREWORK) {
refreshDisguise++;
if (refreshDisguise % 40 == 0) {
if (refreshDisguise == 40) {
refreshDisguise = 0;
DisguiseUtilities.refreshTrackers(disguise);
@ -218,7 +218,7 @@ public abstract class Disguise {
else if (getType() == DisguiseType.EVOKER_FANGS) {
refreshDisguise++;
if (refreshDisguise % 20 == 0) {
if (refreshDisguise == 23) {
refreshDisguise = 0;
DisguiseUtilities.refreshTrackers(disguise);

View File

@ -880,74 +880,73 @@ public class DisguiseUtilities {
if (mainThread != Thread.currentThread())
throw new IllegalStateException("Cannot modify disguises on an async thread");
if (disguise.getEntity().isValid()) {
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
if (!disguise.getEntity().isValid()) {
return;
}
try {
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
removeSelfDisguise((Player) disguise.getEntity());
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
selfDisguised.add(disguise.getEntity().getUniqueId());
try {
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
removeSelfDisguise((Player) disguise.getEntity());
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
selfDisguised.add(disguise.getEntity().getUniqueId());
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
catch (Exception ex) {
ex.printStackTrace();
}
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
}, 2);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}, 2);
}
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) {
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
.get(entityTrackerEntry);
if (entityTrackerEntry != null) {
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
.get(entityTrackerEntry);
final Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
for (final Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p);
for (final Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p);
if (disguise.getEntity() != player && disguise.canSee(player)) {
clear.invoke(entityTrackerEntry, p);
if (disguise.getEntity() != player && disguise.canSee(player)) {
clear.invoke(entityTrackerEntry, p);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
@Override
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
}, 2);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}, 2);
}
}
}
catch (
Exception ex) {
ex.printStackTrace();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
@ -46,6 +47,14 @@ public class PacketListenerViewDisguises extends PacketAdapter {
}
if (!DisguiseAPI.isSelfDisguised(observer)) {
if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
if (disguise != null && disguise.isSelfDisguiseVisible()) {
event.setCancelled(true);
}
}
return;
}