Read desc
Lots of code cleaned up Added viewing yourself as a disguise - It can be laggy..
This commit is contained in:
parent
0ea559cd60
commit
6af89013c5
@ -5,4 +5,6 @@ Permission: 'libsdisguises.update'
|
||||
# Whats the max size allowed for command disguiseradius
|
||||
DisguiseRadiusMax: 50
|
||||
# Whats the max size allowed for command undisguiseradius
|
||||
UndisguiseRadiusMax: 50
|
||||
UndisguiseRadiusMax: 50
|
||||
# Shall the players view their disguises?
|
||||
ViewDisguises: true
|
@ -1,20 +1,41 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseSound;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseSound.SoundType;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.Events.DisguisedEvent;
|
||||
import me.libraryaddict.disguise.Events.RedisguisedEvent;
|
||||
import me.libraryaddict.disguise.Events.UndisguisedEvent;
|
||||
import net.minecraft.server.v1_6_R2.AttributeMapServer;
|
||||
import net.minecraft.server.v1_6_R2.Block;
|
||||
import net.minecraft.server.v1_6_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R2.EntityInsentient;
|
||||
import net.minecraft.server.v1_6_R2.EntityLiving;
|
||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
import net.minecraft.server.v1_6_R2.MobEffect;
|
||||
import net.minecraft.server.v1_6_R2.Packet17EntityLocationAction;
|
||||
import net.minecraft.server.v1_6_R2.Packet20NamedEntitySpawn;
|
||||
import net.minecraft.server.v1_6_R2.Packet28EntityVelocity;
|
||||
import net.minecraft.server.v1_6_R2.Packet35EntityHeadRotation;
|
||||
import net.minecraft.server.v1_6_R2.Packet39AttachEntity;
|
||||
import net.minecraft.server.v1_6_R2.Packet40EntityMetadata;
|
||||
import net.minecraft.server.v1_6_R2.Packet41MobEffect;
|
||||
import net.minecraft.server.v1_6_R2.Packet44UpdateAttributes;
|
||||
import net.minecraft.server.v1_6_R2.Packet5EntityEquipment;
|
||||
import net.minecraft.server.v1_6_R2.WatchableObject;
|
||||
import net.minecraft.server.v1_6_R2.World;
|
||||
import net.minecraft.server.v1_6_R2.WorldServer;
|
||||
|
||||
@ -22,12 +43,13 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.Packets.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ConnectionSide;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
@ -40,14 +62,20 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
public class DisguiseAPI {
|
||||
|
||||
private static HashMap<Entity, Disguise> disguises = new HashMap<Entity, Disguise>();
|
||||
private static LibsDisguises libsDisguises;
|
||||
private static PacketListener packetListener;
|
||||
private static JavaPlugin plugin;
|
||||
private static boolean sendVelocity;
|
||||
private static boolean soundsEnabled;
|
||||
private static HashMap<Integer, Integer> values = new HashMap<Integer, Integer>();
|
||||
private static boolean viewDisguises;
|
||||
private static PacketListener viewDisguisesListener;
|
||||
|
||||
private synchronized static Disguise access(Entity entity, Disguise... args) {
|
||||
if (args.length == 0)
|
||||
return disguises.get(entity);
|
||||
if (args.length == 0) {
|
||||
if (disguises.containsKey(entity))
|
||||
return disguises.get(entity);
|
||||
return null;
|
||||
}
|
||||
if (args[0] == null)
|
||||
disguises.remove(entity);
|
||||
else
|
||||
@ -86,6 +114,8 @@ public class DisguiseAPI {
|
||||
}
|
||||
put(entity, disguise);
|
||||
refresh(entity);
|
||||
if (entity instanceof Player)
|
||||
setupPlayer((Player) entity);
|
||||
}
|
||||
|
||||
public static void enableSounds(boolean isSoundsEnabled) {
|
||||
@ -116,9 +146,15 @@ public class DisguiseAPI {
|
||||
return get((Entity) disguiser);
|
||||
}
|
||||
|
||||
protected static void init(JavaPlugin mainPlugin) {
|
||||
plugin = mainPlugin;
|
||||
packetListener = new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL,
|
||||
public static int getFakeDisguise(int id) {
|
||||
if (values.containsKey(id))
|
||||
return values.get(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected static void init(LibsDisguises mainPlugin) {
|
||||
libsDisguises = mainPlugin;
|
||||
packetListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL,
|
||||
Packets.Server.NAMED_SOUND_EFFECT, Packets.Server.ENTITY_STATUS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
@ -280,6 +316,80 @@ public class DisguiseAPI {
|
||||
}
|
||||
}
|
||||
};
|
||||
viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,
|
||||
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE,
|
||||
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
||||
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
|
||||
Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT,
|
||||
Packets.Server.ENTITY_STATUS, Packets.Server.ENTITY_VELOCITY, 44) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld());
|
||||
org.bukkit.entity.Entity entity = entityModifer.read(0);
|
||||
if (entity == event.getPlayer() && values.containsKey(entity.getEntityId())) {
|
||||
PacketContainer[] packets = libsDisguises.fixUpPacket(event.getPacket(), event.getPlayer());
|
||||
try {
|
||||
for (PacketContainer packet : packets) {
|
||||
if (packet.equals(event.getPacket()))
|
||||
packet = packet.deepClone();
|
||||
packet.getModifier().write(0, values.get(entity.getEntityId()));
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
Iterator<WatchableObject> itel = ((List<WatchableObject>) mods.read(1)).iterator();
|
||||
while (itel.hasNext()) {
|
||||
WatchableObject watch = itel.next();
|
||||
if (watch.a() == 0) {
|
||||
byte b = (Byte) watch.b();
|
||||
byte a = (byte) (b | 1 << 5);
|
||||
if ((b & 1 << 3) != 0)
|
||||
a = (byte) (a | 1 << 3);
|
||||
watch.a(a);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (event.getPacketID()) {
|
||||
case Packets.Server.NAMED_ENTITY_SPAWN:
|
||||
case Packets.Server.ATTACH_ENTITY:
|
||||
case Packets.Server.REL_ENTITY_MOVE:
|
||||
case Packets.Server.REL_ENTITY_MOVE_LOOK:
|
||||
case Packets.Server.ENTITY_LOOK:
|
||||
case Packets.Server.ENTITY_TELEPORT:
|
||||
case Packets.Server.ENTITY_HEAD_ROTATION:
|
||||
case Packets.Server.MOB_EFFECT:
|
||||
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
List watchableList = new ArrayList();
|
||||
byte b = (byte) (0 | 1 << 5);
|
||||
if (event.getPlayer().isSprinting())
|
||||
b = (byte) (b | 1 << 3);
|
||||
watchableList.add(new WatchableObject(0, 0, b));
|
||||
mods.write(1, watchableList);
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (event.getPacketID() == Server.ENTITY_STATUS)
|
||||
System.out.print(event.isCancelled());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,10 +431,141 @@ public class DisguiseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeVisibleDisguise(Player player) {
|
||||
if (values.containsKey(player.getEntityId())) {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.DESTROY_ENTITY);
|
||||
packet.getModifier().write(0, new int[] { values.get(player.getEntityId()) });
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
values.remove(player.getEntityId());
|
||||
}
|
||||
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
||||
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities.get(player
|
||||
.getEntityId());
|
||||
tracker.trackedPlayers.remove(entityplayer);
|
||||
}
|
||||
|
||||
private static void setupPlayer(Player player) {
|
||||
removeVisibleDisguise(player);
|
||||
if (!viewDisguises())
|
||||
return;
|
||||
int id = 0;
|
||||
try {
|
||||
Field field = net.minecraft.server.v1_6_R2.Entity.class.getDeclaredField("entityCount");
|
||||
field.setAccessible(true);
|
||||
id = field.getInt(null);
|
||||
field.set(null, id + 1);
|
||||
values.put(player.getEntityId(), id);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
||||
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities.get(player
|
||||
.getEntityId());
|
||||
|
||||
tracker.trackedPlayers.add(entityplayer);
|
||||
|
||||
// CraftBukkit end
|
||||
Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn((EntityHuman) entityplayer);
|
||||
entityplayer.playerConnection.sendPacket(packet);
|
||||
if (!tracker.tracker.getDataWatcher().d()) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet40EntityMetadata(id, tracker.tracker.getDataWatcher(), true));
|
||||
}
|
||||
|
||||
if (tracker.tracker instanceof EntityLiving) {
|
||||
AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) tracker.tracker).aW();
|
||||
Collection collection = attributemapserver.c();
|
||||
|
||||
if (!collection.isEmpty()) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet44UpdateAttributes(player.getEntityId(), collection));
|
||||
}
|
||||
}
|
||||
|
||||
tracker.j = tracker.tracker.motX;
|
||||
tracker.k = tracker.tracker.motY;
|
||||
tracker.l = tracker.tracker.motZ;
|
||||
boolean isMoving = false;
|
||||
try {
|
||||
Field field = EntityTrackerEntry.class.getDeclaredField("isMoving");
|
||||
field.setAccessible(true);
|
||||
isMoving = field.getBoolean(tracker);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (isMoving) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet28EntityVelocity(id, tracker.tracker.motX, tracker.tracker.motY,
|
||||
tracker.tracker.motZ));
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
if (tracker.tracker.vehicle != null && id > tracker.tracker.vehicle.id) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker, tracker.tracker.vehicle));
|
||||
} else if (tracker.tracker.passenger != null && id > tracker.tracker.passenger.id) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker.passenger, tracker.tracker));
|
||||
}
|
||||
|
||||
if (tracker.tracker instanceof EntityInsentient && ((EntityInsentient) tracker.tracker).bI() != null) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(1, tracker.tracker,
|
||||
((EntityInsentient) tracker.tracker).bI()));
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
if (tracker.tracker instanceof EntityLiving) {
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
||||
|
||||
if (itemstack != null) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(id, i, itemstack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tracker.tracker instanceof EntityHuman) {
|
||||
EntityHuman entityhuman = (EntityHuman) tracker.tracker;
|
||||
|
||||
if (entityhuman.isSleeping()) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet17EntityLocationAction(tracker.tracker, 0, (int) Math
|
||||
.floor(tracker.tracker.locX), (int) Math.floor(tracker.tracker.locY), (int) Math
|
||||
.floor(tracker.tracker.locZ)));
|
||||
}
|
||||
}
|
||||
|
||||
// CraftBukkit start - Fix for nonsensical head yaw
|
||||
tracker.i = (int) Math.floor(tracker.tracker.getHeadRotation() * 256.0F / 360.0F); // tracker.ao() should be
|
||||
// getHeadRotation
|
||||
tracker.broadcast(new Packet35EntityHeadRotation(id, (byte) tracker.i));
|
||||
// CraftBukkit end
|
||||
|
||||
if (tracker.tracker instanceof EntityLiving) {
|
||||
EntityLiving entityliving = (EntityLiving) tracker.tracker;
|
||||
Iterator iterator = entityliving.getEffects().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
MobEffect mobeffect = (MobEffect) iterator.next();
|
||||
|
||||
entityplayer.playerConnection.sendPacket(new Packet41MobEffect(id, mobeffect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setVelocitySent(boolean sendVelocityPackets) {
|
||||
sendVelocity = sendVelocityPackets;
|
||||
}
|
||||
|
||||
public static void setViewDisguises(boolean seeOwnDisguise) {
|
||||
if (viewDisguises != seeOwnDisguise) {
|
||||
viewDisguises = seeOwnDisguise;
|
||||
if (viewDisguises) {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* - Undisguises him
|
||||
@ -342,5 +583,11 @@ public class DisguiseAPI {
|
||||
if (entity.isValid()) {
|
||||
refresh(entity);
|
||||
}
|
||||
if (entity instanceof Player)
|
||||
removeVisibleDisguise((Player) entity);
|
||||
}
|
||||
|
||||
public static boolean viewDisguises() {
|
||||
return viewDisguises;
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,7 +24,8 @@ public class DisguiseListener implements Listener {
|
||||
+ ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!";
|
||||
|
||||
public DisguiseListener(LibsDisguises libsDisguises) {
|
||||
this.plugin = libsDisguises;
|
||||
|
||||
plugin = libsDisguises;
|
||||
permission = plugin.getConfig().getString("Permission");
|
||||
if (plugin.getConfig().getBoolean("NotifyUpdate")) {
|
||||
currentVersion = plugin.getDescription().getVersion();
|
||||
@ -95,4 +94,5 @@ public class DisguiseListener implements Listener {
|
||||
disguiseRunnable.put(player, runnable);
|
||||
disguiseSlap.put(player, disguise);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -225,21 +225,23 @@ public class Disguise {
|
||||
Vector vector = entity.getVelocity();
|
||||
if (vector.getY() != 0)
|
||||
return;
|
||||
|
||||
net.minecraft.server.v1_6_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
for (EntityPlayer player : getPerverts()) {
|
||||
if (entity != player) {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
if (nmsEntity == player) {
|
||||
if (!DisguiseAPI.viewDisguises())
|
||||
continue;
|
||||
mods.write(0, DisguiseAPI.getFakeDisguise(entity.getEntityId()));
|
||||
} else
|
||||
mods.write(0, entity.getEntityId());
|
||||
mods.write(1, (int) (vector.getX() * 8000));
|
||||
mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069)));
|
||||
mods.write(3, (int) (vector.getZ() * 8000));
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager()
|
||||
.sendServerPacket(player.getBukkitEntity(), packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mods.write(1, (int) (vector.getX() * 8000));
|
||||
mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069)));
|
||||
mods.write(3, (int) (vector.getZ() * 8000));
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (sendMovementPacket) {
|
||||
@ -254,6 +256,16 @@ public class Disguise {
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (DisguiseAPI.viewDisguises()) {
|
||||
PacketContainer specialPacket = new PacketContainer(Packets.Server.REL_ENTITY_MOVE);
|
||||
mods = packet.getModifier();
|
||||
mods.write(0, DisguiseAPI.getFakeDisguise(entity.getEntityId()));
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
|
||||
specialPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,85 +80,29 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
private void addPacketListeners() {
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
manager.addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,
|
||||
manager.addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGH,
|
||||
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ENTITY_METADATA, Packets.Server.ARM_ANIMATION,
|
||||
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
||||
Packets.Server.ADD_EXP_ORB, Packets.Server.VEHICLE_SPAWN, Packets.Server.MOB_SPAWN,
|
||||
Packets.Server.ENTITY_PAINTING, Packets.Server.COLLECT, 44) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
try {
|
||||
Player observer = event.getPlayer();
|
||||
// First get the entity, the one sending this packet
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == event.getPacketID() ? 1 : 0));
|
||||
// If the entity is the same as the sender. Don't disguise!
|
||||
// Prevents problems and there is no advantage to be gained.
|
||||
if (entity == observer)
|
||||
return;
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
// If disguised.
|
||||
if (disguise != null) {
|
||||
// If packet is Packets.Server.UPDATE_ATTRIBUTES - For some reason maven doesn't let me..
|
||||
// This packet sends attributes
|
||||
if (event.getPacketID() == 44) {
|
||||
// Grab the values which are 'approved' to be sent for this entity
|
||||
HashMap<String, Double> values = Values.getAttributesValues(disguise.getType());
|
||||
Collection collection = new ArrayList<AttributeSnapshot>();
|
||||
for (AttributeSnapshot att : (List<AttributeSnapshot>) event.getPacket().getModifier().read(1)) {
|
||||
if (values.containsKey(att.a())) {
|
||||
collection.add(new AttributeSnapshot(null, att.a(), values.get(att.a()), att.c()));
|
||||
}
|
||||
}
|
||||
if (collection.size() > 0) {
|
||||
event.setPacket(new PacketContainer(event.getPacketID()));
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
mods.write(1, collection);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// Else if the packet is sending entity metadata
|
||||
else if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
|
||||
List<WatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
(List<WatchableObject>) event.getPacket().getModifier().read(1));
|
||||
event.setPacket(new PacketContainer(event.getPacketID()));
|
||||
StructureModifier<Object> newMods = event.getPacket().getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
newMods.write(1, watchableObjects);
|
||||
}
|
||||
// Else if the packet is spawning..
|
||||
else if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN
|
||||
|| event.getPacketID() == Packets.Server.MOB_SPAWN
|
||||
|| event.getPacketID() == Packets.Server.ADD_EXP_ORB
|
||||
|| event.getPacketID() == Packets.Server.VEHICLE_SPAWN
|
||||
|| event.getPacketID() == Packets.Server.ENTITY_PAINTING) {
|
||||
PacketContainer[] packets = constructPacket(disguise, entity);
|
||||
event.setPacket(packets[0]);
|
||||
if (packets.length > 1) {
|
||||
sendDelayedPacket(packets[1], observer);
|
||||
}
|
||||
}
|
||||
// Else if the disguise is attempting to send players a forbidden packet
|
||||
else if (event.getPacketID() == Packets.Server.ARM_ANIMATION
|
||||
|| event.getPacketID() == Packets.Server.COLLECT) {
|
||||
if (disguise.getType().isMisc()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// Else if the disguise is moving.
|
||||
else if (Packets.Server.REL_ENTITY_MOVE_LOOK == event.getPacketID()
|
||||
|| Packets.Server.ENTITY_LOOK == event.getPacketID()
|
||||
|| Packets.Server.ENTITY_TELEPORT == event.getPacketID()) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
byte value = (Byte) mods.read(4);
|
||||
mods.write(4, getYaw(disguise.getType(), DisguiseType.getType(entity.getType()), value));
|
||||
}
|
||||
Player observer = event.getPlayer();
|
||||
// First get the entity, the one sending this packet
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == event.getPacketID() ? 1 : 0));
|
||||
// If the entity is the same as the sender. Don't disguise!
|
||||
// Prevents problems and there is no advantage to be gained.
|
||||
if (entity == observer)
|
||||
return;
|
||||
PacketContainer[] packets = fixUpPacket(event.getPacket(), event.getPlayer());
|
||||
if (packets.length == 0)
|
||||
event.setCancelled(true);
|
||||
else {
|
||||
event.setPacket(packets[0]);
|
||||
for (int i = 1; i < packets.length; i++) {
|
||||
sendDelayedPacket(packets[i], event.getPlayer());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -183,56 +127,6 @@ public class LibsDisguises extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
private byte getYaw(DisguiseType disguiseType, DisguiseType entityType, byte value) {
|
||||
switch (disguiseType) {
|
||||
case ENDER_DRAGON:
|
||||
value -= 128;
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
case ARROW:
|
||||
value = (byte) -value;
|
||||
break;
|
||||
case PAINTING:
|
||||
value = (byte) -(value + 128);
|
||||
break;
|
||||
default:
|
||||
if (disguiseType.isMisc()) {
|
||||
value -= 64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (entityType) {
|
||||
case ENDER_DRAGON:
|
||||
value += 128;
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
case ARROW:
|
||||
value = (byte) -value;
|
||||
break;
|
||||
case PAINTING:
|
||||
value = (byte) -(value - 128);
|
||||
break;
|
||||
default:
|
||||
if (entityType.isMisc()) {
|
||||
value += 64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void sendDelayedPacket(final PacketContainer packet, final Player player) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected PacketContainer[] constructPacket(Disguise disguise, Entity disguisedEntity) {
|
||||
PacketContainer[] spawnPackets = new PacketContainer[2];
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
@ -397,8 +291,9 @@ public class LibsDisguises extends JavaPlugin {
|
||||
HashMap c = (HashMap) map.get(newWatcher);
|
||||
// Calling c() gets the watchable objects exactly as they are.
|
||||
List<WatchableObject> list = watcher.c();
|
||||
for (WatchableObject watchableObject : flagWatcher.convert(list))
|
||||
for (WatchableObject watchableObject : flagWatcher.convert(list)) {
|
||||
c.put(watchableObject.a(), watchableObject);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -406,6 +301,137 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
protected PacketContainer[] fixUpPacket(PacketContainer sentPacket, Player observer) {
|
||||
PacketContainer[] packets = new PacketContainer[] { sentPacket };
|
||||
try {
|
||||
// First get the entity, the one sending this packet
|
||||
StructureModifier<Entity> entityModifer = sentPacket.getEntityModifier(observer.getWorld());
|
||||
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == sentPacket.getID() ? 1 : 0));
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
// If disguised.
|
||||
if (disguise != null) {
|
||||
// If packet is Packets.Server.UPDATE_ATTRIBUTES - For some reason maven doesn't let me..
|
||||
// This packet sends attributes
|
||||
|
||||
switch (sentPacket.getID()) {
|
||||
case 44:
|
||||
|
||||
{
|
||||
// Grab the values which are 'approved' to be sent for this entity
|
||||
HashMap<String, Double> values = Values.getAttributesValues(disguise.getType());
|
||||
Collection collection = new ArrayList<AttributeSnapshot>();
|
||||
for (AttributeSnapshot att : (List<AttributeSnapshot>) sentPacket.getModifier().read(1)) {
|
||||
if (values.containsKey(att.a())) {
|
||||
collection.add(new AttributeSnapshot(null, att.a(), values.get(att.a()), att.c()));
|
||||
}
|
||||
}
|
||||
if (collection.size() > 0) {
|
||||
packets[0] = new PacketContainer(sentPacket.getID());
|
||||
StructureModifier<Object> mods = packets[0].getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
mods.write(1, collection);
|
||||
} else {
|
||||
packets = new PacketContainer[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Else if the packet is sending entity metadata
|
||||
case Packets.Server.ENTITY_METADATA:
|
||||
|
||||
{
|
||||
List<WatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
(List<WatchableObject>) packets[0].getModifier().read(1));
|
||||
packets[0] = new PacketContainer(sentPacket.getID());
|
||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
newMods.write(1, watchableObjects);
|
||||
break;
|
||||
}
|
||||
|
||||
// Else if the packet is spawning..
|
||||
case Packets.Server.NAMED_ENTITY_SPAWN:
|
||||
case Packets.Server.MOB_SPAWN:
|
||||
case Packets.Server.ADD_EXP_ORB:
|
||||
case Packets.Server.VEHICLE_SPAWN:
|
||||
case Packets.Server.ENTITY_PAINTING:
|
||||
|
||||
{
|
||||
packets = constructPacket(disguise, entity);
|
||||
break;
|
||||
}
|
||||
|
||||
// Else if the disguise is attempting to send players a forbidden packet
|
||||
case Packets.Server.ARM_ANIMATION:
|
||||
case Packets.Server.COLLECT:
|
||||
|
||||
{
|
||||
if (disguise.getType().isMisc())
|
||||
packets = new PacketContainer[0];
|
||||
break;
|
||||
|
||||
}
|
||||
// Else if the disguise is moving.
|
||||
case Packets.Server.REL_ENTITY_MOVE_LOOK:
|
||||
case Packets.Server.ENTITY_LOOK:
|
||||
case Packets.Server.ENTITY_TELEPORT:
|
||||
|
||||
{
|
||||
packets[0] = sentPacket.shallowClone();
|
||||
StructureModifier<Object> mods = packets[0].getModifier();
|
||||
byte value = (Byte) mods.read(4);
|
||||
mods.write(4, getYaw(disguise.getType(), DisguiseType.getType(entity.getType()), value));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return packets;
|
||||
}
|
||||
|
||||
private byte getYaw(DisguiseType disguiseType, DisguiseType entityType, byte value) {
|
||||
switch (disguiseType) {
|
||||
case ENDER_DRAGON:
|
||||
value -= 128;
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
case ARROW:
|
||||
value = (byte) -value;
|
||||
break;
|
||||
case PAINTING:
|
||||
value = (byte) -(value + 128);
|
||||
break;
|
||||
default:
|
||||
if (disguiseType.isMisc()) {
|
||||
value -= 64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (entityType) {
|
||||
case ENDER_DRAGON:
|
||||
value += 128;
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
case ARROW:
|
||||
value = (byte) -value;
|
||||
break;
|
||||
case PAINTING:
|
||||
value = (byte) -(value - 128);
|
||||
break;
|
||||
default:
|
||||
if (entityType.isMisc()) {
|
||||
value += 64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||
@ -419,6 +445,7 @@ public class LibsDisguises extends JavaPlugin {
|
||||
DisguiseAPI.init(this);
|
||||
DisguiseAPI.enableSounds(true);
|
||||
DisguiseAPI.setVelocitySent(true);
|
||||
DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises"));
|
||||
try {
|
||||
// Here I use reflection to set the plugin for Disguise..
|
||||
// Kinda stupid but I don't want open API calls.
|
||||
@ -566,6 +593,18 @@ public class LibsDisguises extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDelayedPacket(final PacketContainer packet, final Player player) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String toReadable(String string) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : string.split("_")) {
|
||||
|
Loading…
Reference in New Issue
Block a user