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

PlayerInteractEvent firing twice under specific circumstances

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Minor
    • None
    • None
    • Windows 10
      Java 16

    • 3168-Spigot-a483d2c-bc00005 (MC: 1.17) (Implementing API version 1.17-R0.1-SNAPSHOT)
    • Yes

    Description

      PlayerInteractEvent fires twice if the Player is in Adventure Mode, the action is RIGHT_CLICK_BLOCK, and will be holding an ItemStack with a modified ItemMeta after the first PlayerInteractEvent fired.

      You can easily replicate this bug using this snippet below.

      @EventHandler
      public void onInteract(PlayerInteractEvent e){
          if (e.getItem() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
              ItemStack i;
              ItemMeta im;
              switch (e.getItem().getType()){
                  case WHITE_WOOL:
                      i = new ItemStack(Material.BLACK_WOOL);
                      im = i.getItemMeta();
                      im.setDisplayName("§lBLACK WOOL TEST");
                      i.setItemMeta(im);
                      e.getPlayer().getInventory().setItemInMainHand(i);
                      break;
                  case BLACK_WOOL:
                      i = new ItemStack(Material.WHITE_WOOL);
                      im = i.getItemMeta();
                      im.setDisplayName("§lWHITE WOOL TEST");
                      i.setItemMeta(im);
                      e.getPlayer().getInventory().setItemInMainHand(i);
                      break;
              }
              e.getPlayer().sendMessage(e.getAction().toString());
          }
      }
      

      If you right click a block with a normal white wool in your hand in adventure mode using this piece of code, you will be holding the white wool generated by the code, instead of the black wool.

       

      If you use the code below, you will skip every second iteration of the cycle, meaning you will go from white to black, from black to light gray, and from light gray to white.

      @EventHandler
      public void onInteract(PlayerInteractEvent e){
          if (e.getItem() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) {
              ItemStack i;
              ItemMeta im;
              switch (e.getItem().getType()){
                  case WHITE_WOOL:
                      i = new ItemStack(Material.LIGHT_GRAY_WOOL);
                      im = i.getItemMeta();
                      im.setDisplayName("§lLIGHT GRAY WOOL TEST");
                      i.setItemMeta(im);
                      e.getPlayer().getInventory().setItemInMainHand(i);
                      break;
                  case LIGHT_GRAY_WOOL:
                      i = new ItemStack(Material.BLACK_WOOL);
                      im = i.getItemMeta();
                      im.setDisplayName("§lBLACK WOOL TEST");
                      i.setItemMeta(im);
                      e.getPlayer().getInventory().setItemInMainHand(i);
                      break;
                  case BLACK_WOOL:
                      i = new ItemStack(Material.WHITE_WOOL);
                      im = i.getItemMeta();
                      im.setDisplayName("§lWHITE WOOL TEST");
                      i.setItemMeta(im);
                      e.getPlayer().getInventory().setItemInMainHand(i);
                      break;
              }
              e.getPlayer().sendMessage(e.getAction().toString());
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Kikikan Krisztián Gyöngyösi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: