Fix player interactions packets not working properly on armorstand and when clicking block behind entity
This commit is contained in:
parent
77125b3a24
commit
cc0f12f6c8
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import mineplex.core.common.DummyEntity;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.event.CustomTagEvent;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
@ -29,6 +30,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -49,22 +51,26 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
private NautHashMap<String, NautHashMap<Integer, String>> _entityNameMap = new NautHashMap<String, NautHashMap<Integer, String>>();
|
||||
private HashSet<String> _loggedIn = new HashSet<String>();
|
||||
private HashSet<Integer> _ignoreSkulls = new HashSet<Integer>();
|
||||
|
||||
|
||||
private NautHashMap<UUID, Long> _exemptTimeMap = new NautHashMap<UUID, Long>();
|
||||
private NautHashMap<UUID, NautHashMap<CheckType, Long>> _doubleStrike = new NautHashMap<UUID, NautHashMap<CheckType, Long>>();
|
||||
private PacketHandler _packetHandler;
|
||||
|
||||
public CustomTagFix(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
super("Custom Tag Fix", plugin);
|
||||
|
||||
_packetHandler = packetHandler;
|
||||
|
||||
packetHandler.addPacketHandler(this, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class,
|
||||
PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, PacketPlayInUseEntity.class);
|
||||
PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class,
|
||||
PacketPlayInUseEntity.class);
|
||||
|
||||
NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
|
||||
NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
|
||||
NCPHookManager.addHook(CheckType.ALL, this);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
@ -72,88 +78,91 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
_entityNameMap.remove(event.getPlayer().getName());
|
||||
_loggedIn.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void ncpExempt(final PlayerToggleFlightEvent event)
|
||||
{
|
||||
long ignoreTime = System.currentTimeMillis() + 1500;
|
||||
|
||||
|
||||
if (_exemptTimeMap.containsKey(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(), Math.max(ignoreTime, _exemptTimeMap.get(event.getPlayer().getUniqueId())));
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(),
|
||||
Math.max(ignoreTime, _exemptTimeMap.get(event.getPlayer().getUniqueId())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
NCPExemptionManager.exemptPermanently(event.getPlayer());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(), ignoreTime);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void ncpExemptVelocity(final PlayerVelocityEvent event)
|
||||
{
|
||||
long ignoreTime = System.currentTimeMillis() + (long)(event.getVelocity().length() * 2000);
|
||||
long ignoreTime = System.currentTimeMillis() + (long) (event.getVelocity().length() * 2000);
|
||||
if (_exemptTimeMap.containsKey(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(), Math.max(ignoreTime, _exemptTimeMap.get(event.getPlayer().getUniqueId())));
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(),
|
||||
Math.max(ignoreTime, _exemptTimeMap.get(event.getPlayer().getUniqueId())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_exemptTimeMap.put(event.getPlayer().getUniqueId(), ignoreTime);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void unexempt(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
|
||||
for (Iterator<Entry<UUID, Long>> iterator = _exemptTimeMap.entrySet().iterator(); iterator.hasNext();)
|
||||
{
|
||||
final Entry<UUID, Long> entry = iterator.next();
|
||||
|
||||
|
||||
if (System.currentTimeMillis() > entry.getValue())
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<Entry<UUID, NautHashMap<CheckType, Long>>> iterator = _doubleStrike.entrySet().iterator(); iterator.hasNext();)
|
||||
|
||||
for (Iterator<Entry<UUID, NautHashMap<CheckType, Long>>> iterator = _doubleStrike.entrySet().iterator(); iterator
|
||||
.hasNext();)
|
||||
{
|
||||
Entry<UUID, NautHashMap<CheckType, Long>> entry = iterator.next();
|
||||
|
||||
for (Iterator<Entry<CheckType, Long>> innerIterator = entry.getValue().entrySet().iterator(); innerIterator.hasNext();)
|
||||
{
|
||||
final Entry<CheckType, Long> entry2 = innerIterator.next();
|
||||
|
||||
|
||||
if (System.currentTimeMillis() > entry2.getValue())
|
||||
{
|
||||
innerIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (entry.getValue() == null || entry.getValue().size() == 0)
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void cleanMap(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
|
||||
for (Iterator<String> iterator = _loggedIn.iterator(); iterator.hasNext();)
|
||||
{
|
||||
String player = iterator.next();
|
||||
|
||||
|
||||
if (Bukkit.getPlayerExact(player) == null)
|
||||
{
|
||||
iterator.remove();
|
||||
@ -161,19 +170,19 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
_entityNameMap.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Bukkit.getServer().getOnlinePlayers().size() < _loggedIn.size())
|
||||
{
|
||||
System.out.println("PROBLEM - _loggedIn TOOOOOO BIIIIIGGGGG.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
if (packetInfo.isCancelled())
|
||||
return;
|
||||
|
||||
|
||||
Packet packet = packetInfo.getPacket();
|
||||
Player owner = packetInfo.getPlayer();
|
||||
PacketVerifier verifier = packetInfo.getVerifier();
|
||||
@ -186,61 +195,62 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
_entityNameMap.put(owner.getName(), new NautHashMap<Integer, String>());
|
||||
_loggedIn.add(owner.getName());
|
||||
}
|
||||
|
||||
|
||||
if (packet instanceof PacketPlayOutSpawnEntityLiving)
|
||||
{
|
||||
PacketPlayOutSpawnEntityLiving spawnPacket = (PacketPlayOutSpawnEntityLiving)packet;
|
||||
PacketPlayOutSpawnEntityLiving spawnPacket = (PacketPlayOutSpawnEntityLiving) packet;
|
||||
|
||||
// Ignore Armor stand packets
|
||||
if (spawnPacket.b == 30 || spawnPacket.l == null || spawnPacket.l.c() == null || spawnPacket.a == 777777)
|
||||
{
|
||||
if (spawnPacket.b == 30)
|
||||
{
|
||||
_ignoreSkulls.add(spawnPacket.a);
|
||||
_ignoreSkulls.add(spawnPacket.a);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>)spawnPacket.l.c())
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>) spawnPacket.l.c())
|
||||
{
|
||||
if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte)watchable.b()) == 1)
|
||||
if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte) watchable.b()) == 1)
|
||||
{
|
||||
final String entityName = spawnPacket.l.getString(2);
|
||||
|
||||
|
||||
if (entityName.isEmpty())
|
||||
{
|
||||
_entityNameMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_entityMap.get(owner.getName()).containsKey(spawnPacket.a))
|
||||
{
|
||||
verifier.bypassProcess(new PacketPlayOutEntityDestroy(new int[]
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[]
|
||||
{
|
||||
_entityMap.get(owner.getName()).get(spawnPacket.a)
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
int newId = UtilEnt.getNewEntityId();
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier);
|
||||
_entityMap.get(owner.getName()).put(spawnPacket.a, newId);
|
||||
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutEntityMetadata)
|
||||
{
|
||||
PacketPlayOutEntityMetadata metaPacket = (PacketPlayOutEntityMetadata)packet;
|
||||
|
||||
if (!_entityMap.get(owner.getName()).containsKey(metaPacket.a) && metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a))
|
||||
PacketPlayOutEntityMetadata metaPacket = (PacketPlayOutEntityMetadata) packet;
|
||||
|
||||
if (!_entityMap.get(owner.getName()).containsKey(metaPacket.a) && metaPacket.a != 777777
|
||||
&& !_ignoreSkulls.contains(metaPacket.a))
|
||||
{
|
||||
String entityName = "";
|
||||
boolean nameShowing = false;
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>)metaPacket.b)
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>) metaPacket.b)
|
||||
{
|
||||
if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte) watchable.b()) == 1)
|
||||
{
|
||||
@ -251,7 +261,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
entityName = (String) watchable.b();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nameShowing && !entityName.isEmpty())
|
||||
{
|
||||
int newId = UtilEnt.getNewEntityId();
|
||||
@ -273,7 +283,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
if (_entityMap.get(owner.getName()).containsKey(id))
|
||||
{
|
||||
verifier.bypassProcess(new PacketPlayOutEntityDestroy(new int[]
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[]
|
||||
{
|
||||
_entityMap.get(owner.getName()).get(id)
|
||||
}));
|
||||
@ -286,14 +296,14 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutSpawnEntity)
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutSpawnEntity)
|
||||
{
|
||||
PacketPlayOutSpawnEntity spawnPacket = (PacketPlayOutSpawnEntity) packet;
|
||||
if (spawnPacket.j == 66 && spawnPacket.a != 777777)
|
||||
{
|
||||
_ignoreSkulls.add(spawnPacket.a);
|
||||
}
|
||||
PacketPlayOutSpawnEntity spawnPacket = (PacketPlayOutSpawnEntity) packet;
|
||||
if (spawnPacket.j == 66 && spawnPacket.a != 777777)
|
||||
{
|
||||
_ignoreSkulls.add(spawnPacket.a);
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayInUseEntity)
|
||||
{
|
||||
@ -303,15 +313,24 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
if (entry.getValue() == usePacket.a)
|
||||
{
|
||||
usePacket.a = entry.getKey();
|
||||
PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity();
|
||||
newPacket.a = entry.getKey();
|
||||
newPacket.action = usePacket.action;
|
||||
newPacket.c = usePacket.c;
|
||||
|
||||
if (_packetHandler.handlePacket(owner, newPacket))
|
||||
{
|
||||
((CraftPlayer) owner).getHandle().playerConnection.a(newPacket);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName, final PacketVerifier packetList)
|
||||
|
||||
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName,
|
||||
final PacketVerifier packetList)
|
||||
{
|
||||
CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
@ -321,107 +340,91 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
final PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
|
||||
packet.a = newEntityId;
|
||||
packet.b = (byte) 30;
|
||||
packet.c = (int)MathHelper.floor(100*32);
|
||||
packet.d = (int)MathHelper.floor(64 * 32.0D);
|
||||
packet.e = (int)MathHelper.floor(100*32);
|
||||
packet.i = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
packet.j = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
packet.k = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
final PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
|
||||
spawnPacket.a = newEntityId;
|
||||
spawnPacket.b = (byte) 30;
|
||||
spawnPacket.c = (int) MathHelper.floor(100 * 32);
|
||||
spawnPacket.d = (int) MathHelper.floor(64 * 32.0D);
|
||||
spawnPacket.e = (int) MathHelper.floor(100 * 32);
|
||||
spawnPacket.i = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
spawnPacket.j = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
spawnPacket.k = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
|
||||
double var2 = 3.9D;
|
||||
double var4 = 0;
|
||||
double var6 = 0;
|
||||
double var8 = 0;
|
||||
double var2 = 3.9D;
|
||||
double var4 = 0;
|
||||
double var6 = 0;
|
||||
double var8 = 0;
|
||||
|
||||
if (var4 < -var2)
|
||||
{
|
||||
var4 = -var2;
|
||||
}
|
||||
if (var4 < -var2)
|
||||
{
|
||||
var4 = -var2;
|
||||
}
|
||||
|
||||
if (var6 < -var2)
|
||||
{
|
||||
var6 = -var2;
|
||||
}
|
||||
if (var6 < -var2)
|
||||
{
|
||||
var6 = -var2;
|
||||
}
|
||||
|
||||
if (var8 < -var2)
|
||||
{
|
||||
var8 = -var2;
|
||||
}
|
||||
if (var8 < -var2)
|
||||
{
|
||||
var8 = -var2;
|
||||
}
|
||||
|
||||
if (var4 > var2)
|
||||
{
|
||||
var4 = var2;
|
||||
}
|
||||
if (var4 > var2)
|
||||
{
|
||||
var4 = var2;
|
||||
}
|
||||
|
||||
if (var6 > var2)
|
||||
{
|
||||
var6 = var2;
|
||||
}
|
||||
if (var6 > var2)
|
||||
{
|
||||
var6 = var2;
|
||||
}
|
||||
|
||||
if (var8 > var2)
|
||||
{
|
||||
var8 = var2;
|
||||
}
|
||||
if (var8 > var2)
|
||||
{
|
||||
var8 = var2;
|
||||
}
|
||||
|
||||
packet.f = (int)(var4 * 8000.0D);
|
||||
packet.g = (int)(var6 * 8000.0D);
|
||||
packet.h = (int)(var8 * 8000.0D);
|
||||
|
||||
final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld)owner.getWorld()).getHandle()));
|
||||
|
||||
watcher.a(0, Byte.valueOf((byte)0));
|
||||
watcher.a(1, Short.valueOf((short)300));
|
||||
spawnPacket.f = (int) (var4 * 8000.0D);
|
||||
spawnPacket.g = (int) (var6 * 8000.0D);
|
||||
spawnPacket.h = (int) (var8 * 8000.0D);
|
||||
|
||||
final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
|
||||
|
||||
watcher.a(0, Byte.valueOf((byte) 0));
|
||||
watcher.a(1, Short.valueOf((short) 300));
|
||||
watcher.a(2, "");
|
||||
watcher.a(3, Byte.valueOf((byte) 0));
|
||||
watcher.a(4, Byte.valueOf((byte)0));
|
||||
watcher.a(4, Byte.valueOf((byte) 0));
|
||||
watcher.a(7, Integer.valueOf(0));
|
||||
watcher.a(8, Byte.valueOf((byte)0));
|
||||
watcher.a(9, Byte.valueOf((byte)0));
|
||||
watcher.a(8, Byte.valueOf((byte) 0));
|
||||
watcher.a(9, Byte.valueOf((byte) 0));
|
||||
watcher.a(6, Float.valueOf(1.0F));
|
||||
watcher.a(10, Byte.valueOf((byte)0));
|
||||
|
||||
// Set invisible
|
||||
int i1 = watcher.getByte(0);
|
||||
watcher.watch(0, Byte.valueOf((byte)(i1 | 1 << 5)));
|
||||
|
||||
// Set small
|
||||
byte b1 = watcher.getByte(10);
|
||||
b1 = (byte)(b1 | 0x1);
|
||||
|
||||
watcher.watch(10, Byte.valueOf(b1));
|
||||
|
||||
watcher.watch(2, finalEntityName);
|
||||
watcher.watch(3, Byte.valueOf((byte)1));
|
||||
|
||||
packet.l = watcher;
|
||||
|
||||
packetList.bypassProcess(packet);
|
||||
|
||||
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
vehiclePacket.b = packet.a;
|
||||
vehiclePacket.c = entityId;
|
||||
|
||||
packetList.bypassProcess(vehiclePacket);
|
||||
|
||||
/* TODO dynamic attach handling?
|
||||
if (_entityVehicleMap.get(owner).containsValue(entityId))
|
||||
{
|
||||
vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
|
||||
for (Entry<Integer, Integer> entry : _entityVehicleMap.get(owner).entrySet())
|
||||
{
|
||||
if (entry.getValue() == entityId)
|
||||
vehiclePacket.b = entry.getKey();
|
||||
}
|
||||
watcher.a(10, Byte.valueOf((byte) 0));
|
||||
|
||||
vehiclePacket.c = packet.a;
|
||||
}
|
||||
*/
|
||||
// Set invisible
|
||||
int i1 = watcher.getByte(0);
|
||||
watcher.watch(0, Byte.valueOf((byte) (i1 | 1 << 5)));
|
||||
|
||||
// Set small
|
||||
byte b1 = watcher.getByte(10);
|
||||
b1 = (byte) (b1 | 0x1);
|
||||
|
||||
watcher.watch(10, Byte.valueOf(b1));
|
||||
|
||||
watcher.watch(2, finalEntityName);
|
||||
watcher.watch(3, Byte.valueOf((byte) 1));
|
||||
|
||||
spawnPacket.l = watcher;
|
||||
|
||||
UtilPlayer.sendPacket(owner, spawnPacket);
|
||||
|
||||
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
vehiclePacket.b = spawnPacket.a;
|
||||
vehiclePacket.c = entityId;
|
||||
|
||||
UtilPlayer.sendPacket(owner, vehiclePacket);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -442,28 +445,28 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo violationInfo)
|
||||
{
|
||||
boolean failure = false;
|
||||
|
||||
|
||||
if (checkType == CheckType.MOVING_SURVIVALFLY || checkType == CheckType.MOVING_PASSABLE)
|
||||
{
|
||||
{
|
||||
failure = _exemptTimeMap.containsKey(player.getUniqueId());
|
||||
|
||||
|
||||
if (failure)
|
||||
MovingData.getData(player).clearFlyData();
|
||||
}
|
||||
|
||||
|
||||
// This is the second strike system.
|
||||
if (!failure)
|
||||
{
|
||||
if (!_doubleStrike.containsKey(player.getUniqueId()) || !_doubleStrike.get(player.getUniqueId()).containsKey(checkType.getParent()))
|
||||
if (!_doubleStrike.containsKey(player.getUniqueId())
|
||||
|| !_doubleStrike.get(player.getUniqueId()).containsKey(checkType.getParent()))
|
||||
failure = true;
|
||||
|
||||
if (!_doubleStrike.containsKey(player.getUniqueId()))
|
||||
_doubleStrike.put(player.getUniqueId(), new NautHashMap<CheckType, Long>());
|
||||
|
||||
|
||||
_doubleStrike.get(player.getUniqueId()).put(checkType.getParent(), System.currentTimeMillis() + 5000);
|
||||
}
|
||||
|
||||
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,183 @@
|
||||
package mineplex.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
{
|
||||
private HashMap<String, HashSet<Integer>> _armorStands = new HashMap<String, HashSet<Integer>>();
|
||||
private HashSet<Player> _leftClicked = new HashSet<Player>();
|
||||
private int _lastTick;
|
||||
|
||||
public PacketsInteractionFix(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
super("Packets Interaction Fix", plugin);
|
||||
|
||||
packetHandler.addPacketHandler(this, true, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutEntityDestroy.class,
|
||||
PacketPlayInUseEntity.class);
|
||||
}
|
||||
|
||||
private void checkLeftClicks()
|
||||
{
|
||||
if (MinecraftServer.currentTick == _lastTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastTick = MinecraftServer.currentTick;
|
||||
_leftClicked.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmAnimation(PlayerAnimationEvent event)
|
||||
{
|
||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_leftClicked.remove(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CraftEventFactory.callPlayerInteractEvent(((CraftPlayer) player).getHandle(), Action.LEFT_CLICK_AIR,
|
||||
((CraftPlayer) player).getHandle().inventory.getItemInHand());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_leftClicked.remove(event.getPlayer().getName());
|
||||
_armorStands.remove(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void removeDeadNames(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
Iterator<String> itel = _armorStands.keySet().iterator();
|
||||
|
||||
while (itel.hasNext())
|
||||
{
|
||||
String name = itel.next();
|
||||
|
||||
Player player = Bukkit.getPlayerExact(name);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
itel.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!event.getAction().name().contains("LEFT"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
_leftClicked.add(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
Player player = packetInfo.getPlayer();
|
||||
|
||||
if (!player.isOnline())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (packetInfo.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_armorStands.containsKey(player.getName()))
|
||||
{
|
||||
_armorStands.put(player.getName(), new HashSet<Integer>());
|
||||
}
|
||||
|
||||
HashSet<Integer> list = _armorStands.get(player.getName());
|
||||
|
||||
if (packetInfo.getPacket() instanceof PacketPlayOutSpawnEntityLiving)
|
||||
{
|
||||
PacketPlayOutSpawnEntityLiving packet = (PacketPlayOutSpawnEntityLiving) packetInfo.getPacket();
|
||||
|
||||
if (packet.b != EntityType.ARMOR_STAND.getTypeId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
list.add(packet.a);
|
||||
}
|
||||
else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy)
|
||||
{
|
||||
PacketPlayOutEntityDestroy packet = (PacketPlayOutEntityDestroy) packetInfo.getPacket();
|
||||
|
||||
list.removeAll(Arrays.asList(packet.a));
|
||||
}
|
||||
else if (packetInfo.getPacket() instanceof PacketPlayInUseEntity)
|
||||
{
|
||||
PacketPlayInUseEntity packet = (PacketPlayInUseEntity) packetInfo.getPacket();
|
||||
|
||||
if (!list.contains(packet.a))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.action == EnumEntityUseAction.ATTACK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CraftEventFactory.callPlayerInteractEvent(((CraftPlayer) player).getHandle(), Action.RIGHT_CLICK_AIR,
|
||||
((CraftPlayer) player).getHandle().inventory.getItemInHand());
|
||||
}
|
||||
}
|
||||
}
|
@ -40,11 +40,23 @@ public class PacketHandler extends MiniPlugin
|
||||
.get(event.getPlayer()));
|
||||
}
|
||||
|
||||
public boolean handlePacket(Player player, Packet packet)
|
||||
{
|
||||
if (!_playerVerifierMap.containsKey(player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PacketVerifier verifier = _playerVerifierMap.get(player);
|
||||
|
||||
return handlePacket(new PacketInfo(player, packet, verifier));
|
||||
}
|
||||
|
||||
public boolean handlePacket(PacketInfo packetInfo)
|
||||
{
|
||||
if (!_packetHandlers.containsKey(packetInfo.getPacket().getClass()))
|
||||
{
|
||||
System.err.print("Received packet " + packetInfo.getPacket().getClass() + " but am not listening for it!");
|
||||
// aSystem.err.print("Received packet " + packetInfo.getPacket().getClass() + " but am not listening for it!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -87,7 +99,8 @@ public class PacketHandler extends MiniPlugin
|
||||
/**
|
||||
* This should only be used for incoming packets
|
||||
*/
|
||||
public void addPacketHandler(IPacketHandler packetHandler, boolean forceMainThread, Class<? extends Packet>... packetsToListen)
|
||||
public void addPacketHandler(IPacketHandler packetHandler, boolean forceMainThread,
|
||||
Class<? extends Packet>... packetsToListen)
|
||||
{
|
||||
if (packetsToListen.length == 0)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.CustomTagFix;
|
||||
import mineplex.core.PacketsInteractionFix;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.antihack.AntiHack;
|
||||
@ -138,6 +139,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
new MemoryFix(this);
|
||||
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
|
||||
new CustomTagFix(this, packetHandler);
|
||||
new PacketsInteractionFix(this, packetHandler);
|
||||
new ResPackManager(new ResUnloadCheck()
|
||||
{
|
||||
public boolean canSendUnload(Player player)
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.FoodDupeFix;
|
||||
import mineplex.core.PacketsInteractionFix;
|
||||
import mineplex.core.globalpacket.GlobalPacketManager;
|
||||
import net.minecraft.server.v1_8_R3.BiomeBase;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
@ -152,6 +153,7 @@ public class Arcade extends JavaPlugin
|
||||
|
||||
new MemoryFix(this);
|
||||
new CustomTagFix(this, packetHandler);
|
||||
new PacketsInteractionFix(this, packetHandler);
|
||||
new FoodDupeFix(this);
|
||||
|
||||
//Updates
|
||||
|
Loading…
Reference in New Issue
Block a user