Update disguises for 1.8, add sleeping ability to player disguises

This commit is contained in:
libraryaddict 2015-03-17 17:48:29 +13:00
parent 65a9073c69
commit 921deb5270
5 changed files with 852 additions and 464 deletions

View File

@ -3,7 +3,6 @@ package mineplex.core.disguise.disguises;
import mineplex.core.common.*;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import net.minecraft.server.v1_7_R4.DataWatcher;
@ -11,8 +10,6 @@ import net.minecraft.server.v1_7_R4.Entity;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
import org.bukkit.entity.*;
public abstract class DisguiseBase
{
protected Entity Entity;
@ -23,9 +20,13 @@ public abstract class DisguiseBase
public boolean Global = true;
public DisguiseBase(org.bukkit.entity.Entity entity)
{
Entity = ((CraftEntity)entity).getHandle();
DataWatcher = new DataWatcher(new DummyEntity(((CraftWorld)entity.getWorld()).getHandle()));
{
if (entity != null)
{
setEntity(entity);
}
DataWatcher = new DataWatcher(new DummyEntity(null));
DataWatcher.a(0, Byte.valueOf((byte)0));
DataWatcher.a(1, Short.valueOf((short)300));
@ -33,6 +34,11 @@ public abstract class DisguiseBase
_soundDisguise = this;
}
public void setEntity(org.bukkit.entity.Entity entity)
{
Entity = ((CraftEntity) entity).getHandle();
}
public void UpdateDataWatcher()
{
DataWatcher.watch(0, Entity.getDataWatcher().getByte(0));
@ -64,11 +70,6 @@ public abstract class DisguiseBase
{
Entity.world.makeSound(location.getX(), location.getY(), location.getZ(), _soundDisguise.getHurtSound(), _soundDisguise.getVolume(), _soundDisguise.getPitch());
}
public void UpdateEntity(Entity entity)
{
Entity = entity;
}
public Entity GetEntity()
{

View File

@ -72,22 +72,4 @@ public abstract class DisguiseInsentient extends DisguiseLiving
{
_showArmor = false;
}
public List<Packet> getArmorPackets()
{
List<PacketPlayOutEntityEquipment> p5 = new ArrayList<PacketPlayOutEntityEquipment>();
net.minecraft.server.v1_7_R4.ItemStack[] armorContents = Entity.getEquipment();
for (short i=0; i < armorContents.length; i++)
{
net.minecraft.server.v1_7_R4.ItemStack armorSlot = armorContents[i];
if (armorSlot != null)
{
p5.add(new PacketPlayOutEntityEquipment(Entity.getId(), i, armorSlot));
}
}
return null;
}
}

View File

@ -2,52 +2,76 @@ package mineplex.core.disguise.disguises;
import java.util.Random;
import net.minecraft.server.v1_7_R4.EntityLiving;
public abstract class DisguiseLiving extends DisguiseBase
{
private static Random _random = new Random();
private boolean _invisible;
public DisguiseLiving(org.bukkit.entity.Entity entity)
{
super(entity);
DataWatcher.a(6, Float.valueOf(1.0F));
DataWatcher.a(7, Integer.valueOf(0));
DataWatcher.a(8, Byte.valueOf((byte)0));
DataWatcher.a(9, Byte.valueOf((byte)0));
DataWatcher.a(7, Integer.valueOf(0));
DataWatcher.a(8, Byte.valueOf((byte) 0));
DataWatcher.a(9, Byte.valueOf((byte) 0));
}
public void UpdateDataWatcher()
{
super.UpdateDataWatcher();
byte b0 = DataWatcher.getByte(0);
DataWatcher.watch(6, Entity.getDataWatcher().getFloat(6));
DataWatcher.watch(7, Entity.getDataWatcher().getInt(7));
DataWatcher.watch(8, Entity.getDataWatcher().getByte(8));
DataWatcher.watch(9, Entity.getDataWatcher().getByte(9));
if (_invisible)
DataWatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << 5)));
else
DataWatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << 5))));
if (Entity instanceof EntityLiving)
{
DataWatcher.watch(6, Entity.getDataWatcher().getFloat(6));
DataWatcher.watch(7, Entity.getDataWatcher().getInt(7));
DataWatcher.watch(8, Entity.getDataWatcher().getByte(8));
DataWatcher.watch(9, Entity.getDataWatcher().getByte(9));
}
}
protected String getHurtSound()
{
return "damage.hit";
}
protected float getVolume()
{
return 1.0F;
}
protected float getPitch()
{
return (_random.nextFloat() - _random.nextFloat()) * 0.2F + 1.0F;
}
public void setHealth(float health)
{
DataWatcher.watch(6, Float.valueOf(health));
}
public float getHealth()
{
return DataWatcher.getFloat(6);
}
public boolean isInvisible()
{
return _invisible;
}
public void setInvisible(boolean invisible)
{
_invisible = invisible;
}
protected String getHurtSound()
{
return "damage.hit";
}
protected float getVolume()
{
return 1.0F;
}
protected float getPitch()
{
return (_random.nextFloat() - _random.nextFloat()) * 0.2F + 1.0F;
}
public void setHealth(float health)
{
DataWatcher.watch(6, Float.valueOf(health));
}
public float getHealth()
{
return DataWatcher.getFloat(6);
}
}

