diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 73138c191..9d03f8f82 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -22,6 +22,7 @@ import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; +import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction; import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; @@ -55,15 +56,12 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook private NautHashMap _exemptTimeMap = new NautHashMap(); private NautHashMap> _doubleStrike = new NautHashMap>(); - private PacketHandler _packetHandler; public CustomTagFix(JavaPlugin plugin, PacketHandler packetHandler) { super("Custom Tag Fix", plugin); - _packetHandler = packetHandler; - - packetHandler.addPacketHandler(this, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class, + packetHandler.addPacketHandler(this, true, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class, PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, PacketPlayInUseEntity.class); @@ -353,10 +351,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity(); newPacket.a = entry.getKey(); - newPacket.action = usePacket.action; - newPacket.c = usePacket.c; + newPacket.action = EnumEntityUseAction.INTERACT; - if (_packetHandler.handlePacket(owner, newPacket)) { ((CraftPlayer) owner).getHandle().playerConnection.a(newPacket); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/PacketsInteractionFix.java b/Plugins/Mineplex.Core/src/mineplex/core/PacketsInteractionFix.java index a5f302e97..227cba9bb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/PacketsInteractionFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/PacketsInteractionFix.java @@ -5,11 +5,15 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.MovingObjectPosition; 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 net.minecraft.server.v1_8_R3.Vec3D; +import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -18,9 +22,6 @@ 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; @@ -33,8 +34,6 @@ import mineplex.core.updater.event.UpdateEvent; public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler { private HashMap> _armorStands = new HashMap>(); - private HashSet _leftClicked = new HashSet(); - private int _lastTick; public PacketsInteractionFix(JavaPlugin plugin, PacketHandler packetHandler) { @@ -44,42 +43,9 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler 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()); } @@ -91,8 +57,6 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler return; } - checkLeftClicks(); - Iterator itel = _armorStands.keySet().iterator(); while (itel.hasNext()) @@ -110,19 +74,6 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler } } - //@EventHandler - public void onPlayerInteract(PlayerInteractEvent event) - { - if (!event.getAction().name().contains("LEFT")) - { - return; - } - - checkLeftClicks(); - - _leftClicked.add(event.getPlayer()); - } - @Override public void handle(PacketInfo packetInfo) { @@ -166,12 +117,38 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler { PacketPlayInUseEntity packet = (PacketPlayInUseEntity) packetInfo.getPacket(); - if (!list.contains(packet.a)) + if (packet.action == EnumEntityUseAction.ATTACK) { + EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle(); + + float f1 = nmsPlayer.pitch; + float f2 = nmsPlayer.yaw; + double d0 = nmsPlayer.locX; + double d1 = nmsPlayer.locY + nmsPlayer.getHeadHeight(); + double d2 = nmsPlayer.locZ; + Vec3D vec3d = new Vec3D(d0, d1, d2); + + float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F); + float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F); + float f5 = -MathHelper.cos(-f1 * 0.01745329F); + float f6 = MathHelper.sin(-f1 * 0.01745329F); + float f7 = f4 * f5; + float f8 = f3 * f5; + nmsPlayer.playerInteractManager.getGameMode(); + double d3 = nmsPlayer.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE ? 5 : 4.5; + Vec3D vec3d1 = vec3d.add(f7 * d3, f6 * d3, f8 * d3); + MovingObjectPosition movingobjectposition = nmsPlayer.world.rayTrace(vec3d, vec3d1, false); + + if (movingobjectposition != null && movingobjectposition.type == MovingObjectPosition.EnumMovingObjectType.BLOCK) + { + CraftEventFactory.callPlayerInteractEvent(nmsPlayer, Action.LEFT_CLICK_AIR, + nmsPlayer.inventory.getItemInHand()); + } + return; } - if (packet.action == EnumEntityUseAction.ATTACK) + if (!list.contains(packet.a)) { return; }