<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>

    <parent>
        <groupId>com.magmaguy</groupId>
        <artifactId>ResourcePackManager-parent</artifactId>
        <version>2.3.1</version>
    </parent>

    <artifactId>ResourcePackManager</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>MagmaCore</artifactId>
        </dependency>
        <dependency>
            <groupId>org.geysermc.geyser</groupId>
            <artifactId>api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.bstats</groupId>
            <artifactId>bstats-bukkit</artifactId>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-mixer</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-bedrock</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-bridge-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-geyser-bridge</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-http-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-velocity</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.magmaguy</groupId>
            <artifactId>resourcepackmanager-bungee</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>ResourcePackManager</finalName>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>plugin.yml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>plugin.yml</exclude>
                </excludes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <minimizeJar>false</minimizeJar>
                            <relocations>
                                <relocation>
                                    <pattern>org.apache.hc</pattern>
                                    <shadedPattern>com.magmaguy.resourcepackmanager.org.apache.hc</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.bstats</pattern>
                                    <shadedPattern>com.magmaguy.resourcepackmanager.bstats</shadedPattern>
                                </relocation>
                                <!-- Relocate the shaded MagmaCore so its static singleton (and
                                     config-folder resolution via MagmaCore.getInstance().getRequestingPlugin())
                                     is isolated per plugin. Without this, every plugin that ships MagmaCore
                                     unrelocated shares one instance/requestingPlugin, so their configs
                                     (e.g. setupDone) collide in a single data folder and never persist
                                     per-plugin. -->
                                <relocation>
                                    <pattern>com.magmaguy.magmacore</pattern>
                                    <shadedPattern>com.magmaguy.resourcepackmanager.magmacore</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <!-- Mirror the built plugin jar to the shared top-level dist/ folder.
         Active only when MC_DIST_DIR is set, so clones/CI/public builds stay
         unaffected and no machine-specific path is ever committed. -->
    <profiles>
        <profile>
            <id>mc-dist-mirror</id>
            <activation>
                <property>
                    <name>env.MC_DIST_DIR</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>copy-to-mc-dist</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <copy file="${project.build.directory}/${project.build.finalName}.jar"
                                              todir="${env.MC_DIST_DIR}" overwrite="true"/>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
