Klasse CustomImage

java.lang.Object
net.risingworld.api.objects.CustomImage

public class CustomImage extends Object
Represents a custom image (i.e a "poster").
Example: Find out who uploaded a particular custom image
1//We're going to listen for the "ObjectInteractionEvent". This is triggered when
2//a player interacts with an object (i.e when he presses the interaction key F
3//while looking at the object).
4
5@EventMethod
6public void onObjectInteraction(PlayerObjectInteractionEvent event) {
7 //Get the object definition
8 Objects.ObjectDefinition def = event.getObjectDefinition();
9
10 //Check if the object we're looking at is a poster
11 if (def.type == Objects.Type.Poster) {
12 //Get the related custom image. The ID is stored in the info field (!)
13 ObjectElement o = event.getObject();
14 CustomImage image = Server.getCustomImage(o.getInfo());
15
16 //It's always a good idea to perform a null check
17 if (image != null) {
18 //Get player database ID from the image...
19 int dbID = image.getPlayerDbID();
20
21 //Check if player is currently online
22 Player player = Server.getPlayerByDbID(dbID);
23
24 //If player is not null, he's currently online
25 if (player != null) {
26 System.out.println("Image owner " + player.getName() + " is currently online!");
27 }
28 //Else if player is offline, we just get his name form the server
29 else {
30 String playerName = Server.getLastKnownPlayerName(dbID);
31 System.out.println("Image owner " + playerName + " is currently offline!");
32 }
33 }
34 }
35}
Siehe auch:
  • Methodendetails

    • getID

      public long getID()
      Gets the global, unique ID of the custom image.
      Gibt zurück:
      the unique image ID.
    • isValid

      public boolean isValid()
      Checks if this instance is still valid.
      Gibt zurück:
      true if the instance is valid, false if not.
    • getPlayerDbID

      public int getPlayerDbID()
      Gets the database ID of the player who uploaded this image.
      Gibt zurück:
      the player database ID who uploaded the image, or -1 if this image was not uploaded by a player.
    • getName

      public String getName()
      Gets the original file name of the image.
      Gibt zurück:
      the original image file name.
    • getExtension

      public String getExtension()
      Gets the extension of the original image file (e.g ".png" or ".jpg" etc).
      Gibt zurück:
      the original image extension.
    • getChecksum

      public String getChecksum()
      Gets an SHA1 hash of the raw image texture data.
      Gibt zurück:
      the checksum of the texture data.
    • getWidth

      public int getWidth()
      Gets the width of the texture.
      Gibt zurück:
      the texture width in pixels.
    • getHeight

      public int getHeight()
      Gets the height of the texture.
      Gibt zurück:
      the texture height in pixels.
    • getTextureFormat

      public String getTextureFormat()
      Gets the internal texture format. Typically images are compressed, so the format is usually DXT1 (for images without alpha channel) or DXT5.
      Gibt zurück:
      the internal texture format.
    • getCreationDate

      public long getCreationDate()
      Gets the creation/upload date of the image as a timestamp in milliseconds
      Gibt zurück:
      a timestamp (milliseconds) representing the original upload date of the image.
    • getLastAccess

      public long getLastAccess()
      Gets a timestamp in milliseconds representing the time when the last access to this image occurred. Access via API is not taken into account.
      Gibt zurück:
      a timestamp (milliseconds) representing the last access date of the image (e.g when a player requested the image etc).
    • getRawTextureData

      public byte[] getRawTextureData()
      Gets the raw texture data, depending on the texture format (see getTextureFormat()). It typically also contains mipmaps.
      Gibt zurück:
      the raw texture data.
    • setRawTextureData

      public void setRawTextureData(int width, int height, String format, byte[] data)
      Sets the raw texture data. It's highly recommendable to use a compressed texture format like DXT1 or DXT5.
      Parameter:
      width - the new width of the texture.
      height - the new height of the texture.
      format - the texture data format.
      data - the raw texture data.
      Example: Copy texture data from one image to another
      1//Our two images
      2CustomImage image1 = Server.getCustomImage(...);
      3CustomImage image2 = Server.getCustomImage(...);
      4
      5//Get texture data, width, height and format from image 1
      6int width = image1.getWidth();
      7int height = image1.getHeight();
      8String format = image1.getTextureFormat();
      9byte[] data = image1.getRawTextureData();
      10
      11//Assign data to image2
      12image2.setRawTextureData(width, height, format, data);
    • getTexturePixelData

      public int[] getTexturePixelData()
      Gets the image pixel data. Note: This is a rather expensive call (because it internally parses and converts the texture data first), so it's recommendable to call this once and cache the result!
      Gibt zurück:
      an int array containing the RGBA pixel data.