SignApi icon

SignApi -----

Used to open Sgin-gui with predetermined text which will be recognized from the Server when closed



What it does:
With this api you can open a SignGui wtih predetermend text which can be read with the SignChangeEvent.

How it works:
The api scans the blocks at hight -63 in a square field(200x200) around the player. When a block at hight -63 is bedrock a sign is placed under it which is then edited and opened.

Custom event:
When the sign is closed by the player the api will call an custom event called CustomSignEditEvent.
-When this event is cancelled the sign will not be replaced with the previous material.
-When you set the previous material of the event (event.setPreviousMaterial(<Material>);) the sign will be replaced with this material.


Usage:
To use this api download it, add it to your buildpath.
I strongly recommend adding it also to your plugin folder for less code and safer approach.

Code examples:
Add Dependency to your plugin.yml:

Code (Text):
depend: [SignApi]


Examplme code with api in plugin folder:

Code (Text):
import org.bukkit.entity.Player;

import de.officeryoda.SignApi;

public class exampleClass {
 
    private void openSignGui(Player player, String[] lines) {
        if(lines.length == 0)
            SignApi.openNewSign(player, "text in line 1", "text in line 2", "text in line 3", "text in line 4");
        else
            SignApi.openNewSign(player, lines);
    }
}


Examplme code with api NOT in plugin folder:
Code (Java):
import java.util.HashMap ;
import java.util.Map ;

import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.block.SignChangeEvent ;

import de.officeryoda.SignApi ;

public class exampleClass implements Listener {
    Map <Location, Material > signs ;

    public exampleClass ( ) {
        signs = new HashMap <> ( ) ;
    }
 
    public void openSignGui (Player player, String [ ] lines ) {
        if (lines. length == 0 )
            signs. putAll (SignApi. openNewSign (player, "text in line 1", "text in line 2", "text in line 3", "text in line 4" ) ) ;
        else
            signs. putAll (SignApi. openNewSign (player, lines ) ) ;
    }
 
    @EventHandler
    public void onSignChange (SignChangeEvent event ) {
        Location location = event. getBlock ( ). getLocation ( ) ;
        if ( !signs. containsKey (location ) ) //checks if the sign is a sign placed by the plugin/api
            return ;

        location. getWorld ( ). getBlockAt (location ). setType (signs. get (location ) ) ; //replaces the sign with the block which was there first
        signs. remove (location, signs. get (location ) ) ; //removes sign from list
    }
}
Read the sign with api in plugin folder:
Code (Java):
import org.bukkit.ChatColor ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;

import de.officeryoda.CustomSignEditEvent ;
import de.officeryoda.SignApi ;

public class exampleClass implements Listener {

    public void openSignGui (Player player, String [ ] lines ) {
        if (lines. length == 0 )
            SignApi. openNewSign (player, "text of line 1", "text of line 2", "text of line 3", "text of line 3" ) ;
        else
            SignApi. openNewSign (player, lines ) ;
    }

    @EventHandler
    public void onSignChange (CustomSignEditEvent event ) {
        Player player = event. getPlayer ( ) ; //gets the player
        String [ ] lines = event. getLines ( ) ; //gets the lines

        for ( int i = 0 ; i < lines. length ; i ++ ) {
            player. sendMessage (ChatColor. GRAY + "line " + i + ": " + ChatColor. WHITE + lines [i ] ) ;
        }
        return ;
    }
}

Read the sign with api NOT in plugin folder:
Code (Java):
import java.util.HashMap ;
import java.util.Map ;

import org.bukkit.ChatColor ;
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.block.SignChangeEvent ;

import de.officeryoda.SignApi ;

public class exampleClass implements Listener {
    Map <Location, Material > signs ;

    public exampleClass ( ) {
        signs = new HashMap <> ( ) ;
    }
 
    public void openSignGui (Player player, String [ ] lines ) {
        if (lines. length == 0 )
            signs. putAll (SignApi. openNewSign (player, "text of line 1", "text of line 2", "text of line 3", "text of line 3" ) ) ;
        else
            signs. putAll (SignApi. openNewSign (player, lines ) ) ;
    }
 
    @EventHandler
    public void onSignChange (SignChangeEvent event ) {
        Player player = event. getPlayer ( ) ; //gets the player
        String [ ] lines = event. getLines ( ) ; //gets the lines
        Location location = event. getBlock ( ). getLocation ( ) ; //gets the location

        if (signs. containsKey (location ) ) { //checks if the sign is a sign placed by the plugin/api
            for ( int i = 0 ; i < lines. length ; i ++ ) {
                player. sendMessage (ChatColor. GRAY + "line " + i + ": " + ChatColor. WHITE + lines [i ] ) ; //send the lines
            }
            return ;
        }
        return ;
    }
}
[​IMG]
Resource Information
Author:
----------
Total Downloads: 71
First Release: Jan 13, 2022
Last Update: Jan 13, 2022
Category: ---------------
All-Time Rating:
1 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings