Skip to content

Commit

Permalink
Improve API & Deploy to BlueColored Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Jul 21, 2024
1 parent 88eaf41 commit e570137
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 63 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to BlueColored Repo

on:
release:
types: [ released ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
TAG_NAME:
description: 'GitHub Tag Name (for comparing with project version)'
required: true

env:
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Check tag with project version
run: |
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
# Remove 'v' prefix from tag name
TAG_VERSION=$(sed 's/^v//g' <<< "$TAG_NAME")
if [ "$PROJECT_VERSION" != "$TAG_VERSION" ]; then
echo "Project version ($PROJECT_VERSION) does not match tag ($TAG_VERSION)"
exit 1
fi
- name: Set up credentials
shell: bash
env:
PASSWORD: ${{ secrets.MAVEN_SECRET }}
run: echo "<settings><servers><server><id>bluecolored-releases</id><username>technicjelle</username><password>$PASSWORD</password></server></servers></settings>" > ~/.m2/settings.xml
- name: Deploy
run: mvn clean deploy
16 changes: 8 additions & 8 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/configure-pages@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
- name: Generate JavaDoc
run: mvn javadoc:javadoc
run: mvn javadoc:javadoc -Dmaven.test.skip=true
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: 'target/site/apidocs/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
6 changes: 6 additions & 0 deletions .idea/copyright/MPL2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# MCUtils
A small library with a collection of useful functions for Minecraft paper plugins.
[![Latest Release](https://repo.bluecolored.de/api/badge/latest/releases/com/technicjelle/MCUtils?name=Latest%20Release&prefix=v)](https://repo.bluecolored.de/#/releases/com/technicjelle/MCUtils)

## Installation
Visit https://jitpack.io/#TechnicJelle/MCUtils for details on how to install this library.
A small library with a collection of useful functions for Minecraft Paper plugins.

## Usage
Please see the javadoc for the full API reference: [technicjelle.com/MCUtils](https://technicjelle.com/MCUtils/com/technicjelle/MCUtils.html)
## Install as dependency in Maven/Gradle
Visit https://repo.bluecolored.de/#/releases/com/technicjelle/MCUtils
for instructions on how to add this library as a dependency to your project.

You may want to shade the library!

## Usage/Overview of Features
Please see the javadoc for the full API reference:
- main (latest commit): https://technicjelle.com/MCUtils
- latest release: https://repo.bluecolored.de/javadoc/releases/com/technicjelle/MCUtils/latest
- Also has docs for previous releases (v2.0 and up)

### Copy Plugin Resource to Config Directory
This function copies any resource file from your plugin jar to your plugin's config directory.
This is useful for adding default configuration files to your plugin.
```java
copyPluginResourceToConfigDir(plugin, String fromResource, String toConfigFile, boolean overwrite)
ConfigUtils.copyPluginResourceToConfigDir(plugin, String fromResource, String toConfigFile, boolean overwrite)
```

### Download image from URL
This function downloads an image from a URL and returns the image as a BufferedImage.
```java
downloadImage(String);
downloadImage(URL)
ImageUtils.downloadImage(String)
ImageUtils.downloadImage(URL)
```

## TODO:
Expand Down
69 changes: 61 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,97 @@

<groupId>com.technicjelle</groupId>
<artifactId>MCUtils</artifactId>
<version>1.0</version>
<version>2.0</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>16</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<distributionManagement>
<repository>
<id>bluecolored-releases</id>
<url>https://repo.bluecolored.de/releases</url>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>deploy</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.8.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>deploy</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<links>
<link>https://jd.papermc.io/paper/1.13</link>
</links>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>papermc-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.1.0</version>
<version>24.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package com.technicjelle;
/*
* This file is part of MCUtils, licensed under the MPL2 License (MPL).
* Please keep tabs on https://github.com/TechnicJelle/MCUtils for updates.
*
* Copyright (c) TechnicJelle <https://technicjelle.com>
* Copyright (c) contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package com.technicjelle.MCUtils;

import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class MCUtils {

private MCUtils() {
/**
* Utility functions for dealing with configs
*/
public class ConfigUtils {
private ConfigUtils() {
throw new IllegalStateException("Utility class");
}

Expand All @@ -43,34 +54,4 @@ public static void copyPluginResourceToConfigDir(@NotNull JavaPlugin plugin, @No
in.transferTo(out);
}
}

/**
* Downloads an image from the given URL.
*
* @param url URL of the image
* @return The image, or <code>null</code> if it could not be found, or the url was invalid
*/
public static @Nullable BufferedImage downloadImage(@NotNull String url) {
try {
return downloadImage(new URL(url));
} catch (IOException e) {
return null;
}
}

/**
* Downloads an image from the given URL.
*
* @param url URL of the image
* @return The image, or <code>null</code> if it could not be found
*/
public static @Nullable BufferedImage downloadImage(@NotNull URL url) {
try (
InputStream in = url.openStream()
) {
return ImageIO.read(in);
} catch (IOException e) {
return null;
}
}
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/technicjelle/MCUtils/ImageUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of MCUtils, licensed under the MPL2 License (MPL).
* Please keep tabs on https://github.com/TechnicJelle/MCUtils for updates.
*
* Copyright (c) TechnicJelle <https://technicjelle.com>
* Copyright (c) contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package com.technicjelle.MCUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
* Utility functions for dealing with images
*/
public class ImageUtils {
private ImageUtils() {
throw new IllegalStateException("Utility class");
}

/**
* Downloads an image from the given URL.
*
* @param url URL of the image
* @return The image, or <code>null</code> if it could not be found, or the url was invalid
*/
public static @Nullable BufferedImage downloadImage(@NotNull String url) {
try {
return downloadImage(new URL(url));
} catch (IOException e) {
return null;
}
}

/**
* Downloads an image from the given URL.
*
* @param url URL of the image
* @return The image, or <code>null</code> if it could not be found
*/
public static @Nullable BufferedImage downloadImage(@NotNull URL url) {
try (
InputStream in = url.openStream()
) {
return ImageIO.read(in);
} catch (IOException e) {
return null;
}
}
}
Loading

0 comments on commit e570137

Please sign in to comment.