WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code
MIT License
466 stars 111 forks source link

gradle error #293

Closed Flouzl closed 9 months ago

Flouzl commented 9 months ago

hi, i'm trying to create an anvil with gradle but it doesn't work can you help

my code:

build.gradle

`
plugins {
    id 'java'
    id("com.github.johnrengelman.shadow") version "8.1.1"
}

repositories {
    mavenCentral()
    mavenLocal()
    maven {
        name = "codemc-snapshots"
        url = ("https://repo.codemc.io/repository/maven-snapshots/")
    }
}

dependencies {
    compileOnly ("net.wesjd:anvilgui:1.9.0-SNAPSHOT")
}
`

code for open anvil :

`package me.Plugin;

import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

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

public class Commandrename implements CommandExecutor {
    private final Plugin plugin;

    public Commandrename(Plugin plugin) {
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;

            new AnvilGUI.Builder()
                    .onClose(stateSnapshot -> {
                        stateSnapshot.getPlayer().sendMessage("You closed the inventory.");
                    })
                    .onClick((slot, stateSnapshot) -> { // Either use sync or async variant, not both
                        if(slot != AnvilGUI.Slot.OUTPUT) {
                            return Collections.emptyList();
                        }

                        if(stateSnapshot.getText().equalsIgnoreCase("you")) {
                            stateSnapshot.getPlayer().sendMessage("You have magical powers!");
                            return Arrays.asList(AnvilGUI.ResponseAction.close());
                        } else {
                            return Arrays.asList(AnvilGUI.ResponseAction.replaceInputText("Try again"));
                        }
                    })
                    .preventClose()                                                    //prevents the inventory from being closed
                    .text("What is the meaning of life?")                              //sets the text the GUI should start with
                    .title("Enter your answer.")                                       //set the title of the GUI (only works in 1.14+)
                    .plugin(plugin)                                          //set the plugin instance
                    .open(player);                                                   //opens the GUI for the player provided

        }
        return true;
    }
}
`

my error :

[19:42:27] [Server thread/ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'countryrename' in plugin Plugin v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] at org.bukkit.craftbukkit.v1_20_R2.CraftServer.dispatchCommand(CraftServer.java:879) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:50) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:265) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:?] at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:320) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:304) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1827) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.network.PlayerConnection.lambda$15(PlayerConnection.java:1789) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.util.thread.IAsyncTaskHandler.b(SourceFile:67) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source) ~[?:?] at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:156) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1133) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.util.thread.IAsyncTaskHandler.x(SourceFile:130) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.bg(MinecraftServer.java:1112) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1105) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.util.thread.IAsyncTaskHandler.bp(SourceFile:115) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.u_(MinecraftServer.java:1088) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1000) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:298) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3886-Spigot-17ca32d-f0661c3] at java.lang.Thread.run(Unknown Source) ~[?:?] Caused by: java.lang.NoClassDefFoundError: net/wesjd/anvilgui/AnvilGUI$Builder at me.Plugin.Commandrename.onCommand(Commandrename.java:37) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] ... 23 more Caused by: java.lang.ClassNotFoundException: net.wesjd.anvilgui.AnvilGUI$Builder at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:147) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:99) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:?] at me.Plugin.Commandrename.onCommand(Commandrename.java:37) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?] ... 23 more

command for create plugin :

gradle shadowJar

portlek commented 9 months ago

use implementation instead of compileOnly.

Flouzl commented 9 months ago

thanks now it works