Fix crashes as reported by andrewkm
This commit is contained in:
parent
6c6d6c6fe2
commit
a3297c918b
@ -1,6 +1,7 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -385,6 +386,22 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
||||||
|
*/
|
||||||
|
private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) {
|
||||||
|
PacketContainer[] packets = PacketsManager.transformPacket(packet, player);
|
||||||
|
try {
|
||||||
|
for (PacketContainer p : packets) {
|
||||||
|
p = p.deepClone();
|
||||||
|
p.getIntegers().write(0, fakeId);
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||||
|
}
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the self disguise to the player
|
* Sends the self disguise to the player
|
||||||
*/
|
*/
|
||||||
@ -415,12 +432,12 @@ public class DisguiseUtilities {
|
|||||||
.getNmsEntity(player));
|
.getNmsEntity(player));
|
||||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||||
// Send the player a packet with himself being spawned
|
// Send the player a packet with himself being spawned
|
||||||
manager.sendServerPacket(player, manager.createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
|
sendSelfPacket(player, manager.createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
|
||||||
.createPacket(player));
|
.createPacket(player), fakeId);
|
||||||
manager.sendServerPacket(
|
manager.sendServerPacket(
|
||||||
player,
|
player,
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, fakeId,
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(),
|
||||||
WrappedDataWatcher.getEntityWatcher(player), true).createPacket(fakeId,
|
WrappedDataWatcher.getEntityWatcher(player), true).createPacket(player.getEntityId(),
|
||||||
WrappedDataWatcher.getEntityWatcher(player), true));
|
WrappedDataWatcher.getEntityWatcher(player), true));
|
||||||
|
|
||||||
boolean isMoving = false;
|
boolean isMoving = false;
|
||||||
@ -434,22 +451,22 @@ public class DisguiseUtilities {
|
|||||||
// Send the velocity packets
|
// Send the velocity packets
|
||||||
if (isMoving) {
|
if (isMoving) {
|
||||||
Vector velocity = player.getVelocity();
|
Vector velocity = player.getVelocity();
|
||||||
manager.sendServerPacket(
|
sendSelfPacket(
|
||||||
player,
|
player,
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, fakeId, velocity.getX(),
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(),
|
||||||
velocity.getY(), velocity.getZ()).createPacket(fakeId, velocity.getX(), velocity.getY(),
|
velocity.getX(), velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(),
|
||||||
velocity.getZ()));
|
velocity.getX(), velocity.getY(), velocity.getZ()), fakeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why the hell would he even need this. Meh.
|
// Why the hell would he even need this. Meh.
|
||||||
if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
|
if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
|
||||||
manager.sendServerPacket(player,
|
sendSelfPacket(player,
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
|
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
|
||||||
.createPacket(0, player, player.getVehicle()));
|
.createPacket(0, player, player.getVehicle()), fakeId);
|
||||||
} else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) {
|
} else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) {
|
||||||
manager.sendServerPacket(player,
|
sendSelfPacket(player,
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
|
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
|
||||||
.createPacket(0, player.getPassenger(), player));
|
.createPacket(0, player.getPassenger(), player), fakeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resend the armor
|
// Resend the armor
|
||||||
@ -462,28 +479,28 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
manager.sendServerPacket(player,
|
sendSelfPacket(
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, fakeId, i, item)
|
player,
|
||||||
.createPacket(fakeId, i, item));
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i,
|
||||||
|
item).createPacket(player.getEntityId(), i, item), fakeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
// If the disguised is sleeping for w/e reason
|
// If the disguised is sleeping for w/e reason
|
||||||
if (player.isSleeping()) {
|
if (player.isSleeping()) {
|
||||||
manager.sendServerPacket(
|
sendSelfPacket(
|
||||||
player,
|
player,
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.BED, player, loc.getBlockX(), loc.getBlockY(),
|
manager.createPacketConstructor(PacketType.Play.Server.BED, player, loc.getBlockX(), loc.getBlockY(),
|
||||||
loc.getBlockZ()).createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockZ()).createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), fakeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resend any active potion effects
|
// Resend any active potion effects
|
||||||
Iterator iterator = player.getActivePotionEffects().iterator();
|
Iterator iterator = player.getActivePotionEffects().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
PotionEffect potionEffect = (PotionEffect) iterator.next();
|
PotionEffect potionEffect = (PotionEffect) iterator.next();
|
||||||
manager.sendServerPacket(
|
sendSelfPacket(player,
|
||||||
player,
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
|
||||||
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, fakeId, potionEffect).createPacket(
|
.createPacket(player.getEntityId(), potionEffect), fakeId);
|
||||||
fakeId, potionEffect));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
@ -1118,7 +1118,7 @@ public class PacketsManager {
|
|||||||
/**
|
/**
|
||||||
* Transform the packet magically into the one I have always dreamed off. My true luv!!!
|
* Transform the packet magically into the one I have always dreamed off. My true luv!!!
|
||||||
*/
|
*/
|
||||||
private static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer) {
|
public static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer) {
|
||||||
PacketContainer[] packets = new PacketContainer[] { sentPacket };
|
PacketContainer[] packets = new PacketContainer[] { sentPacket };
|
||||||
try {
|
try {
|
||||||
// First get the entity, the one sending this packet
|
// First get the entity, the one sending this packet
|
||||||
@ -1229,7 +1229,8 @@ public class PacketsManager {
|
|||||||
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
|
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
|
||||||
watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4)));
|
watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4)));
|
||||||
}
|
}
|
||||||
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler delay.
|
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler
|
||||||
|
// delay.
|
||||||
packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock };
|
packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock };
|
||||||
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset
|
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset
|
||||||
// it.
|
// it.
|
||||||
|
Loading…
Reference in New Issue
Block a user