ProtocolLib

3M Downloads

Hi i use ProtocolLib and i have this issue :

zBvczx opened this issue ยท 0 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • i do
  • This isn't an issue caused by another plugin
  • i do
  • You've checked for duplicate issues
  • i tried
  • You didn't use /reload
  • i didnt.

Describe the question
i built a plugin using the protocollib but i have that issue i cant find why . . i need help.

API method(s) used
List what API method(s) you're using

Expected behavior
A clear and concise description of what you expected to happen.

Code
package com.bara.untitled;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketListener;
import org.bukkit.plugin.java.JavaPlugin;

public final class Untitled extends JavaPlugin {

private ProtocolManager protocolManager;
private PacketListener deathEffectsListener;

@Override
public void onEnable() {
    getLogger().info("Plugin is starting...");

    // Ensure ProtocolLib is loaded
    if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
        getLogger().severe("ProtocolLib is not installed or not loaded.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }

    // Initialize ProtocolLib manager
    protocolManager = ProtocolLibrary.getProtocolManager();
    if (protocolManager == null) {
        getLogger().severe("Failed to get ProtocolManager instance.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }

    getLogger().info("ProtocolManager instance retrieved successfully.");

    // Listener to intercept and modify packets related to death effects
    deathEffectsListener = new PacketAdapter(this, PacketType.Play.Server.ENTITY_METADATA, PacketType.Play.Server.ENTITY_EFFECT) {
        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
                // Handle entity metadata packets
            } else if (event.getPacketType() == PacketType.Play.Server.ENTITY_EFFECT) {
                // Handle entity effect packets
            }
        }
    };

    // Register the packet listener
    protocolManager.addPacketListener(deathEffectsListener);

    getLogger().info("Untitled plugin has been enabled.");
}

@Override
public void onDisable() {
    // Unregister the packet listener
    if (protocolManager != null && deathEffectsListener != null) {
        protocolManager.removePacketListener(deathEffectsListener);
        getLogger().info("Packet listener has been removed.");
    }

    getLogger().info("Untitled plugin has been disabled.");
}

}
Additional context
my plugin.yml is :
name: untitled
version: '1'
main: com.bara.untitled.Untitled
api-version: '1.20'
depend: [ProtocolLib]
my pom.xml is :


4.0.0

<groupId>com.bara</groupId>
<artifactId>untitled</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>untitled</name>

<properties>
    <java.version>17</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

<build>
    <defaultGoal>clean package</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<repositories>
    <repository>
        <id>spigotmc-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>sonatype</id>
        <url>https://oss.sonatype.org/content/groups/public/</url>
    </repository>
    <repository>
        <id>dmulloy2-repo</id>
        <url>https://repo.dmulloy2.net/repository/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.20.4-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.comphenix.protocol</groupId>
        <artifactId>ProtocolLib</artifactId>
        <version>4.8.0</version>
    </dependency>
</dependencies>