【问题标题】:invalid plugin.yml bukkit plugin error无效的 plugin.yml bukkit 插件错误
【发布时间】:2014-08-16 20:53:21
【问题描述】:

嘿,所以我在发布此问题之前确实在多个站点上查找了此问题,并且我所做的一切都是正确的,但是当我尝试加载我的插件时仍然收到此错误,它说错误不能 无效的plugin.yml,然后只给出一堆代码行和东西(我假设来自bukkit文件中的代码等等,是的,我的plugin.yml保存在src文件夹而不是包中,当我导出它我确实将它导出为 .jar,无论如何这是我的 plugin.yml 文件

name: ProtHome
main: com.yahoo.m1kesanders.ProtHome.ProtHome 
version: 1.0.0
Description: A simple /home plugin 

commands:


  sethome:
    Description: sets players home

  home:
    Description: teleports player to their home

我也确实使用了 4 个空格,并且没有使用 tab 键,命令后有两个空格:每个命令后还有两个空格

这是我在 Eclipse 中的插件代码,以防您需要它来检查名称和其他内容

package com.yahoo.m1kesanders.ProtHome;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class ProtHome extends JavaPlugin{

    public static ProtHome plugin;

    public File folder = plugin.getDataFolder();
    public static File file = new File("Homes.yml");
    public static YamlConfiguration Homes = new YamlConfiguration();

    public void onEnable(){

        if(!folder.exists()){

            folder.mkdir();
        }

        if(!file.exists()){

            file.mkdir();
        }

        try {
            Homes.load(file);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public boolean onCommand(CommandSender cmdsender, Command cmd, Player player) throws FileNotFoundException, IOException, InvalidConfigurationException{

        if(cmdsender.equals("sethome")){

            ProtHome.Homes.load(ProtHome.file);

            Homes.set(player.getName() + ".x", player.getLocation().getBlockX());
            Homes.set(player.getName() + ".y", player.getLocation().getBlockY());
            Homes.set(player.getName() + ".z", player.getLocation().getBlockZ());
            Homes.set(player.getName() + ".world", player.getWorld().getName());

            ProtHome.Homes.save(ProtHome.file);
        }

        else if(cmdsender.equals("home")){

            int x = (int) Homes.get(player.getName() + ".x");
            int y = (int) Homes.get(player.getName() + ".y");
            int z = (int) Homes.get(player.getName() + ".z");

            String world = (String) Homes.get(player.getName() + ".world");

            World realworld = Bukkit.getServer().getWorld(world);

            Location loc = new Location(realworld,x,y,z);

            player.teleport(loc);

        }

        return false;

    }

}

如果你们能帮助我,那将非常感谢您的阅读

【问题讨论】:

  • 首先,确保您使用的是空格,而不是制表符。其次,也许删除描述中的/?第三,确保plugin.yml不在任何包中,而是在你的src中,最后,尝试重新导出插件。

标签: java eclipse file plugins bukkit


【解决方案1】:

部分问题可能是您在 bukkit 示例 plugin.yml 中将 D 中的 D 大写,所有键都是小写的。

尝试使用小写的d 导出虽然这可能不是问题,但使用正确的编码语法总是有帮助的。 Bukkit 对它的 yaml 解析器非常挑剔。

另外,为了将来参考,通常包名没有大写字母,只有类。

您的包裹com.yahoo.m1kesanders.ProtHome

大多数包com.yahoo.m1kesanders.prothome

我不能确定,但​​通常特别建议 ​​bukkit 插件遵循这个一般规则。我不知道 bukkit 的类加载器是如何工作的,但是这个大写的包名肯定没有帮助。

【讨论】:

    【解决方案2】:

    正如 TheJavaCoder16 所说,您似乎也没有使用正确的onCommand 方法。这就是你所拥有的(不包括throws ... 和主要内容):

    public boolean onCommand(CommandSender cmdsender, Command cmd, Player player)
    

    正确的方法是:

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    

    要让玩家检查sender instanceof Player,然后将发件人转换为Player

    if (sender instanceof Player) {
        Player player = (Player) sender;
        //Rest of your code goes here
    }
    

    您还应该注意的是,返回 false 会向发件人发送一个错误,警告他们该命令的使用不正确/无效。除非您希望它发送此消息,否则您应该尝试返回 true。

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) throws FileNotFoundException, IOException, InvalidConfigurationException{
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if(cmdsender.equals("sethome")){
    
                ProtHome.Homes.load(ProtHome.file);
    
                Homes.set(player.getName() + ".x", player.getLocation().getBlockX());
                Homes.set(player.getName() + ".y", player.getLocation().getBlockY());
                Homes.set(player.getName() + ".z", player.getLocation().getBlockZ());
                Homes.set(player.getName() + ".world", player.getWorld().getName());
    
                ProtHome.Homes.save(ProtHome.file);
            } else if(cmdsender.equals("home")){
    
                int x = (int) Homes.get(player.getName() + ".x");
                int y = (int) Homes.get(player.getName() + ".y");
                int z = (int) Homes.get(player.getName() + ".z");
    
                String world = (String) Homes.get(player.getName() + ".world");
    
                World realworld = Bukkit.getServer().getWorld(world);
    
                Location loc = new Location(realworld,x,y,z);
    
                player.teleport(loc);
    
            }
        }
    
        return true;
    
    }
    

    【讨论】:

      【解决方案3】:

      通常情况下,您确实可以正确地做所有事情,但它仍然会引发错误或异常。这似乎是一个愚蠢的答案,但是您在导出之前是否刷新了 plugin.yml 文件?这种情况经常发生,而且比您想象的更常见。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-16
        • 2015-03-14
        • 2014-09-04
        • 2021-08-27
        • 1970-01-01
        相关资源
        最近更新 更多