Resource AnvilGUI - Easily use anvil guis to get a user's input

Discussion in 'Spigot Plugin Development' started by WesJD, May 8, 2016.

  1. Just released version 1.3.0. Adds support for supplying a fully custom ItemStack to be used in the input slot of the anvil. I also added better documentation on methods in the readme.
     
  2. Hey, I have a Problem with your ressource:
    Using it on a PaperMC 1.15.2 Server and I get the following error on Plugin load:

    Code (Text):
    [15:14:24 ERROR]: [SkiftyRPG] Plugin SkiftyRPG v1.0.0 has failed to register events for class Skifty.SkiftyRPG.CustomWeapons.weaponCmd because net/wesjd/anvilgui/AnvilGUI$Response does not exist.
     
    Here are my repositories and dependencies if it helps to find the problem:
    Code (Text):
        <repositories>
        <!-- This adds the Spigot Maven repository to the build -->
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.15.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
    <dependency>
        <groupId>com.github.WesJD.AnvilGUI</groupId>
        <artifactId>anvilgui</artifactId>
        <version>8853507add</version>
    </dependency>

    </dependencies>
     
  3. please use the latest build from the jitpack.io which is;
    Code (Text):
    <dependency>
        <groupId>com.github.WesJD.AnvilGUI</groupId>
        <artifactId>anvilgui</artifactId>
        <version>99a504a3bb</version>
    </dependency>
     
  4. Same result
     
  5. Anyone know how I can use the AnvilGUI.Builder to get a variable populated and have the plugin not continue on it's merry way before getting the answer from the user? So I have a sign listener which checks if the user enters the word [shop] on the first line of the sign and if it does it calls the AnvilGUI to get the name of the shop. Problem is the code continues on whilst the GUI is open, so the name variable is an empty string when setting up the shop. I know I could get the shop name from the sign also, but the anvil approach is used everywhere in the plugin to get other things, so I will need to make it a generic routine at some point.

    Here's my test script.
    Code (Text):
    @EventHandler
        public void onSign(final SignChangeEvent e) {

            p = e.getPlayer();

            log.log(Level.INFO, "[PluginTest] debug - line0: " + e.getLine(0));
            if (e.getLine(0).equalsIgnoreCase("[shop]")) {

                ItemStack it = new ItemStack(Material.PAPER);
                ItemMeta meta = it.getItemMeta();
                meta.setDisplayName("Enter shop name");
                meta.setLore(Arrays.asList("Click here to confirm"));
                it.setItemMeta(meta);

                        AnvilGUI gui = new AnvilGUI.Builder().onClose(p -> {
                            p.sendMessage("Shop will be called " + name);
                        }).onComplete((p, shopname) -> {
                            name = shopname;
                            return AnvilGUI.Response.close();
                        }).preventClose()
                        .text("Type Name/Amount").title("Enter your shop name").item(it)
                        .plugin(Bukkit.getPluginManager().getPlugin("PluginTest")).open(p);

            }

            log.log(Level.INFO, "[PluginTest] debug - name = " + name);

            ...
            rest of code to set up shop
            ...

        }
    Thanks for any help!

    F451
     
  6. AnvilGUI builder has async completion interface. If you want to do something after input in gui completed, you should place completion code in onComplete(...) lambda of gui instance.

    Code (Text):

                         AnvilGUI gui = new AnvilGUI.Builder().onClose(p -> {
                            p.sendMessage("Shop will be called " + name);
                        }).onComplete((p, shopname) -> {
                            name = shopname;
                            /**
                              * !!! PLACE HERE your completion code !!!
                              **/
                            return AnvilGUI.Response.close();
                        }).preventClose()
                        .text("Type Name/Amount").title("Enter your shop name").item(it)
                        .plugin(Bukkit.getPluginManager().getPlugin("PluginTest")).open(p);

     
     
    • Informative Informative x 1
  7. Oh my. How simple! Thanks a lot CraftCoder.
     
  8. This is awesome and I have used it but, could you do the same for writable book or is it too much to ask? For long string inputs you have a limit and with signs you have the same problem
     
  9. Same happens to me. And I used the lastest version :/
     
  10. You might need to include the dependent jars in your plugin jar. I had a similar error at first and then used the maven-shade-plugin to automatically include the AnvilGUI dependent jar, since I am using maven.
     
  11. I am also using maven but I don't know how to do that. Could you tell me how?
     
  12. You should be able to achieve it with this in your plugins section of your pom.xml

    Code (Text):
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.4</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
     
  13. upload_2020-7-1_10-19-22.png
    check this out http://maven.apache.org/guides/introduction/introduction-to-repositories.html
    and this http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
     
  14. copy from here
    https://github.com/spigotplugins/anvil-login/blob/master/pom.xml
     
  15. please just compare it with yours. spend your time to understand how I made and what's wrong with your pom.xml.
     
  16. still, you don't compare your pom with mine. look closely;
    upload_2020-7-1_11-35-28.png
     
  17. I try to learn how you can write your pom.xml with these links and I don't want to say the exact answer, I want to teach you how you can learn `ANYTHING`
    check this out http://maven.apache.org/guides/introduction/introduction-to-repositories.html
    and this http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
    but you're still don't listen me, anyways, I give up. forget my posts.
     
  18. you can't learn anything with this mentality.
    Code (Text):
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>Azu</groupId>
        <artifactId>Azu</artifactId>
        <version>0.0.1-SNAPSHOT</version>

        <repositories>
            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>com.github.WesJD.AnvilGUI</groupId>
                <artifactId>anvilgui</artifactId>
                <version>master-SNAPSHOT</version>
            </dependency>
        </dependencies>

        <build>
            <sourceDirectory>src</sourceDirectory>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</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>
                                <minimizeJar>true</minimizeJar>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    </project>
     
  19. https://google.com/search?q=your+question+here
    ^ that's the answer to every question you'll ever ask

    EDIT: your posts made my day xd they are hilarious
     
    • Funny Funny x 1