Compare commits

...

9 Commits

Author SHA1 Message Date
Andreas Troelsen 29c5d7f56d Release 0.108. 2024-01-01 20:15:55 +01:00
Andreas Troelsen e40fc6ef84 Add `publish-hangar` GitHub Actions workflow.
Introduces a new workflow that runs when a new build has been published
on GitHub Releases. It converts the release notes to Hangar Markdown and
sends it to Hangar along with the jar-file.

Note: The workflow currently relies on the version string being appended
to the filename of the jar-file. Without it, the file reference in the
`curl` request that uploads the build would need to change.

The workflow references a new secret, `HANGAR_TOKEN`, which is just an
API key for the Hangar API. The token was created in the Hangar profile
settings (API Keys), and its only permission is `create_version`.

In order to properly upload a new build to Hangar, we need to construct
a somewhat complex JSON object. This is because the Hangar API allows
for publishing releases on multiple platforms and for multiple versions,
which makes the simple use case for MobArena's single file upload look a
bit overcomplicated. Unlike the CurseForge API, the Hangar API supports
"normal" platform version strings, so we don't need to map anything. It
also supports patch version wildcards, so we can get away with `1.18.x`,
`1.19.x`, etc. for each version supported. The API only uses the API key
for authentication, which means we need to grab a JWT and use that for
the actual upload request. Note that the `pluginDependencies` property
is currently required, but it can be left empty.

The workflow can be invoked directly via the `workflow_dispatch` event,
which might come in handy if something in the pipeline breaks.

The Hangar base URL and project slug are both hardcoded, and things
would probably be cleaner if they were made into variables, but we don't
need this workflow anywhere else, so it's fine for now.
2024-01-01 17:05:41 +01:00
Andreas Troelsen be6fd85a6d Add `publish-curseforge` GitHub Actions workflow.
Introduces a new workflow that runs when a new build has been published
on GitHub Releases. It converts the release notes to CurseForge HTML and
sends it to CurseForge along with the jar-file.

Note: The workflow currently relies on the version string being appended
to the filename of the jar-file. Without it, the file reference in the
`curl` request that uploads the build would need to change.

The workflow references a new secret, `CURSEFORGE_TOKEN`, which is just
an API key for the CurseForge API. The token was created on CurseForge
under profile settings (My API Tokens).

In order to properly upload a new build to CurseForge, we need a list of
"game version IDs", which isn't completely trivial. The API gives us a
means of looking up _all_ Minecraft game version IDs, but we then have
to manually filter out the ones that don't apply to Bukkit plugins, as
there are duplicate entries for each Minecraft version, and only some of
them work for Bukkit plugins (which turns out to be the ones with game
version type ID 1). The structure of the `metadata` field combined with
how incredibly difficult bash can be to work with has resulted in some
gnarly text processing trying to filter the JSON response and turning it
into a list for use in the `jq` template, but it gets the job done.

The CurseForge base URL and project ID are both hardcoded, and things
would probably be cleaner if they were made into variables, but we don't
need this workflow anywhere else, so it's fine for now.

The workflow can be invoked directly via the `workflow_dispatch` event,
which might come in handy if something in the pipeline breaks.

Lots of inspiration was found in the probably really great GitHub Action
`curseforge-upload` [1]. We could have probably just used that, but it's
nice to have full control of the process. At any rate, thanks to itsmeow
and NotMyFault for publishing their work.

---

[1] https://github.com/itsmeow/curseforge-upload
2024-01-01 16:46:38 +01:00
Andreas Troelsen b881943656 Add `hangar` format to release note script.
Hangar uses Markdown, so this is a very easy release note "conversion"
just like GitHub Releases.
2023-12-31 15:14:25 +01:00
Andreas Troelsen 8e5d2f0d23 Make InventoryThingParser package-private.
We don't need the parser exposed outside of the `things` package, and
none of the other thing parsers are public anyway. Coincidentally, this
fixes a warning about exposing InventoryThing outside of its visibility
scope, so yay.
2024-01-01 18:34:20 +01:00
Andreas Troelsen 3b7b638b00 Make LexeMatcher package-private.
We don't need it outside of the `formula` package.

This fixes warnings about exposing Lexeme outside of its visibility
scope, so yay.
2024-01-01 18:26:44 +01:00
Andreas Troelsen eb51a31720 Remove unused ThingManager constructor.
This fixes a warning about exposing ItemStackThingParser outside of its
visibility scope, but really it's just a good little cleanup step, since
the constructor in question is never used for anything. We might want to
eventually expose the ItemStackThingParser and use it in more places in
the code base, but in that case, and in that case it would probably make
sense to re-introduce the constructor, but I'm calling YAGNI on this in
order to nuke a warning.
2024-01-01 18:23:54 +01:00
Andreas Troelsen 82f00c5535 Fix "unary operator" warnings in FormulaManagerIT.
Okay, the reason the code included the unary plus was to more directly
represent the resulting expression, but I'm guessing the compiler isn't
going to respect that intent even if it could somehow understand it, so
it will probably remove the symbols and just parse it all the same.

