ProtocolLib

3M Downloads

[ProtocolLib] INTERNAL ERROR: Cannot load ProtocolLib.

XxDraggy opened this issue ยท 0 comments

commented

Describe the question

I am currently coding a plugin using ProtocolLib to create a Sign Input. After updating to 1.20 (5.1.0) I now get this error.

API methods used

  • ProtocolLibrary:getProtocolManager() - To get the manager
  • ProtocolManager:addPacketListener(PacketListener listener) - To add a listener
  • ProtocolManager:createPacket(PacketType type) - To create the sign packets
  • ProtocolManager:sendServerPacket(Player receiver, PacketContainer packet) - To send the sign packets to the player

Expected behavior

  • Plugin starting without any error
  • Registering /input command
  • On usage of /input command open Sing GUI
  • On done button click send message to player with entered content

Code

I am using to of my classes to do the work.
First a manager (InputManager.java), second a 'creator class' (InputGUI.java) where the user can modify the setting

InputManager.java

package com.xxdraggy.utils.input;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

public class InputManager {
    private static JavaPlugin plugin;
    private static ProtocolManager manager;
    public static ProtocolManager getManager() {
        return InputManager.manager;
    }

    private static final Map<Player, InputGui> currentInputs = new HashMap<>();
    public static Map<Player, InputGui> getCurrentInputs() {
        return currentInputs;
    }

    public static void register(JavaPlugin plugin) {
        InputManager.plugin = plugin;
        InputManager.manager = ProtocolLibrary.getProtocolManager();

        Bukkit.getLogger().log(Level.INFO, "[BukkitUtils/InputController] Registered listener!");

        if(InputManager.isInstalled()) {
            InputManager.listen();
        }
        else {
            Bukkit.getLogger().log(Level.SEVERE, "[BukkitUtils/InputController] Could not find ProtocolLib in the plugin folder.\nPlease install it from https://github.com/dmulloy2/ProtocolLib");
        }
    }

    public static boolean isInstalled() {
        return ProtocolLibrary.getProtocolManager() != null;
    }

    private static void listen() {
        InputManager.getManager().addPacketListener(new PacketAdapter(plugin, PacketType.Play.Client.UPDATE_SIGN) {
            @Override
            public void onPacketReceiving(PacketEvent event) {
                Player player = event.getPlayer();
                InputGui gui = currentInputs.remove(player);

                if (gui == null) {
                    return;
                }

                event.setCancelled(true);

                boolean success = gui.getChecker().test(player, event.getPacket().getStringArrays().read(0));

                if (!success && gui.isReopen() && !gui.isForceClose()) {
                    Bukkit.getScheduler().runTaskLater(plugin, () -> gui.open(player), 2L);
                }
                else {
                    gui.getCallback().apply(player, event.getPacket().getStringArrays().read(0));
                }

                Bukkit.getScheduler().runTaskLater(plugin, () -> {
                    if (player.isOnline()) {
                        Location location = gui.getBlockPosition().toLocation(player.getWorld());

                        player.sendBlockChange(location, location.getBlock().getBlockData());
                    }
                }, 2L);
            }
        });
    }
}

InputGUI.java

package com.xxdraggy.utils.input;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.xxdraggy.utils.data.SignType;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;

public class InputGui {
    private SignType signType = SignType.Birch;
    public void setSignType(SignType signType) {
        this.signType = signType;
    }
    public SignType getSignType() {
        return signType;
    }

    private List<String> lines = new ArrayList<>();
    public void setLines(List<String> lines) {
        this.lines = lines;
    }
    public List<String> getLines() {
        return lines;
    }

    private BiFunction<Player, String[], Void> callback = (player, strings) -> null;
    public void setCallback(BiFunction<Player, String[], Void> callback) {
        this.callback = callback;
    }
    public BiFunction<Player, String[], Void> getCallback() {
        return callback;
    }

    private BiPredicate<Player, String[]> checker = (player, strings) -> true;
    public void setChecker(BiPredicate<Player, String[]> checker) {
        this.checker = checker;
    }
    public BiPredicate<Player, String[]> getChecker() {
        return checker;
    }

    private boolean reopen = true;
    public void setReopen(boolean reopen) {
        this.reopen = reopen;
    }
    public boolean isReopen() {
        return reopen;
    }

    private boolean forceClose;
    public void setForceClose(boolean forceClose) {
        this.forceClose = forceClose;
    }
    public boolean isForceClose() {
        return forceClose;
    }

    private BlockPosition blockPosition;
    public BlockPosition getBlockPosition() {
        return blockPosition;
    }

