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

CraftWorld#playEffect incorrectly validates MaterialData

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None

      When validating data provided in World#playEffect(Location loc, Effect effect, T data), CraftBukkit checks if the required Class of data equals the provided one. This is incorrect, as the provided class may extend the required Class.

      The line in question:

      Validate.isTrue(data.getClass().equals(effect.getData()), "Wrong kind of data for this effect!");
      

      The fix:

      Validate.isTrue(effect.getData().isAssignableFrom(data.getClass()), "Wrong kind of data for this effect!");
      

      To replicate this issue, the following listener can be used.

          @EventHandler
          public void onPlayerInteract(PlayerInteractEvent event) {
              if (!event.hasBlock()) {
                  return;
              }
              Block clicked = event.getClickedBlock();
              MaterialData data = clicked.getState().getData();
              Bukkit.broadcastMessage("Comparing " + Effect.TILE_BREAK.getData() + " and " + data.getClass());
              Bukkit.broadcastMessage("Assignable: " + TILE_BREAK.getData().isAssignableFrom(data.getClass()));
              Bukkit.broadcastMessage("Equal: " + Effect.TILE_BREAK.getData().equals(state.getData().getClass()));
              clicked.getWorld().playEffect(clicked.getLocation(), Effect.TILE_BREAK, data);
          }
      

      When clicking a Block with a special MaterialData, such as wheat, an IllegalArgumentException is thrown.

      Technically this is a Spigot bug as Craftbukkit does not provide any particles which accept a MaterialData, but I believe it would be better to fix it on the Craftbukkit side as it is a Craftbukkit shortcoming.

            md_5 md_5
            Jikoo Jikoo
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: