Giter Site home page Giter Site logo

signgui's Introduction

SignGUI Build Maven Central Javadoc

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

Integration

Maven dependency:

<dependency>
    <groupId>de.rapha149.signgui</groupId>
    <artifactId>signgui</artifactId>
    <version>2.3.3</version>
</dependency>

Usage

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

SignGUI gui = SignGUI.builder()
    // set lines
    .setLines("§6Line 1", null, "§6Line 3")

    // set specific line, starting index is 0
    .setLine(3, "Line 4")

    // set the sign type
    .setType(Material.DARK_OAK_SIGN)

    // set the sign color
    .setColor(DyeColor.YELLOW)

    // set the handler/listener (called when the player finishes editing)
    .setHandler((p, result) -> {
        // get a speficic line, starting index is 0
        String line0 = result.getLine(0);

        // get a specific line without color codes
        String line1 = result.getLineWithoutColor(1);

        // get all lines
        String[] lines = result.getLines();

        // get all lines without color codes
        String[] linesWithoutColor = result.getLinesWithoutColor();

        if (line1.isEmpty()) {
            // The user has not entered anything on line 2, so we open the sign again
            return List.of(SignGUIAction.displayNewLines("§6Line 1", null, "§6Line 3", "Line 4"));
        }

        if (line1.equals("inv")) {
            // close the sign and open an inventory
            return List.of(
                // "this" = your JavaPlugin instance
                SignGUIAction.openInventory(this, Bukkit.createInventory(player, 27)),
                SignGUIAction.run(() -> player.sendMessage("Inventory opened!"))
            );
        }

        // Just close the sign by not returning any actions
        return Collections.emptyList();
    })

    // build the SignGUI
    .build();

// open the sign
gui.open(player);

// you can also open the sign for multiple players
gui.open(player2);

You don't have to call all methods. Only setHandler is mandatory.

By default, the handler is called by an asynchronous thread. You can change that behaviour by calling the method callHandlerSynchronously of the builder. An explanation for the different methods can be found on the Javadoc.

Limitations

The location of the sign

Especially in newer versions, I encountered the problem that the sign had to be near the player in order to edit it.
In older versions it worked by placing the sign at the bottom of the world but that does not seem to be the case anymore, in my tests anyway.

Because of that the default location is three blocks behind the player (three blocks in the opposite view direction). The only problem with this is that if you tell the api to redisplay the sign if the player e.g. typed something wrong, the player could slowly turn and then see the sign because there is a slight delay before the gui opens again and in that time the player can turn around a little bit.
You are, naturally, free to experiment with the location of the sign yourself.

Of course the sign is not really placed, it's just sent to the player, so other players won't see it.

Opening a sign after a player joins

Since the sign is not actually placed on the server, it can get overwritten when the chunks are sent to the player, which is the case when the player joins.

Because of that you may encounter the problem that the sign does not display any text when you send it to the player directly when he joins.
But even with a 20 tick (1 second) delay after the PlayerJoinEvent, the sign in my tests was empty sometimes.
I would recommend waiting at least a few more seconds before opening the gui.

Credits

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

signgui's People

Contributors

cyr1en avatar ebicep avatar rapha149 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

signgui's Issues

SignGUIResult does not exist

Hello,
I'm getting the following error when my plugin starts:

Plugin SimpleTrade v1.0-SNAPSHOT has failed to register events for class com.zayatv.simpletrade.listeners.InventoryClickListener because de/rapha149/signgui/SignGUIResult does not exist.

And this is the code I have with this api:

private void openSign(Player player)
{
    SignGUI gui = SignGUI.builder().setLine(0, "Type amount below").setHandler((p, result) -> {
        String input = result.getLineWithoutColor(1);
        plugin.tradeInv.openTradeInventory(player);

        return Collections.emptyList();
    }).build();
    inEconomyMenu.add(player);
    gui.open(player);
}

I don't know what might have caused this since my plugin is the only one on the server right now.

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.zayatv</groupId>
    <artifactId>simpletrade</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SimpleTrade</name>

    <properties>
        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>spigotmc-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
        </repository>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
        <repository>
            <id>dmulloy2-repo</id>
            <url>https://repo.dmulloy2.net/repository/public/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>1.20.4-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.github.MilkBowl</groupId>
            <artifactId>VaultAPI</artifactId>
            <version>1.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>de.rapha149.signgui</groupId>
            <artifactId>signgui</artifactId>
            <version>2.3.2</version>
        </dependency>
    </dependencies>
</project>

cannot find symbol method of(de.rapha149.signgui.SignGUIAction,de.rapha149.signgui.SignGUIAction)

Do I need to return a "List.of" or would it be valid if I return an "Arrays.asList" instead? Am I missing a class import? Please advise me as to what I maybe doing incorrectly and thank you in advance for any assistance.

Error-

