Vault 无法正确加载。 [PaperSpigot 1.21.1]

问题描述 投票:0回答:1

所以我正在为Paper 1.21.1 编写一个minecraft 插件。这个概念是 PaySign,因此您可以放置一个特殊的标志,当您右键单击它时,它会将钱发送给另一个玩家。

我将 VaultAPI 和

depend: Vault
的依赖项添加到我的plugin.yml 文件中,但它仍然不起作用。

其他插件:

  • AuthMe-5.6.0
  • EssentialsX-2.21.0-dev
  • LogBlock-1.19.0.0
  • SkinsRestorer 最新
  • 避难所1.17.3

启动服务器后生成的堆栈跟踪:

java.lang.NoClassDefFoundError: net/milkbowl/vault/economy/Economy
        at paysignssr-1.0-SNAPSHOT.jar/com.github.hc12.paysignssr.PaySignSSR.setupEconomy(PaySignSSR.java:27) ~[paysignssr-1.0-SNAPSHOT.jar:?]
        at paysignssr-1.0-SNAPSHOT.jar/com.github.hc12.paysignssr.PaySignSSR.onEnable(PaySignSSR.java:18) ~[paysignssr-1.0-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:288) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:109) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:520) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.CraftServer.enablePlugin(CraftServer.java:640) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:589) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:754) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:516) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:329) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1215) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:330) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.ClassNotFoundException: net.milkbowl.vault.economy.Economy
        at io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader.loadClass(PaperPluginClassLoader.java:146) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader.loadClass(PaperPluginClassLoader.java:107) ~[paper-1.21.1.jar:1.21.1-52-e08e667]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?]
        ... 14 more

代码库

PaySignSSR.java

package com.github.hc12.paysignssr;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public final class PaySignSSR extends JavaPlugin {

    // Declare the econ variable here
    private static Economy econ = null;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new SignHandler(), this);
        getServer().getPluginManager().registerEvents(new SignClickEvent(), this);
        getServer().broadcastMessage("PaySign Loaded");

        if (!setupEconomy()) {
            getLogger().severe("Vault dependency not found or no economy plugin available! Disabling plugin.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
    }

    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }

    public static Economy getEconomy() {
        return econ;
    }
}

SignHandler.java

package com.github.hc12.paysignssr;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.jetbrains.annotations.NotNull;


public class SignHandler implements Listener {

    @EventHandler
    public void onSignChange(SignChangeEvent event) {
        String firstLine = event.getLine(0);
        String secondLine = event.getLine(1);
        String thirdLine = event.getLine(2);
        String fourthLine = event.getLine(3);

        if (firstLine.equalsIgnoreCase("[PaySign]") && secondLine != null && thirdLine != null) {
            event.setLine(0, "§2[PaySign]");
            String target = secondLine;
            Integer amount = Integer.parseInt(thirdLine);
        }
    }
}

SignClickEvent.java

package com.github.hc12.paysignssr;

import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class SignClickEvent implements Listener {
    @EventHandler
    public void OnPlayerInteract(PlayerInteractEvent event) {
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            Block clickedBlock = event.getClickedBlock();
            if (clickedBlock != null && (clickedBlock.getType() == Material.OAK_SIGN ||
                    clickedBlock.getType() == Material.OAK_WALL_SIGN ||
                    clickedBlock.getType() == Material.BIRCH_SIGN ||
                    clickedBlock.getType() == Material.BIRCH_WALL_SIGN ||
                    clickedBlock.getType() == Material.SPRUCE_SIGN ||
                    clickedBlock.getType() == Material.SPRUCE_WALL_SIGN ||
                    clickedBlock.getType() == Material.JUNGLE_SIGN ||
                    clickedBlock.getType() == Material.JUNGLE_WALL_SIGN ||
                    clickedBlock.getType() == Material.ACACIA_SIGN ||
                    clickedBlock.getType() == Material.ACACIA_WALL_SIGN ||
                    clickedBlock.getType() == Material.DARK_OAK_SIGN ||
                    clickedBlock.getType() == Material.DARK_OAK_WALL_SIGN ||
                    clickedBlock.getType() == Material.CRIMSON_SIGN ||
                    clickedBlock.getType() == Material.CRIMSON_WALL_SIGN ||
                    clickedBlock.getType() == Material.WARPED_SIGN ||
                    clickedBlock.getType() == Material.WARPED_WALL_SIGN ||
                    clickedBlock.getType() == Material.MANGROVE_SIGN ||
                    clickedBlock.getType() == Material.MANGROVE_WALL_SIGN)) {
                Sign sign = (Sign) clickedBlock.getState();
                String[] lines = sign.getLines();
                if (lines[0] == "§2[PaySign]" && lines[1] != null && lines[2] != null) {
                    Player player = event.getPlayer();
                    Player target = Bukkit.getPlayer(lines[1]);
                    Double amount = Double.parseDouble(lines[2]);
                    Integer time = Integer.parseInt(lines[3]);
                    if (time == null) {
                        time = 1000;
                    } else {
                        time = time * 1000;
                    }
                    Economy econ = PaySignSSR.getEconomy();
                    if (econ.getBalance(player) < amount) {
                        player.sendMessage("§cJesteś za biedny!");
                    } else {
                        econ.withdrawPlayer(player, amount);
                        econ.depositPlayer(target, amount);
                        player.sendMessage("§aZapłaciłeś " + ChatColor.GOLD + amount + "§agraczowi " + ChatColor.WHITE + target);

                    }
                }
            }
        }
    }
}

pom.xml

<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.github.hc12</groupId>
    <artifactId>paysignssr</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>paysignssr</name>

    <properties>
        <java.version>21</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.13.0</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.5.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>papermc-repo</id>
            <url>https://repo.papermc.io/repository/maven-public/</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>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>io.papermc.paper</groupId>
            <artifactId>paper-api</artifactId>
            <version>1.21.1-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>
    </dependencies>
</project>

插件.yml

name: paysignssr
version: '1.0-SNAPSHOT'
main: com.github.hc12.paysignssr.PaySignSSR
api-version: '1.21'
depend: Vault

我尝试重新安装 Vault 并检查了其他一些东西,但没有任何效果:/

java maven plugins minecraft spigot
1个回答
0
投票

depend
文件中的
plugin.yml
键仅允许数组输入。

depend: Vault
替换为
depend: [Vault]
即可解决您的问题。

另外:确保 Vault 也正确加载,并提供完整的日志以及输出

/plugins
以查看插件是否正确加载,如果 Vault 未加载,这可以解释您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.