Class FakePlayer

All Implemented Interfaces:
CommandSender, DataContainer, EventHandler, EquipmentHandler, PermissionHandler, Viewable

public class FakePlayer
extends Player
A fake player will behave exactly the same way as would do a Player backed by a netty 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.

  • Method Details

    • initPlayer

      public static void initPlayer​(@NotNull java.util.UUID uuid, @NotNull java.lang.String username, @NotNull FakePlayerOption option, @Nullable java.util.function.Consumer<FakePlayer> spawnCallback)
      Inits 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 java.util.UUID uuid, @NotNull java.lang.String username, @Nullable java.util.function.Consumer<FakePlayer> spawnCallback)
      Inits 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 FakePlayerOption getOption()
      Gets the fake player option container.
      Returns:
      the fake player option
    • getController

      @NotNull public FakePlayerController getController()
    • showPlayer

      protected void showPlayer​(@NotNull PlayerConnection connection)
      Description copied from class: Player
      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 Player.addViewer(Player).

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