Fixed comparison issue in server page UI.

Added DisguiseBlock for disguises.
This commit is contained in:
Jonathan Williams 2013-09-09 18:42:20 -07:00
parent a6a32e45e0
commit 0d98868a1f
3 changed files with 104 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import net.minecraft.server.v1_6_R2.Packet31RelEntityMove;
import net.minecraft.server.v1_6_R2.Packet33RelEntityMoveLook;
import net.minecraft.server.v1_6_R2.Packet34EntityTeleport;
import net.minecraft.server.v1_6_R2.Packet40EntityMetadata;
import net.minecraft.server.v1_6_R2.Packet44UpdateAttributes;
import net.minecraft.server.v1_6_R2.Packet5EntityEquipment;
import net.minecraft.server.v1_6_R2.Packet62NamedSoundEffect;
@ -38,6 +39,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilMath;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseBlock;
import mineplex.core.disguise.disguises.DisguiseInsentient;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.packethandler.IPacketRunnable;
@ -56,6 +58,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
private NautHashMap<String, EntityType> _addTempList = new NautHashMap<String, EntityType>();
private HashSet<String> _delTempList = new HashSet<String>();
private Field _attributesA;
private Field _soundB;
private Field _soundC;
private Field _soundD;
@ -68,6 +71,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
try
{
_attributesA = Packet44UpdateAttributes.class.getDeclaredField("a");
_attributesA.setAccessible(true);
_soundB = Packet62NamedSoundEffect.class.getDeclaredField("b");
_soundB.setAccessible(true);
_soundC = Packet62NamedSoundEffect.class.getDeclaredField("c");
@ -273,6 +278,30 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
return false;
}
}
else if (packet instanceof Packet44UpdateAttributes)
{
int entityId = -1;
try
{
entityId = (int)_attributesA.get((Packet44UpdateAttributes)packet);
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
if (_spawnPacketMap.containsKey(entityId) && owner.getEntityId() != entityId)
{
// Crash clients with meta to a block id.
if (_spawnPacketMap.get(entityId) instanceof DisguiseBlock)
return false;
}
}
else if (packet instanceof Packet40EntityMetadata)
{
int entityId = ((Packet40EntityMetadata)packet).a;

View File

@ -0,0 +1,70 @@
package mineplex.core.disguise.disguises;
import java.util.Random;
import net.minecraft.server.v1_6_R2.MathHelper;
import net.minecraft.server.v1_6_R2.Packet;
import net.minecraft.server.v1_6_R2.Packet23VehicleSpawn;
public class DisguiseBlock extends DisguiseBase
{
private static Random _random = new Random();
private int _blockId;
private int _blockData;
public DisguiseBlock(org.bukkit.entity.Entity entity, int blockId, int blockData)
{
super(entity);
_blockId = blockId;
_blockData = blockData;
}
@Override
public Packet GetSpawnPacket()
{
Packet23VehicleSpawn packet = new Packet23VehicleSpawn();
packet.a = Entity.id;
packet.b = MathHelper.floor(Entity.locX * 32.0D);
packet.c = MathHelper.floor(Entity.locY * 32.0D);
packet.d = MathHelper.floor(Entity.locZ * 32.0D);
packet.h = MathHelper.d(Entity.pitch * 256.0F / 360.0F);
packet.i = MathHelper.d(Entity.yaw * 256.0F / 360.0F);
packet.j = 70;
packet.k = _blockId | _blockData << 16;
double d1 = Entity.motX;
double d2 = Entity.motY;
double d3 = Entity.motZ;
double d4 = 3.9D;
if (d1 < -d4) d1 = -d4;
if (d2 < -d4) d2 = -d4;
if (d3 < -d4) d3 = -d4;
if (d1 > d4) d1 = d4;
if (d2 > d4) d2 = d4;
if (d3 > d4) d3 = d4;
packet.e = ((int)(d1 * 8000.0D));
packet.f = ((int)(d2 * 8000.0D));
packet.g = ((int)(d3 * 8000.0D));
return packet;
}
protected String getHurtSound()
{
return "damage.hit";
}
protected float getVolume()
{
return 1.0F;
}
protected float getPitch()
{
return (_random.nextFloat() - _random.nextFloat()) * 0.2F + 1.0F;
}
}

View File

@ -13,12 +13,12 @@ public class ServerSorter implements Comparator<ServerInfo>
public int compare(ServerInfo a, ServerInfo b)
{
if ((a.MOTD.contains("Restarting")))
return 1;
if ((b.MOTD.contains("Restarting")))
return -1;
if ((a.MOTD.contains("Restarting")))
return 1;
if ((a.MOTD.contains("Recruiting") || a.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || a.MOTD.contains("Cup")) && !b.MOTD.contains("Recruiting") && !b.MOTD.contains("Waiting") && !b.MOTD.contains("Starting") && !b.MOTD.contains("Cup"))
return -1;
@ -26,10 +26,10 @@ public class ServerSorter implements Comparator<ServerInfo>
return 1;
if (a.MaxPlayers - a.CurrentPlayers < _requiredSlots && b.MaxPlayers - b.CurrentPlayers >= _requiredSlots)
return 1;
return -1;
if (b.MaxPlayers - b.CurrentPlayers < _requiredSlots && a.MaxPlayers - a.CurrentPlayers >= _requiredSlots)
return -1;
return 1;
if (a.CurrentPlayers > b.CurrentPlayers)
return -1;