CraftItemStack doesn't exist?

Discussion in 'Plugin Development' started by NoobDoesMC, Jun 24, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    NoobDoesMC

    I am trying to use CraftItemStack in one of my plugins, but Maven tells me it doesn't exist:

    Code:
    package io.github.theonlygusti.wizardserver;
    
    import org.bukkit.craftbukkit.inventory.CraftItemStack;
    import org.bukkit.event.*;
    
    public class PlayerListener implements Listener {
      public static WizardServer plugin; // another one of my classes
    
      @EventHandler(priority=EventPriority.HIGH)
      public void onPlayerInteract(PlayerInteractEvent event) {
        CraftItemStack cis = new CraftItemStack();
      }
    }
    Trying to mvn clean install the above code throws the error:

    Code:
    [ERROR] /Users/.../plugins/WizardServer/src/main/java/io/github/theonlygusti/wizardserver/PlayerListener.java:[16,40] package org.bukkit.craftbukkit.inventory does not exist
    [ERROR] /Users/.../plugins/WizardServer/src/main/java/io/github/theonlygusti/wizardserver/PlayerListener.java:[11,5] cannot find symbol
    [ERROR] symbol:   class CraftItemStack
    [ERROR] location: class io.github.theonlygusti.wizardserver.PlayerListener
    Of course, this is just an example. I am trying to use CraftItemStack inside an actual project, but I cannot figure out how to import it.

    ------------------------------------------------------------------------------------------------------------------------------------​

    My pom.xml:
    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>io.github.theonlygusti</groupId>
      <artifactId>WizardServer</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <repositories>
        <repository>
          <id>bukkit-repo</id>
          <url>http://repo.bukkit.org/content/groups/public/</url>
        </repository>
      </repositories>
      <dependencies>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>bukkit</artifactId>
          <version>1.7.9-R0.2</version>
          <type>jar</type>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>craftbukkit</artifactId>
          <version>1.10</version>
          </dependency>
      </dependencies>
    </project>
     
    Last edited: Jun 26, 2016
  2. Offline

    I Al Istannen

    @NoobDoesMC
    Never used maven, but you need to have CraftBukkit/The whole spigot jar on your build path, not just bukkit. Don't know how Maven handles that.

    The other reason could be that you use two different versions of the craftbukkit jar? Imports will break then.
     
    ArsenArsen likes this.
  3. Offline

    N00BHUN73R

    @NoobDoesMC
    I thought that Craft classes were under the craftbukkit.jar
    I don't know if Spigot has them but normal bukkit does not
     
  4. Offline

    NoobDoesMC

    Okay, thank you for letting me know.

    I assume you use eclipse (most sane people do xD) so what is the process for adding the spigot (please) jar to an eclipse project? (I will be able to perform the same process with maven if you show me how it is done with Eclipse.)

    Basically, now I need to see how one adds the spigot jar to their build path.
     
  5. Offline

    MisterErwin

    @NoobDoesMC Either use the system-scope and tell maven where your craftbukkit jarfile is using the systempath or let the buildtools install craftbukkit to your local maven repository.


    Code:
    <dependency>
      <groupId>org.bukkit</groupId>
      <artifactId>craftbukkit</artifactId>
      <scope>system</scope>
      <systempath>C:/myCraftBukkitJarFile.jar</systempath>
    </dependency>
    
    
    Code:
    <dependency>
      <groupId>org.bukkit</groupId>
      <artifactId>craftbukkit</artifactId>
      <version>Your version</version>
    </dependency>
    
     
    I Al Istannen likes this.
  6. Offline

    I Al Istannen

    @MisterErwin
    Can't judge, will trust you! :) Thanks though!


    @NoobDoesMC
    Many also use IntelliJ, while I don't like it, it could be a nice alternative for you. The community edition is free, as far as I know.

    But for eclipse:

    Right click on project
    -> Properties
    -> Java Build path (on the left)
    -> Libararies
    -> Add external jar
    -> Navigate to your spigot.jar, which you use to start the server
    -> Select it and apply the new settings.
     
  7. @NoobDoesMC
    2 things
    1. Why the static abuse?
    2. Why are you importing EVERY class from org.bukkit.event
     
    MisterErwin likes this.
  8. Offline

    NoobDoesMC

    Neither of these methods worked for me.
     
  9. Offline

    MisterErwin

  10. Offline

    NoobDoesMC

    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>io.github.theonlygusti</groupId>
      <artifactId>WizardServer</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <repositories>
        <repository>
          <id>bukkit-repo</id>
          <url>http://repo.bukkit.org/content/groups/public/</url>
        </repository>
      </repositories>
      <dependencies>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>bukkit</artifactId>
          <version>1.7.9-R0.2</version>
          <type>jar</type>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>craftbukkit</artifactId>
          <version>1.10</version>
          </dependency>
      </dependencies>
    </project>
    My entire pom.xml
     
  11. Offline

    CeramicTitan

    Its one or the other....Remove the Bukkit dependency.
     
  12. Offline

    NoobDoesMC

    I tried that, same errors being thrown:

    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>io.github.theonlygusti</groupId>
      <artifactId>WizardServer</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <repositories>
        <!--repository>
          <id>bukkit-repo</id>
          <url>http://repo.bukkit.org/content/groups/public/</url>
        </repository-->
        <repository>
          <id>in-project</id>
          <url>file:///Users/.../server/craftbukkit-1.10.jar</url>
        </repository>
      </repositories>
      <dependencies>
        <!--dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>bukkit</artifactId>
          <version>1.7.9-R0.2</version>
          <type>jar</type>
          <scope>provided</scope>
        </dependency-->
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>craftbukkit</artifactId>
          <version>1.10</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </project>
    
    I've added my pom.xml file, and latter attempts, above.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 26, 2016
Thread Status:
Not open for further replies.

Share This Page