View File

@ -1,5 +1,7 @@
package mineplex.core.disguise.disguises;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -13,6 +15,7 @@ public class DisguisePlayer extends DisguiseHuman
{
private GameProfile _profile;
private boolean _sneaking;
private BlockFace _sleeping;
public DisguisePlayer(org.bukkit.entity.Entity entity)
{
@ -22,7 +25,7 @@ public class DisguisePlayer extends DisguiseHuman
public DisguisePlayer(org.bukkit.entity.Entity entity, GameProfile profile)
{
this(entity);
setProfile(profile);
}
@ -31,27 +34,41 @@ public class DisguisePlayer extends DisguiseHuman
_profile = profile;
}
public BlockFace getSleepingDirection()
{
return _sleeping;
}
/**
* Don't use this if the disguise is already on as it will not work the way you want it to. Contact libraryaddict if you need
* that added.
*/
public void setSleeping(BlockFace sleeping)
{
_sleeping = sleeping;
}
public void setSneaking(boolean sneaking)
{
_sneaking = sneaking;
}
public Packet getOldInfoPacket(boolean add)
{
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo();
if (Entity instanceof Player)
{
playerInfo.username = Entity.getName();
playerInfo.action = add ? 0 : 4;
playerInfo.ping = 90;
playerInfo.player = ((CraftPlayer)(Player)Entity).getProfile();
playerInfo.player = ((CraftPlayer) (Player) Entity).getProfile();
playerInfo.gamemode = 0;
}
return playerInfo;
}
public Packet getNewInfoPacket(boolean add)
{
PacketPlayOutPlayerInfo newDisguiseInfo = new PacketPlayOutPlayerInfo();
@ -61,37 +78,54 @@ public class DisguisePlayer extends DisguiseHuman
newDisguiseInfo.player = _profile;
newDisguiseInfo.gamemode = 0;
return newDisguiseInfo;
}
@Override
public void UpdateDataWatcher()
{
super.UpdateDataWatcher();
byte b0 = DataWatcher.getByte(0);
if (_sneaking)
DataWatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << 1)));
else
DataWatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << 1))));
if (_sneaking)
DataWatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << 1)));
else
DataWatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << 1))));
}
public PacketPlayOutNamedEntitySpawn spawnBeforePlayer(Location spawnLocation)
{
Location loc = spawnLocation.add(spawnLocation.getDirection().normalize().multiply(30));
loc.setY(Math.max(loc.getY(), 0));
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
packet.a = Entity.getId();
packet.b = _profile;
packet.c = MathHelper.floor(loc.getX() * 32.0D);
packet.d = MathHelper.floor(loc.getY() * 32.0D);
packet.e = MathHelper.floor(loc.getZ() * 32.0D);
packet.f = (byte) ((int) (loc.getYaw() * 256.0F / 360.0F));
packet.g = (byte) ((int) (loc.getPitch() * 256.0F / 360.0F));
packet.i = DataWatcher;
return packet;
}
@Override
public Packet GetSpawnPacket()
public PacketPlayOutNamedEntitySpawn GetSpawnPacket()
{
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
packet.a = Entity.getId();
packet.b = _profile;
packet.c = MathHelper.floor(Entity.locX * 32.0D);
packet.d = MathHelper.floor(Entity.locY * 32.0D);
packet.e = MathHelper.floor(Entity.locZ * 32.0D);
packet.f = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
packet.g = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
packet.a = Entity.getId();
packet.b = _profile;
packet.c = MathHelper.floor(Entity.locX * 32.0D);
packet.d = MathHelper.floor(Entity.locY * 32.0D);
packet.e = MathHelper.floor(Entity.locZ * 32.0D);
packet.f = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
packet.g = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
packet.i = DataWatcher;
return packet;
return packet;
}
public String getName()