Klasse 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}
Siehe auch:
  • Methodendetails

    • getID

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

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

      public Vector3f getWorldPosition()
      Gets the world position of the sign.
      Gibt zurück:
      the object world position.
    • getChunkPositionX

      public int getChunkPositionX()
      Gets the x offset of the chunk (which contains the object).
      Gibt zurück:
      the x chunk offset.
    • getChunkPositionY

      public int getChunkPositionY()
      Gets the y offset of the chunk (which contains the object).
      Gibt zurück:
      the y chunk offset.
    • getChunkPositionZ

      public int getChunkPositionZ()
      Gets the z offset of the chunk (which contains the object).
      Gibt zurück:
      the z chunk offset.
    • getChunkPosition

      public Vector3i getChunkPosition()
      Gets the chunk position of the sign object.
      Gibt zurück:
      the sign object chunk coordinates.
    • getText

      public String getText()
      Gets the text of this sign. May be null.
      Gibt zurück:
      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.
      Parameter:
      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.
      Gibt zurück:
      the font.
    • setFont

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

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

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

      public TextAnchor getTextAnchor()
      Gets the text anchor, i.e the pivot positioni of the text.
      Gibt zurück:
      the text anchor of the text.
    • setTextAnchor

      public void setTextAnchor(TextAnchor anchor)
      Sets the text anchor, i.e the pivot position of the text.
      Parameter:
      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.
      Gibt zurück:
      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.
      Gibt zurück:
      the actual object representation in the world.
    • equals

      public boolean equals(Object o)
      Setzt außer Kraft:
      equals in Klasse Object
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse Object