How do I set up my workspace?

So i follow the instructions here, multiple times, to the letter and i cannot figure it out. I am using eclipse and i open it in what i think is the repo folder (where is the repo folder), i have git installed and have tried different methods, The setup workspace tutorial from spong is just not detailed enough for me to understand. Where to i create my plugin class, how do i get it so i can edit in eclipse and how do i export it.

thanks in advance to anyone who decided to help me

We can’t tell what is going wrong without more information. Its like you told your mechanic that your car is broken and then are expecting them to fix it based off that

@disconsented
well i opened a new folder, and cloned my fork of the git repository with the ‘git bash’, then opened a command prompt in that folder and ran ‘gradlew setupDecompWorkspace’, and then ‘gradlew eclipse’, then, in eclipse i set that folder as the workspace and now i am confused were to go from there. How do i get the project to show up in eclipse? In forge there is an ‘eclipse’ folder, and in my folder for sponge there is not, so im not sure if there is supposed to be one or not. I have EGit installed if there is some way to use that to set up the project…

Point Eclipse towards the eclipse directory inside your project folder should work

@disconsented
My apologies, my grammar was horrible in my earlier post, and I meant to say that an eclipse folder does not appear, even though there are no errors in the build, from gradle or git. Is an eclipse folder supposed to appear?

You should be looking for /eclipse/ on the same level as gradlew.

@disconsented
It does not appear. Does sponge setup similar to forge? The eclipse folder is not there, I feel like I have this problem before, put i cannot remeber how to fix it…

“gradlew setupDecompWorkspace eclipse” works fine for me on 8.1, you may need to try running it with elevated permissions (you will need to do research on your own) and/or (if you’re on windows) using “gradlew.bat setupDecompWorkSpace eclipse”. Are you running the command via a script file or via C.L.I.?

I strongly recommend getting the gradle plugin for eclipse. Once you have the plugin you can actually go “import -> Gradle” and select the folder where you cloned the sponge repository and then the plugin does absolutely everything else for you.

If you’re having problems getting it to work, then this should probably get you going a lot more easily.

Question. Is your project a fork of Sponge, or a plugin?

@bdubz4552
plugin.

Ok then that tutorial you were looking at is good and all, but I don’t think its what you’re looking for. So here’s what I did for my Eclipse workspace. (I use Maven)

  1. Create a workspace path when you start Eclipse. Mine is “C:\Users<my name>\Home\Java Stuffs\Sponge\Plugins”. That “Home” folder in there is cause I like Linux file organization better, and to make sort of a “mock-user-folder” that I can control what goes in it. I hate when programs just drop things in your user folder. >.<

Edit: You can hold multiple plugin projects in one workspace. I have ~8 projects in my workspace.

  1. Create a new Maven project. Check the box that says “Simple project”. Fill out a group id and artifact id on the next page (group id is commonly part of a package namespace that is constant across many projects; GitHub pages users can use io.github.. as a namespace for packages, hence, io.github. makes a good group id), and while it is not necessary (oddly enough), you can restate the project name in the “Name” box, but I find this to be arbitrary. Artifact id is quite simply the name of whatever project you have. Hit finish.

  2. Woo! You have a Maven project! But, its just an empty shell. To use the Sponge API, you must add it as a Maven dependency. Look in your project explorer for pom.xml, and open it. A special screen will pop up with tabs at the bottom. Tab over to “pom.xml”. Pasted below is part of my pom.xml for one of my projects.

Another Edit: I should add that all of this needs to be contained within the project and /project brackets (I’m slightly peeved that I can’t openly use <> tags in plain text…)

This defines the remote Maven repository for the API.

<repositories>
<repository>
    <id>sponge-maven-repo</id>
    <name>Sponge maven repo</name>
    <url>http://repo.spongepowered.org/Sponge/maven</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
</repositories>

This defines the Sponge API dependency. You may need to change the version value over time.

<dependencies>
<dependency>
    <groupId>org.spongepowered</groupId>
    <artifactId>spongeapi</artifactId>
    <version>1.0</version>
</dependency>
</dependencies>

This section is not necessary, but something I find handy. This tells Maven to use Java 7. Normally (for my Eclipse installation at least) Maven projects default to J2SE 1.5, and while you can tell it on your own to use Java 7, if you ever do a Maven project refresh, it will reset to J2SE 1.5.

<build>
  <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
              <source>1.7</source>
              <target>1.7</target>
          </configuration>
      </plugin>
  </plugins>
</build>
  1. With your pom.xml now set up, the sandbox is built, filled with sand, and a bucket and shovel are at your feet. Get crafting. If you need some pointers on how to get started:
  • Your main plugin class will need an annotation to declare it as the main plugin class
    @Plugin(id = “A unique ID, can be the same as name”, name = “A User Friendly Name”, version = “whatever version you’re on”)
  • Similar to Bukkit, event handlers are declared by annotation. Use @Subscribe on a method to create an event handler.
  • You will need to register any event handling classes outside of your main plugin class. Note: You still need @Subscribe for event handling methods in the main class, you just don’t have to register them, this is done for you when your plugin is started. Someone please tag me if this is not right or has changed
  • Your main class can use the events found in “org.spongepowered.api.event.state” to make the Sponge equivalent of Bukkit’s onEnable() and onDisable() methods. I’m sorry to those who like to dig a chasm between Bukkit and Sponge, but lets be real, some things are relatively the same in concept.
  • If I had a crystal clear idea on how commands worked, I would share, but I’m still scratching my head at commands. It looks like you implement CommandCallable and just build your command around that?

Tag me again if you have any questions, or if I derped and said some nonsense that doesn’t make sense or is false.

2 Likes