java - Spigot/Bukkit插件开发1.15.2自定义播放器头部报错找不到符号

标签 java bukkit

public HelloCommand(Main plugin) {
        this.plugin = plugin;
        plugin.getCommand("tptest").setExecutor(this);
    }
    private static ItemStack createSkull(String url) {
        @SuppressWarnings("deprecation")
        ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
        if (url.isEmpty())
            return head;

        SkullMeta headMeta = (SkullMeta) head.getItemMeta();
        GameProfile profile = new GameProfile(UUID.randomUUID(), null);

        profile.getProperties().put("textures", new Property("textures", url));

        try {
            Field profileField = headMeta.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(headMeta, profile);

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        head.setItemMeta(headMeta);
        return head;
    }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players may execute this command!");
            return true;
        }
        Player player = (Player) sender;
        if (player.hasPermission("testplugin.test")) {
            player.sendMessage("Perms are loaded!");

            /*ItemStack item = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta meta = (SkullMeta)item.getItemMeta();
            meta.setOwningPlayer(Bukkit.getPlayer(UUID.fromString("23077a1b-183a-438c-bc14-e01a8d0381a1")));
            meta.setDisplayName("Urn");
            item.setItemMeta(meta);

            player.sendMessage(ChatColor.GREEN + "You have been given " +  ChatColor.YELLOW + "an urn!");
            player.getInventory().addItem(item);*/
            player.getInventory().addItem(createSkull("c4fe135c311f7086edcc5e6dbc4ef4b23f819fddaa42f827dac46e3574de2287"));
            return true;
        } else {
            player.sendMessage("You do not have permission to execute this command!");

        }
        return false;
    }

我遵循了本教程:https://www.spigotmc.org/threads/using-custom-head-textures.311562/因为我找不到任何其他与我想做的事情类似的事情。

我的错误maven错误:

[ERROR] PATH(HIDDEN)/HelloCommand.java:[37,53] cannot find symbol
[ERROR]   symbol:   class Property
[ERROR]   location: class me.testwebsite.testplugin.commands.HelloCommand

有人有解决办法吗?我希望能够使用此网站获得自定义头部:https://minecraft-heads.com/custom-heads/decoration/35007-ultimate-solar-generator放置在 block 上然后使用。我在获取头部对象时遇到问题。

最佳答案

解决方案没有读取整个错误,也没有在 pom.xml 文件中导入 mojang。

关于java - Spigot/Bukkit插件开发1.15.2自定义播放器头部报错找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61984984/

相关文章:

java - Mockito - 使用预期参数验证方法调用但忽略某些字段

java - Minecraft 插件 WorldEdit 获取区域

Java(Bukkit)如何在没有这个的情况下访问Config?

java - 使用自定义方法和其他类的方法创建类? java

java - Process.getOutputStream() 不起作用?

java - 查找流程图中的所有方法?

JavaFX 如何并排居中多个组件

java - 如何在mapreduce驱动程序类中获取输入文件总大小?

java - Apache Commons FTPClient,检查远程目录是否存在并获取权限(linux - unix)

Java编码审查词