5zig / The-5zig-API

The official client API of The 5zig Mod.
Apache License 2.0
11 stars 2 forks source link

Use the API from a maven project #1

Closed ghost closed 7 years ago

ghost commented 7 years ago

It looks like the API is set up for IntelliJ.

How can I create a plugin using maven?

5zig commented 7 years ago

I don't use maven to build the 5zig mod, that's why the 5zig mod API doesn't use maven either. That may change at some point in the future since I do realize that systems like maven make it a lot easier to get started quickly. Nevertheless, it should not be too hard to import the 5zig mod API into a maven project. Simply download the jar file from the releases tab of this github repository and add the downloaded file as a local dependency in your pom.xml. Also, don't forget to add all local minecraft dependencies mentioned in the readme file.

ghost commented 7 years ago

Do I add the minecraft dependencies in the same way? Should I just copy the jars to my project directory and add it as a dependency?

ghost commented 7 years ago

Also, when I add the dependency, what are its groupId and artifactId?

5zig commented 7 years ago

Yes, you can add the Minecraft dependencies the same way. GroupId and artifactId should not matter, you could use for example net.the5zig and 5zigApi. If you need more help, a little Google search shouldn't be too hard ;)

ghost commented 7 years ago

I can't find the necessary Minecraft dependencies.

5zig commented 7 years ago

They are located in .minecraft/libraries

ghost commented 7 years ago

No, they aren't. Not the jar files you've said should be the dependencies.

5zig commented 7 years ago

They are, just check every directory in there.

ghost commented 7 years ago

For example, I don't have the required lwjgl-2.9.4. I only have lwjgl-2.9.2 and lwjgl-2.9.1

5zig commented 7 years ago

You may need to launch Minecraft 1.11.2 once. But there should not by any major difference between both versions you mentioned.

ghost commented 7 years ago

Hmm, funny that playing with 5zig mod 1.11.2 wouldn't generate those files.

Thank you for all your help! I haven't yet tried to fix b/c don't have access to MC servers, but will try in 4 hours.

ghost commented 7 years ago

Hmm, it doesn't seem to work.

Here's my dir structure:

.
├── lib
│   ├── The-5zig-API-1.0.9.jar
│   ├── authlib-1.5.24.jar
│   ├── log4j-api-2.0-beta9.jar
│   ├── log4j-core-2.0-beta9.jar
│   ├── lwjgl-2.9.1.jar
│   └── netty-all-4.0.23.Final.jar
├── pom.xml
└── src
    └── main
        └── java
            └── io
                └── github
                    └── theonlygusti
                        └── fivezigaddons
                            └── Main.java

My class Main.java:

package io.github.theonlygusti.fivezigaddons;

import eu.the5zig.mod.plugin.Plugin;
import eu.the5zig.mod.event.ChatSendEvent;
import eu.the5zig.mod.event.EventHandler;

@Plugin(name = "AddOns", version = "1.0")
public class Main {
  @EventHandler
  public void onChatSend(ChatSendEvent event) { // called whenever the player wants to send a chat message to the server.
    if (event.getMessage().equals("hello")) {
      event.setMessage("heya");
    }
  }
}

And what I expect to be the relevant parts of my pom.xml:

  <build>
    <!-- by outputting binaries straight to the minecraft foldder we can test
         the plugin without having to move them ourselves -->
    <directory>/Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins</directory>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- I took the version from building without this tag -->
        <version>3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>net.the5zig</groupId>
      <artifactId>5zigApi</artifactId>
      <version>1.0.9</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/The-5zig-API-1.0.9.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty</artifactId>
      <version>4.0.23</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/netty-all-4.0.23.Final.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>org.apache.logging</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.0-beta9</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/log4j-api-2.0-beta9.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>org.apache.logging</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.0-beta9</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/log4j-core-2.0-beta9.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>com.mojang</groupId>
      <artifactId>authlib</artifactId>
      <version>1.5.24</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/authlib-1.5.24.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>org.lwjgl</groupId>
      <artifactId>lwjgl</artifactId>
      <version>2.9.1</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/lwjgl-2.9.1.jar</systemPath>
    </dependency>
  </dependencies>
