Fix custom tags, improve Packet handling
This commit is contained in:
parent
fa30ba1e16
commit
34d535f153
@ -222,27 +222,31 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>)spawnPacket.l.c())
|
||||
{
|
||||
if ((watchable.a() == 11 || watchable.a() == 3) && watchable.b() instanceof Byte && ((Byte)watchable.b()) == 1)
|
||||
if ((watchable.a() == 11 || watchable.a() == 3) && watchable.b() instanceof Byte
|
||||
&& ((Byte) watchable.b()) == 1)
|
||||
{
|
||||
final String entityName = spawnPacket.l.getString(10);
|
||||
|
||||
if (entityName.isEmpty())
|
||||
{
|
||||
_entityNameMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entityMap.get(owner.getName()).containsKey(spawnPacket.a))
|
||||
{
|
||||
verifier.bypassProcess(new PacketPlayOutEntityDestroy(_entityMap.get(owner.getName()).get(spawnPacket.a)));
|
||||
verifier.bypassProcess(new PacketPlayOutEntityDestroy(_entityMap.get(owner.getName()).get(
|
||||
spawnPacket.a)));
|
||||
|
||||
_entityNameMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
_entityMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
}
|
||||
|
||||
|
||||
final String entityName = spawnPacket.l.getString(10);
|
||||
|
||||
if (entityName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int newId = UtilEnt.getNewEntityId();
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true);
|
||||
|
||||
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
|
||||
_entityMap.get(owner.getName()).put(spawnPacket.a, newId);
|
||||
|
||||
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -253,7 +257,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
|
||||
if (metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a))
|
||||
{
|
||||
boolean spawnedAlready = _entityMap.get(owner.getName()).containsKey(metaPacket.a);
|
||||
boolean isDisplaying = _entityMap.get(owner.getName()).containsKey(metaPacket.a);
|
||||
String currentName = _entityNameMap.get(owner.getName()).get(metaPacket.a);
|
||||
|
||||
if (currentName == null)
|
||||
@ -262,7 +266,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
}
|
||||
|
||||
String newName = currentName;
|
||||
boolean newDisplay = spawnedAlready;
|
||||
boolean newDisplay = isDisplaying;
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>) metaPacket.b)
|
||||
{
|
||||
@ -278,24 +282,24 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
}
|
||||
|
||||
// If the name has changed and the name should be showing, or the name display status has changed.
|
||||
if ((!newName.equals(currentName) && newDisplay) || newDisplay != spawnedAlready)
|
||||
if ((!newName.equals(currentName) && newDisplay) || newDisplay != isDisplaying)
|
||||
{
|
||||
// If name should be changing, we are just going to spawn a new one or change the existing
|
||||
// If name is still being displayed
|
||||
if (newDisplay)
|
||||
{
|
||||
int newId;
|
||||
|
||||
if (spawnedAlready)
|
||||
if (isDisplaying) // Sending metadata
|
||||
{
|
||||
newId = _entityMap.get(owner.getName()).get(metaPacket.a);
|
||||
}
|
||||
else
|
||||
else // Spawning new entity
|
||||
{
|
||||
newId = UtilEnt.getNewEntityId();
|
||||
_entityMap.get(owner.getName()).put(metaPacket.a, newId);
|
||||
}
|
||||
|
||||
sendProtocolPackets(owner, metaPacket.a, newId, newName, verifier, !spawnedAlready);
|
||||
sendProtocolPackets(owner, metaPacket.a, newId, newName, verifier, !isDisplaying);
|
||||
|
||||
_entityNameMap.get(owner.getName()).put(metaPacket.a, newName);
|
||||
}
|
||||
|
@ -2,8 +2,7 @@ package mineplex.core.packethandler;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.server.v1_7_R4.EnumProtocol;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
@ -21,7 +20,7 @@ import mineplex.core.common.util.NautHashMap;
|
||||
public class PacketHandler extends MiniPlugin
|
||||
{
|
||||
private NautHashMap<Player, PacketVerifier> _playerVerifierMap = new NautHashMap<Player, PacketVerifier>();
|
||||
private HashSet<IPacketHandler> _packetHandlers = new HashSet<IPacketHandler>();
|
||||
private ArrayList<IPacketHandler> _packetHandlers = new ArrayList<IPacketHandler>();
|
||||
|
||||
public PacketHandler(JavaPlugin plugin)
|
||||
{
|
||||
@ -65,21 +64,17 @@ public class PacketHandler extends MiniPlugin
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
_playerVerifierMap.put(event.getPlayer(), new PacketVerifier(event.getPlayer()));
|
||||
_playerVerifierMap.put(event.getPlayer(), new PacketVerifier(event.getPlayer(), _packetHandlers));
|
||||
|
||||
((CraftPlayer) event.getPlayer()).getHandle().playerConnection.PacketVerifier.addPacketVerifier(_playerVerifierMap
|
||||
.get(event.getPlayer()));
|
||||
|
||||
for (IPacketHandler packetHandler : _packetHandlers)
|
||||
{
|
||||
_playerVerifierMap.get(event.getPlayer()).addPacketHandler(packetHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
((CraftPlayer) event.getPlayer()).getHandle().playerConnection.PacketVerifier.clearVerifiers();
|
||||
_playerVerifierMap.remove(event.getPlayer()).clearHandlers();
|
||||
_playerVerifierMap.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
public PacketVerifier getPacketVerifier(Player player)
|
||||
@ -90,14 +85,9 @@ public class PacketHandler extends MiniPlugin
|
||||
public void addPacketHandler(IPacketHandler packetHandler)
|
||||
{
|
||||
_packetHandlers.add(packetHandler);
|
||||
|
||||
for (PacketVerifier verifier : _playerVerifierMap.values())
|
||||
{
|
||||
verifier.addPacketHandler(packetHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<IPacketHandler> getPacketHandlers()
|
||||
public ArrayList<IPacketHandler> getPacketHandlers()
|
||||
{
|
||||
return _packetHandlers;
|
||||
}
|
||||
@ -105,10 +95,5 @@ public class PacketHandler extends MiniPlugin
|
||||
public void removePacketHandler(IPacketHandler packetHandler)
|
||||
{
|
||||
_packetHandlers.remove(packetHandler);
|
||||
|
||||
for (PacketVerifier verifier : _playerVerifierMap.values())
|
||||
{
|
||||
verifier.removePacketHandler(packetHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,23 @@
|
||||
package mineplex.core.packethandler;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.IPacketVerifier;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityVelocity;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMoveLook;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutUpdateAttributes;
|
||||
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketVerifier implements IPacketVerifier
|
||||
{
|
||||
private static Field _destroyId;
|
||||
private Player _owner;
|
||||
|
||||
private List<IPacketHandler> _packetHandlers = new ArrayList<IPacketHandler>();
|
||||
private ArrayList<IPacketHandler> _packetHandlers;
|
||||
|
||||
public PacketVerifier(Player owner)
|
||||
public PacketVerifier(Player owner, ArrayList<IPacketHandler> packetHandlers)
|
||||
{
|
||||
_owner = owner;
|
||||
|
||||
if (_destroyId == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_destroyId = PacketPlayOutEntityDestroy.class.getDeclaredField("a");
|
||||
_destroyId.setAccessible(true);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Field exception in CustomTagFix : ");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
_packetHandlers = packetHandlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,19 +47,4 @@ public class PacketVerifier implements IPacketVerifier
|
||||
{
|
||||
((CraftPlayer)_owner).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
public void clearHandlers()
|
||||
{
|
||||
_packetHandlers.clear();
|
||||
}
|
||||
|
||||
public void addPacketHandler(IPacketHandler packetHandler)
|
||||
{
|
||||
_packetHandlers.add(packetHandler);
|
||||
}
|
||||
|
||||
public void removePacketHandler(IPacketHandler packetHandler)
|
||||
{
|
||||
_packetHandlers.remove(packetHandler);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user