Nullpointer for ProtocolManger.
AlbusThePenguin opened this issue ยท 2 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin
- You've checked for duplicate issues
- You didn't use
/reload
Describe the question
Hey, so I am having some nullpointer issue with ProtocolLib.
I am checking onEnable() if the plugin exists by doing Plugin protocolLibs = Bukkit.getPluginManager().getPlugin("ProtocolLib");
and it finds it.
API method(s) used
I am using maven, 5.1.0 (image below), Minecraft 1.20.4. downloaded from https://ci.dmulloy2.net/job/ProtocolLib//lastBuild/
Expected behavior
To make it not return null, and find where I fail.
Code
` private final Nucleus nucleus;
private final ProtocolManager protocolManager;
private final Map<Player, BreakData> breakDataMap = new ConcurrentHashMap<>();
public BlockBreakListener(Nucleus nucleus, ProtocolManager protocolManager) {
this.nucleus = nucleus;
this.protocolManager = protocolManager;
if(protocolManager == null) {
Bukkit.getLogger().warning("ProtocolManager is null?");
}
}
public void register() {
protocolManager.addPacketListener(new PacketAdapter(nucleus, ListenerPriority.NORMAL, PacketType.Play.Server.BLOCK_BREAK_ANIMATION) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
Block block = player.getTargetBlockExact(5);
if(block == null) return;
if(!blockTypes().contains(block.getType())) {
removeSlow(player);
return;
}
BreakData data = breakDataMap.getOrDefault(player, new BreakData());
int blockDuration = data.getDigs() + 1;
if(blockDuration > 45) {
block.breakNaturally();
breakDataMap.remove(player);
removeSlow(player);
return;
}
BlockPosition position = new BlockPosition(new Vector(block.getX(), block.getY(), block.getZ()));
PacketContainer container = event.getPacket();
container.getBlockPositionModifier().write(0, position);
int animationStage = (int) Math.ceil((double) blockDuration / 45 * 9); // Adjust 9 as needed
container.getIntegers().write(0, animationStage);
container.getIntegers().write(1, 9); // The maximum stage of the break animation
protocolManager.sendServerPacket(player, container);
player.sendMessage("Sending packet value of " + animationStage);
data.setDigs(blockDuration);
addSlow(player, 999);
breakDataMap.put(player, data);
}
});
}` (full code here https://pastebin.com/9prp8RWb) the null pointer is this protocolmanager protocolManager.addPacketListener()
Additional context
Add any other context about the problem here.
If you need any more / other information let me know.