Class LocalSession

java.lang.Object
com.sk89q.worldedit.LocalSession
All Implemented Interfaces:
TextureHolder

public class LocalSession extends Object implements TextureHolder
Stores session information.
  • Field Details

    • MAX_HISTORY_SIZE

      public static transient int MAX_HISTORY_SIZE
  • Constructor Details

    • LocalSession

      public LocalSession()
      Construct the object.

      setConfiguration(LocalConfiguration) should be called later with configuration.

    • LocalSession

      public LocalSession(@Nullable LocalConfiguration config)
      Construct the object.
      Parameters:
      config - the configuration
  • Method Details

    • setConfiguration

      public void setConfiguration(LocalConfiguration config)
      Set the configuration.
      Parameters:
      config - the configuration
    • postLoad

      public void postLoad()
      Called on post load of the session from persistent storage.
    • loadSessionHistoryFromDisk

      public boolean loadSessionHistoryFromDisk(UUID uuid, World world)
    • isDirty

      public boolean isDirty()
      Get whether this session is "dirty" and has changes that needs to be committed.
      Returns:
      true if dirty
    • getHistoryIndex

      public int getHistoryIndex()
    • getHistoryNegativeIndex

      public int getHistoryNegativeIndex()
    • getHistory

      public List<ChangeSet> getHistory()
    • save

      public boolean save()
    • compareAndResetDirty

      public boolean compareAndResetDirty()
      Get whether this session is "dirty" and has changes that needs to be committed, and reset it to false.
      Returns:
      true if the dirty value was true
    • getTimeZone

      public ZoneId getTimeZone()
      Get the session's timezone.
      Returns:
      the timezone
    • setTimezone

      public void setTimezone(ZoneId timezone)
      Set the session's timezone.
      Parameters:
      timezone - the user's timezone
    • clearHistory

      public void clearHistory()
      Clear history.
    • remember

      public void remember(EditSession editSession)
      Remember an edit session for the undo history. If the history maximum size is reached, old edit sessions will be discarded.
      Parameters:
      editSession - the edit session
    • remember

      public void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit)
    • remember

      public void remember(EditSession editSession, boolean append, int limitMb)
    • undo

      public EditSession undo(@Nullable BlockBag newBlockBag, Actor actor)
      Performs an undo.
      Parameters:
      newBlockBag - a new block bag
      actor - the actor
      Returns:
      whether anything was undone
    • redo

      public EditSession redo(@Nullable BlockBag newBlockBag, Actor actor)
      Performs a redo
      Parameters:
      newBlockBag - a new block bag
      actor - the actor
      Returns:
      whether anything was redone
    • hasWorldOverride

      public boolean hasWorldOverride()
    • getWorldOverride

      @Nullable public World getWorldOverride()
    • setWorldOverride

      public void setWorldOverride(@Nullable World worldOverride)
    • isTickingWatchdog

      public boolean isTickingWatchdog()
    • setTickingWatchdog

      public void setTickingWatchdog(boolean tickingWatchdog)
    • isTracingActions

      public boolean isTracingActions()
    • setTracingActions

      public void setTracingActions(boolean tracingActions)
    • getDefaultRegionSelector

      public RegionSelectorType getDefaultRegionSelector()
      Get the default region selector.
      Returns:
      the default region selector
    • setDefaultRegionSelector

      public void setDefaultRegionSelector(RegionSelectorType defaultSelector)
      Set the default region selector.
      Parameters:
      defaultSelector - the default region selector
    • getRegionSelector

      public RegionSelector getRegionSelector(World world)
      Get the region selector for defining the selection. If the selection was defined for a different world, the old selection will be discarded.
      Parameters:
      world - the world
      Returns:
      position the position
    • setRegionSelector

      public void setRegionSelector(World world, RegionSelector selector)
      Set the region selector.
      Parameters:
      world - the world
      selector - the selector
    • isSelectionDefined

      public boolean isSelectionDefined(World world)
      Returns true if the region is fully defined for the specified world.
      Parameters:
      world - the world
      Returns:
      true if a region selection is defined
    • getSelection

      public Region getSelection() throws IncompleteRegionException
      Get the selection region. If you change the region, you should call learnRegionChanges(). If the selection is not fully defined, the IncompleteRegionException exception will be thrown.

      Note that this method will return a region in the current selection world, which is not guaranteed to be the player's world or even the current world override. If you require a specific world, use the getSelection(World) overload instead.

      Returns:
      the selected region
      Throws:
      IncompleteRegionException - if the region is not fully defined
    • getSelection

      public Region getSelection(@Nullable World world) throws IncompleteRegionException
      Get the selection region. If you change the region, you should call learnRegionChanges(). If the selection is defined in a different world, or the selection isn't fully defined, the IncompleteRegionException exception will be thrown.
      Parameters:
      world - the world
      Returns:
      a region
      Throws:
      IncompleteRegionException - if no region is selected, or the provided world is null
    • getSelectionWorld

      @Nullable public World getSelectionWorld()
      Get the selection world.
      Returns:
      the the world of the selection
    • getClipboard

      public ClipboardHolder getClipboard() throws EmptyClipboardException
      Gets the clipboard.
      Returns:
      clipboard
      Throws:
      EmptyClipboardException - thrown if no clipboard is set
    • getExistingClipboard

      @Nullable public ClipboardHolder getExistingClipboard()
    • addClipboard

      public void addClipboard(@Nonnull MultiClipboardHolder toAppend)
    • flushClipboard

      public void flushClipboard()
      Ensure the player's clipboard is flushed. (will only do something with clipboard-on-disk)
    • setClipboard

      public void setClipboard(@Nullable ClipboardHolder clipboard)
      Sets the clipboard.

      Pass null to clear the clipboard.

      Parameters:
      clipboard - the clipboard, or null if the clipboard is to be cleared
    • isToolControlEnabled

      @Deprecated public boolean isToolControlEnabled()
      Deprecated.
      The wand is now a tool that can be bound/unbound.
      Returns:
      true always - see deprecation notice
    • setToolControl

      @Deprecated public void setToolControl(boolean toolControl)
      Deprecated.
      The wand is now a tool that can be bound/unbound.
      Parameters:
      toolControl - unused - see deprecation notice
    • getBlockChangeLimit

      public int getBlockChangeLimit()
      Get the maximum number of blocks that can be changed in an edit session.
      Returns:
      block change limit
    • setBlockChangeLimit

      public void setBlockChangeLimit(int maxBlocksChanged)
      Set the maximum number of blocks that can be changed.
      Parameters:
      maxBlocksChanged - the maximum number of blocks changed
    • getTimeout

      public int getTimeout()
      Get the maximum time allowed for certain executions to run before cancelling them, such as expressions.
      Returns:
      timeout time, in milliseconds
    • setTimeout

      public void setTimeout(int timeout)
      Set the maximum number of blocks that can be changed.
      Parameters:
      timeout - the time, in milliseconds, to limit certain executions to, or -1 to disable
    • hasSuperPickAxe

      public boolean hasSuperPickAxe()
      Checks whether the super pick axe is enabled.
      Returns:
      status
    • enableSuperPickAxe

      public void enableSuperPickAxe()
      Enable super pick axe.
    • disableSuperPickAxe

      public void disableSuperPickAxe()
      Disable super pick axe.
    • toggleSuperPickAxe

      public boolean toggleSuperPickAxe()
      Toggle the super pick axe.
      Returns:
      whether the super pick axe is now enabled
    • getPlacementPosition

      public BlockVector3 getPlacementPosition(Actor actor) throws IncompleteRegionException
      Get the position use for commands that take a center point (i.e. //forestgen, etc.).
      Parameters:
      actor - the actor
      Returns:
      the position to use
      Throws:
      IncompleteRegionException - thrown if a region is not fully selected
    • setPlaceAtPos1

      public void setPlaceAtPos1(boolean placeAtPos1)
    • isPlaceAtPos1

      public boolean isPlaceAtPos1()
    • togglePlacementPosition

      public boolean togglePlacementPosition()
      Toggle placement position.
      Returns:
      whether "place at position 1" is now enabled
    • getBlockBag

      @Nullable public BlockBag getBlockBag(Player player)
      Get a block bag for a player.
      Parameters:
      player - the player to get the block bag for
      Returns:
      a block bag
    • getSnapshot

      @Nullable public Snapshot getSnapshot()
      Get the legacy snapshot that has been selected.
      Returns:
      the legacy snapshot
    • setSnapshot

      public void setSnapshot(@Nullable Snapshot snapshot)
      Select a legacy snapshot.
      Parameters:
      snapshot - a legacy snapshot
    • getSnapshotExperimental

      @Nullable public Snapshot getSnapshotExperimental()
      Get the snapshot that has been selected.
      Returns:
      the snapshot
    • setSnapshotExperimental

      public void setSnapshotExperimental(@Nullable Snapshot snapshotExperimental)
      Select a snapshot.
      Parameters:
      snapshotExperimental - a snapshot
    • getSuperPickaxe

      public BlockTool getSuperPickaxe()
      Get the assigned block tool.
      Returns:
      the super pickaxe tool mode
    • setSuperPickaxe

      public void setSuperPickaxe(BlockTool tool)
      Set the super pick axe tool.
      Parameters:
      tool - the tool to set
    • getTool

      @Nullable @Deprecated public Tool getTool(ItemType item, Player player)
      Deprecated.
      Get the tool assigned to the item.
      Parameters:
      item - the item type
      Returns:
      the tool, which may be null
    • getTool

      @Nullable @Deprecated public Tool getTool(ItemType item)
      Deprecated.
      This method is deprecated and only for compatibility with WorldEdit. Use getTool(BaseItem, Player) instead.
      Get the tool assigned to the item.
      Parameters:
      item - the item type
      Returns:
      the tool, which may be null
    • getTool

      @Nullable public Tool getTool(Player player)
    • getTool

      public Tool getTool(BaseItem item, Player player)
    • loadDefaults

      public void loadDefaults(Actor actor, boolean force)
    • getBrushTool

      @Deprecated public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException
      Deprecated.
      FAWE binds to the item, not the type - this allows brushes to persist, also deprecated in upstream
      Get the brush tool assigned to the item. If there is no tool assigned or the tool is not a brush tool, the slot will be replaced with the brush tool.
      Parameters:
      item - the item type
      Returns:
      the tool, or null
      Throws:
      InvalidToolBindException - if the item can't be bound to that item
    • getBrushTool

      public BrushTool getBrushTool(Player player) throws InvalidToolBindException
      Throws:
      InvalidToolBindException
    • getBrushTool

      public BrushTool getBrushTool(Player player, boolean create) throws InvalidToolBindException
      Throws:
      InvalidToolBindException
    • getBrushTool

      public BrushTool getBrushTool(BaseItem item, Player player, boolean create) throws InvalidToolBindException
      Throws:
      InvalidToolBindException
    • getBrush

      @Nullable public BrushTool getBrush(ItemType item)
      Get the brush tool assigned to this item.
      Parameters:
      item - the item type
      Returns:
      the brush tool assigned to the item type
    • setTool

      public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException
      Set the tool.
      Parameters:
      item - the item type
      tool - the tool to set, which can be null
      Throws:
      InvalidToolBindException - if the item can't be bound to that item
    • setTool

      public void setTool(Player player, @Nullable Tool tool) throws InvalidToolBindException
      Throws:
      InvalidToolBindException
    • setTool

      public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException
      Throws:
      InvalidToolBindException
    • isUsingInventory

      public boolean isUsingInventory()
      Returns whether inventory usage is enabled for this session.
      Returns:
      if inventory is being used
    • setUseInventory

      public void setUseInventory(boolean useInventory)
      Set the state of inventory usage.
      Parameters:
      useInventory - if inventory is to be used
    • getLastScript

      @Nullable public String getLastScript()
      Get the last script used.
      Returns:
      the last script's name
    • setLastScript

      public void setLastScript(@Nullable String lastScript)
      Set the last script used.
      Parameters:
      lastScript - the last script's name
    • tellVersion

      public void tellVersion(Actor actor)
      Tell the player the WorldEdit version.
      Parameters:
      actor - the actor
    • shouldUseServerCUI

      public boolean shouldUseServerCUI()
    • setUseServerCUI

      public void setUseServerCUI(boolean useServerCUI)
    • updateServerCUI

      public void updateServerCUI(Actor actor)
      Update server-side WorldEdit CUI.
      Parameters:
      actor - The player
    • dispatchCUIEvent

      public void dispatchCUIEvent(Actor actor, CUIEvent event)
      Dispatch a CUI event but only if the actor has CUI support.
      Parameters:
      actor - the actor
      event - the event
    • dispatchCUISetup

      public void dispatchCUISetup(Actor actor)
      Dispatch the initial setup CUI messages.
      Parameters:
      actor - the actor
    • dispatchCUISelection

      public void dispatchCUISelection(Actor actor)
      Send the selection information.
      Parameters:
      actor - the actor
    • describeCUI

      public void describeCUI(Actor actor)
      Describe the selection to the CUI actor.
      Parameters:
      actor - the actor
    • handleCUIInitializationMessage

      public void handleCUIInitializationMessage(String text, Actor actor)
      Handle a CUI initialization message.
      Parameters:
      text - the message
    • hasCUISupport

      public boolean hasCUISupport()
      Gets the status of CUI support.
      Returns:
      true if CUI is enabled
    • setCUISupport

      public void setCUISupport(boolean support)
      Sets the status of CUI support.
      Parameters:
      support - true if CUI is enabled
    • getCUIVersion

      public int getCUIVersion()
      Gets the client's CUI protocol version
      Returns:
      the CUI version
    • setCUIVersion

      public void setCUIVersion(int cuiVersion)
      Sets the client's CUI protocol version
      Parameters:
      cuiVersion - the CUI version
    • detectDate

      @Nullable public Calendar detectDate(String input)
      Detect date from a user's input.
      Parameters:
      input - the input to parse
      Returns:
      a date
    • createEditSession

      public EditSession createEditSession(Actor actor)
      Construct a new edit session.
      Parameters:
      actor - the actor
      Returns:
      an edit session
    • createEditSession

      public EditSession createEditSession(Actor actor, String command)
    • getSideEffectSet

      public SideEffectSet getSideEffectSet()
      Gets the side effect applier of this session.
      Returns:
      the side effect applier
    • setSideEffectSet

      public void setSideEffectSet(SideEffectSet sideEffectSet)
      Sets the side effect applier for this session
      Parameters:
      sideEffectSet - the side effect applier
    • hasFastMode

      @Deprecated public boolean hasFastMode()
      Deprecated.
      Checks if the session has fast mode enabled.
      Returns:
      true if fast mode is enabled
    • setFastMode

      @Deprecated public void setFastMode(boolean fastMode)
      Deprecated.
      Set fast mode.
      Parameters:
      fastMode - true if fast mode is enabled
    • getReorderMode

      public EditSession.ReorderMode getReorderMode()
      Gets the reorder mode of the session.
      Returns:
      The reorder mode
    • setReorderMode

      public void setReorderMode(EditSession.ReorderMode reorderMode)
      Sets the reorder mode of the session.
      Parameters:
      reorderMode - The reorder mode
    • getMask

      public Mask getMask()
      Get the mask.
      Returns:
      mask, may be null
    • getSourceMask

      public Mask getSourceMask()
      Get the mask.
      Returns:
      mask, may be null
    • setMask

      public void setMask(Mask mask)
      Set a mask.
      Parameters:
      mask - mask or null
    • setSourceMask

      public void setSourceMask(Mask mask)
      Set a mask.
      Parameters:
      mask - mask or null
    • setTextureUtil

      public void setTextureUtil(TextureUtil texture)
    • getTextureUtil

      public TextureUtil getTextureUtil()
      Get the TextureUtil currently being used
      Specified by:
      getTextureUtil in interface TextureHolder
    • getWandItem

      public String getWandItem()
      Get the preferred wand item for this user, or null to use the default
      Returns:
      item id of wand item, or null
    • getNavWandItem

      public String getNavWandItem()
      Get the preferred navigation wand item for this user, or null to use the default
      Returns:
      item id of nav wand item, or null
    • getLastDistribution

      public List<Countable<BlockState>> getLastDistribution()
      Get the last block distribution stored in this session.
      Returns:
      block distribution or null
    • setLastDistribution

      public void setLastDistribution(List<Countable<BlockState>> dist)
      Store a block distribution in this session.
    • getTransform

      public ResettableExtent getTransform()
    • setTransform

      public void setTransform(ResettableExtent transform)
    • onIdle

      public void onIdle()
      Call when this session has become inactive.

      This is for internal use only.