java: cannot find symbol
symbol: method of(de.rapha149.signgui.SignGUIAction,de.rapha149.signgui.SignGUIAction)
location: interface java.util.List

section of code usage and imports-

import de.rapha149.signgui.*;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.cmptrwhz.dezomarket.gui.MainSelect;
import org.cmptrwhz.dezomarket.gui.GetSellingItm;

import java.util.*;

if (isNumeric(line0)) {
	// close the sign and open an inventory
	return List.of(
			// "this" = your JavaPlugin instance
			SignGUIAction.openInventory(this, SellItemGui.getInventory()),
			SignGUIAction.run(() -> player.sendMessage("Selling Item for: " + line0))
	);
}

sign gui keeps blinking

hi, I installed SignGUI and integrated into my custom plugin.

but SignGUI doesn't show any lines and it keeps blinking.
And my mouse cursor is fixed to the center of the sign and I can't type anything.

versions:
sign-gui: v1.9.1
test server: paper 1.19.3 (no other plugins)

code:
`
@eventhandler
public void onPlayerJoin(PlayerJoinEvent event) {

    Player player = event.getPlayer();
    SignGUI s = new SignGUI()
        .lines("t", "e", "s", "t")
        .onFinish((p, lines) -> {
            return lines;
        }).open(player);
}

`

thanks in advance.

[Bug] Teleporting when connecting with Bedrock over Geyser

API version

2.3.3

Server software and version

Purpur 1.20.4

Steps to reproduce

1. Open the SignGui using Bedrock client

Expected behaviour

Hopefully it doesn't have this teleportation effect. Teleportation is visual only, but the bedrock player cannot be teleported. In fact, if he types, for example, /spawn, he is teleported, but only for other players seeing him, in the bedrock player's view, he does not move.

What is actually happening?

image
In the bedrock player's view, you are teleported to a strange place, it seems like you were teleported to the sky after opening the sign.

Code snippets

No response

Any additional comments?

No response

[Problem] ClassNotFoundException for class Wrapper1_20_R3

API version

2.3.2

Server software and version

1.20.4 Paper

What are you trying to do?

I want to get text input from a sign so players deposit and withdraw money easier in my banking system

What do you need help with?

I get a ClassNotFoundException when trying to use the SignGUI for the Wrapper1_20_R3 class in module 1_20_R3.

I tried shading it, but I am not that experienced with shading in gradle.

https://pastes.dev/CK2y60Fp7D -- here is the error

Code snippets


shadowJar {
    // minimizes the libraries to only include classes you actually used
    minimize()

    // shade the signgui library
    dependencies {
        include(dependency("de.rapha149.signgui:signgui:2.3.2"))
        include(dependency("com.github.kangarko:Foundation:6.7.14"))
    }
}

assemble.dependsOn(shadowJar)
implementation("de.rapha149.signgui:signgui:2.3.2")

Any additional comments?

I am using JAVA 17

No sign gui is being displayed for the player

What are you trying to do?
I have an inventory gui displayed to the player. within the inventory gui I have a sign for the user to click on. The purpose of the sign is to get the numerical amount the player wants to sell their item for.

What do you need help with?
I am not getting any errors when the player clicks the sign but yet there is no sign being displayed.

Code snippets
Java plugin main

package org.cmptrwhz.dezomarket;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.cmptrwhz.dezomarket.dezcommands.DezCommands;
import org.cmptrwhz.dezomarket.dezevents.DezEvents;
import org.cmptrwhz.dezomarket.dezsql.Database;

import java.sql.SQLException;
import java.util.PrimitiveIterator;

public final class DezoMarket extends JavaPlugin {

    FileConfiguration config = this.getConfig();
    private static DezoMarket instance;
    private Database database;

    @Override
    public void onEnable() {
        // Plugin startup logic
        instance = this;
        this.saveDefaultConfig();

        String sqlhost = config.getString("host");
        String sqlport = config.getString("port");
        String sqldatabase = config.getString("database");
        String sqlusername = config.getString("username");
        String sqlpassword = config.getString("password");

        database = new Database(sqlhost, sqlport, sqldatabase, sqlusername, sqlpassword);

        try {
            database.initializeDatabase();
            System.out.println("[DezoMarket]: Initialize database successful.");
        }catch (SQLException e){
            e.printStackTrace();
            System.out.println("[DezoMarket]: Could not initialize database.");
        }

        getServer().getPluginManager().registerEvents(new DezEvents(), this);
        DezCommands commands = new DezCommands();
        getCommand("dezomarket").setExecutor(commands);
        getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[DezoMarket]: Plugin is enabled");
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
        instance = null;
        database.disconnect();
        getServer().getConsoleSender().sendMessage(ChatColor.RED + "[DezoMarket]: Plugin is disabled");
    }

    public static DezoMarket getInstance() {
        return instance;
    }

}