Unlike with the unary plus, the unary minus can be "fixed" by wrapping
it in parentheses. The end result is of course the exact same, but the
intent is perhaps a bit clearer this way. We want to try to coerce the
compiler into creating an expression with "add a negative value", just
for the sake of "correctness" at the runtime evaluation level, but even
if that isn't what will actually happen, the explicit code is still a
bit easier to read. While unary plus is easy to disregard, "fixing" an
unnecessary unary minus would mean having to change the binary operator
before it, which muddies the intent of the expression.
2024-01-01 17:49:21 +01:00
Andreas Troelsen d8fdbb80c0 Simplify formula operation interfaces.
This commit releases the BinaryOperation and UnaryOperation interfaces
of the `formula` package from their `java.util.function` supertypes and
redeclares the previously inherited functions directly in the operation
interfaces, but also reifies them by explicitly using primitive doubles
instead of generics and wrapper classes. Doing so does not change the
functionality or any other code at all, but it makes the interfaces much
"stronger", since they no longer need to consider `null` values, which
they didn't actually take into account anyway. This fixes a warning in
Visual Studio Code (not sure how to get the same warning in IntelliJ)
about the operator registrations in the default formula environment
factory method being unsafe.
2024-01-01 19:39:59 +01:00
11 changed files with 189 additions and 21 deletions

View File

@ -0,0 +1,77 @@
name: publish-curseforge
on:
release:
types:
- 'released'
workflow_dispatch:
inputs:
tag_name:
description: 'The tag name of the release to publish'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
env:
TAG_NAME: ${{ github.event.release.tag_name || inputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download release assets
run: gh release download "${TAG_NAME}"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Publish to CurseForge
run: |
echo 'Extract release notes'
changelog=$(scripts/extract-release-notes -f curse "${TAG_NAME}")
echo 'Look up game version IDs'
game_version_type_id=1
game_version_names='"1.20","1.19","1.18","1.17","1.16","1.15","1.14","1.13"'
type_condition="(.gameVersionTypeID == ${game_version_type_id})"
name_condition="(.name | startswith(${game_version_names}))"
game_version_ids=$(
curl -s -X GET 'https://minecraft.curseforge.com/api/game/versions' \
-H "X-Api-Token: ${{ secrets.CURSEFORGE_TOKEN }}" \
| jq -c ".[] | select(${type_condition} and ${name_condition}) | .id" \
| paste -sd, - \
)
echo 'Create metadata file'
cat << EOF > metadata.jq
{
changelog: \$changelog,
changelogType: "html",
displayName: \$displayName,
gameVersions: \$gameVersions,
releaseType: "beta"
}
EOF
jq -c -n \
--arg changelog "${changelog}" \
--arg displayName "MobArena v${TAG_NAME}" \
--argjson gameVersions "[${game_version_ids}]" \
-f metadata.jq \
> metadata.json
echo 'Publish build to CurseForge'
base_url='https://minecraft.curseforge.com'
project_id=31265
curl -s -X POST "${base_url}/api/projects/${project_id}/upload-file" \
-H "X-Api-Token: ${{ secrets.CURSEFORGE_TOKEN }}" \
-F 'metadata=<metadata.json' \
-F "file=@MobArena-${TAG_NAME}.jar"

79
.github/workflows/publish-hangar.yml vendored Normal file
View File

@ -0,0 +1,79 @@
name: publish-hangar
on:
release:
types:
- 'released'
workflow_dispatch:
inputs:
tag_name:
description: 'The tag name of the release to publish'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
env:
TAG_NAME: ${{ github.event.release.tag_name || inputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download release assets
run: gh release download "${TAG_NAME}"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Publish to Hangar
run: |
echo 'Extract release notes'
changelog=$(scripts/extract-release-notes -f hangar "${TAG_NAME}")
echo 'Create version upload file'
cat << EOF > version-upload.jq
{
version: \$version,
channel: "Release",
description: \$changelog,
platformDependencies: {
"PAPER": [
"1.13.x",
"1.14.x",
"1.15.x",
"1.16.x",
"1.17.x",
"1.18.x",
"1.19.x",
"1.20.x"
]
},
pluginDependencies: {},
files: [
{ platforms: ["PAPER"] }
]
}
EOF
jq -c -n \
--arg version "${TAG_NAME}" \
--arg changelog "${changelog}" \
-f version-upload.jq \
> version-upload.json
echo 'Authenticate with Hangar'
base_url='https://hangar.papermc.io/api/v1'
key=${{ secrets.HANGAR_TOKEN }}
jwt=$(curl -s -X POST "${base_url}/authenticate?apiKey=${key}" | jq -r '.token')
echo 'Publish build to Hangar'
project_slug='MobArena'
curl -s -X POST "${base_url}/projects/${project_slug}/upload" \
-H "Authorization: ${jwt}" \
-F 'versionUpload=<version-upload.json;type=application/json' \
-F "files=@MobArena-${TAG_NAME}.jar"

View File

@ -4,7 +4,7 @@ plugins {
}
group = "com.garbagemule"
version = "0.107.1-SNAPSHOT"
version = "0.108"
repositories {
mavenLocal()

View File

@ -11,6 +11,8 @@ These changes will (most likely) be included in the next version.
## [Unreleased]
## [0.108] - 2024-01-01
### Added
- Support for chest references in item syntax. The new `inv` syntax allows for referencing container indices in the config-file. This should help bridge the gap between class chests and various other parts of the config-file, such as rewards and upgrade waves.
- Support for saved items. The new `/ma save-item` command can be used to save the currently held item to disk, which allows it to be used in various places in the config-file. This should help bridge the gap between the config-file and class chests for config-file centric setups.
@ -259,7 +261,8 @@ Thanks to:
- Swatacular for help with testing bug fixes
- Haileykins for contributions to the code base
[Unreleased]: https://github.com/garbagemule/MobArena/compare/0.107...HEAD
[Unreleased]: https://github.com/garbagemule/MobArena/compare/0.108...HEAD
[0.108]: https://github.com/garbagemule/MobArena/compare/0.107...0.108
[0.107]: https://github.com/garbagemule/MobArena/compare/0.106...0.107
[0.106]: https://github.com/garbagemule/MobArena/compare/0.105...0.106
[0.105]: https://github.com/garbagemule/MobArena/compare/0.104.2...0.105

View File

@ -26,7 +26,7 @@ def parse_args():
parser.add_argument(
'--format',
'-f',
choices=['github', 'spigot', 'curse'],
choices=['github', 'hangar', 'spigot', 'curse'],
help='the format to output the release notes in',
)
@ -80,6 +80,8 @@ def extract(target):
def output(lines, fmt):
if fmt == 'github':
output_as_github_markdown(lines)
elif fmt == 'hangar':
output_as_hangar_markdown(lines)
elif fmt == 'spigot':
output_as_spigot_bbcode(lines)
elif fmt == 'curse':
@ -97,6 +99,15 @@ def output_as_github_markdown(lines):
output_raw(lines[1:])
def output_as_hangar_markdown(lines):
"""
Hangar Versions use Markdown in the same format as GitHub Releases, so we
don't actually need to do anything else here either. Just strip the first
line so we don't get a duplicate header.
"""
output_raw(lines[1:])
def output_as_spigot_bbcode(lines):
"""
Spigot uses BBCode for resource update descriptions. It's very similar to

View File

@ -1,7 +1,8 @@
package com.garbagemule.MobArena.formula;
import java.util.function.BiFunction;
@FunctionalInterface
public interface BinaryOperation extends BiFunction<Double, Double, Double> {
public interface BinaryOperation {
double apply(double left, double right);
}

View File

@ -1,7 +1,8 @@
package com.garbagemule.MobArena.formula;
import java.util.function.Function;
@FunctionalInterface
public interface UnaryOperation extends Function<Double, Double> {
public interface UnaryOperation {
double apply(double value);
}

View File

@ -6,7 +6,7 @@ import org.bukkit.World;
import java.util.function.Supplier;
public class InventoryThingParser implements ThingParser {
class InventoryThingParser implements ThingParser {
private static final String PREFIX = "inv(";
private static final String SUFFIX = ")";

View File

@ -10,21 +10,17 @@ public class ThingManager implements ThingParser {
private final List<ThingParser> parsers;
private final ItemStackThingParser items;
public ThingManager(MobArena plugin, ItemStackThingParser parser) {
public ThingManager(MobArena plugin) {
parsers = new ArrayList<>();
parsers.add(new CommandThingParser());
parsers.add(new MoneyThingParser(plugin));
parsers.add(new PermissionThingParser(plugin));
parsers.add(new PotionEffectThingParser());
parsers.add(new InventoryThingParser(plugin.getServer()));
items = parser;
items = new ItemStackThingParser();
items.register(new SavedItemParser(plugin));
}
public ThingManager(MobArena plugin) {
this(plugin, new ItemStackThingParser());
}
/**
* Register a new thing parser in the manager.
*

View File

@ -230,8 +230,8 @@ public class FormulaManagerIT {
@Parameters(name = "{0} = {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"1 + +1.2", 1 + +1.2},
{"1 + -1.2", 1 + -1.2},
{"1 + +1.2", 1 + 1.2},
{"1 + -1.2", 1 + (-1.2)},
});
}
@ -259,8 +259,8 @@ public class FormulaManagerIT {
@Parameters(name = "{0} = {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"1+-2", 1 + -2},
{"3-+4", 3 - +4},
{"1+-2", 1 + (-2)},
{"3-+4", 3 - 4},
{"3*7.5", 3 * 7.5},
{"10/2.5", 10 / 2.5},
{"9%4", 9 % 4},

View File

@ -6,7 +6,7 @@ import org.hamcrest.TypeSafeMatcher;
import java.util.Objects;
public class LexemeMatcher extends TypeSafeMatcher<Lexeme> {
class LexemeMatcher extends TypeSafeMatcher<Lexeme> {
private final TokenType type;
private final String value;