Class PlayerSelectFileEvent

java.lang.Object
net.risingworld.api.events.Event
net.risingworld.api.events.player.PlayerEvent
net.risingworld.api.events.player.ui.PlayerSelectFileEvent

public final class PlayerSelectFileEvent extends PlayerEvent
Called when a player selected a file in the file browser (or closed the file browser without selecting a file). The file browser can be opened via Player.showFileBrowser(java.lang.String, java.lang.String[], net.risingworld.api.callbacks.Callback). If a callback was provided there, the callback receives the same event object before the event is triggered.
See Also:

Example: Let the player select a model file
1player.showFileBrowser("Select a model", new String[]{"fbx", "obj"}, (PlayerSelectFileEvent event) -> {
2 if (event.isAborted()) {
3 player.showStatusMessage("No file selected", 3);
4 return;
5 }
6 ClientFile file = event.getFile();
7 player.showStatusMessage("Selected " + file.getName() + " (" + file.getSize() + " bytes)", 3);
8});
  • Method Details

    • getFile

      public ClientFile getFile()
      Gets the file the player has selected. The returned object stays valid after the event (until the player disconnects or the plugins are reloaded).
      Returns:
      the selected file, or null if the player closed the file browser without selecting a file.
    • isAborted

      public boolean isAborted()
      Gets whether or not the player closed the file browser without selecting a file. This is also the case if the platform of the player has no file system (consoles), if the selected file did not match the provided file extensions, or if it could not be read by the player.
      Returns:
      true if no file was selected, false if not.
    • isTooLarge

      public boolean isTooLarge()
      Gets whether or not the selected file exceeds the size limit of the file browser (see Player.showFileBrowser(java.lang.String, java.lang.String[], long, net.risingworld.api.callbacks.Callback) and the server limit Plugins_MaxFileUploadSize). In this case the file is still available via getFile() (name and size), but it has no checksum and cannot be uploaded.
      Returns:
      true if the file is too large, false if not.
    • requestFileUpload

      public void requestFileUpload(String targetDirectory, long maxBytes, Callback<PlayerFileUploadEvent> callback)
      Uploads the selected file into the provided directory on the server. This is just a shortcut for getFile().upload(targetDirectory, maxBytes, callback), see ClientFile.upload(java.lang.String, long, net.risingworld.api.callbacks.Callback). Note that the upload can also be started at a later time (the ClientFile object stays valid).
      Parameters:
      targetDirectory - the directory on the server where the file should be stored.
      maxBytes - the max allowed file size (bytes). Set to 0 to use the limit of the server.
      callback - optional callback which is invoked once the upload is finished. May be null.
      Throws:
      IllegalStateException - if no file was selected (see isAborted()), or another upload of this player is still active.
      IllegalArgumentException - if the target directory is null, empty or not a valid path.