Coder Social home page Coder Social logo

signgui's Introduction

SignGUI

An api to get input text via a sign in Minecraft.
The api supports the Minecraft versions from 1.8 to 1.20.1.

Integration

Put the following in your pom.xml:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>
	<dependency>
	    <groupId>com.github.Despical.SignGUI</groupId>
	    <artifactId>signgui</artifactId>
	    <version>1.20.1</version>
	</dependency>

Usage

To open a sign editor gui for a player, do the following:

new SignGUI()
    .lines("§6Line 1", null, "§6Line 3")
    .line(3, "Line 4")
    .type(Material.DARK_OAK_SIGN)
    .color(DyeColor.YELLOW)
    .stripColor()
    .onFinish((p, lines) -> {
        if (!lines[1].isEmpty() && !lines[3].isEmpty()) {
            player.sendMessage("Line 2: " + lines[1] + "\nLine 4:" + lines[3]);
            return null;
        } else
            // Due to stripColor the sign won't display line 1 and 3 in orange after it has been closed once.
            return lines;
    }).open(player);

You don't have to call all methods. Only onFinish and open are mandatory.
Here is the explanation of the different methods:

lines(String... lines)

Sets the lines to show when the sign is opened. You don't have to pass 4 strings. The default is 4 empty lines. You can pass null for an empty line.

line(int index, String line)

Sets the line at the specific index. The index has to be between 0 and 3. You can pass null for an empty line.

type(Material type)

Sets the type of the sign. The default is OAK_SIGN.

color(DyeColor color)

Sets the color of the text. The default is BLACK. You can also use color codes to color your text. The cursor will be always in the given color, however. The returned lines will not be colored in this color.

stripColor()

Executes stripColor(true)

stripColor(true)

If enabled, the returned lines will not have any colors. Colors stated by the plugin and by players will be stripped (Players can use color codes by pasting a §)

signLocation(Location)

Sets the location of the sign. Default is the player's coordinates, but y = 1.

onFinish(Function<String[], String[]>

Same as onFinish(BiFunction<Player, String[], String[]> but without the player.
Overrides onFinish(BiFunction<Player, String[], String[]>

onFinish(BiFunction<Player, String[], String[]>

Sets the function which will be executed when the player finishes editing. You can return null or new lines. If you return new lines, the sign editor will be opened with these lines again.
Overrides onFinish(Function<String[], String[]>
Please note that due to packet listening the function will be executed asynchronously. If you want to execute synchronous actions such as inventory handling or block placing, you have to do that in a Bukkit task.

open(Player player)

Opens the sign editor for the player. You can call this method multiple times.

Credits

This project structure was inspired by WesJD's AnvilGUI and I used some code from Cleymax's SignGUI.

signgui's People

Contributors

rapha149 avatar despical avatar ebicep avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.