Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5957

PlayerInteractEvent doesn't cancel / animation glitched

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • None
    • git-Spigot-8918ad0-7a9e4f7 (MC: 1.16.1)
    • Yes

      Expected:
      When setting use to DENY or cancelling the event, it should stop the animation and action that is being done, but it doesn't.

      The crossbow loaded item image and the fireworks' stack amount does not change unless you interact with the items.

      Code:

      @SuppressWarnings("deprecation")
      @EventHandler(priority = EventPriority.LOWEST)
      public void onPlayerInteract(PlayerInteractEvent event) {
          Player pl = event.getPlayer();
          ItemStack is = event.getHand() == EquipmentSlot.HAND ? pl.getInventory().getItemInMainHand() : pl.getInventory().getItemInOffHand();
          if (is == null) return;
          pl.sendMessage("[INFO] cancelled "+event.isCancelled()+" block "+event.useInteractedBlock().name()+" hand "+event.useItemInHand().name());
      
          if (is.getType() == Material.CROSSBOW) {
              ItemStack fw_is = event.getHand() == EquipmentSlot.HAND ? pl.getInventory().getItemInOffHand() : pl.getInventory().getItemInMainHand();
              if (fw_is != null && fw_is.getType() == Material.FIREWORK_ROCKET) {
                  pl.sendMessage(ChatColor.RED+"  Cannot load fireworks in your crossbow.");
                  event.setUseItemInHand(Result.DENY);
                  event.setCancelled(true);
               }
          }
          pl.sendMessage("[INFO] cancelled "+event.isCancelled()+" block "+event.useInteractedBlock().name()+" hand "+event.useItemInHand().name());
      }

        

      https://youtu.be/JNi1109oul8

       

            Unassigned Unassigned
            YourCoal YourCoal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: