Вопрос Пытаюсь внедрить в своё плагин сообщения Toast через достижения

Версия Minecraft
1.20.X

Hahatyn

Разработчик
Пользователь
Сообщения
237
Решения
16
Пытаюсь внедрить в своё плагин сообщения Toast через достижения, нашёл YouTube мастера и взял у него код, пытался разобраться но ничего не получается, помогите!

Java:
package org.hahatyn.zyengine.utils;

import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.hahatyn.zyengine.ZyEngine;

import java.util.UUID;

public final class Toast {

    private final NamespacedKey key;
    private final String icon;
    private final String message;
    private final Style style;

    private Toast(String icon, String message, Style style) {
        this.key = new NamespacedKey(ZyEngine.instance, UUID.randomUUID().toString());
        this.icon = icon;
        this.message = message;
        this.style = style;
    }

    private void start(Player player) {
        createAdvancement();
        grantAdvancement(player);

        Bukkit.getScheduler().runTaskLater(ZyEngine.instance, () -> {
            revokeAdvancement(player);
        }, 10);
    }

    private void createAdvancement() {
        Bukkit.getUnsafe().loadAdvancement(key, "{\n" +
                "    \"criteria\": {\n" +
                "        \"trigger\": {\n" +
                "            \"trigger\": \"minecraft:impossible\"\n" +
                "        }\n" +
                "    },\n" +
                "    \"display\": {\n" +
                "        \"icon\": {\n" +
                "            \"item\": \"minecraft:" + icon + "\"\n" +
                "        },\n" +
                "        \"title\": {\n" +
                "            \"text\": \"" + message.replace("|", "\n") + "\"\n" +
                "        },\n" +
                "        \"description\": {\n" +
                "            \"text\": \"\"\n" +
                "        },\n" +
                "        \"background\": \"minecraft:textures/gui/advancements/backgrounds/adventure.png\",\n" +
                "        \"frame\": \"" + style.toString().toLowerCase() + "\",\n" +
                "        \"announce_to_chat\": false,\n" +
                "        \"show_toast\": true,\n" +
                "        \"hidden\": true\n" +
                "    },\n" +
                "    \"requirements\": [\n" +
                "        [\n" +
                "            \"trigger\"\n" +
                "        ]\n" +
                "    ]\n" +
                "}");
    }

    private void grantAdvancement(Player player) {
        player.getAdvancementProgress(Bukkit.getAdvancement(key)).awardCriteria("trigger");
    }

    private void revokeAdvancement(Player player) {
        player.getAdvancementProgress(Bukkit.getAdvancement(key)).revokeCriteria("trigger");
    }

    public static void displayTo(Player player, String icon, String message, Style style) {
        new Toast(icon, message, style).start(player);
    }

    public static enum Style {
        GOAL,
        TASK,
        CHALLENGE
    }
}

Вот ошибка в консоле:
Код:
[15:05:52] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to ZyEngine v0.1
java.lang.UnsupportedOperationException: null
    at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:781) ~[guava-32.1.2-jre.jar:?]
    at org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers.loadAdvancement(CraftMagicNumbers.java:317) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at org.hahatyn.zyengine.utils.Toast.createAdvancement(Toast.java:34) ~[ZyEngine-0.1.jar:?]
    at org.hahatyn.zyengine.utils.Toast.start(Toast.java:25) ~[ZyEngine-0.1.jar:?]
    at org.hahatyn.zyengine.utils.Toast.displayTo(Toast.java:73) ~[ZyEngine-0.1.jar:?]
    at org.hahatyn.zyengine.discord.Discord.onJoinPlayer(Discord.java:31) ~[ZyEngine-0.1.jar:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor5.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[purpur-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:77) ~[purpur-api-1.20.2-R0.1-SNAPSHOT.jar:git-Purpur-2064]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[purpur-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:126) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:617) ~[purpur-api-1.20.2-R0.1-SNAPSHOT.jar:?]
    at net.minecraft.server.players.PlayerList.placeNewPlayer(PlayerList.java:325) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.server.network.ServerConfigurationPacketListenerImpl.handleConfigurationFinished(ServerConfigurationPacketListenerImpl.java:130) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket.handle(ServerboundFinishConfigurationPacket.java:18) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket.a(ServerboundFinishConfigurationPacket.java:9) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:53) ~[?:?]
    at net.minecraft.server.TickTask.run(TickTask.java:18) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1349) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:193) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
    at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1326) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1319) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
    at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1297) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1185) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318) ~[purpur-1.20.2.jar:git-Purpur-2064]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
 
Смотрел... он на kotlin'e
Разобраться при желании можно. Лично я туториалов рабочих не нашёл, ну и просто вызываю команду аннонсера. Но при желании можно скопировать оттуда к себе, переведя всё на жаву (чатгпт поможет кстати)
 
Разобраться при желании можно. Лично я туториалов рабочих не нашёл, ну и просто вызываю команду аннонсера. Но при желании можно скопировать оттуда к себе, переведя всё на жаву (чатгпт поможет кстати)
ТОЧНО! Спасибо большое
 
Назад
Сверху Снизу