Registered events for when a user clicks on something in the inventory gui that is open.

package org.cmptrwhz.dezomarket.dezevents;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.cmptrwhz.dezomarket.gui.MainSelect;
import org.cmptrwhz.dezomarket.gui.GetSellingItm;
import org.cmptrwhz.dezomarket.gui.SignScreen;

public class DezEvents implements Listener {

    private GetSellingItm SellItemGui = new GetSellingItm();

    @EventHandler
    public void onClick(InventoryClickEvent e){
        if (e.getClickedInventory() == null) { return; }

        //GUI.MainSelect
        if (e.getClickedInventory().getHolder() instanceof MainSelect) {
            e.setCancelled(true);
            Player player = (Player) e.getWhoClicked();
            if (e.getCurrentItem() == null) { return; }
            if (e.getSlot() == 11){
                //selling an item, open screen to accept user item
                player.openInventory(SellItemGui.getInventory());
            }
            else if (e.getSlot() == 13){
                //claiming an item, open screen to show user items purchased
                player.closeInventory();
            }
            else if (e.getSlot() == 15){
                //managing items for sale, open screen to show user items they have for sale
                player.closeInventory();
            }
        }

        //GUI.GetSellingItm
        if (e.getClickedInventory().getHolder() instanceof GetSellingItm) {
            e.setCancelled(true);
            Player player = (Player) e.getWhoClicked();
            if (e.getCurrentItem() == null) { return; }
            if (e.getSlot() == 11 || e.getCurrentItem().getType() == Material.STONE_BUTTON){
                //take player item, save to yml, open GUI.GetSellingItm replace button with item
                player.closeInventory();
            } else if (e.getSlot() == 11 || e.getCurrentItem().getType() != Material.STONE_BUTTON) {
                //return item back to their inventory
                player.closeInventory();
            } else if (e.getSlot() == 13){
                //get amount from player
                player.closeInventory();
                SignScreen signScreen = new SignScreen(player);
                signScreen.MakeSign();
            }
            else if (e.getSlot() == 15){
                //save transaction to mysql, clean up player item yml file, return to mainselect
                player.closeInventory();
            }
        }

        //GUI.CLAIMSCREEN

        //GUI.MANAGESCREEN

    }

}

Sign creation class

package org.cmptrwhz.dezomarket.gui;

import de.rapha149.signgui.SignGUI;
import de.rapha149.signgui.SignGUIAction;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.cmptrwhz.dezomarket.DezoMarket;

import java.util.Arrays;
import java.util.Collections;

public class SignScreen {

    private GetSellingItm SellItemGui = new GetSellingItm();
    private Player player;

    public SignScreen(Player p){
        this.player = p;
    }

    public void MakeSign () {
        //https://github.com/Rapha149/SignGUI
        SignGUI signGUI = SignGUI.builder()
                // set lines
                .setLines(null, "§6Enter Selling Amount", "§6--------------", "§6-------")

                // set the sign type
                .setType(Material.SPRUCE_SIGN)

                // set the handler/listener (called when the player finishes editing)
                .setHandler((p, result) -> {
                    // get a speficic line, starting index is 0
                    String line0 = result.getLine(0);

                    if (isNumeric(line0)) {
                        // close the sign and open an inventory
                        return Arrays.asList(
                                SignGUIAction.openInventory(DezoMarket.getInstance(), SellItemGui.getInventory()),
                                SignGUIAction.run(() -> player.sendMessage("Selling Item for: " + line0))
                        );
                    }
                    // Just close the sign by not returning any actions
                    return Collections.emptyList();
                })

                // build the SignGUI
                .build();

        // open the sign
        signGUI.open(player);
    }

    private static boolean isNumeric(String strNum) {
        if (strNum == null) {
            return false;
        }
        try {
            Integer i = Integer.parseInt(strNum);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    }
}

Error messages
No errors are being reported during compile, none on player screen, and no errors in console.

Additional context
Add any other context about the problem here.

Non-Functional Repository

The provided repository in README.md is not usable.

<repository>
    <id>rapha149-repo</id>
    <url>https://rapha149-robot:&#103;&#104;&#112;&#95;&#53;&#68;&#122;&#76;&#52;&#107;&#103;&#107;&#98;&#52;&#117;&#81;&#57;&#70;&#109;&#117;&#75;&#49;&#84;&#114;&#71;&#56;&#57;&#103;&#102;&#114;&#51;&#85;&#84;&#89;&#49;&#113;&#113;&#104;&#54;&#104;@maven.pkg.github.com/Rapha149/*</url>
</repository>

The URL translates to https://rapha149-robot:[email protected]/Rapha149/* which is not a valid repository. Using JitPack is still the only working option. Looks like a personal token - Probably should be fixed.

Maven repository not found

When I attempt to add your dependency to my project I am getting an error stating your groupId is not being found.

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.