    public void open(Player player) {
        Objects.requireNonNull(player, "Player must be given!");

        if (!player.isOnline())
            return;

        PacketContainer openSign = InputManager.getManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
        PacketContainer signData = InputManager.getManager().createPacket(PacketType.Play.Server.TILE_ENTITY_DATA);

        Location playerLocation = player.getLocation();

        this.blockPosition = new BlockPosition(
                playerLocation.getBlockX(),
                playerLocation.getBlockY()
                        +
                        (255 - playerLocation.getBlockY()),
                playerLocation.getBlockZ());

        player.sendBlockChange(this.blockPosition.toLocation(playerLocation.getWorld()), signType.getBlock().createBlockData());

        openSign.getBlockPositionModifier().write(0, this.blockPosition);

        NbtCompound signNBT = (NbtCompound) signData.getNbtModifier().read(0);

        for (int line = 0; line < 4; line++) {
            signNBT.put(
                    "text"
                    +
                    (line + 1),
                    this.lines.size() > line
                    ?
                    String.format("{\"text\":\"%s\"}", ChatColor.translateAlternateColorCodes('&', this.lines.get(line)))
                    :
                    ""
            );
        }

        signNBT.put("x", this.blockPosition.getX());
        signNBT.put("y", this.blockPosition.getY());
        signNBT.put("z", this.blockPosition.getZ());
        signNBT.put("id", signType.getId());

        signData.getBlockPositionModifier().write(0, this.blockPosition);
        signData.getNbtModifier().write(0, signNBT);

        InputManager.getManager().sendServerPacket(player, signData);
        InputManager.getManager().sendServerPacket(player, openSign);

        InputManager.getCurrentInputs().put(player, this);
    }

    public void close(Player player) {
        this.close(player, false);
    }

    public void close(Player player, boolean forceClose) {
        this.setForceClose(forceClose);

        if (player.isOnline())
            player.closeInventory();
    }
}

Additional context

This is the error message

[my:time] [Server thread/ERROR]:   [ProtocolLib] INTERNAL ERROR: Cannot load ProtocolLib.
  If this problem hasn't already been reported, please open a ticket
  at https://github.com/dmulloy2/ProtocolLib/issues with the following data:
 Stack Trace:
  java.lang.IllegalArgumentException: Unable to find a field that matches {modifiers=[required: 10000, banned: 1000], type={ type input instanceof interface java.util.Map }}
        at com.comphenix.protocol.reflect.FuzzyReflection.getField(FuzzyReflection.java:352)
        at com.comphenix.protocol.injector.packet.PacketRegistry.createNewRegister(PacketRegistry.java:188)
        at com.comphenix.protocol.injector.packet.PacketRegistry.initialize(PacketRegistry.java:292)
        at com.comphenix.protocol.injector.packet.PacketRegistry.getClientPacketTypes(PacketRegistry.java:327)
        at com.comphenix.protocol.injector.PacketFilterManager.<init>(PacketFilterManager.java:120)
        at com.comphenix.protocol.injector.PacketFilterBuilder.build(PacketFilterBuilder.java:121)
        at com.comphenix.protocol.ProtocolLib.onLoad(ProtocolLib.java:183)
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.loadPlugins(CraftServer.java:442)
        at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:219)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:954)
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:298)
        at java.base/java.lang.Thread.run(Thread.java:1589)
  Dump:
  Parameters:
    [NULL]
  Sender:
    com.comphenix.protocol.ProtocolLib@7143a6f3[
      statistics=<null>
      packetTask=<null>
      tickCounter=0
      configExpectedMod=-1
      updater=com.comphenix.protocol.updater.SpigotUpdater@190a9c76
      redirectHandler=<null>
      scheduler=com.comphenix.protocol.scheduler.DefaultScheduler@28a42436
      commandProtocol=<null>
      commandPacket=<null>
      commandFilter=<null>
      packetLogging=<null>
      skipDisable=false
      isEnabled=false
      loader=org.bukkit.plugin.java.JavaPluginLoader@22d23429
      server=CraftServer{serverName=CraftBukkit,serverVersion=3923-Spigot-dba3cdc-224f733,minecraftVersion=1.20.2}
      file=plugins\ProtocolLib.jar
      description=org.bukkit.plugin.PluginDescriptionFile@2ca90690
      dataFolder=plugins\ProtocolLib
      classLoader=org.bukkit.plugin.java.PluginClassLoader@7a913fe7
      naggable=true
      newConfig=YamlConfiguration[path='', root='YamlConfiguration']
      configFile=plugins\ProtocolLib\config.yml
      logger=org.bukkit.plugin.PluginLogger@2f260fe6
    ]
  Version:
    ProtocolLib v5.1.0
  Java Version:
    19.0.1
  Server:
    3923-Spigot-dba3cdc-224f733 (MC: 1.20.2)