Class Sign

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

public class Sign extends Object
Represents a sign object.
Example: Heal a player when he interacts with specific signs
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 using is a sign
11 if (def.type == Objects.Type.Sign) {
12 //Get the related sign
13 Sign sign = World.getSign(event.getGlobalID());
14
15 //It's always a good idea to check if sign isn't null...
16 if(sign != null){
17 //Now we check if the text equals "HEAL"
18 if(sign.getText().equals("HEAL")){
19 //Heal the player, i.e set his health to 100
20 event.getPlayer().setHealth(100);
21
22 //Cancel the event, so the player cannot edit the sign (optional)
23 event.setCancelled(true);
24 }
25 }
26 }
27}
See Also:
  • Method Details

    • getID

      public long getID()
      Gets the global, unique ID of the sign.
      Returns:
      the unique object ID.
    • isValid

      public boolean isValid()
      Checks if this instance is still valid.
      Returns:
      true if the instance is valid, false if not.
    • getWorldPosition

      public Vector3f getWorldPosition()
      Gets the world position of the sign.
      Returns:
      the object world position.
    • getChunkPositionX

      public int getChunkPositionX()
      Gets the x offset of the chunk (which contains the object).
      Returns:
      the x chunk offset.
    • getChunkPositionY

      public int getChunkPositionY()
      Gets the y offset of the chunk (which contains the object).
      Returns:
      the y chunk offset.
    • getChunkPositionZ

      public int getChunkPositionZ()
      Gets the z offset of the chunk (which contains the object).
      Returns:
      the z chunk offset.
    • getChunkPosition

      public Vector3i getChunkPosition()
      Gets the chunk position of the sign object.
      Returns:
      the sign object chunk coordinates.
    • getText

      public String getText()
      Gets the text of this sign. May be null.
      Returns:
      the text of this sign.
    • setText

      public void setText(String text)
      Sets the text of this sign. To create a new line, use the escape character \n.
      Parameters:
      text - the text you want to set.
      Example: Set a red text on the sign
      1sign.setText("<color=red>Hello World!</color>");

      Example: Set a colored multi-line text on the sign
      1sign.setText("<color=red>This is a red text line!\n<color=green>This is a green text line!</color>");
    • getFont

      public Font getFont()
      Gets the font that is currently used by the sign.
      Returns:
      the font.
    • setFont

      public void setFont(Font font)
      Sets the font for this sign.
      Parameters:
      font - the new font.
    • getFontSize

      public float getFontSize()
      Gets the font size of the sign. By default it's 1.0
      Returns:
      the font size of the sign.
    • setFontSize

      public void setFontSize(float size)
      Sets a new font size for the sign.
      Parameters:
      size - the new font size.
    • getTextAnchor

      public TextAnchor getTextAnchor()
      Gets the text anchor, i.e the pivot positioni of the text.
      Returns:
      the text anchor of the text.
    • setTextAnchor

      public void setTextAnchor(TextAnchor anchor)
      Sets the text anchor, i.e the pivot position of the text.
      Parameters:
      anchor - the new text anchor you want to set for the text.
    • getLastModifyPlayerDbID

      public int getLastModifyPlayerDbID()
      Gets the database id of the player who last modified the sign text.
      Returns:
      the player database id or -1 if the text was set by the game or the API.
    • getRelatedObject

      public ObjectElement getRelatedObject()
      Gets the object element which represents this meta object in the world.
      Returns:
      the actual object representation in the world.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object