Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Teleporting hidden by default entity across worlds resets which players can see it

Open Sytm opened this issue 7 months ago • 1 comments

Expected behavior

When hiding an entity by using entity.setVisibleByDefault(false); and showing it to a player with player.showEntity(plugin, entity); the entity remains visible to the player in question even after teleporting the entity across dimensions (basically teleporting it after the player teleports himself across dimensions).

Observed/Actual behavior

When teleporting across large distances in the same dimension, the entity remains visible, but once a teleport is performed across dimensions, the entity is no longer visible to the player and player.canSee(entity); reflects that.

I just noticed this happening when testing my plugin on 1.21.5, but it was introduced with 1.21.3-19 (bcbd10804f46bf9bd6fd99eea65ac4383cef2313).

Steps/models to reproduce

Using the following code, run /create and then /create 0, you will see the armorstand at your location, then teleport into another dimension (/execute in minecraft:the_nether run tp ~ 129 ~) and see that the armorstand is not visible. Then run /create 0 again, the armor stand is visible once more and the message states that the player previously could not see the entity.

@SuppressWarnings("UnstableApiUsage")
public class Sandbox extends JavaPlugin implements Listener {

  @Override
  public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
    getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
      commands.registrar().register("create", new CMD());
    });
  }

  private ArmorStand stand = null;

  @EventHandler
  public void on(PlayerTeleportEvent e) {
    if (stand == null) return;
    stand.teleportAsync(e.getTo());
  }

  public class CMD implements BasicCommand {
    @Override
    public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] strings) {
      Player p = (Player) commandSourceStack.getSender();
      if (strings.length == 0) {
        stand = p.getWorld().spawn(p.getLocation(), ArmorStand.class, entity -> {
          entity.setVisibleByDefault(false);
          entity.setCustomNameVisible(true);
          entity.customName(Component.text("Where did I go?"));
        });
      } else {
        if (stand != null) {
          p.sendPlainMessage("Showing entity. Old state: " + p.canSee(stand));
          p.showEntity(Sandbox.this, stand);
        }
      }
    }
  }
}

The compiled test plugin: paper-j-sandbox-1.0.0-SNAPSHOT.jar.zip

Plugin and Datapack List

Just the test plugin

Paper version

[22:23:16 INFO]: This server is running Paper version 1.21.5-101-main@a033e3b (2025-05-25T07:31:15Z) (Implementing API version 1.21.5-R0.1-SNAPSHOT) You are 1 version(s) behind Download the new version at: https://papermc.io/downloads/paper Previous version: 1.21.4-150-46f4fda (MC: 1.21.4)

Other

No response

Sytm avatar May 28 '25 20:05 Sytm

Ok i feel this is a issue when the hide/show entity API was added... when the entity its removed (kill, discard, change_dimension, unload) its removed from the reference for all the players where if you make something like spawn entity, hide and teleport when check the canSee that return true now... this not apply to players.

Doc94 avatar Nov 24 '25 15:11 Doc94