Lorenzo0111 / QualityArmory

A quality gun plugin similar to CrackShot.
GNU General Public License v3.0
95 stars 50 forks source link

[bug]A bug with left click #583

Closed 86881 closed 1 month ago

86881 commented 1 month ago

Confirmations I am using the latest plugin version with the required dependencies. There isn't any open issue that shows my problem What happened? When I left-click on a mob, the gun hits it instead of firing. I tried to find a setting in the config, but I couldn't find anything about it.

Expected Behaviour The gun should be fired

Plugins QualityArmory ProtocolLib CMILib1.5.1.0

Server Version This server is running CraftBukkit version 4216-Spigot-146439e-eae9f76 (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)

Relevant log output No response

Thank you for your assistance.

86881 commented 1 month ago

I wrote a plugin to temporarily fix this problem. The main idea is to replace the event of hitting a mob with a click on the air. Here is the key part of the code:

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof org.bukkit.entity.Player) { org.bukkit.entity.Player player = (org.bukkit.entity.Player) event.getDamager(); ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); if (itemInMainHand != null && itemInMainHand.getType() == Material.CROSSBOW) { if (debugEnabled) { player.sendMessage("Debug: You cannot attack while holding a crossbow."); } // Cancel the damage event event.setCancelled(true); // Simulate a left-click in the air PlayerInteractEvent interactEvent = new PlayerInteractEvent( player, Action.LEFT_CLICK_AIR, itemInMainHand, null, null ); Bukkit.getServer().getPluginManager().callEvent(interactEvent); } } }

Here is a link for anyone who encounters this problem like I did:(for 1.19+) https://gofile.me/7j6gw/Xt13m0Vqj

Lorenzo0111 commented 1 month ago

Sadly this issue is caused by Minecraft and cannot be fixed. Calling PlayerInteractEvent manually is not a valid workaround as it could break other plugins.