Class FakePlayer

All Implemented Interfaces:
Audience, Identified, Pointered, Sound.Emitter, HoverEventSource<HoverEvent.ShowEntity>, Localizable, CommandSender, NavigableEntity, EventHandler<EntityEvent>, EquipmentHandler, PermissionHandler, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Schedulable, NamedAndIdentified, Viewable

public class FakePlayer extends Player implements NavigableEntity
A fake player will behave exactly the same way as would do a Player backed by a socket connection (events, velocity, gravity, player list, etc...) with the exception that you need to control it server-side using a FakePlayerController (see getController()).

You can create one using initPlayer(UUID, String, Consumer). Be aware that this really behave exactly like a player and this is a feature not a bug, you will need to check at some place if the player is a fake one or not (instanceof) if you want to change it.

  • Constructor Details

    • FakePlayer

      protected FakePlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull FakePlayerOption option, @Nullable @Nullable Consumer<FakePlayer> spawnCallback)
      Initializes a new FakePlayer with the given uuid, username and option's.
      Parameters:
      uuid - The unique identifier for the fake player.
      username - The username for the fake player.
      option - Any option for the fake player.
  • Method Details

    • initPlayer

      public static void initPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull FakePlayerOption option, @Nullable @Nullable Consumer<FakePlayer> spawnCallback)
      Initializes a new FakePlayer.
      Parameters:
      uuid - the FakePlayer uuid
      username - the FakePlayer username
      spawnCallback - the optional callback called when the fake player first spawn
    • initPlayer

      public static void initPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @Nullable @Nullable Consumer<FakePlayer> spawnCallback)
      Initializes a new FakePlayer without adding it in cache.

      If you want the fake player to be obtainable with the ConnectionManager you need to specify it in a FakePlayerOption and use initPlayer(UUID, String, FakePlayerOption, Consumer).

      Parameters:
      uuid - the FakePlayer uuid
      username - the FakePlayer username
      spawnCallback - the optional callback called when the fake player first spawn
    • getOption

      @NotNull public @NotNull FakePlayerOption getOption()
      Gets the fake player option container.
      Returns:
      the fake player option
    • getController

      @NotNull public @NotNull FakePlayerController getController()
      Retrieves the controller for the fake player.
      Returns:
      The fake player's controller.
    • update

      public void update(long time)
      Description copied from class: Entity
      Called each tick.
      Overrides:
      update in class Player
      Parameters:
      time - time of the update in milliseconds
    • setInstance

      public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance, @NotNull @NotNull Pos spawnPosition)
      Description copied from class: Player
      Changes the player instance and load surrounding chunks if needed.

      Be aware that because chunk operations are expensive, it is possible for this method to be non-blocking when retrieving chunks is required.

      Overrides:
      setInstance in class Player
      Parameters:
      instance - the new player instance
      spawnPosition - the new position of the player
      Returns:
      a future called once the player instance changed
    • updateNewViewer

      public void updateNewViewer(@NotNull @NotNull Player player)
      Description copied from class: Entity
      Called when a new viewer must be shown. Method can be subject to deadlocking if the target's viewers are also accessed.
      Overrides:
      updateNewViewer in class LivingEntity
      Parameters:
      player - the player to send the packets to
    • showPlayer

      protected void showPlayer(@NotNull @NotNull PlayerConnection connection)
      Sends all the related packet to have the player sent to another with related data (create player, spawn position, velocity, metadata, equipments, passengers, team).

      WARNING: this alone does not sync the player, please use Entity.addViewer(Player).

      Overrides:
      showPlayer in class Player
      Parameters:
      connection - the connection to show the player to
    • getNavigator

      @NotNull public @NotNull Navigator getNavigator()
      Specified by:
      getNavigator in interface NavigableEntity