Using ProtocolLibs packet listener

Discussion in 'Plugin Development' started by HeyAwesomePeople, Mar 22, 2015.

Thread Status:
Not open for further replies.
  1. Hello! I am trying to use ProtocolLib's packet listener.

    Code:
        @Override
        public void onEnable() {
            instance = this;
    
            getServer().getPluginManager().registerEvents(this, this);
           // line below this is error line, NPE
            ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this,
    ListenerPriority.NORMAL, PacketType.Play.Client.RESOURCE_PACK_STATUS) {
                @Override
                public void onPacketSending(PacketEvent event) {
                    Bukkit.broadcastMessage("1");
                    if (event.getPacketType() == PacketType.Play.Client.RESOURCE_PACK_STATUS) {
                        Bukkit.broadcastMessage(event.getPacket().getStrings().read(0));
                    }
                }
            });
        }
    Only issue is that there is an NPE. Why is this?

    I use maven and shade in ProtocolLib when I save the project.
    Code:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>me.heyawesomepeople.forceresourcepack</groupId>
        <artifactId>ForceResourcePack</artifactId>
        <version>-SNAPSHOT</version>
    
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
            </repository>
            <repository>
                <id>shadowvolt-repo</id>
                <url>http://ci.shadowvolt.com/plugin/repository/everything/</url>
            </repository>
        </repositories>
    
        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.8.3-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.comphenix.protocol</groupId>
                <artifactId>ProtocolLib</artifactId>
                <version>3.6.3-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>test</groupId>
                <artifactId>x</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>C:\Users\Bryan\Dropbox\Bukkit Coding\Dependincies\Craftbukkit.jar</systemPath>
            </dependency>
        </dependencies>
    
    
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.1</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>1.7</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
    
                                <transformers>
                                    <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>com.comphenix.protocol</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
            </plugins>
        </build>
    
    </project>
    I t seems to work, as my plugin file size is now like 1600kb. But yeah, any ideas?

    - HeyAwesomePeople
     
  2. Offline

    nverdier

    Last edited by a moderator: Mar 22, 2015
  3. Offline

    nverdier

    @HeyAwesomePeople But what line is the NPE on? Is there a stack trace? Please post that.
     
Thread Status:
Not open for further replies.

Share This Page