Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Build and release plugin to CurseForge and Modrinth
on:
push:
tags:
- 'v*' # adjust to your tagging pattern
- 'v*'
workflow_dispatch:

env:
CURSEFORGE_PROJECT_ID: ${{ vars.CURSEFORGE_PROJECT_ID }}
MODRINTH_PROJECT_ID: ${{ vars.MODRINTH_PROJECT_ID }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -30,7 +34,13 @@ jobs:
id: jar
run: |
JAR_NAME=$(ls target/*.jar | grep -v 'original' | head -n 1)
echo "::set-output name=jar-path::$JAR_NAME"
echo "jar-path=$JAR_NAME" >> $GITHUB_OUTPUT
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: plugin-jar
path: ${{ steps.jar.outputs.jar-path }}


generate-changelog:
runs-on: ubuntu-latest
Expand All @@ -57,16 +67,41 @@ jobs:
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "Tag is: $TAG_NAME"
if echo "$TAG_NAME" | grep -iq "release"; then
echo "::set-output name=release_type::release"
echo "release_type=release" >> $GITHUB_OUTPUT
else
echo "::set-output name=release_type::beta"
echo "release_type=beta" >> $GITHUB_OUTPUT
fi

publish:
runs-on: ubuntu-latest
needs: [build, generate-changelog]

steps:
- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: plugin-jar
path: ./target

- name: Extract version string
id: version
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
CLEAN_VERSION=$(echo "$TAG_NAME" | grep -oE '[0-9]+(\.[0-9]+)*(-[A-Za-z0-9]+)?')
echo "version=$CLEAN_VERSION" >> "$GITHUB_OUTPUT"

- name: Upload to Modrinth
uses: cloudnode-pro/[email protected]
with:
token: ${{ secrets.MODRINTH_TOKEN }}
project: ${{ env.MODRINTH_PROJECT_ID }}
name: BasicHomes ${{ steps.version.outputs.version }}
version: ${{ steps.version.outputs.version }}
changelog: ${{ needs.generate-changelog.outputs.changelog }}
files: ${{ needs.build.outputs.jar-path }}
game-versions: '[ "1.21" ]'
loaders: '[ "bukkit", "spigot" ]'
status: listed

- name: Upload to CurseForge
uses: itsmeow/curseforge-upload@v3
with:
Expand All @@ -76,14 +111,4 @@ jobs:
file_path: ${{ needs.build.outputs.jar-path }}
changelog: ${{ needs.generate-changelog.outputs.changelog }}
changelog_type: markdown
release_type: ${{ needs.generate-changelog.outputs.release_type }}

- name: Upload to Modrinth
uses: cloudnode-pro/modrinth-publish@v1
with:
token: ${{ secrets.MODRINTH_TOKEN }}
project_id: ${{ env.MODRINTH_PROJECT_ID }}
file: ${{ needs.build.outputs.jar-path }}
version_number: ${{ github.ref_name }}
changelog: ${{ needs.generate-changelog.outputs.changelog }}
version_type: ${{ needs.generate-changelog.outputs.release_type }}
release_type: ${{ needs.generate-changelog.outputs.release_type }}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.gamecreep</groupId>
<artifactId>BasicHomes</artifactId>
<version>1.9.4-RELEASE-1.21</version>
<version>1.9.5-RELEASE-1.21.7</version>
<packaging>jar</packaging>

<name>BasicHomes</name>
Expand Down Expand Up @@ -83,7 +83,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.6-R0.1-SNAPSHOT</version>
<version>1.21.7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/gamecreep/basichomes/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Constants {

public static final String PLUGIN_VERSION = "1.9.4";
public static final String PLUGIN_VERSION = "1.9.5";
public static final int BSTATS_PLUGIN_ID = 25429;

public static final ChatColor INFO_COLOR = ChatColor.DARK_AQUA;
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/fr/gamecreep/basichomes/files/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class DataStore<T> {
private final File file;
Expand All @@ -25,14 +27,23 @@ public DataStore(final String fileName, final T defaultData, final Type type) {
this.data = this.loadOrCreate();
}

@SuppressWarnings("unchecked")
private T wrapMutable(T data) {
if (data instanceof List) {
return (T) new ArrayList<>((List<?>) data);
}
return data;
}

private T loadOrCreate() {
if (!this.file.exists()) {
this.saveData(this.defaultData);
return this.defaultData;
return this.wrapMutable(this.defaultData);
}

try (final FileReader reader = new FileReader(this.file)) {
return this.gson.fromJson(reader, this.type);
T loadedData = this.gson.fromJson(reader, this.type);
return this.wrapMutable(loadedData);
} catch (IOException e) {
LoggerUtils.logWarning("Failed to load data from " + this.file.getName());
return this.defaultData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

Expand All @@ -19,7 +18,7 @@ public class PositionDataHandler {
private final DataStore<List<SavedPosition>> dataStore;

public PositionDataHandler(@NonNull final String fileName) {
this.dataStore = new DataStore<>(fileName, Collections.emptyList(), new TypeToken<List<SavedPosition>>(){}.getType());
this.dataStore = new DataStore<>(fileName, new ArrayList<>(), new TypeToken<List<SavedPosition>>(){}.getType());
}

public void create(@NonNull final SavedPosition pos) {
Expand Down
Loading