</project>

Sorry for such a ridiculously large dump of data, I'm just not sure how else to get all this info. across.

ghost commented 7 years ago

Building completes successfully, but I'm not sure if the dependencies are handled correctly.

maven outputs:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for io.github.theonlygusti:fivezigaddons:jar:0.0.1
[WARNING] 'dependencies.dependency.systemPath' for net.the5zig:5zigApi:jar should not point at files within the project directory, ${basedir}/lib/The-5zig-API-1.0.9.jar will be unresolvable by dependent projects @ line 66, column 19
[WARNING] 'dependencies.dependency.systemPath' for io.netty:netty:jar should not point at files within the project directory, ${basedir}/lib/netty-all-4.0.23.Final.jar will be unresolvable by dependent projects @ line 73, column 19
[WARNING] 'dependencies.dependency.systemPath' for org.apache.logging:log4j-api:jar should not point at files within the project directory, ${basedir}/lib/log4j-api-2.0-beta9.jar will be unresolvable by dependent projects @ line 80, column 19
[WARNING] 'dependencies.dependency.systemPath' for org.apache.logging:log4j-core:jar should not point at files within the project directory, ${basedir}/lib/log4j-core-2.0-beta9.jar will be unresolvable by dependent projects @ line 87, column 19
[WARNING] 'dependencies.dependency.systemPath' for com.mojang:authlib:jar should not point at files within the project directory, ${basedir}/lib/authlib-1.5.24.jar will be unresolvable by dependent projects @ line 94, column 19
[WARNING] 'dependencies.dependency.systemPath' for org.lwjgl:lwjgl:jar should not point at files within the project directory, ${basedir}/lib/lwjgl-2.9.1.jar will be unresolvable by dependent projects @ line 101, column 19
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building 5zigAddOns 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ fivezigaddons ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/theonlygust/Documents/Programming/Minecraft/5zigAddOns/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ fivezigaddons ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ fivezigaddons ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/theonlygusti/Documents/Programming/Minecraft/5zigAddOns/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ fivezigaddons ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ fivezigaddons ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ fivezigaddons ---
[INFO] Building jar: /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ fivezigaddons ---
[INFO] Building jar: /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar
[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing.
Instead of attaching the assembly file: /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar, it will become the file for main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[WARNING] Replacing pre-existing project main-artifact file: /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar
with assembly file: /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ fivezigaddons ---
[INFO] Installing /Users/theonlygusti/Library/Application Support/minecraft/the5zigmod/plugins/fivezigaddons-0.0.1.jar to /Users/theonlygusti/.m2/repository/io/github/theonlygusti/fivezigaddons/0.0.1/fivezigaddons-0.0.1.jar
[INFO] Installing /Users/theonlygusti/Documents/Programming/Minecraft/5zigAddOns/pom.xml to /Users/theonlygusti/.m2/repository/io/github/theonlygusti/fivezigaddons/0.0.1/fivezigaddons-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.988 s
[INFO] Finished at: 2017-03-18T17:06:49+00:00
[INFO] Final Memory: 17M/213M
[INFO] ------------------------------------------------------------------------
5zig commented 7 years ago

Your workspace seems fine to me. The only thing that is missing is the plugin.json, found here: plugin.json. Create the file in your resources directory and change the main class to io.github.theonlygusti.fivezigaddons.Main. You can also include some debug messages when the plugin has been loaded, as seen here.

ghost commented 7 years ago

hey thanks! What's a resource dir?

./src/main/resources?

5zig commented 7 years ago

Correct.

ghost commented 7 years ago

Thank you so much for all your help, all fixed!

Can probably be closed now ;)

5zig commented 7 years ago

Nice, glad it works! :)