Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed May 6, 2023
0 parents commit aa4429c
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Generate JavaDoc and Deploy to Pages

on:
push:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Generate JavaDoc
run: mvn javadoc:javadoc
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: 'target/site/apidocs/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
9 changes: 9 additions & 0 deletions .idea/.gitignore

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

7 changes: 7 additions & 0 deletions .idea/encodings.xml

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

19 changes: 19 additions & 0 deletions .idea/misc.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# MCUtils
A small library with a collection of useful functions for Minecraft paper plugins.

## Installation
Visit https://jitpack.io/#TechnicJelle/MCUtils for details on how to install this library.

## Usage
Please see the javadoc for the full API reference: [technicjelle.com/MCUtils](https://technicjelle.com/MCUtils/com/technicjelle/MCUtils.html)

### 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
copyJarResourceToBlueMap(BlueMapAPI, ClassLoader, String fromResource, String toAsset, boolean overwrite)
```

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

## TODO:
- [ ] Config helper stuff
- [ ] Logging helper stuff
- [ ] And more?
39 changes: 39 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.technicjelle</groupId>
<artifactId>MCUtils</artifactId>
<version>1.0</version>

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

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

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

</project>
71 changes: 71 additions & 0 deletions src/main/java/com/technicjelle/MCUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.technicjelle;

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 {
/**
* Copies any resource from your plugin's resource folder in the jar, to your plugin's config folder.
*
* @param plugin Your plugin instance. Usually <code>this</code>
* @param fromResource The path to the resource, relative to your plugin's resource folder
* @param toConfigFile The path to the config file, relative to your plugin's data folder
* @param overwrite Whether to overwrite the config file if it already exists
* @throws IOException If the resource could not be found or copied
*/
public static void copyPluginResourceToConfigDir(@NotNull JavaPlugin plugin, @NotNull String fromResource, @NotNull String toConfigFile, boolean overwrite) throws IOException {
Path toPath = plugin.getDataFolder().toPath().resolve(toConfigFile);

if (Files.exists(toPath) && !overwrite) return;
Files.createDirectories(toPath.getParent());
try (
@Nullable InputStream in = plugin.getResource(fromResource);
// To prevent creating empty files, make output stream null if input stream is null:
@Nullable OutputStream out = in == null ? null : Files.newOutputStream(toPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
) {
if (in == null) throw new IOException("Resource not found: " + fromResource);
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;
}
}
}

0 comments on commit aa4429c

Please sign in to comment.