Compare commits
55 Commits
7927ef83e3
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 72ac29a620 | |||
| 7135acbfed | |||
| 4bc838cbe7 | |||
| 8a37231777 | |||
| 17f394f9d3 | |||
| 7800db9243 | |||
| d7cea52164 | |||
| 4a600308a1 | |||
| ddef725da5 | |||
| 714609e5b0 | |||
| cf53783bf9 | |||
| d42b9aae09 | |||
| f8dd873189 | |||
| e2a4d57dd9 | |||
| b8d6819cd3 | |||
| 46dea4f781 | |||
| 50a66a254c | |||
| 4d142ad9d1 | |||
| 60e4523ff8 | |||
| 0e84cb1b0f | |||
| b165d67118 | |||
| e4bebd3908 | |||
| 1773361716 | |||
| 46c93685ad | |||
| 6100865cb0 | |||
| b122200f5d | |||
| 1a879be8b7 | |||
| 81da9ece26 | |||
| 3f49117286 | |||
| 3d6195e15d | |||
| be91726ccb | |||
| 78cd1fbdf0 | |||
| 4bb0046b26 | |||
| c3d76e84f2 | |||
| 03232e90f6 | |||
| 1e19b4cf4d | |||
|
|
fefa4a5ecc | ||
| 6d4cffed16 | |||
| 16be005595 | |||
| fa9d422eca | |||
|
|
0c60e4bd0c | ||
|
|
e769ba7088 | ||
|
|
6efed9abf2 | ||
|
|
bd0b4e38aa | ||
|
|
eb8bc5ab45 | ||
|
|
76656e471f | ||
|
|
7c3c703fc9 | ||
|
|
815d0be2d8 | ||
|
|
42e8f6078e | ||
|
|
c0ac52b40a | ||
|
|
e9c53a1b24 | ||
|
|
69dddfb6a0 | ||
|
|
116ec79bc7 | ||
|
|
eaaafa3fee | ||
|
|
bc8d6b9529 |
30
.env.example
Normal file
30
.env.example
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Configuration for tools/*.sh. Values are read as KEY=value data, not executed.
|
||||||
|
# Unquoted values may contain spaces; matching outer quotes are removed.
|
||||||
|
|
||||||
|
# Paper server
|
||||||
|
PAPER_VERSION=26.2
|
||||||
|
PAPER_BUILD=129
|
||||||
|
PAPER_USER_AGENT="majinnaibu-plugin-dev/1.0 (https://github.com/majinnaibu)"
|
||||||
|
JAVA_OPTS="-Xms2G -Xmx2G"
|
||||||
|
STOP_TIMEOUT=60
|
||||||
|
MINECRAFT_SERVER_JAR=paper-26.2-129.jar
|
||||||
|
|
||||||
|
# Relative paths are resolved from the project root; ~/ is expanded.
|
||||||
|
MINECRAFT_SERVER_PATH=./server
|
||||||
|
MINECRAFT_BACKUP_PATH=./backups
|
||||||
|
|
||||||
|
# Modrinth publishing
|
||||||
|
# Release version is read from Gradle and checked against the jar's plugin.yml.
|
||||||
|
MODRINTH_TOKEN=
|
||||||
|
MODRINTH_PROJECT_ID=5NYwxysp
|
||||||
|
# Optional Markdown override; empty generates notes from commits since the last tag.
|
||||||
|
MODRINTH_CHANGELOG=
|
||||||
|
MODRINTH_GAME_VERSIONS=26.2,26.3
|
||||||
|
MODRINTH_LOADERS=paper
|
||||||
|
MODRINTH_VERSION_TYPE=
|
||||||
|
MODRINTH_DEPENDENCIES=
|
||||||
|
MODRINTH_FILE=
|
||||||
|
# Sync project body/README to Modrinth during publish (true/false)
|
||||||
|
MODRINTH_SYNC_BODY=true
|
||||||
|
MODRINTH_DESCRIPTION_FILE=docs/modrinth-description.md
|
||||||
|
|
||||||
62
.github/workflows/gradle.yml
vendored
Normal file
62
.github/workflows/gradle.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
name: Java CI with Gradle
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main", "develop" ]
|
||||||
|
tags: [ "v*" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main", "develop" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 25
|
||||||
|
uses: actions/setup-java@v6
|
||||||
|
with:
|
||||||
|
java-version: '25'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Setup Gradle 9.8.0
|
||||||
|
uses: gradle/actions/setup-gradle@v5
|
||||||
|
with:
|
||||||
|
gradle-version: '9.8.0'
|
||||||
|
cache-read-only: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run: ./gradlew test
|
||||||
|
|
||||||
|
- name: Upload Test Report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: ScoreKeeper-test-report
|
||||||
|
path: |
|
||||||
|
build/reports/tests/test
|
||||||
|
build/test-results/test
|
||||||
|
if-no-files-found: ignore
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
- name: Build with Gradle Wrapper
|
||||||
|
run: ./tools/build-plugin.sh
|
||||||
|
|
||||||
|
- name: Extract Project Version
|
||||||
|
id: project_info
|
||||||
|
run: |
|
||||||
|
VERSION=$(./gradlew properties --no-daemon -q | awk -F ': ' '$1 == "version" {print $2}')
|
||||||
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Upload Plugin Artifact
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: ScoreKeeper-${{ steps.project_info.outputs.version }}
|
||||||
|
path: build/libs/*.jar
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 14
|
||||||
168
.github/workflows/release.yml
vendored
Normal file
168
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Git tag to release (e.g., v1.0.0)'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
prepare-release:
|
||||||
|
name: Validate Tag & Prepare Release Branch
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
tag_commit: ${{ steps.validate.outputs.tag_commit }}
|
||||||
|
tag_name: ${{ steps.validate.outputs.tag_name }}
|
||||||
|
release_branch: ${{ steps.validate.outputs.release_branch }}
|
||||||
|
version_name: ${{ steps.validate.outputs.version_name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Configure Git identity
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
|
- name: Validate Tag, Develop, Main, and Create Release Branch
|
||||||
|
id: validate
|
||||||
|
run: |
|
||||||
|
TAG="${{ github.event.inputs.tag }}"
|
||||||
|
echo "Target tag: $TAG"
|
||||||
|
|
||||||
|
# Fetch remote branches and tags
|
||||||
|
git fetch origin develop:develop main:main --tags
|
||||||
|
|
||||||
|
# 1. Verify tag exists
|
||||||
|
if ! git rev-parse -q --verify "refs/tags/$TAG" > /dev/null; then
|
||||||
|
echo "::error::Tag '$TAG' does not exist in the repository."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
|
||||||
|
echo "Tag '$TAG' points to commit: $TAG_COMMIT"
|
||||||
|
|
||||||
|
# 2. Verify tag commit is in develop branch
|
||||||
|
if ! git merge-base --is-ancestor "$TAG_COMMIT" origin/develop; then
|
||||||
|
echo "::error::Tag '$TAG' (commit $TAG_COMMIT) is not in the develop branch."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Confirmed: Tag '$TAG' is in develop branch."
|
||||||
|
|
||||||
|
# 3. Verify tag commit is in main, or fast-forward merge it to main
|
||||||
|
if git merge-base --is-ancestor "$TAG_COMMIT" origin/main; then
|
||||||
|
echo "Confirmed: Tag '$TAG' is already in main branch."
|
||||||
|
else
|
||||||
|
echo "Tag '$TAG' is not in main. Attempting fast-forward only merge..."
|
||||||
|
git checkout main
|
||||||
|
if ! git merge --ff-only "$TAG_COMMIT"; then
|
||||||
|
echo "::error::Tag '$TAG' cannot be fast-forward merged into main."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
git push origin main
|
||||||
|
echo "Successfully fast-forward merged '$TAG' into main."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. Create and push the release/v* branch from the tag commit
|
||||||
|
RELEASE_BRANCH="release/${TAG}"
|
||||||
|
echo "Creating release branch '$RELEASE_BRANCH' from commit $TAG_COMMIT..."
|
||||||
|
git checkout -B "$RELEASE_BRANCH" "$TAG_COMMIT"
|
||||||
|
git push -u origin "$RELEASE_BRANCH" --force
|
||||||
|
|
||||||
|
VERSION_NAME="${TAG#v}"
|
||||||
|
|
||||||
|
echo "tag_commit=$TAG_COMMIT" >> $GITHUB_OUTPUT
|
||||||
|
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
|
||||||
|
echo "release_branch=$RELEASE_BRANCH" >> $GITHUB_OUTPUT
|
||||||
|
echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
scorekeeper-release:
|
||||||
|
name: Build, Test & Publish Release
|
||||||
|
needs: prepare-release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout release commit
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.prepare-release.outputs.tag_commit }}
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Ensure tag ref is checked out
|
||||||
|
run: |
|
||||||
|
git checkout -q "refs/tags/${{ needs.prepare-release.outputs.tag_name }}"
|
||||||
|
|
||||||
|
- name: Validate Modrinth Credentials
|
||||||
|
id: check_credentials
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ secrets.MODRINTH_TOKEN }}" ]; then
|
||||||
|
echo "::warning::Modrinth release token was not provided. Release will not be published to Modrinth."
|
||||||
|
echo "::error::Missing MODRINTH_TOKEN secret. Please configure MODRINTH_TOKEN in repository secrets."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Set up JDK 25
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '25'
|
||||||
|
|
||||||
|
- name: Setup Gradle 9.8.0
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
with:
|
||||||
|
gradle-version: '9.8.0'
|
||||||
|
|
||||||
|
- name: Make Gradle wrapper executable
|
||||||
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run: ./gradlew test
|
||||||
|
|
||||||
|
- name: Upload Test Report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ScoreKeeper-test-report-${{ needs.prepare-release.outputs.tag_name }}
|
||||||
|
path: |
|
||||||
|
build/reports/tests/test
|
||||||
|
build/test-results/test
|
||||||
|
if-no-files-found: ignore
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
- name: Build ScoreKeeper Plugin Jar
|
||||||
|
run: ./tools/build-plugin.sh
|
||||||
|
|
||||||
|
- name: Upload Release Jar
|
||||||
|
if: success()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ScoreKeeper-${{ needs.prepare-release.outputs.version_name }}
|
||||||
|
path: build/libs/*.jar
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
- name: Publish to Modrinth & Update Description
|
||||||
|
env:
|
||||||
|
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||||
|
MODRINTH_VERSION: ${{ needs.prepare-release.outputs.version_name }}
|
||||||
|
TAG: ${{ needs.prepare-release.outputs.tag_name }}
|
||||||
|
run: |
|
||||||
|
chmod +x ./tools/publish-modrinth.sh
|
||||||
|
./tools/publish-modrinth.sh
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ needs.prepare-release.outputs.tag_name }}
|
||||||
|
name: ScoreKeeper ${{ needs.prepare-release.outputs.tag_name }}
|
||||||
|
files: build/libs/*.jar
|
||||||
|
generate_release_notes: true
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,3 +1,8 @@
|
|||||||
.gradle/
|
.gradle/
|
||||||
build/
|
build/
|
||||||
target/
|
target/
|
||||||
|
.worktrees/
|
||||||
|
bin/
|
||||||
|
/backups/
|
||||||
|
/server/
|
||||||
|
.env
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#Sun Mar 04 01:03:26 PST 2012
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
encoding//src/main/java=UTF-8
|
|
||||||
encoding//src/main/resources=UTF-8
|
|
||||||
encoding/<project>=UTF-8
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.apt.aptEnabled=false
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
|
||||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#Sun Feb 19 04:11:11 PST 2012
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
version=1
|
|
||||||
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
@@ -1,3 +1,10 @@
|
|||||||
{
|
{
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
"[java]": {
|
||||||
}
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"java.configuration.updateBuildConfiguration": "interactive",
|
||||||
|
"java.compile.nullAnalysis.mode": "automatic",
|
||||||
|
"chat.tools.terminal.autoApprove": {
|
||||||
|
"printf": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
90
AGENTS.md
Normal file
90
AGENTS.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Score Keeper: Shared Working Rules
|
||||||
|
|
||||||
|
These rules apply to agents and human contributors. Start with
|
||||||
|
[CONTRIBUTING.md](CONTRIBUTING.md) for setup, tasks, server safety, and release
|
||||||
|
procedures; [README.md](README.md) is the user-facing behavior reference.
|
||||||
|
|
||||||
|
## Quick orientation
|
||||||
|
|
||||||
|
- Java 25, Gradle 9.8.0 wrapper, Paper 26.2/26.3 only; no Bukkit/Spigot target.
|
||||||
|
- [ScoreKeeperPlugin.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreKeeperPlugin.java)
|
||||||
|
owns lifecycle, buckets, UUID-keyed scores, YAML persistence, archives,
|
||||||
|
reporting, and scheduled high-score runs.
|
||||||
|
- [ScoreBucket.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreBucket.java)
|
||||||
|
validates immutable definitions; [ScoreReporting.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreReporting.java)
|
||||||
|
defines audiences. [commands/](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/commands/)
|
||||||
|
contains eight executors wired in `onEnable` and
|
||||||
|
[plugin.yml](src/main/resources/plugin.yml).
|
||||||
|
- [CONTRIBUTING.md](CONTRIBUTING.md#project-overview-and-source-map) owns the source
|
||||||
|
map and architecture overview. Consult the [domain reference](docs/domain-score-tracking.md)
|
||||||
|
or [integration reference](docs/plugin-integration-and-event-wiring.md) only when
|
||||||
|
the task needs their detail. There are no built-in gameplay listeners or registered API service.
|
||||||
|
|
||||||
|
## Change discipline
|
||||||
|
|
||||||
|
- Inspect the source and current diff before editing. Preserve unrelated work;
|
||||||
|
make scoped, complete changes and document intentional behavior changes.
|
||||||
|
- Use **Score Keeper** in human-facing prose/display text. Keep `ScoreKeeper`
|
||||||
|
for repository URLs, plugin ID/data folder, Gradle/artifact names, and Java
|
||||||
|
symbols. Preserve scraper identifiers exactly as currently stored in
|
||||||
|
[project-description.json](docs/project-description.json).
|
||||||
|
Ask before renaming existing files or changing these integration identifiers.
|
||||||
|
- Follow existing Java patterns, Adventure components, UUID identity, and
|
||||||
|
plugin logging. Use Spotless rather than hand-formatting Java; preserve the
|
||||||
|
[AGPL header](config/license-header.txt). Do not add silent error recovery or
|
||||||
|
success messages for failed operations.
|
||||||
|
- Keep state and Paper API calls on the main thread. Do not introduce async
|
||||||
|
map access; marshal asynchronous results through Paper's synchronous scheduler.
|
||||||
|
- Wire command/API changes across executors, manifest, lifecycle, reporting,
|
||||||
|
persistence, and documentation as applicable. Preserve existing public overloads
|
||||||
|
and legacy YAML loading unless a migration is explicitly agreed.
|
||||||
|
- Preserve documented quirks until intentionally changed: unguarded score
|
||||||
|
mutations, signed integer arithmetic, lazy score entries, case-sensitive bucket
|
||||||
|
IDs, shutdown-only saves, and run snapshot restoration. Do not "fix" these as
|
||||||
|
incidental cleanup.
|
||||||
|
- Prefer existing helpers and dependencies. Do not introduce a service layer,
|
||||||
|
test harness, runtime dependency, or supported platform without a task need.
|
||||||
|
- Edit source, not generated `build/`, `bin/`, or `.gradle/` files. Never read,
|
||||||
|
expose, or commit `.env` credentials, server player data, or publishing tokens.
|
||||||
|
|
||||||
|
## Validation
|
||||||
|
|
||||||
|
- With JDK 25/JAVA_HOME configured, use `./gradlew spotlessCheck build` for Java
|
||||||
|
changes (`.\gradlew.bat` on Windows). For macOS/Linux bootstrapping, use
|
||||||
|
`./tools/build-plugin.sh spotlessCheck`. Run narrower relevant tasks when enough.
|
||||||
|
- `./gradlew spotlessApply` applies Java style; review the resulting diff and
|
||||||
|
avoid unrelated formatting churn.
|
||||||
|
- There are currently **no Java test sources/dependencies**; `test` is
|
||||||
|
`NO-SOURCE`, and no `integrationTest` task exists. Never claim a build proves
|
||||||
|
behavior or claim JUnit coverage. When tests are added, keep normal tests
|
||||||
|
server-free; real Paper integration tests should be explicit/opt-in.
|
||||||
|
- Use [human-tests.md](docs/human-tests.md) for affected runtime scenarios and
|
||||||
|
pre-release testing. Report checks actually run and any remaining unverified
|
||||||
|
behavior. For docs-only work, check relative links and metadata instead of building.
|
||||||
|
|
||||||
|
## Documentation and operational safety
|
||||||
|
|
||||||
|
- Keep [README.md](README.md), [Modrinth description](docs/modrinth-description.md),
|
||||||
|
[project-description.md](docs/project-description.md), and
|
||||||
|
[project-description.json](docs/project-description.json) aligned with source.
|
||||||
|
Validate the JSON as a slug-keyed object against
|
||||||
|
[projects.schema.json](docs/projects.schema.json). Keep manual scenarios
|
||||||
|
separate from automated coverage claims.
|
||||||
|
- When updating [project-description.json](docs/project-description.json),
|
||||||
|
preserve the existing top-level project key, `id`, `title`, `docId`, and all
|
||||||
|
image URLs (`image.url` and `headerImage.url`, when present). These are fixed
|
||||||
|
in the consuming project; routine metadata updates must not reset them.
|
||||||
|
Preserve a null or absent `headerImage` as well. Image paths such as
|
||||||
|
`/projects/score-keeper/logo.png` are relative to the consuming project's
|
||||||
|
root, not this repository: do not resolve them locally, rewrite them as
|
||||||
|
repository URLs, or replace them with generated/remote image URLs.
|
||||||
|
Change these protected fields only when the user explicitly requests it.
|
||||||
|
- New project plans belong in [docs/](docs/); use checkboxes for actionable
|
||||||
|
work only. [Modernize.md](docs/Modernize.md) supersedes the historical `.cursor`
|
||||||
|
plan/rules. Planning/documentation tasks should not opportunistically implement
|
||||||
|
the plan's code changes.
|
||||||
|
- Do not run server start/stop, deploy, restore, tagging, or publishing operations
|
||||||
|
without explicit authorization. Bash start/stop currently match all local
|
||||||
|
Java `paper-*.jar` processes; restore replaces archived top-level items.
|
||||||
|
PowerShell start/stop can force termination. Prefer a clean console `stop`
|
||||||
|
and inspect exact server paths/processes on isolated test machines.
|
||||||
326
CONTRIBUTING.md
326
CONTRIBUTING.md
@@ -1,45 +1,295 @@
|
|||||||
# Contributing to ScoreKeeper
|
# Contributing to Score Keeper
|
||||||
|
|
||||||
Thank you for your interest in contributing to the ScoreKeeper plugin! This guide will help you set up your development environment and follow best practices for working with the project.
|
**Start here to work on Score Keeper.** This guide covers the project structure,
|
||||||
|
setup, validation, and publishing. The display name is **Score Keeper**; the
|
||||||
|
repository, Gradle project, plugin ID, and jar basename remain `ScoreKeeper`.
|
||||||
|
|
||||||
## Development Environment Setup
|
## Your first contribution
|
||||||
|
|
||||||
To develop and test the ScoreKeeper plugin, you will need:
|
1. Read [the project overview](#project-overview-and-source-map) below.
|
||||||
- A Paper Minecraft server (for plugin deployment and testing)
|
Consult [README.md](README.md) if you need user-facing commands and behavior.
|
||||||
- The official Minecraft Java Edition client (for connecting to your test server)
|
2. Read [AGENTS.md](AGENTS.md) once for the shared rules humans and agents follow.
|
||||||
|
This guide owns onboarding; that file owns change discipline and safety rules.
|
||||||
|
3. Follow [prerequisites and checkout](#prerequisites-and-checkout) to build.
|
||||||
|
4. Make a scoped change, then use [build and validation tasks](#build-format-and-validation-tasks).
|
||||||
|
Set up a local Paper server only if the affected behavior needs runtime testing.
|
||||||
|
5. Run the relevant [manual checks](docs/human-tests.md) and report what you verified.
|
||||||
|
|
||||||
### 1. Setting up the Paper Server (macOS/Linux/WSL)
|
You do **not** need to read every document before starting. Use these deeper
|
||||||
1. Download the latest Paper server jar from [https://papermc.io/downloads](https://papermc.io/downloads).
|
references when your task needs them:
|
||||||
2. Create a directory for your test server and place the Paper jar inside.
|
|
||||||
3. Set the following environment variables in your shell profile (e.g., `.bashrc`, `.zshrc`, or manually in your terminal):
|
|
||||||
```bash
|
|
||||||
export MINECRAFT_SERVER_PATH=/path/to/your/server
|
|
||||||
export MINECRAFT_SERVER_JAR=paper-<version>.jar # Can be relative to MINECRAFT_SERVER_PATH or absolute
|
|
||||||
```
|
|
||||||
4. Use the provided scripts to manage your server:
|
|
||||||
- To start (or restart) the server: `tools/bash/start-server.sh`
|
|
||||||
- To stop the server: `tools/bash/stop-server.sh`
|
|
||||||
These scripts use the environment variables above to locate and manage your server.
|
|
||||||
5. On first run, accept the EULA by editing `eula.txt` and setting `eula=true` in your server directory.
|
|
||||||
6. Place your built plugin jar in the `plugins/` directory.
|
|
||||||
7. Use the start script again to restart the server and load the plugin.
|
|
||||||
|
|
||||||
### 2. Setting up the Minecraft Client
|
- [Domain reference](docs/domain-score-tracking.md): score rules, YAML layout,
|
||||||
- **macOS/Linux:**
|
archives, and ranking.
|
||||||
- Download and install the official Minecraft Launcher from [minecraft.net](https://www.minecraft.net/en-us/download).
|
- [Integration reference](docs/plugin-integration-and-event-wiring.md): detailed
|
||||||
- Log in with your Mojang/Microsoft account and launch the Java Edition client.
|
command/lifecycle wiring and API usage, especially for companion-plugin authors.
|
||||||
- **WSL (Windows Subsystem for Linux):**
|
- [Modernization plan](docs/Modernize.md) and [TODO.md](TODO.md): planned work,
|
||||||
- For best performance, run the Minecraft client directly under Windows, not inside WSL.
|
not additional onboarding requirements.
|
||||||
- Download and install the official Minecraft Launcher for Windows from [minecraft.net](https://www.minecraft.net/en-us/download).
|
|
||||||
- Use WSL for server and plugin development, and connect to your test server from the Windows client.
|
|
||||||
|
|
||||||
### 3. Connecting the Client to Your Server
|
The old `.cursor` plan and rules are historical context, not the current setup
|
||||||
- Start your Paper server (see above).
|
or validation procedure. In particular, the Maven migration is already complete.
|
||||||
- In the Minecraft client, add a new server with the address:
|
|
||||||
- `localhost` (if running both client and server on the same machine)
|
|
||||||
- Or use your machine's IP address if connecting across devices.
|
|
||||||
|
|
||||||
### 4. Notes
|
## Project overview and source map
|
||||||
- You can automate server startup and plugin deployment with bash scripts for faster testing.
|
|
||||||
- For automated testing or CI, run the Paper server in a headless Linux environment (including WSL, Docker, or CI runners).
|
Score Keeper is a command-driven Paper scoring engine: named buckets hold
|
||||||
- Always use the provided scripts and environment variables for consistent server management.
|
UUID-keyed integer scores with custom units, initial values, and reporting.
|
||||||
|
It provides eight commands, score archives, high-score runs, and a public Java
|
||||||
|
API. Gameplay events do not award scores automatically; companion plugins can
|
||||||
|
provide that behavior.
|
||||||
|
|
||||||
|
| Source | Responsibility |
|
||||||
|
| --- | --- |
|
||||||
|
| [ScoreKeeperPlugin.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreKeeperPlugin.java) | Entry point, state, public API, persistence, reporting, ranking, and run completion |
|
||||||
|
| [ScoreBucket.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreBucket.java) | Immutable bucket definition and validation |
|
||||||
|
| [ScoreReporting.java](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreReporting.java) | Reporting policy enum and parsing |
|
||||||
|
| [commands/](src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/commands/) | Eight executors: arguments, online targets, selected permission guards, and messages |
|
||||||
|
| [plugin.yml](src/main/resources/plugin.yml) | Plugin identity, entry point, API version, command declarations, and admin permission |
|
||||||
|
| [tools/](tools/) / [PowerShell helpers](tools/powershell/) | Developer/server/release tooling; platform differences are documented below |
|
||||||
|
| [.env.example](.env.example) | Bash helper configuration template, not plugin configuration |
|
||||||
|
|
||||||
|
### Architecture in one minute
|
||||||
|
|
||||||
|
```text
|
||||||
|
Paper command -> executor parses/checks permissions/resolves online target
|
||||||
|
-> ScoreKeeperPlugin selects bucket and updates UUID-keyed state
|
||||||
|
-> bucket reporting OR run reporting and target completion
|
||||||
|
|
||||||
|
onEnable -> wire commands -> initialize points -> load scores and archives
|
||||||
|
-> check existing runs -> schedule synchronous checks every 20 ticks
|
||||||
|
onDisable -> save scores.yml (version 3) and archives.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Most behavior lives in the entry-point class; there is no separate service layer,
|
||||||
|
custom scoring event API, ServicesManager registration, or standalone API artifact.
|
||||||
|
State uses nested `LinkedHashMap` collections and is not thread-safe. Keep state
|
||||||
|
and Paper API calls on the main thread.
|
||||||
|
|
||||||
|
There is no plugin `config.yml`: commands/API create buckets and policies,
|
||||||
|
which are stored in the plugin's data files. Do not edit generated `build/`,
|
||||||
|
`bin/`, or `.gradle/` outputs.
|
||||||
|
|
||||||
|
### Behavior to understand before changing it
|
||||||
|
|
||||||
|
- Scores, assignments, active runs, and archives save **on disable**, not every
|
||||||
|
mutation. Crashes can lose recent changes; the two YAML writes are not a transaction.
|
||||||
|
Loading supports legacy flat UUID scores but is not comprehensive schema validation.
|
||||||
|
- Score get/add/subtract/reset and archive-list are unguarded; players can modify
|
||||||
|
any online player's score. Archive creation, bucket administration, and run
|
||||||
|
management require `scorekeeper.admin`; self bucket selection is open.
|
||||||
|
- Named targets are online-only. `/score-get` reads the target's active bucket,
|
||||||
|
lazily creates an entry at its initial value, and shows only the numeric score.
|
||||||
|
An explicit bucket argument is pending SK-13; the API already has that overload.
|
||||||
|
- Amounts are signed Java integers; negatives are allowed and overflow wraps.
|
||||||
|
Bucket IDs are case-sensitive.
|
||||||
|
- `until-disabled` runs are saved/resumed across clean restarts, not ended by
|
||||||
|
disable. Reset runs restore the pre-run snapshot. Results are announced/logged,
|
||||||
|
not automatically archived; stop a run before archiving its bucket.
|
||||||
|
|
||||||
|
The [domain reference](docs/domain-score-tracking.md) explains these rules in
|
||||||
|
detail. Treat changes to them as deliberate behavior changes, not incidental cleanup.
|
||||||
|
|
||||||
|
## Prerequisites and checkout
|
||||||
|
|
||||||
|
The project targets **Paper 26.2 and 26.3 only**, compiles against
|
||||||
|
`io.papermc.paper:paper-api:26.2.build.129-stable`, and uses **Java 25** and the
|
||||||
|
**Gradle 9.8.0 wrapper**. Bukkit and Spigot servers are not supported.
|
||||||
|
|
||||||
|
Install Git and a JDK 25, and set `JAVA_HOME` to the JDK root (not its `bin`
|
||||||
|
directory). Confirm `java -version` and `javac -version` report 25. The Gradle
|
||||||
|
toolchain resolver can download the compile JDK, but Gradle itself still needs
|
||||||
|
a compatible JVM to start. Automatic local JDK detection is disabled in
|
||||||
|
[gradle.properties](gradle.properties); `JAVA_HOME` is the configured discovery source.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/headhunter45/ScoreKeeper.git
|
||||||
|
cd ScoreKeeper
|
||||||
|
./gradlew spotlessCheck build
|
||||||
|
```
|
||||||
|
|
||||||
|
On Windows, use `.\gradlew.bat spotlessCheck build` from PowerShell instead.
|
||||||
|
No globally installed Gradle or Maven is required.
|
||||||
|
|
||||||
|
On macOS/Linux, [tools/build-plugin.sh](tools/build-plugin.sh) is an alternative:
|
||||||
|
it downloads/caches Temurin 25 under `.gradle/user-home/jdks`, sets `JAVA_HOME`
|
||||||
|
for that invocation, and runs `build`. It accepts additional Gradle arguments:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tools/build-plugin.sh spotlessCheck
|
||||||
|
```
|
||||||
|
|
||||||
|
That JDK selection is local to the script; it does not configure Java for your
|
||||||
|
terminal, IDE, Paper server, or later direct wrapper invocations.
|
||||||
|
|
||||||
|
## Build, format, and validation tasks
|
||||||
|
|
||||||
|
Run these from the repository root, using the Windows wrapper where applicable.
|
||||||
|
|
||||||
|
| Command | Purpose |
|
||||||
|
| --- | --- |
|
||||||
|
| `./gradlew build` | Compile, package, and run configured checks, including Spotless and `test`. |
|
||||||
|
| `./gradlew assemble` | Package without running the full check lifecycle. |
|
||||||
|
| `./gradlew spotlessCheck` | Verify Java formatting, imports, and license headers. |
|
||||||
|
| `./gradlew spotlessApply` | Apply the configured Java formatting; inspect the diff afterward. |
|
||||||
|
| `./gradlew test` | Run the default test task; currently there are no test sources/dependencies, so this is `NO-SOURCE`. |
|
||||||
|
| `./gradlew javadoc` | Generate Java API documentation. |
|
||||||
|
| `./gradlew properties --property version` | Inspect the Git-derived version. |
|
||||||
|
| `./gradlew publishToMavenLocal` | Publish the Java component to your local Maven repository for companion-plugin development. |
|
||||||
|
|
||||||
|
Build configuration lives in [build.gradle](build.gradle) (Groovy DSL), with
|
||||||
|
`java-library` and `maven-publish`. Paper is a `compileOnly` dependency supplied
|
||||||
|
by the server; no third-party runtime dependencies are bundled.
|
||||||
|
Spotless 8.10.3 uses google-java-format 1.36.1, import cleanup/order, and
|
||||||
|
[the license header](config/license-header.txt). The wrapper version/checksum
|
||||||
|
are pinned in [wrapper properties](gradle/wrapper/gradle-wrapper.properties);
|
||||||
|
the Foojay toolchain resolver is configured in [settings.gradle](settings.gradle).
|
||||||
|
|
||||||
|
The plugin artifact is `build/libs/ScoreKeeper-<version>.jar`. Versioning uses
|
||||||
|
`org.danilopianini.git-sensitive-semantic-versioning` version 7.0.24, a minimum
|
||||||
|
project version of `0.2.1`, and `v`-prefixed tags. Do not hardcode a release
|
||||||
|
version in the manifest:
|
||||||
|
[plugin.yml](src/main/resources/plugin.yml) expands `${version}` during resource processing.
|
||||||
|
|
||||||
|
There is **no behavioral automated coverage yet** and no `integrationTest` task.
|
||||||
|
The test infrastructure and coverage are pending SK-08 through SK-12 in
|
||||||
|
[TODO.md](TODO.md). A successful build is not proof that in-game behavior works.
|
||||||
|
For code changes, run the smallest relevant existing checks, then exercise the
|
||||||
|
affected scenarios in [human-tests.md](docs/human-tests.md). Documentation-only
|
||||||
|
changes need link/metadata checks, not a Paper server.
|
||||||
|
|
||||||
|
CI in [gradle.yml](.github/workflows/gradle.yml) runs for pushes and pull requests
|
||||||
|
to `main` and `develop`, and any `v*` tags. Manual releases are handled via
|
||||||
|
[release.yml](.github/workflows/release.yml). It invokes `test`, builds with the
|
||||||
|
Bash helper, and uploads jar artifacts (test reports only if present). It does
|
||||||
|
not start Paper or verify the two-version runtime compatibility claim.
|
||||||
|
|
||||||
|
## Local Paper server: macOS, Linux, or WSL
|
||||||
|
|
||||||
|
The Bash server/deploy/backup/restore/publish scripts read a root `.env`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit it using [the example](.env.example) as the configuration reference:
|
||||||
|
|
||||||
|
- `PAPER_VERSION`, `PAPER_BUILD`, and `MINECRAFT_SERVER_JAR` must agree.
|
||||||
|
The example pins `26.2`, build `129`, and `paper-26.2-129.jar`. To test 26.3,
|
||||||
|
select a build for that version or clear both build and jar values to resolve
|
||||||
|
the latest stable build.
|
||||||
|
- `MINECRAFT_SERVER_PATH` and `MINECRAFT_BACKUP_PATH` accept project-relative
|
||||||
|
paths, absolute paths, or `~/` paths. Defaults in the example are `./server`
|
||||||
|
and `./backups`.
|
||||||
|
- Values are literal `KEY=value` data, not shell code. Matching outer quotes
|
||||||
|
are removed, but `$HOME`, variable references, and command substitutions are
|
||||||
|
**not expanded**. Existing nonempty exported environment variables take precedence.
|
||||||
|
- Keep `.env` and publishing credentials out of Git.
|
||||||
|
|
||||||
|
For server startup, install `curl`, `jq`, `java` (Java 25), and `shasum`.
|
||||||
|
[start-server.sh](tools/start-server.sh) downloads missing Paper jars via the
|
||||||
|
Fill v3 API, verifies the supplied SHA-256 checksum, and runs Java in the
|
||||||
|
foreground with `--nogui`. It does not open a management GUI.
|
||||||
|
|
||||||
|
**Process safety:** the Bash start helper calls the stop helper, which matches
|
||||||
|
all Java processes running `paper-*.jar`, not just the configured server.
|
||||||
|
Backup/restore helpers also check for any such running server. Do not use these
|
||||||
|
helpers on a shared host without inspecting the processes and intended paths.
|
||||||
|
The safest stop is `stop` in your own server console; do not rely on forced
|
||||||
|
termination to save plugin data.
|
||||||
|
|
||||||
|
On an isolated development machine:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./tools/build-plugin.sh
|
||||||
|
./tools/deploy-plugin.sh
|
||||||
|
./tools/start-server.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Read and accept Minecraft's EULA before setting `eula=true` in the server's
|
||||||
|
`eula.txt`. The first launch exits until this is done; rerun the start helper
|
||||||
|
after accepting it. Use the matching Minecraft Java Edition client and connect
|
||||||
|
to `localhost` (or the server host's address). For WSL, run the client on Windows.
|
||||||
|
|
||||||
|
To redeploy, stop the server cleanly, build, copy the jar, and restart. Both
|
||||||
|
deploy helpers select the newest jar and **only warn** about stale sources;
|
||||||
|
they do not rebuild or reject stale artifacts. Remove older Score Keeper jars
|
||||||
|
from the test server's `plugins` directory so only the intended version loads.
|
||||||
|
|
||||||
|
### Backup and restore
|
||||||
|
|
||||||
|
[backup-server.sh](tools/backup-server.sh) archives plugins, config, world
|
||||||
|
directories containing `level.dat`, and top-level settings into a timestamped
|
||||||
|
`.tar.bz2`. Stop the server first; `--force` permits a potentially inconsistent
|
||||||
|
live backup. Generated Paper remapping caches and world session locks are excluded.
|
||||||
|
|
||||||
|
[restore-server.sh](tools/restore-server.sh) defaults to the newest backup,
|
||||||
|
asks for confirmation, and takes a pre-restore backup unless `--no-backup` is
|
||||||
|
specified. It **replaces** top-level items present in the archive. Inspect the
|
||||||
|
archive and resolved paths first, and use only a disposable/test server.
|
||||||
|
|
||||||
|
## Windows / PowerShell
|
||||||
|
|
||||||
|
The PowerShell helpers are not equivalent to the Bash server tooling: they do
|
||||||
|
not parse `.env`, download Paper, or provide backup/restore/publishing helpers.
|
||||||
|
Install JDK 25, obtain a Paper 26.2 or 26.3 server jar from
|
||||||
|
[Paper downloads](https://papermc.io/downloads/paper), and configure it manually.
|
||||||
|
Start it once, read/accept the EULA, and then launch it again.
|
||||||
|
|
||||||
|
Set real absolute paths in the current PowerShell session:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:MINECRAFT_SERVER_PATH = "$HOME\Projects\MCServer"
|
||||||
|
$env:MINECRAFT_SERVER_JAR = "paper-26.2-129.jar"
|
||||||
|
.\tools\powershell\Build-Plugin.ps1
|
||||||
|
.\tools\powershell\Deploy-Plugin.ps1
|
||||||
|
Set-Location $env:MINECRAFT_SERVER_PATH
|
||||||
|
java -jar $env:MINECRAFT_SERVER_JAR --nogui
|
||||||
|
```
|
||||||
|
|
||||||
|
Use your actual downloaded jar filename. Build uses the wrapper and your
|
||||||
|
configured Java environment. The legacy PowerShell start/stop helpers attempt
|
||||||
|
to discover Java processes by command line and forcibly terminate matches.
|
||||||
|
Prefer starting Java explicitly and typing `stop` in its console for reliable
|
||||||
|
shutdown and persistence.
|
||||||
|
|
||||||
|
## Publishing
|
||||||
|
|
||||||
|
[tools/publish-local.sh](tools/publish-local.sh) bootstraps a local JDK like the
|
||||||
|
build helper, then runs `publishToMavenLocal`. Coordinates are
|
||||||
|
`com.majinnaibu.minecraft.plugins:ScoreKeeper:<version>`.
|
||||||
|
|
||||||
|
[tools/publish-modrinth.sh](tools/publish-modrinth.sh) uploads a jar version to
|
||||||
|
Modrinth. Run it **only when intentionally publishing**, after validation:
|
||||||
|
|
||||||
|
1. Decide whether this is a tagged stable release or a development build.
|
||||||
|
For a stable release, tag the approved commit with `v<version>` and rebuild
|
||||||
|
from that tag; inspect Gradle's resulting version and jar metadata.
|
||||||
|
2. Configure `.env` with `MODRINTH_TOKEN`, project ID, game versions, and loaders.
|
||||||
|
Defaults advertise Paper `26.2,26.3` and the `paper` loader; test both before
|
||||||
|
publishing that compatibility claim.
|
||||||
|
3. Build the intended artifact. Optionally set `MODRINTH_FILE` to its exact path;
|
||||||
|
otherwise the newest non-`-all.jar` jar is selected.
|
||||||
|
4. Run the publisher with JDK 25 available to the wrapper. It checks the jar's
|
||||||
|
manifest version against Gradle, derives changelog notes from commits unless
|
||||||
|
overridden, and infers `beta` for versions containing `-`, otherwise `release`.
|
||||||
|
`MODRINTH_VERSION_TYPE` can override this with `alpha`, `beta`, or `release`;
|
||||||
|
`MODRINTH_DEPENDENCIES`, if supplied, must be a JSON array.
|
||||||
|
|
||||||
|
The publisher needs `curl`, `jq`, and `unzip`; it creates a version, **not** an
|
||||||
|
update to the hosted project description. Keep [modrinth-description.md](docs/modrinth-description.md)
|
||||||
|
and [modrinth.json](docs/modrinth.json) current and update the hosted description
|
||||||
|
separately when releasing.
|
||||||
|
|
||||||
|
## Documentation and scraper metadata
|
||||||
|
|
||||||
|
Keep [README.md](README.md), [modrinth-description.md](docs/modrinth-description.md),
|
||||||
|
[project-description.md](docs/project-description.md), and
|
||||||
|
[project-description.json](docs/project-description.json) consistent with implemented
|
||||||
|
features. Do not present planned work or manual checks as completed coverage.
|
||||||
|
|
||||||
|
The scraper JSON must validate against [projects.schema.json](docs/projects.schema.json).
|
||||||
|
It is a **slug-keyed object**, currently `{ "score-keeper": { ... } }`, not a
|
||||||
|
single unwrapped project. Follow [AGENTS.md](AGENTS.md#documentation-and-operational-safety):
|
||||||
|
the existing key, `id`, `title`, `docId`, and image URLs are fixed in the
|
||||||
|
consuming project and must remain unchanged during routine metadata updates.
|
||||||
|
Image paths are relative to that project's root, not this repository.
|
||||||
|
Preserve the route, repository links, and filenames unless the consumer contract
|
||||||
|
is intentionally changed. Use "Score Keeper" in descriptive prose.
|
||||||
|
|||||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
156
README.md
156
README.md
@@ -1,21 +1,135 @@
|
|||||||
# ScoreKeeper Plugin
|
# Score Keeper
|
||||||
|
|
||||||
## Running
|
[](https://github.com/headhunter45/ScoreKeeper/actions/workflows/gradle.yml)
|
||||||
|
|
||||||
### Commands
|
Score Keeper tracks player scores in named buckets for server events, competitions,
|
||||||
|
and companion plugins. Buckets support custom units, initial values, reporting,
|
||||||
* `/score-get [playerName]` - Displays the player's score.
|
archives, and target-based or timed high-score runs. Gameplay does not award points
|
||||||
* `/score-add [playerName] <amount>` - Add amount points to the player's score.
|
automatically: use commands or another plugin calling the public API.
|
||||||
* `/score-subtract [playerName] <amount>` - Subtracts amount points from the player's score.
|
|
||||||
* `/score-reset [playerName]` - Resets the player's score to 0.
|
Supports **Paper 26.2 and 26.3 only**, with **Java 25**. Bukkit and Spigot servers
|
||||||
* `/score-archive [playerName]` - Saves the player's score to a "High Scores" table and resets their current score to 0.
|
are not supported. The display name is Score Keeper; the repository and installed
|
||||||
|
plugin identifier remain `ScoreKeeper`.
|
||||||
NOTES:
|
|
||||||
* All commands will use the executing player in place of [playerName] if it is omitted.
|
## Installation
|
||||||
* Permissions support is coming AFTER I get archive to work.
|
|
||||||
* The commands aside from get are intended for admins and whatnot as some other plugin should be using the methods instead of letting player's execute commands.
|
1. Obtain a plugin jar from [Modrinth](https://modrinth.com/plugin/scorekeeper)
|
||||||
|
or build it using [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
## Development
|
2. Stop your Paper server cleanly. Back up existing plugin data.
|
||||||
|
3. Put `ScoreKeeper-<version>.jar` in the server's `plugins` directory, removing
|
||||||
See [CONTRIBUTING.md](CONTRIBUTING.md) for development environment setup instructions.
|
older Score Keeper jars so only one version loads.
|
||||||
|
4. Start the server and verify the plugin enables without errors.
|
||||||
|
|
||||||
|
Scores, bucket definitions, reporting, player assignments, and active runs load
|
||||||
|
from `plugins/ScoreKeeper/scores.yml`; archives load from
|
||||||
|
`plugins/ScoreKeeper/archives.yml`. Both are saved **on plugin disable/clean
|
||||||
|
shutdown**, not after every command. Crashes or forced termination can lose
|
||||||
|
changes since the last successful save. Do not edit these files while running.
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
### Commands
|
||||||
|
|
||||||
|
For commands with an optional player name, players can omit it to target themselves.
|
||||||
|
Named targets must be online. Console and RCON must provide a player name for
|
||||||
|
score get/add/subtract/reset; archive also supports `all` and `bucket` scopes.
|
||||||
|
Bucket IDs are case-sensitive and allow letters, numbers, `_`, and `-`.
|
||||||
|
Command-created singular/plural labels each occupy one argument.
|
||||||
|
Add/subtract accept signed 32-bit integers, including zero and negative amounts.
|
||||||
|
|
||||||
|
* `/score-get [playerName]` - Displays the target player's score in their active bucket.
|
||||||
|
* `/score-add <amount>` - Adds an amount to your score in your active bucket.
|
||||||
|
* `/score-add <playerName> <amount>` - Adds an amount to the target player's score.
|
||||||
|
* `/score-subtract <amount>` - Subtracts an amount from your score in your active bucket.
|
||||||
|
* `/score-subtract <playerName> <amount>` - Subtracts an amount from the target player's score.
|
||||||
|
* `/score-reset [playerName]` - Resets the target player's score in their active bucket to that bucket's initial value.
|
||||||
|
* `/score-archive` - Archives and resets your score in your active bucket.
|
||||||
|
* `/score-archive <playerName>` - Archives and resets the target player's score in their active bucket.
|
||||||
|
* `/score-archive all` - Archives and resets scores in every bucket.
|
||||||
|
* `/score-archive bucket <bucketId>` - Archives and resets every score in one bucket.
|
||||||
|
* `/score-archive-list` - Lists saved archive IDs, newest first.
|
||||||
|
* `/score-archive-list <archiveId>` - Displays the saved scores in one archive.
|
||||||
|
* `/score-bucket` - Displays your active bucket.
|
||||||
|
* `/score-bucket <bucketId>` - Switches your active bucket.
|
||||||
|
* `/score-bucket create <id> <singular> <plural> <initialValue> [reporting]` - Creates a bucket. Reporting is `admin`, `global`, `player`, or `none` and defaults to `none`.
|
||||||
|
* `/score-bucket <playerName> <bucketId>` - Switches a player's active bucket.
|
||||||
|
* `/score-bucket all <bucketId>` - Changes the server's default bucket and clears individual bucket assignments.
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> target <score>` - Starts a run that ends when a score reaches the target.
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> duration <time>` - Starts a timed run. Use a positive number followed by lowercase `s`, `m`, `h`, `d`, or `w` (for example, `4h`).
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> until-disabled` - Starts a run with no automatic end, including across clean restarts.
|
||||||
|
* `/score-run stop <bucketId>` - Ends an active run.
|
||||||
|
|
||||||
|
The reset argument for a run is the literal `true` or `false`, not `reset:true`.
|
||||||
|
Top N must be at least 1. For example:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/score-bucket create event point points 0 player
|
||||||
|
/score-bucket event
|
||||||
|
/score-run start event 3 true duration 4h
|
||||||
|
/score-add 10
|
||||||
|
/score-get
|
||||||
|
/score-run stop event
|
||||||
|
/score-archive bucket event
|
||||||
|
```
|
||||||
|
|
||||||
|
### Permissions
|
||||||
|
|
||||||
|
The `scorekeeper.admin` permission (default: operators) is required for
|
||||||
|
`score-archive`, bucket creation, switching another player/all players, and run
|
||||||
|
management. Viewing/selecting your own bucket requires no admin permission.
|
||||||
|
Score get/add/subtract/reset and archive-list currently have no permission
|
||||||
|
checks; add, subtract, and reset can target **any online player**. Restrict command
|
||||||
|
access externally if that is inappropriate for your server's scoring rules.
|
||||||
|
|
||||||
|
### Reporting, runs, and archives
|
||||||
|
|
||||||
|
When a player's active bucket changes, they are told the bucket name and their current score with its singular or plural unit.
|
||||||
|
|
||||||
|
Bucket reporting defaults to `none`; `admin` notifies operators and score admins
|
||||||
|
and logs the change, `global` notifies all online players, and `player` notifies
|
||||||
|
only the scored player. Only changed values produce reports. With `none`, a
|
||||||
|
successful add/subtract/reset can be silent; use `/score-get` to inspect the
|
||||||
|
numeric score. Scores can go negative and arithmetic overflow is not checked.
|
||||||
|
|
||||||
|
Each bucket can have one active run. During it, players receive their own score
|
||||||
|
changes regardless of the bucket reporting policy; changes by players in the
|
||||||
|
top N after the update are reported globally. Rankings include all recorded
|
||||||
|
bucket entries, even offline players. Ties sort by case-insensitive name, then UUID,
|
||||||
|
and have consecutive places. Finished runs announce/log the top-N table and each
|
||||||
|
online player's place. Reset runs restore the pre-run bucket scores; non-reset
|
||||||
|
runs leave earned scores intact. Timed runs use wall-clock time, including time
|
||||||
|
offline. An existing target can end a non-reset run immediately.
|
||||||
|
|
||||||
|
Run results are not automatically archived. Stop the run before archiving its
|
||||||
|
bucket. Archives snapshot the selected recorded scores and reset them to the
|
||||||
|
bucket initial value; they become durable at clean shutdown.
|
||||||
|
|
||||||
|
## Plugin API
|
||||||
|
|
||||||
|
Other plugins can create buckets with
|
||||||
|
`createBucket(id, singular, plural, initialValue, ScoreReporting)` and use
|
||||||
|
bucket-aware score methods. Existing no-bucket methods use the player's active
|
||||||
|
bucket. Runs use `startTargetScoreRun`, `startTimedScoreRun`,
|
||||||
|
`startUntilDisabledScoreRun`, and `stopHighScoreRun`.
|
||||||
|
|
||||||
|
Declare a dependency on plugin ID `ScoreKeeper`, obtain the enabled
|
||||||
|
`ScoreKeeperPlugin` instance, and call it on Paper's main thread. There is no
|
||||||
|
separate service registration or automatic gameplay integration. See
|
||||||
|
[plugin integration and event wiring](docs/plugin-integration-and-event-wiring.md)
|
||||||
|
for setup, overloads, and failure handling.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Start with [CONTRIBUTING.md](CONTRIBUTING.md) and the shared rules in
|
||||||
|
[AGENTS.md](AGENTS.md). The project uses Gradle 9.8.0, Java 25 toolchains, and
|
||||||
|
Spotless. The compile toolchain can be downloaded automatically, but the wrapper
|
||||||
|
still needs a compatible JVM to start.
|
||||||
|
|
||||||
|
There are currently no automated Java tests; a passing build does not exercise
|
||||||
|
plugin behavior. Use [human-tests.md](docs/human-tests.md) before releases.
|
||||||
|
See [the contributor guide's project overview](CONTRIBUTING.md#project-overview-and-source-map) for architecture and
|
||||||
|
[the modernization plan](docs/Modernize.md) for remaining work.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Score Keeper is licensed under the [GNU AGPL v3 or later](LICENSE).
|
||||||
|
|||||||
37
TODO.md
37
TODO.md
@@ -1,17 +1,22 @@
|
|||||||
# Migration TODOs for Paper Modernization
|
# Score Keeper Tasks
|
||||||
|
|
||||||
- [x] Switch all player score storage to use UUID instead of Player as the key
|
**Done** means implemented in source, not validated by automated behavioral tests.
|
||||||
- [ ] Update logger usage to use getLogger() from JavaPlugin
|
**Ready** means not yet implemented. See [docs/Modernize.md](docs/Modernize.md)
|
||||||
- [ ] Remove or modernize any old/deprecated event registration (use @EventHandler and registerEvents)
|
for the broader roadmap and [docs/human-tests.md](docs/human-tests.md) for manual
|
||||||
- [ ] Review and update player lookup logic to use getPlayerExact or handle case sensitivity
|
pre-release validation.
|
||||||
- [x] Ensure all commands are properly defined in plugin.yml
|
|
||||||
- [x] Initialize Gradle build system
|
| ID | Status | Title |
|
||||||
- [x] Set project metadata in build.gradle
|
| --- | --- | --- |
|
||||||
- [x] Add repositories and dependencies
|
| SK-01 | Done | Save scores between clean server launches using enable-time load and disable-time save. Crash-safe/periodic persistence is still future work. |
|
||||||
- [x] Configure Java version
|
| SK-02 | Done | Track independent UUID-keyed scores by named bucket with singular/plural units and initial values; support default and individual assignments. |
|
||||||
- [x] Ensure resource handling for plugin.yml
|
| SK-03 | Done | Add per-bucket `admin`, `global`, `player`, and `none` reporting policies. |
|
||||||
- [x] Add Gradle plugins as needed (e.g., Shadow)
|
| SK-04 | Done | Notify affected online players when their active bucket changes, including current score and units. |
|
||||||
- [x] Update .gitignore for Gradle
|
| SK-05 | Done | Implement target-score, timed, and manually stopped bucket runs with configurable top N, optional initial reset/snapshot restoration, global leader reporting, and final personal standings. Active runs persist across clean restarts. |
|
||||||
- [x] Remove Maven files
|
| SK-06 | Done | Archive player, bucket, or all-bucket scores and reset live entries to initial values; list archive IDs and contents. |
|
||||||
- [x] Update documentation and scripts
|
| SK-07 | Done | Replace the release plugin with Git-sensitive semantic versioning (minimum `0.2.1`, `v` tag prefix) and re-enable Gradle configuration cache. Versions are Git-derived, not a hardcoded snapshot. |
|
||||||
- [x] Test the Gradle build
|
| SK-08 | Ready | Add JUnit 5 test infrastructure and keep the default Gradle `test` task server-free. Use a compatible in-memory Paper harness such as MockBukkit; use Mockito only for narrow boundaries where a harness is unnecessary. |
|
||||||
|
| SK-09 | Ready | Add fast score/bucket tests: validation and duplicates, initial values, UUID isolation, lazy entries, default/per-player selection, and signed add/subtract/reset behavior. |
|
||||||
|
| SK-10 | Ready | Test YAML round trips, assignments, active runs/snapshots, archive contents/resets, legacy loading, and malformed/unknown entries using temporary data directories. |
|
||||||
|
| SK-11 | Ready | Test command validation/dispatch/permissions, reporting/messages, bucket switches, ranking/ties, top-N thresholds, target/duration/manual completion, and restoration. Use controllable time/scheduling where needed. |
|
||||||
|
| SK-12 | Ready | Add a separate opt-in `integrationTest` source set/task for real Paper loading, command dispatch, companion API wiring, and restart persistence. Keep it outside normal `test`/`build`. |
|
||||||
|
| SK-13 | Ready | Add an option to `/score-get` for a specific bucket, preserving current optional-player syntax. |
|
||||||
|
|||||||
82
build.gradle
82
build.gradle
@@ -1,15 +1,65 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'com.diffplug.spotless' version '8.10.3'
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'org.danilopianini.git-sensitive-semantic-versioning' version '7.0.24'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.majinnaibu.minecraft.plugins.'
|
group = 'com.majinnaibu.minecraft.plugins'
|
||||||
version = '0.2.0-SNAPSHOT'
|
description = "Score Keeper"
|
||||||
|
|
||||||
description = "ScoreKeeper"
|
gitSemVer {
|
||||||
|
minimumVersion.set('0.2.1')
|
||||||
|
versionPrefix.set('v')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
// options.compilerArgs << "-Xlint:deprecation"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(Javadoc).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'io.papermc.paper:paper-api:26.2.build.129-stable'
|
||||||
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion = JavaLanguageVersion.of(21)
|
// Paper 26.1+ requires Java 25.
|
||||||
|
languageVersion = JavaLanguageVersion.of(25)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('wrapper') {
|
||||||
|
gradleVersion = '9.8.0'
|
||||||
|
distributionType = Wrapper.DistributionType.BIN
|
||||||
|
distributionBase = Wrapper.PathBase.PROJECT
|
||||||
|
distributionPath = '.gradle/wrapper/dists'
|
||||||
|
archiveBase = Wrapper.PathBase.PROJECT
|
||||||
|
archivePath = '.gradle/wrapper/dists'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('updateDaemonJvm') {
|
||||||
|
languageVersion = JavaLanguageVersion.of(25)
|
||||||
|
}
|
||||||
|
|
||||||
|
def pluginVersion = project.version.toString()
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", pluginVersion
|
||||||
|
filesMatching('plugin.yml') {
|
||||||
|
expand(version: pluginVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,17 +68,13 @@ repositories {
|
|||||||
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
|
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
spotless {
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT'
|
java {
|
||||||
}
|
googleJavaFormat('1.36.1')
|
||||||
|
importOrder 'java', 'javax', 'com', 'net', 'org', ''
|
||||||
tasks.withType(JavaCompile).configureEach {
|
licenseHeaderFile 'config/license-header.txt'
|
||||||
options.encoding = 'UTF-8'
|
target 'src/**/*.java'
|
||||||
// options.compilerArgs << "-Xlint:deprecation"
|
removeUnusedImports()
|
||||||
}
|
toggleOffOn()
|
||||||
|
}
|
||||||
processResources {
|
|
||||||
filesMatching('plugin.yml') {
|
|
||||||
expand(project.properties)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
config/license-header.txt
Normal file
17
config/license-header.txt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
128
docs/Modernize.md
Normal file
128
docs/Modernize.md
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# Score Keeper Modernization Plan
|
||||||
|
|
||||||
|
Current baseline: October 2026. This replaces
|
||||||
|
[the historical Cursor plan](../.cursor/plans/Modernize.md) as the maintained
|
||||||
|
roadmap. It is a plan, not authorization to change runtime behavior or publish.
|
||||||
|
Read [CONTRIBUTING.md](../CONTRIBUTING.md) and [AGENTS.md](../AGENTS.md) first.
|
||||||
|
|
||||||
|
## Baseline: already implemented
|
||||||
|
|
||||||
|
The old Maven/Java 17/older Minecraft migration is no longer pending.
|
||||||
|
|
||||||
|
| Area | Current implementation |
|
||||||
|
| --- | --- |
|
||||||
|
| Build | Gradle 9.8.0 wrapper, Java 25 toolchain, Foojay resolver, configuration cache, Spotless |
|
||||||
|
| Paper target | API `26.2.build.129-stable`, manifest API `26.2`, documented Paper 26.2/26.3 support |
|
||||||
|
| Identity and messaging | UUID-based scores, Paper/Adventure messages, plugin logger, online `getPlayerExact` lookup |
|
||||||
|
| Domain | Named buckets, initial values, four reporting policies, default/individual assignments |
|
||||||
|
| Persistence | Version-3 scores YAML, archives YAML, legacy flat UUID score loading, shutdown save/enable load |
|
||||||
|
| Competitions | Target/timed/manual runs, scheduled checks, top-N rankings, score snapshots/restoration |
|
||||||
|
| Tooling | Bash build/deploy/server/backup/restore/local and Modrinth publishing; legacy PowerShell subset |
|
||||||
|
| Documentation | Contributor entry point, shared agent rules, current domain/integration references, manual release checklist, schema-shaped project metadata |
|
||||||
|
|
||||||
|
Implemented is not the same as verified on every advertised server version.
|
||||||
|
There are no automated Java tests yet; the CI `test` task is currently `NO-SOURCE`.
|
||||||
|
There is no real-server integration task and no automatic publishing workflow.
|
||||||
|
|
||||||
|
## Phase 1: reliable regression coverage (SK-08 through SK-11)
|
||||||
|
|
||||||
|
These are prerequisites for changing persistence, permissions, arithmetic, or
|
||||||
|
run behavior. Keep the default test task server-free.
|
||||||
|
|
||||||
|
- [ ] Add JUnit 5 infrastructure and an in-memory Paper harness compatible with
|
||||||
|
the current Java/Paper API (for example, MockBukkit if compatible). Use Mockito
|
||||||
|
only for narrow boundaries where a harness is unnecessary; verify compatibility
|
||||||
|
before choosing/pinning dependencies.
|
||||||
|
- [ ] Cover bucket ID/label/reporting validation, duplicates, initial values,
|
||||||
|
UUID isolation, lazy reads, active/default selection, all-player assignment
|
||||||
|
clearing, and signed add/subtract/reset semantics.
|
||||||
|
- [ ] Cover YAML round trips in temporary data directories: buckets, scores,
|
||||||
|
assignments, runs/snapshots, archives, and legacy flat scores. Include invalid
|
||||||
|
UUIDs, unknown buckets, malformed values, and empty archive buckets.
|
||||||
|
- [ ] Cover all eight command executors: sender/self/online-target resolution,
|
||||||
|
literal reset booleans, duration units/overflow, usage/errors, and existing
|
||||||
|
permission boundaries.
|
||||||
|
- [ ] Verify Adventure reporting audiences, changed-vs-unchanged scores, unit
|
||||||
|
labels, self/other bucket notices, and no duplicate run change notifications.
|
||||||
|
- [ ] Introduce a small controllable clock/scheduler seam where necessary for
|
||||||
|
deterministic run tests; avoid a wholesale architecture rewrite.
|
||||||
|
- [ ] Verify descending/name/UUID run ties, archive UUID ties, offline/unranked
|
||||||
|
entries, top-N boundaries, immediate targets, duration expiration, manual stop,
|
||||||
|
resumed runs, and exact pre-run score restoration (including new run entrants).
|
||||||
|
- [ ] Make CI produce real test reports and fail on these regressions once tests
|
||||||
|
exist; do not mistake missing reports for tested coverage.
|
||||||
|
|
||||||
|
## Phase 2: explicit real-server validation (SK-12)
|
||||||
|
|
||||||
|
- [ ] Add an opt-in `integrationTest` source set/task only for behavior requiring
|
||||||
|
actual Paper. Keep it out of normal `test`/`build`, use disposable directories,
|
||||||
|
and own/stop only the processes it starts.
|
||||||
|
- [ ] Load the built jar on both Paper 26.2 and 26.3 with Java 25; verify real
|
||||||
|
command registration/dispatch, Adventure output, scheduler completion, API
|
||||||
|
integration/load order, and persistence across clean restarts.
|
||||||
|
- [ ] Run [human-tests.md](human-tests.md) on both versions before release.
|
||||||
|
Record artifact version, Paper build, Java version, observations, and logs.
|
||||||
|
- [ ] Review startup/runtime deprecation warnings and unsupported API calls
|
||||||
|
found by builds/runtime tests; update compatibility claims only with evidence.
|
||||||
|
|
||||||
|
Do not broaden support to Spigot, Bukkit, Folia, or future Paper versions by
|
||||||
|
documentation changes alone.
|
||||||
|
|
||||||
|
## Phase 3: persistence and correctness hardening
|
||||||
|
|
||||||
|
Choose behavior changes explicitly and add regression tests first.
|
||||||
|
|
||||||
|
- [ ] Design safe periodic/dirty-state saves or explicit saves so crashes do not
|
||||||
|
lose all changes since shutdown. Decide save cadence and I/O threading while
|
||||||
|
snapshotting mutable state on the main thread.
|
||||||
|
- [ ] Design atomic replacement/recovery and consistency between score resets
|
||||||
|
and archives across the two YAML files. Preserve or migrate legacy data, and
|
||||||
|
ensure save failures are visible to administrators/callers.
|
||||||
|
- [ ] Define validation rules for malformed YAML rather than relying on defaulting
|
||||||
|
getters. Cover invalid integer types, assignments, missing archive fields,
|
||||||
|
empty snapshots, and recovery without overwriting good data.
|
||||||
|
- [ ] Decide whether integer overflow should fail, clamp, or use a wider score
|
||||||
|
type. Preserve negative-score use cases and provide an explicit data/API
|
||||||
|
migration if the type changes.
|
||||||
|
- [ ] Review the misleading `until-disabled` mode name: document current
|
||||||
|
resume-across-disable behavior until any new end-on-disable mode is deliberately
|
||||||
|
designed. Do not silently rename the command or change saved lifetime values.
|
||||||
|
|
||||||
|
## Phase 4: command and integration ergonomics
|
||||||
|
|
||||||
|
- [ ] Design permission nodes/defaults for score get/add/subtract/reset and archive
|
||||||
|
listing; define self-vs-other access and a migration strategy before restricting
|
||||||
|
currently open commands.
|
||||||
|
- [ ] Implement SK-13: explicit bucket selection for `/score-get`, with unambiguous
|
||||||
|
syntax, validation, help, docs, and tests. Preserve existing optional-player usage.
|
||||||
|
- [ ] Align manifest/executor help with supported archive scopes, reporting
|
||||||
|
arguments, and literal reset booleans; consider tab completion as a separate
|
||||||
|
tested improvement.
|
||||||
|
- [ ] Evaluate a smaller API/domain boundary only where needed for tested
|
||||||
|
behavior or companion integration. Retain public overload compatibility and
|
||||||
|
avoid unnecessary service abstractions.
|
||||||
|
|
||||||
|
## Phase 5: safer developer and release tooling
|
||||||
|
|
||||||
|
- [ ] Scope Bash start/stop/backup/restore process checks to the configured server
|
||||||
|
or a verified owned PID; never stop another project's Paper process.
|
||||||
|
- [ ] Verify the bootstrap helpers select an actual Java 25 JDK, not merely the
|
||||||
|
first cached Java executable, and document supported hosts.
|
||||||
|
- [ ] Bring PowerShell setup/configuration/process management to deliberate
|
||||||
|
parity with Bash or clearly retain a reduced supported surface. Prefer graceful
|
||||||
|
shutdown over forced termination.
|
||||||
|
- [ ] Make deployment select/verify the intended artifact and version instead of
|
||||||
|
relying only on newest modification time and a stale-source warning.
|
||||||
|
- [ ] Add lightweight local-link and JSON Schema checks for docs/metadata to CI,
|
||||||
|
keeping the scraper's slug-keyed contract and existing filenames.
|
||||||
|
- [ ] Rehearse a tagged release: rebuild after tagging, verify manifest/version,
|
||||||
|
run manual checks, review changelog and compatibility, upload deliberately, and
|
||||||
|
update hosted Modrinth description separately.
|
||||||
|
|
||||||
|
## Completion criteria
|
||||||
|
|
||||||
|
A modernization item is done only when its behavior and failure modes have
|
||||||
|
appropriate tests or recorded manual evidence, directly related docs are current,
|
||||||
|
and existing data/API contracts are preserved or explicitly migrated. Use
|
||||||
|
[TODO.md](../TODO.md) for SK feature/task status; this plan organizes the broader
|
||||||
|
work and must not mark unchecked tests or future infrastructure as implemented.
|
||||||
182
docs/domain-score-tracking.md
Normal file
182
docs/domain-score-tracking.md
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
# Score Keeper - Score-Tracking Domain
|
||||||
|
|
||||||
|
This documents implemented behavior in
|
||||||
|
[ScoreKeeperPlugin.java](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreKeeperPlugin.java),
|
||||||
|
[ScoreBucket.java](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreBucket.java),
|
||||||
|
and [ScoreReporting.java](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreReporting.java).
|
||||||
|
For command syntax see [README.md](../README.md); for runtime wiring see
|
||||||
|
[the integration reference](plugin-integration-and-event-wiring.md).
|
||||||
|
|
||||||
|
## Buckets and live scores
|
||||||
|
|
||||||
|
- A bucket has an immutable ID, singular label, plural label, initial integer
|
||||||
|
value, and reporting policy. IDs match `[A-Za-z0-9_-]+`, are case-sensitive,
|
||||||
|
and must be unique. Labels must be nonblank; reporting cannot be null.
|
||||||
|
- A fresh server has `points` (`point`/`points`, initial value `0`, reporting `none`).
|
||||||
|
Loading bucket data restores this bucket if it is missing.
|
||||||
|
- `_bucketScores` maps bucket ID to `UUID -> int`. Players can have independent
|
||||||
|
scores in multiple buckets. Names are not used as identity keys.
|
||||||
|
- The server default bucket and optional UUID-specific assignments determine a
|
||||||
|
player's active bucket. Selecting the default removes their override.
|
||||||
|
`switchAllPlayers` changes the default and clears **all** assignments,
|
||||||
|
including offline players' assignments, without deleting scores.
|
||||||
|
- `getScore` lazily registers a missing score at the bucket's initial value.
|
||||||
|
Joining alone does not create an entry. Reads therefore affect who appears
|
||||||
|
in a later archive or run ranking.
|
||||||
|
- Add/subtract perform ordinary Java integer arithmetic. Zero/negative amounts
|
||||||
|
are allowed, scores can be negative, and overflow wraps. There are no bonuses,
|
||||||
|
weighting, decay, or automatic gameplay scoring.
|
||||||
|
- Reset writes the bucket initial value, not necessarily zero. Existing
|
||||||
|
no-bucket API methods use the active bucket; explicit-bucket overloads do not
|
||||||
|
change the player's assignment.
|
||||||
|
|
||||||
|
## Reporting and bucket changes
|
||||||
|
|
||||||
|
For a changed value written through `setScore`, outside a run:
|
||||||
|
|
||||||
|
| Policy | Audience |
|
||||||
|
| --- | --- |
|
||||||
|
| `none` (default) | Nobody |
|
||||||
|
| `player` | Scored player |
|
||||||
|
| `global` | All online players |
|
||||||
|
| `admin` | Online operators or holders of `scorekeeper.admin`, plus the server log |
|
||||||
|
|
||||||
|
Writing the same value sends no score-change report. Commands that change scores
|
||||||
|
do not independently promise success messages; inspect `/score-get` when reporting
|
||||||
|
is `none`. A bucket change tells an affected online player the ID and current score.
|
||||||
|
Unit formatting uses the singular label for exactly `1`, plural otherwise.
|
||||||
|
`/score-get` itself displays only the number, without bucket or unit labels.
|
||||||
|
|
||||||
|
Run reporting overrides the bucket policy. Archive resets and run start/restore
|
||||||
|
directly update maps and do not send ordinary per-score change reports.
|
||||||
|
|
||||||
|
## High-score runs
|
||||||
|
|
||||||
|
Each bucket can have at most one active run; different buckets may run concurrently.
|
||||||
|
Top N must be at least one. There are three lifetime modes:
|
||||||
|
|
||||||
|
- **Target score:** finishes when any recorded score reaches/exceeds the target.
|
||||||
|
With reset enabled, the target must exceed the initial value. Without reset,
|
||||||
|
existing scores can finish a run immediately when it starts.
|
||||||
|
- **Duration:** a positive duration, stored as an absolute epoch-millisecond
|
||||||
|
expiration. Time offline counts toward expiration.
|
||||||
|
- **Until disabled:** no automatic end; stop explicitly. Plugin disable saves the
|
||||||
|
run rather than finishing it, so it resumes on restart.
|
||||||
|
|
||||||
|
Starting with reset enabled snapshots existing bucket entries and sets them to
|
||||||
|
the initial value. During the run, a changed score is always reported to its
|
||||||
|
player. If that player is in the top N **after the change**, the report is sent
|
||||||
|
to all other online players too, once per recipient.
|
||||||
|
|
||||||
|
Completion is checked immediately at start/load, synchronously every 20 ticks,
|
||||||
|
and on a changed target-run score. Manual stop also completes the run.
|
||||||
|
The scheduled check uses wall-clock time; under server lag it need not fire at
|
||||||
|
an exact real-time second.
|
||||||
|
|
||||||
|
### Ranking and results
|
||||||
|
|
||||||
|
Rankings include all recorded entries in that bucket, including offline players
|
||||||
|
and entries read/created before the run. The order is:
|
||||||
|
|
||||||
|
1. Descending score.
|
||||||
|
2. Case-insensitive player name, using Paper's offline-player lookup.
|
||||||
|
3. UUID string to break remaining ties.
|
||||||
|
|
||||||
|
Unknown/blank names fall back to the UUID string. Ties have distinct consecutive
|
||||||
|
places, not shared ranks. Top N limits display/reporting, not stored entries.
|
||||||
|
Every online player receives the final top-N table and their own full-ranking
|
||||||
|
place/score, or an unranked result at the initial value. The final table is logged.
|
||||||
|
|
||||||
|
With reset enabled, completion replaces the bucket map with its pre-run snapshot.
|
||||||
|
Players first recorded during the run are removed from that map and get the initial
|
||||||
|
value on their next read. Personal results refer to the finished run, not restored
|
||||||
|
scores. Without reset, earned scores remain. Run completion does **not** create a
|
||||||
|
score archive.
|
||||||
|
|
||||||
|
## Archives
|
||||||
|
|
||||||
|
Player, single-bucket, and all-bucket archives create immutable snapshots with a
|
||||||
|
random UUID ID, scope text, epoch-millisecond creation time, and nested
|
||||||
|
`bucket ID -> UUID -> int` scores. A player archive uses their active bucket;
|
||||||
|
bucket/all archives include all recorded entries, even offline players.
|
||||||
|
|
||||||
|
Live archived entries reset to their respective initial values. Archiving fails
|
||||||
|
before changing any scores if a selected bucket has an active run; stop the run
|
||||||
|
first. Archives do not cap or prune entries.
|
||||||
|
|
||||||
|
[ScoreArchiveListCommand.java](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/commands/ScoreArchiveListCommand.java)
|
||||||
|
lists archives newest first. Within an archive, scores display descending with
|
||||||
|
UUID-string tie-breaking (not the run's name tie-break). Names and unit labels are
|
||||||
|
resolved at display time, not captured in the snapshot; missing bucket definitions
|
||||||
|
use the generic unit `scores`.
|
||||||
|
|
||||||
|
## Persistence
|
||||||
|
|
||||||
|
Both files live in `plugins/ScoreKeeper/`. Loading occurs on enable and saving
|
||||||
|
on disable. There is no periodic autosave or immediate archive write despite
|
||||||
|
the command's "Saved score archive" acknowledgement; a crash can lose recent
|
||||||
|
state. Back up only after a successful clean shutdown.
|
||||||
|
|
||||||
|
### `scores.yml` (currently writes version 3)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: 3
|
||||||
|
default-bucket: points
|
||||||
|
buckets:
|
||||||
|
points:
|
||||||
|
singular: point
|
||||||
|
plural: points
|
||||||
|
initial-value: 0
|
||||||
|
reporting: none
|
||||||
|
scores:
|
||||||
|
"00000000-0000-0000-0000-000000000001": 10
|
||||||
|
player-buckets:
|
||||||
|
"00000000-0000-0000-0000-000000000002": points
|
||||||
|
high-score-runs:
|
||||||
|
points:
|
||||||
|
top-n: 3
|
||||||
|
reset-scores: true
|
||||||
|
lifetime: duration
|
||||||
|
target-score: 0
|
||||||
|
expires-at: 1800000000000
|
||||||
|
previous-scores:
|
||||||
|
"00000000-0000-0000-0000-000000000001": 25
|
||||||
|
```
|
||||||
|
|
||||||
|
This illustrates field shapes, not a file to install unchanged. Overrides equal
|
||||||
|
to the default bucket are normally omitted. Saved lifetime strings are
|
||||||
|
`target_score`, `duration`, and `until_disabled`. The loader reads structure,
|
||||||
|
not a version-dispatch migration table.
|
||||||
|
|
||||||
|
If `buckets` is absent, the loader treats top-level UUID/integer entries as legacy
|
||||||
|
`points` scores. Invalid bucket definitions/UUIDs/runs are skipped with warnings;
|
||||||
|
invalid reporting falls back to `none`, and an unknown default falls back to
|
||||||
|
`points`. Unknown bucket assignments are ignored. Bukkit YAML getters supply
|
||||||
|
defaults for some missing/wrongly typed values: do not assume every malformed
|
||||||
|
value is rejected or logged.
|
||||||
|
|
||||||
|
### `archives.yml`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
archives:
|
||||||
|
"00000000-0000-0000-0000-000000000003":
|
||||||
|
scope: bucket points
|
||||||
|
created-at: 1800000000000
|
||||||
|
buckets:
|
||||||
|
points:
|
||||||
|
scores:
|
||||||
|
"00000000-0000-0000-0000-000000000001": 10
|
||||||
|
```
|
||||||
|
|
||||||
|
This file has no explicit format version. Empty bucket score maps may be omitted
|
||||||
|
on serialization because only individual score entries are written.
|
||||||
|
The two files are saved separately; there is no cross-file transaction or atomic
|
||||||
|
replacement guarantee. Save I/O errors use the plugin logger. Never edit live
|
||||||
|
data while the server is running: shutdown can overwrite it.
|
||||||
|
|
||||||
|
## Validation status
|
||||||
|
|
||||||
|
These are source-level behavior descriptions, not claims of passing automated
|
||||||
|
tests. Pending coverage is tracked in [TODO.md](../TODO.md). Before release,
|
||||||
|
use [human-tests.md](human-tests.md), particularly ranking ties, empty buckets,
|
||||||
|
restoration, malformed data, and restart/upgrade cases.
|
||||||
72
docs/human-tests.md
Normal file
72
docs/human-tests.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Score Keeper Human Testing
|
||||||
|
|
||||||
|
Use this manual pre-release checklist on disposable Paper 26.2 and 26.3 servers
|
||||||
|
(test both before advertising both). Score Keeper stores data in its plugin folder
|
||||||
|
and interacts with players, command senders, and scheduled runs; a passing build
|
||||||
|
alone does not verify these workflows. These are test scenarios, not passing results.
|
||||||
|
See [CONTRIBUTING.md](../CONTRIBUTING.md) for setup and helper-script safety, and
|
||||||
|
[the domain reference](domain-score-tracking.md) for expected behavior.
|
||||||
|
|
||||||
|
## Test Setup
|
||||||
|
|
||||||
|
- Use Java 25 and a backed-up test server. Keep the server log available throughout testing.
|
||||||
|
- Use at least three test players for rankings: an operator, a non-operator with `scorekeeper.admin`, and an ordinary player. Use a console or RCON session for non-player sender cases.
|
||||||
|
- Before each run, preserve `plugins/ScoreKeeper/scores.yml` and `archives.yml`, or use a fresh test server. Archive, reset, and bucket-wide commands intentionally change scores.
|
||||||
|
- Record plugin artifact/version, Paper version/build, Java version, command sender, arguments, expected and observed messages, and score values before and after each operation. Save pass/fail notes and relevant logs outside player data committed to the repo.
|
||||||
|
- Ensure only the intended Score Keeper jar is installed. Stop with `stop` in the server console so disable-time saves run. Do not use helper scripts that can stop other Paper processes on a shared host.
|
||||||
|
|
||||||
|
## Human Checklist
|
||||||
|
|
||||||
|
### Startup and score commands
|
||||||
|
|
||||||
|
- Start Paper and confirm Score Keeper enables, registers every documented command, and loads existing data without errors.
|
||||||
|
- As a player, run `/score-get`, `/score-add 10`, `/score-subtract 3`, and `/score-reset`; inspect `/score-get` after each mutation. Repeat with console/RCON, supplying a player name where required. Missing targets from non-player senders must produce usage, not self-scoring.
|
||||||
|
- Try zero and negative amounts: they are valid signed integers (for example, adding `-3` decreases the score). Try missing/non-numeric/out-of-range amounts: these should produce usage/errors without changing scores. At integer boundaries, record the current wrapping behavior; there is no overflow guard.
|
||||||
|
- Target offline/unknown names and supply extra arguments; verify errors/usage without unrelated changes. Confirm gameplay such as mob kills does not award points unless a companion plugin is installed.
|
||||||
|
- Use two players to verify each player's score is independent. Change a player's Minecraft name if practical, then confirm their score remains associated with their UUID.
|
||||||
|
- Check singular/plural labels at 1, 0, negative, and multiple values in reporting, bucket-change, and run/archive messages. `/score-get` only displays a number; it does not show bucket/units.
|
||||||
|
|
||||||
|
### Buckets and reporting
|
||||||
|
|
||||||
|
- Create a test bucket with a nonzero initial value and distinctive singular/plural labels, for example `/score-bucket create Bread loaf loaves 5 player`. Verify invalid/duplicate IDs, invalid initial values, and unknown reporting policies produce errors. IDs are case-sensitive; command labels each occupy one argument. Use a companion-plugin API test if checking blank/null labels that cannot be supplied naturally as command arguments.
|
||||||
|
- Switch one player to the bucket, add and subtract points, and confirm other players remain in their own active bucket. Switch back and verify the original score is unchanged.
|
||||||
|
- Change the server-wide default with `/score-bucket all <bucketId>`. Confirm individual assignments are cleared, online players receive the appropriate change notice, and new players use the new default.
|
||||||
|
- For each reporting policy (`none`, `player`, `admin`, `global`), change a score and verify exactly the intended audience receives the report. Test with an operator, a `scorekeeper.admin` player, an ordinary player, and the scored player.
|
||||||
|
- Exercise authorized/unauthorized bucket creation and switching another/all players: these require `scorekeeper.admin`. An ordinary player must still be able to view/select their own bucket. Selecting the already-active bucket should not produce a bucket-change notice.
|
||||||
|
- Set reporting to `none` and verify a successful add/subtract/reset can be silent. Writing the same score should not send a change report under any policy. `admin` reports should also reach the server log.
|
||||||
|
- Note that the README says score get/add/subtract/reset currently have no permission checks and can target any online player. Confirm that exposure is acceptable for the server before enabling these commands publicly.
|
||||||
|
|
||||||
|
### Archives
|
||||||
|
|
||||||
|
- Archive one player's active-bucket score as an admin, then inspect `/score-archive-list` and `/score-archive-list <archiveId>`. Confirm the snapshot value/bucket and the live score returns to that bucket's initial value. Ordinary players must be denied archive creation but can list/view archives.
|
||||||
|
- Repeat for `/score-archive bucket <bucketId>` and `/score-archive all`. Confirm only the selected bucket or all buckets are archived and reset as requested.
|
||||||
|
- Check archive IDs are listed newest first, then restart and confirm archives and their contents remain available.
|
||||||
|
- Try an unknown archive ID or bucket ID and verify a useful failure without unrelated scores being changed.
|
||||||
|
- Include recorded offline players and ties: entries sort descending by score then UUID, not run-style name ties. Check empty bucket archives before/after restart and record any omitted empty bucket sections.
|
||||||
|
- Attempt player/bucket/all archiving while a selected bucket has an active run. It must fail before changing any selected scores; stop the run and retry. Archive resets should not send normal per-score reporting.
|
||||||
|
|
||||||
|
### High-score runs
|
||||||
|
|
||||||
|
- Start target/timed runs with at least three players. Use literal booleans, for example `/score-run start Bread 2 true duration 10s`. Top N must be at least 1. Reject invalid booleans, zero/negative/overflowing duration, uppercase time suffixes, unknown buckets, and duplicate runs.
|
||||||
|
- A reset target must exceed the initial value. Without reset, a pre-existing score at/above the target may finish immediately; verify this rather than assuming every start remains active.
|
||||||
|
- Change scores for players inside and outside the current top-N. Verify individual score-change messages and global reporting for current top-N players match the run behavior.
|
||||||
|
- End runs by reaching the target, expiration, and `/score-run stop`. Also start an `until-disabled` run and stop it manually.
|
||||||
|
- Check descending score, case-insensitive name then UUID tie-breaking, distinct consecutive places for ties, each online player's place, unranked players, and the top-N cutoff. Include recorded offline players; top N limits display, not stored entries.
|
||||||
|
- With reset enabled, verify scores begin at the initial value and pre-run entries are restored exactly. A player first recorded during the run should return to the initial value on the next read after completion. With reset disabled, scores remain as earned. Final personal results must show run scores, not restored scores.
|
||||||
|
- Restart cleanly while a run is active. Confirm snapshots survive, timed expiration includes time offline, overdue runs finish on enable, and `until-disabled` resumes until explicitly stopped. Confirm completion happens once and no automatic archive is created.
|
||||||
|
- Run two buckets concurrently and confirm independent completion/restoration. Observe timed completion under lag: checks run every 20 ticks, not at an exact wall-clock second.
|
||||||
|
|
||||||
|
### Persistence and upgrades
|
||||||
|
|
||||||
|
- Restart after changing scores, bucket definitions, reporting policies, the default bucket, and per-player bucket assignments. Verify all values and assignments persist.
|
||||||
|
- Test a clean data folder and copies of older files, including flat top-level UUID scores (loaded into `points`). Verify default/reporting fallbacks and invalid UUID/bucket/run warnings. For malformed types/unknown assignments, record actual getter defaults/ignored values; current loading is not comprehensive validation.
|
||||||
|
- Check `scores.yml` version 3 and the archive fields after a clean shutdown. Both files save only on disable, not each mutation. On an explicitly authorized disposable server, compare a forced crash with the last clean save: loss of recent changes is a known limitation, not successful durability.
|
||||||
|
- If using a companion plugin, verify `depend: [ScoreKeeper]` load order, main-thread awards into an explicit bucket, and visible failure when Score Keeper is absent/disabled. Verify no unintended active-bucket switch.
|
||||||
|
|
||||||
|
## Automated Coverage
|
||||||
|
|
||||||
|
There are currently no Java test sources or test dependencies in this project,
|
||||||
|
and no integration-test source set. Gradle `test` is `NO-SOURCE` and does not
|
||||||
|
exercise Score Keeper behavior. Scenarios remain unverified until actually
|
||||||
|
tested; SK-08 through SK-12 in [TODO.md](../TODO.md) and
|
||||||
|
[the modernization plan](Modernize.md) describe pending automated coverage.
|
||||||
95
docs/modrinth-description.md
Normal file
95
docs/modrinth-description.md
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
**Score Keeper**
|
||||||
|
|
||||||
|
Score Keeper tracks player scores in configurable buckets. Use it for event points,
|
||||||
|
competitions, or other server-side scoring systems, and integrate it with other
|
||||||
|
plugins through the public API. Points are awarded by commands or companion
|
||||||
|
plugins, not by built-in gameplay event listeners.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Requires Java 25 and Paper 26.2 or 26.3. Stop your server cleanly, back up plugin
|
||||||
|
data, and place the downloaded jar in `plugins`, removing older Score Keeper jars.
|
||||||
|
Restart and check the server log. The installed plugin ID and data folder remain
|
||||||
|
`ScoreKeeper`; the display name is Score Keeper.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
Players can omit an optional player name to target themselves. Named targets must
|
||||||
|
be online. Console and RCON must provide a player name for score get/add/subtract/reset;
|
||||||
|
archive also accepts `all` and `bucket` scopes. Add/subtract accept signed 32-bit
|
||||||
|
integers, including zero and negative amounts. Bucket IDs are case-sensitive and
|
||||||
|
allow letters, numbers, `_`, and `-`; each command-created unit label is one argument.
|
||||||
|
|
||||||
|
* `/score-get [playerName]` - Displays the target player's score in their active bucket.
|
||||||
|
* `/score-add <amount>` - Adds an amount to your score in your active bucket.
|
||||||
|
* `/score-add <playerName> <amount>` - Adds an amount to the target player's score.
|
||||||
|
* `/score-subtract <amount>` - Subtracts an amount from your score in your active bucket.
|
||||||
|
* `/score-subtract <playerName> <amount>` - Subtracts an amount from the target player's score.
|
||||||
|
* `/score-reset [playerName]` - Resets the target player's active-bucket score to that bucket's initial value.
|
||||||
|
* `/score-archive` - Archives and resets your score in your active bucket.
|
||||||
|
* `/score-archive <playerName>` - Archives and resets the target player's score in their active bucket.
|
||||||
|
* `/score-archive all` - Archives and resets scores in every bucket.
|
||||||
|
* `/score-archive bucket <bucketId>` - Archives and resets every score in one bucket.
|
||||||
|
* `/score-archive-list` - Lists saved archive IDs, newest first.
|
||||||
|
* `/score-archive-list <archiveId>` - Displays the saved scores in one archive.
|
||||||
|
* `/score-bucket` - Displays your active bucket.
|
||||||
|
* `/score-bucket <bucketId>` - Switches your active bucket.
|
||||||
|
* `/score-bucket create <id> <singular> <plural> <initialValue> [reporting]` - Creates a bucket. Reporting can be `admin`, `global`, `player`, or `none` (default).
|
||||||
|
* `/score-bucket <playerName> <bucketId>` - Switches a player's active bucket.
|
||||||
|
* `/score-bucket all <bucketId>` - Changes the server's default bucket and clears individual bucket assignments.
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> target <score>` - Starts a run that ends when a score reaches the target.
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> duration <time>` - Starts a timed run. Use a positive number and lowercase `s`, `m`, `h`, `d`, or `w`, such as `4h`.
|
||||||
|
* `/score-run start <bucketId> <topN> <true|false> until-disabled` - Starts a run with no automatic end, including across clean restarts.
|
||||||
|
* `/score-run stop <bucketId>` - Ends an active run.
|
||||||
|
|
||||||
|
## Permissions
|
||||||
|
|
||||||
|
The `scorekeeper.admin` permission (default: operators) is required for
|
||||||
|
`score-archive`, bucket creation, switching another player/all players, and run
|
||||||
|
management. Viewing/selecting your own bucket is open. Score get/add/subtract/reset
|
||||||
|
and archive-list have no permission checks; add, subtract, and reset can target
|
||||||
|
**any online player**. Restrict access externally if this does not fit your server.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Create score buckets with custom singular/plural labels, initial values, and reporting policies.
|
||||||
|
* Reporting can notify operators/admins, everyone online, only the scored player, or nobody.
|
||||||
|
* Start target-score, timed, or until-disabled high-score runs with configurable top-N standings and optional score resets.
|
||||||
|
* Archive player, bucket, or all-bucket scores; archived scores reset to their bucket's initial value.
|
||||||
|
* Persist bucket definitions, assignments, scores, active runs, and archives in the plugin's data folder.
|
||||||
|
|
||||||
|
Reporting defaults to `none`, so successful score mutations can be silent; use
|
||||||
|
`/score-get` to inspect the number. Changed scores use singular units for exactly
|
||||||
|
1, plural otherwise. Scores may be negative and overflow is not checked.
|
||||||
|
|
||||||
|
Runs require top N of at least 1 and a literal `true`/`false` reset argument.
|
||||||
|
For example, `/score-run start points 3 true duration 4h`. Run reporting overrides
|
||||||
|
the bucket policy: the scored player always receives changes, and current top-N
|
||||||
|
players' changes are reported globally. Rankings include all recorded bucket
|
||||||
|
entries, even offline players; ties use case-insensitive name then UUID and
|
||||||
|
consecutive places. Final results include each online player's place. Reset runs
|
||||||
|
restore previous scores, while non-reset runs keep earned scores. Timed runs use
|
||||||
|
wall-clock time, including time offline; an existing target can finish a non-reset
|
||||||
|
run immediately.
|
||||||
|
|
||||||
|
Stop a run before archiving its bucket. Final run results are announced/logged,
|
||||||
|
not automatically archived. Archives and live state are saved to
|
||||||
|
`plugins/ScoreKeeper/archives.yml` and `scores.yml` **on clean shutdown/plugin
|
||||||
|
disable**, not after every command. Crashes can lose changes since the last save.
|
||||||
|
Do not edit data files while the server is running.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
Other plugins can create buckets with
|
||||||
|
`createBucket(id, singular, plural, initialValue, ScoreReporting)`, use bucket-aware
|
||||||
|
score methods, and manage runs with `startTargetScoreRun`, `startTimedScoreRun`,
|
||||||
|
`startUntilDisabledScoreRun`, and `stopHighScoreRun`. Declare a dependency on
|
||||||
|
`ScoreKeeper` and call the enabled plugin API on Paper's main thread.
|
||||||
|
See the [integration reference](https://github.com/headhunter45/ScoreKeeper/blob/develop/docs/plugin-integration-and-event-wiring.md).
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
Built exclusively for Paper 26.2 and 26.3 with the Paper API and Adventure APIs. Bukkit and Spigot servers are not supported.
|
||||||
|
|
||||||
|
Source and development instructions are in the
|
||||||
|
[repository](https://github.com/headhunter45/ScoreKeeper). Licensed under GNU AGPL v3 or later.
|
||||||
13
docs/modrinth.json
Normal file
13
docs/modrinth.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Score Keeper",
|
||||||
|
"url": "https://modrinth.com/plugin/scorekeeper",
|
||||||
|
"summary": "A Paper scoring engine with configurable buckets, reporting, high-score runs, shutdown-persisted archives, commands, and a companion-plugin API.",
|
||||||
|
"visibility": "public",
|
||||||
|
"links": {
|
||||||
|
"issueTracker": "https://github.com/headhunter45/ScoreKeeper/issues",
|
||||||
|
"sourceCode": "https://github.com/headhunter45/ScoreKeeper",
|
||||||
|
"wikiPage": null,
|
||||||
|
"discordInvite": null,
|
||||||
|
"donationLinks": []
|
||||||
|
}
|
||||||
|
}
|
||||||
136
docs/plugin-integration-and-event-wiring.md
Normal file
136
docs/plugin-integration-and-event-wiring.md
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Score Keeper - Plugin Integration and Event Wiring
|
||||||
|
|
||||||
|
New Score Keeper contributors should start with
|
||||||
|
[CONTRIBUTING.md](../CONTRIBUTING.md), which covers architecture, setup, and validation.
|
||||||
|
This is an optional detailed reference for runtime wiring and companion-plugin
|
||||||
|
authors, not a second onboarding guide. [domain-score-tracking.md](domain-score-tracking.md)
|
||||||
|
describes state and [README.md](../README.md) gives full command syntax.
|
||||||
|
|
||||||
|
## Paper lifecycle
|
||||||
|
|
||||||
|
The entry point is
|
||||||
|
[ScoreKeeperPlugin](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/ScoreKeeperPlugin.java),
|
||||||
|
declared in [plugin.yml](../src/main/resources/plugin.yml) under the plugin ID
|
||||||
|
`ScoreKeeper`. Compilation targets Paper `26.2.build.129-stable` on Java 25;
|
||||||
|
supported server versions are Paper 26.2 and 26.3.
|
||||||
|
|
||||||
|
| Trigger | Handler / effect |
|
||||||
|
| --- | --- |
|
||||||
|
| Plugin enable | Register eight executors, initialize `points`, load scores/archives, check existing runs, schedule synchronous checks every 20 ticks |
|
||||||
|
| Scheduled check | `checkHighScoreRuns`: finish expired duration runs or runs whose target is reached |
|
||||||
|
| Plugin disable | Serialize bucket definitions, scores, assignments, active runs/snapshots, and archives to two YAML files |
|
||||||
|
| Minecraft join/quit/death/kill | No built-in listeners or automatic score awards |
|
||||||
|
| Companion-plugin API call | Perform requested score/bucket/archive/run operation |
|
||||||
|
|
||||||
|
There are no `Listener` implementations, `@EventHandler` methods, custom scoring
|
||||||
|
events, or event registrations. The scheduler manages runs, not gameplay scoring.
|
||||||
|
Expired saved runs finish during enable; `until-disabled` runs persist and resume.
|
||||||
|
|
||||||
|
## Command wiring
|
||||||
|
|
||||||
|
Each manifest command is explicitly wired in `onEnable` using `getCommand` and
|
||||||
|
`setExecutor`. A missing declaration fails startup via `Objects.requireNonNull`.
|
||||||
|
|
||||||
|
Handlers are in [commands/](../src/main/java/com/majinnaibu/minecraft/plugins/scorekeeper/commands/).
|
||||||
|
|
||||||
|
| Command | Executor | Delegation / effect | Permission |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `score-get` | `ScoreGetCommand` | `getScore`, active bucket, lazy entry creation | None |
|
||||||
|
| `score-add` | `ScoreAddCommand` | `addScore`, signed integer addition | None |
|
||||||
|
| `score-subtract` | `ScoreSubtractCommand` | `subtractScore`, signed integer subtraction | None |
|
||||||
|
| `score-reset` | `ScoreResetCommand` | `resetScore`, active bucket initial value | None |
|
||||||
|
| `score-archive` | `ScoreArchiveCommand` | `archivePlayerScore`, `archiveBucketScores`, or `archiveAllScores` | `scorekeeper.admin` |
|
||||||
|
| `score-archive-list` | `ScoreArchiveListCommand` | `getScoreArchives` or `getScoreArchive` | None |
|
||||||
|
| `score-bucket` | `ScoreBucketCommand` | View/select own bucket, create bucket, switch another/all players | Admin for create/other/all; none for self |
|
||||||
|
| `score-run` | `ScoreRunCommand` | Start target/timed/manual run, or stop it | `scorekeeper.admin` |
|
||||||
|
|
||||||
|
`scorekeeper.admin` defaults to operators in the manifest. Guards are implemented
|
||||||
|
inside selected executors, not per-command manifest permission fields. Public API
|
||||||
|
calls do not enforce sender permissions; the caller must enforce its own policy.
|
||||||
|
|
||||||
|
Named player targets use Paper's `getPlayerExact` and must be online. Players
|
||||||
|
may omit the optional name to target themselves; non-player senders have no
|
||||||
|
self context. Console/RCON can use archive `all`/`bucket` forms without a player.
|
||||||
|
Bucket IDs are case-sensitive even though command keywords such as `all` are not.
|
||||||
|
|
||||||
|
Parse/validation failures are returned as Adventure usage/error messages.
|
||||||
|
Handlers consume commands by returning `true`. Score mutation commands rely on
|
||||||
|
bucket/run reporting instead of unconditional success messages; the default
|
||||||
|
`none` policy can make a successful mutation silent.
|
||||||
|
|
||||||
|
## Companion-plugin integration
|
||||||
|
|
||||||
|
Score Keeper declares no plugin dependencies of its own. A companion that requires
|
||||||
|
it should compile against the matching jar as a provided/compile-only dependency,
|
||||||
|
and declare `depend: [ScoreKeeper]` in its own Bukkit-style manifest so it loads
|
||||||
|
after Score Keeper. For optional integration, use `softdepend` and handle absence
|
||||||
|
or disabled state explicitly.
|
||||||
|
|
||||||
|
There is no ServicesManager registration or standalone API module. Obtain the
|
||||||
|
enabled plugin by ID and check its type, for example during the companion's enable:
|
||||||
|
|
||||||
|
```java
|
||||||
|
Plugin candidate = getServer().getPluginManager().getPlugin("ScoreKeeper");
|
||||||
|
if (!(candidate instanceof ScoreKeeperPlugin scoreKeeper) || !candidate.isEnabled()) {
|
||||||
|
getLogger().severe("Score Keeper is required but is not enabled.");
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Imports for this example are `org.bukkit.plugin.Plugin` and
|
||||||
|
`com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin`. Keep the
|
||||||
|
reference for your integration lifecycle, not as a global singleton.
|
||||||
|
Do not shade a second copy of Score Keeper into the companion jar.
|
||||||
|
|
||||||
|
### Public operations
|
||||||
|
|
||||||
|
| Area | Methods |
|
||||||
|
| --- | --- |
|
||||||
|
| Bucket definition | `createBucket(id, singular, plural, initialValue[, ScoreReporting])`, `getBucket(id)`, `getBuckets()` |
|
||||||
|
| Active selection | `getPlayerBucket(Player)`, `switchPlayerBucket(Player, id)`, `switchAllPlayers(id)` |
|
||||||
|
| Score CRUD | `getScore(Player[, id])`, `setScore(Player[, id], score)`, `addScore(Player[, id], amount)`, `subtractScore(Player[, id], amount)`, `resetScore(Player[, id])` |
|
||||||
|
| Archives | `archivePlayerScore(Player)`, `archiveBucketScores(id)`, `archiveAllScores()`, `getScoreArchives()`, `getScoreArchive(archiveId)` |
|
||||||
|
| Compatibility wrapper | `archiveScore(Player)` delegates to player archive creation but discards the returned ID |
|
||||||
|
| Runs | `startTargetScoreRun(id, topN, resetScores, targetScore)`, `startTimedScoreRun(id, topN, resetScores, Duration)`, `startUntilDisabledScoreRun(id, topN, resetScores)`, `stopHighScoreRun(id)`, `hasActiveHighScoreRun(id)` |
|
||||||
|
| Messaging/logging | `sendMessage(CommandSender, Component)`, `logInfo`, `logWarning`, `logError` |
|
||||||
|
|
||||||
|
The bracket notation above describes overloads, not literal Java syntax.
|
||||||
|
`getBucket` and `getScoreArchive` return null when unknown; mutating/score methods
|
||||||
|
validate bucket existence and throw `IllegalArgumentException` for invalid
|
||||||
|
operations. Do not swallow errors or report success after a failure.
|
||||||
|
Bucket maps and archive snapshots exposed by getters are immutable copies/views.
|
||||||
|
|
||||||
|
Example explicit-bucket award, with imports for `ScoreReporting` and `Player`:
|
||||||
|
|
||||||
|
```java
|
||||||
|
if (scoreKeeper.getBucket("event") == null) {
|
||||||
|
scoreKeeper.createBucket("event", "point", "points", 0, ScoreReporting.PLAYER);
|
||||||
|
}
|
||||||
|
scoreKeeper.addScore(player, "event", 10);
|
||||||
|
```
|
||||||
|
|
||||||
|
Only create a shared bucket if its existing definition meets your integration's
|
||||||
|
requirements; duplicate creation throws. Explicit-bucket scoring does not switch
|
||||||
|
the player's active bucket.
|
||||||
|
|
||||||
|
### Threading and ownership
|
||||||
|
|
||||||
|
All calls touching state, players, or reporting must execute on Paper's main
|
||||||
|
server thread. The plugin's `LinkedHashMap` state and read-modify-write operations
|
||||||
|
are not synchronized. Marshal asynchronous event/work results to a synchronous
|
||||||
|
Paper task before calling this API. Score Keeper does not provide Folia/region
|
||||||
|
scheduler support.
|
||||||
|
|
||||||
|
Do not mutate private maps or write the YAML files from another plugin.
|
||||||
|
Use the API so reporting, validation, target completion, and snapshots remain
|
||||||
|
consistent. API calls change in-memory state; durability is deferred until
|
||||||
|
Score Keeper disables successfully.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
There is currently no automated plugin harness or real-server test task.
|
||||||
|
Validate load ordering, command dispatch, messages, run scheduler behavior, and
|
||||||
|
clean-restart persistence on disposable Paper servers using
|
||||||
|
[human-tests.md](human-tests.md). Do not assume a successful compilation verifies
|
||||||
|
companion load order or runtime API compatibility.
|
||||||
48
docs/project-description.json
Normal file
48
docs/project-description.json
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"score-keeper": {
|
||||||
|
"id": "score-keeper",
|
||||||
|
"title": "Score Keeper",
|
||||||
|
"description": "A Paper 26.2/26.3 scoring engine with named buckets, custom reporting, shutdown-persisted scores and archives, high-score runs, player commands, and a main-thread API for companion plugins.",
|
||||||
|
"docId": "Score-Keeper",
|
||||||
|
"headerImage": null,
|
||||||
|
"platforms": [
|
||||||
|
{
|
||||||
|
"name": "Paper",
|
||||||
|
"info": "Paper 26.2 and 26.3; Java 25 required. Bukkit and Spigot servers are not supported.",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"label": "Download on Modrinth",
|
||||||
|
"url": "https://modrinth.com/plugin/scorekeeper"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"image": {
|
||||||
|
"url": "/projects/score-keeper/logo.png",
|
||||||
|
"alt": "Score Keeper Minecraft plugin logo",
|
||||||
|
"width": 1024,
|
||||||
|
"height": 1024,
|
||||||
|
"backgroundClassName": "bg-surface"
|
||||||
|
},
|
||||||
|
"url": "/projects/score-keeper",
|
||||||
|
"tags": ["Open-Source", "Game", "Minecraft", "Java"],
|
||||||
|
"source": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/headhunter45/ScoreKeeper"
|
||||||
|
},
|
||||||
|
"feedback": {
|
||||||
|
"type": "github-issues",
|
||||||
|
"url": "https://github.com/headhunter45/ScoreKeeper/issues"
|
||||||
|
},
|
||||||
|
"features": [
|
||||||
|
"Named score buckets with custom units, initial values, and reporting policies",
|
||||||
|
"UUID-keyed integer scores with default and per-player bucket selection",
|
||||||
|
"Player, bucket, and all-bucket archives with score resets",
|
||||||
|
"Target-score, timed, and manually stopped high-score runs with top-N results",
|
||||||
|
"Optional pre-run score snapshots and restoration",
|
||||||
|
"YAML persistence on clean shutdown",
|
||||||
|
"Player commands and a main-thread API for companion plugins"
|
||||||
|
],
|
||||||
|
"technology": ["Java 25", "Paper API", "Adventure", "Gradle", "YAML"]
|
||||||
|
}
|
||||||
|
}
|
||||||
31
docs/project-description.md
Normal file
31
docs/project-description.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Score Keeper
|
||||||
|
|
||||||
|
Score Keeper is a reusable scoring engine for Paper 26.2 and 26.3. It gives events,
|
||||||
|
competitions, and companion plugins a shared language for points: named buckets
|
||||||
|
can have custom singular/plural labels, initial values, reporting policies,
|
||||||
|
archives, and high-score runs.
|
||||||
|
|
||||||
|
The plugin is both a player-facing command system and an extension point.
|
||||||
|
Administrators can start target-based, timed, or manually stopped score runs,
|
||||||
|
while other plugins can create buckets, award points, archive results, and build
|
||||||
|
richer game loops through the public API. Gameplay does not automatically award
|
||||||
|
scores. Scores, assignments, active runs, and archives persist across clean server
|
||||||
|
restarts through shutdown saves. Bukkit and Spigot servers are not supported.
|
||||||
|
|
||||||
|
Run standings include deterministic tie-breaking, top-N announcements, personal
|
||||||
|
places, and optional restoration of pre-run scores. Separate archives snapshot
|
||||||
|
player, bucket, or all-bucket scores and reset the live values.
|
||||||
|
|
||||||
|
## Engineering Notes
|
||||||
|
|
||||||
|
- Built with Gradle and Java 25 for modern Paper.
|
||||||
|
- Uses UUID-based player identity and YAML-backed persistence.
|
||||||
|
- Exposes a main-thread Java API for companion plugins; no service registration or built-in gameplay listeners.
|
||||||
|
- Has no automated Java test coverage yet; manual pre-release scenarios are documented, with test infrastructure planned.
|
||||||
|
- Uses the display name "Score Keeper" while retaining `ScoreKeeper` as the repository and plugin identifier.
|
||||||
|
- Licensed under GNU AGPL v3 or later.
|
||||||
|
|
||||||
|
Score get/add/subtract/reset commands currently have no permission checks and can
|
||||||
|
target online players; archive, bucket administration, and run management use
|
||||||
|
`scorekeeper.admin`. Saves happen on disable, not every mutation, so crashes may
|
||||||
|
lose recent state.
|
||||||
114
docs/projects.schema.json
Normal file
114
docs/projects.schema.json
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "Projects",
|
||||||
|
"description": "Project metadata keyed by the project route slug.",
|
||||||
|
"type": "object",
|
||||||
|
"patternProperties": {
|
||||||
|
"^[a-z0-9]+(?:-[a-z0-9]+)*$": { "$ref": "#/definitions/project" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"definitions": {
|
||||||
|
"image": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["url", "width", "height"],
|
||||||
|
"properties": {
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Public asset path or remote image URL. A blank header image URL falls back to image.",
|
||||||
|
"pattern": "^(\\s*|/[^/].*|https?://.+)$"
|
||||||
|
},
|
||||||
|
"alt": { "type": "string" },
|
||||||
|
"prompt": { "type": "string" },
|
||||||
|
"name": { "type": "string" },
|
||||||
|
"width": { "type": "integer", "minimum": 1 },
|
||||||
|
"height": { "type": "integer", "minimum": 1 },
|
||||||
|
"backgroundClassName": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"projectLink": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["url"],
|
||||||
|
"properties": {
|
||||||
|
"type": { "type": "string" },
|
||||||
|
"url": { "type": "string", "pattern": "^(\\s*|https?://.+)$" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"platform": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["name"],
|
||||||
|
"properties": {
|
||||||
|
"name": { "type": "string", "pattern": "\\S" },
|
||||||
|
"info": { "type": "string" },
|
||||||
|
"links": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["label", "url"],
|
||||||
|
"properties": {
|
||||||
|
"label": { "type": "string", "pattern": "\\S" },
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri",
|
||||||
|
"pattern": "^https?://.+"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["id", "title", "description", "tags"],
|
||||||
|
"properties": {
|
||||||
|
"id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
|
||||||
|
"title": { "type": "string", "pattern": "\\S" },
|
||||||
|
"description": { "type": "string", "pattern": "\\S" },
|
||||||
|
"docId": { "type": "string", "minLength": 1 },
|
||||||
|
"image": { "$ref": "#/definitions/image" },
|
||||||
|
"headerImage": {
|
||||||
|
"description": "Optional detail-page logo override. Omit, set to null, or use a blank URL to fall back to image. Listing cards continue to use image.",
|
||||||
|
"anyOf": [{ "$ref": "#/definitions/image" }, { "type": "null" }]
|
||||||
|
},
|
||||||
|
"status": { "type": "string" },
|
||||||
|
"platforms": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/platform" }
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^/projects/[a-z0-9]+(?:-[a-z0-9]+)*$"
|
||||||
|
},
|
||||||
|
"tags": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string", "minLength": 1 },
|
||||||
|
"uniqueItems": true
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "#/definitions/projectLink" },
|
||||||
|
{ "required": ["type"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"feedback": { "$ref": "#/definitions/projectLink" },
|
||||||
|
"repository": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri",
|
||||||
|
"pattern": "^https?://.+"
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string", "minLength": 1 }
|
||||||
|
},
|
||||||
|
"technology": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string", "minLength": 1 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
gradle.properties
Normal file
5
gradle.properties
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
org.gradle.configuration-cache=true
|
||||||
|
org.gradle.daemon=true
|
||||||
|
org.gradle.java.installations.auto-download=true
|
||||||
|
org.gradle.java.installations.auto-detect=false
|
||||||
|
org.gradle.java.installations.fromEnv=JAVA_HOME
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
13
gradle/wrapper/gradle-wrapper.properties
vendored
13
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,8 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=PROJECT
|
||||||
distributionPath=wrapper/dists
|
distributionPath=.gradle/wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
distributionSha256Sum=bafd5ce9cfaea0fbccfdc8439a1ac42fbd4cd9c89dc9a988228d8a2639a58e6c
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
|
||||||
zipStorePath=wrapper/dists
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=PROJECT
|
||||||
|
zipStorePath=.gradle/wrapper/dists
|
||||||
|
|||||||
313
gradlew
vendored
313
gradlew
vendored
@@ -1,78 +1,129 @@
|
|||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
DEFAULT_JVM_OPTS=""
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@@ -81,96 +132,120 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=$(save "$@")
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if $JAVACMD --add-opens java.base/java.lang=ALL-UNNAMED -version ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
DEFAULT_JVM_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED $DEFAULT_JVM_OPTS"
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
cd "$(dirname "$0")"
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|||||||
80
gradlew.bat
vendored
80
gradlew.bat
vendored
@@ -1,4 +1,22 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@@ -9,25 +27,29 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS=
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -35,48 +57,36 @@ goto fail
|
|||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
|
||||||
@rem Get command-line arguments, handling Windows variants
|
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
||||||
|
|
||||||
:win9xME_args
|
|
||||||
@rem Slurp the command line arguments.
|
|
||||||
set CMD_LINE_ARGS=
|
|
||||||
set _SKIP=2
|
|
||||||
|
|
||||||
:win9xME_args_slurp
|
|
||||||
if "x%~1" == "x" goto execute
|
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
|
||||||
|
}
|
||||||
|
|
||||||
rootProject.name = 'ScoreKeeper'
|
rootProject.name = 'ScoreKeeper'
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
||||||
|
|
||||||
|
public final class ScoreBucket {
|
||||||
|
private final String _id;
|
||||||
|
private final String _singular;
|
||||||
|
private final String _plural;
|
||||||
|
private final int _initialValue;
|
||||||
|
private final ScoreReporting _reporting;
|
||||||
|
|
||||||
|
public ScoreBucket(String id, String singular, String plural, int initialValue) {
|
||||||
|
this(id, singular, plural, initialValue, ScoreReporting.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreBucket(
|
||||||
|
String id, String singular, String plural, int initialValue, ScoreReporting reporting) {
|
||||||
|
if (id == null || !id.matches("[A-Za-z0-9_-]+")) {
|
||||||
|
throw new IllegalArgumentException("Bucket ID must contain only letters, numbers, _ or -");
|
||||||
|
}
|
||||||
|
if (singular == null || singular.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Bucket singular label cannot be blank");
|
||||||
|
}
|
||||||
|
if (plural == null || plural.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Bucket plural label cannot be blank");
|
||||||
|
}
|
||||||
|
if (reporting == null) {
|
||||||
|
throw new IllegalArgumentException("Bucket reporting policy cannot be null");
|
||||||
|
}
|
||||||
|
_id = id;
|
||||||
|
_singular = singular;
|
||||||
|
_plural = plural;
|
||||||
|
_initialValue = initialValue;
|
||||||
|
_reporting = reporting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingular() {
|
||||||
|
return _singular;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlural() {
|
||||||
|
return _plural;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInitialValue() {
|
||||||
|
return _initialValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreReporting getReporting() {
|
||||||
|
return _reporting;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +1,812 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.entity.Player;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
(at your option) any later version.
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreAddCommand;
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreArchiveCommand;
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreGetCommand;
|
GNU Affero General Public License for more details.
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreResetCommand;
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractCommand;
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
public class ScoreKeeperPlugin extends JavaPlugin {
|
*/
|
||||||
private final HashMap<UUID, Integer> _playerScores = new HashMap<UUID, Integer>();
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
import java.io.File;
|
||||||
//TODO: save score data to file
|
import java.io.IOException;
|
||||||
}
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
@Override
|
import java.util.Collections;
|
||||||
public void onEnable() {
|
import java.util.Comparator;
|
||||||
//PluginManager pm = getServer().getPluginManager();
|
import java.util.LinkedHashMap;
|
||||||
//pm.registerEvent(Event.Type.BLOCK_PHYSICS, new BlockListener(){}, Priority.Normal, this);
|
import java.util.List;
|
||||||
getCommand("score-get").setExecutor(new ScoreGetCommand(this));
|
import java.util.Locale;
|
||||||
getCommand("score-add").setExecutor(new ScoreAddCommand(this));
|
import java.util.Map;
|
||||||
getCommand("score-subtract").setExecutor(new ScoreSubtractCommand(this));
|
import java.util.Objects;
|
||||||
getCommand("score-reset").setExecutor(new ScoreResetCommand(this));
|
import java.util.UUID;
|
||||||
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
|
import java.util.logging.Level;
|
||||||
|
|
||||||
//TODO: load score data from file
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreAddCommand;
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreArchiveCommand;
|
||||||
PluginDescriptionFile pdFile = this.getDescription();
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreArchiveListCommand;
|
||||||
getLogger().info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!");
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreBucketCommand;
|
||||||
}
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreGetCommand;
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreResetCommand;
|
||||||
public int getPlayerScore(Player player) {
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreRunCommand;
|
||||||
UUID uuid = player.getUniqueId();
|
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractCommand;
|
||||||
if(!_playerScores.containsKey(uuid)){
|
|
||||||
_playerScores.put(uuid, 0);
|
import net.kyori.adventure.text.Component;
|
||||||
}
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
return _playerScores.get(uuid);
|
import org.bukkit.command.CommandSender;
|
||||||
}
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
public void addScore(Player player, int amount) {
|
import org.bukkit.entity.Player;
|
||||||
UUID uuid = player.getUniqueId();
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
int score = getPlayerScore(player);
|
|
||||||
_playerScores.put(uuid, score + amount);
|
public class ScoreKeeperPlugin extends JavaPlugin {
|
||||||
}
|
private final Map<String, ScoreBucket> _buckets = new LinkedHashMap<>();
|
||||||
|
private final Map<String, Map<UUID, Integer>> _bucketScores = new LinkedHashMap<>();
|
||||||
public void subtractScore(Player player, int amount) {
|
private final Map<UUID, String> _playerBuckets = new LinkedHashMap<>();
|
||||||
UUID uuid = player.getUniqueId();
|
private final Map<String, HighScoreRun> _highScoreRuns = new LinkedHashMap<>();
|
||||||
int score = getPlayerScore(player);
|
private final Map<String, ScoreArchive> _scoreArchives = new LinkedHashMap<>();
|
||||||
_playerScores.put(uuid, score - amount);
|
private String _defaultBucketId = "points";
|
||||||
}
|
public final String _logPrefix = "[Score Keeper] ";
|
||||||
|
public final Component _messagePrefix =
|
||||||
public void resetPlayerScore(Player targetPlayer) {
|
Component.text("[")
|
||||||
// TODO Auto-generated method stub
|
.append(Component.text("Score Keeper").color(NamedTextColor.AQUA))
|
||||||
|
.append(Component.text("] ").color(NamedTextColor.WHITE));
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
YamlConfiguration scores = new YamlConfiguration();
|
||||||
|
scores.set("version", 3);
|
||||||
|
scores.set("default-bucket", _defaultBucketId);
|
||||||
|
for (ScoreBucket bucket : _buckets.values()) {
|
||||||
|
String path = "buckets." + bucket.getId();
|
||||||
|
scores.set(path + ".singular", bucket.getSingular());
|
||||||
|
scores.set(path + ".plural", bucket.getPlural());
|
||||||
|
scores.set(path + ".initial-value", bucket.getInitialValue());
|
||||||
|
scores.set(path + ".reporting", bucket.getReporting().name().toLowerCase());
|
||||||
|
for (var entry : _bucketScores.get(bucket.getId()).entrySet()) {
|
||||||
|
scores.set(path + ".scores." + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var entry : _playerBuckets.entrySet()) {
|
||||||
|
scores.set("player-buckets." + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
for (HighScoreRun run : _highScoreRuns.values()) {
|
||||||
|
String path = "high-score-runs." + run.bucketId;
|
||||||
|
scores.set(path + ".top-n", run.topN);
|
||||||
|
scores.set(path + ".reset-scores", run.resetScores);
|
||||||
|
scores.set(path + ".lifetime", run.lifetime.name().toLowerCase(Locale.ROOT));
|
||||||
|
scores.set(path + ".target-score", run.targetScore);
|
||||||
|
scores.set(path + ".expires-at", run.expiresAtMillis);
|
||||||
|
for (var entry : run.previousScores.entrySet()) {
|
||||||
|
scores.set(path + ".previous-scores." + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
scores.save(new File(getDataFolder(), "scores.yml"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logError(ex);
|
||||||
|
}
|
||||||
|
saveArchives();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
Objects.requireNonNull(getCommand("score-get")).setExecutor(new ScoreGetCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-add")).setExecutor(new ScoreAddCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-subtract"))
|
||||||
|
.setExecutor(new ScoreSubtractCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-reset")).setExecutor(new ScoreResetCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-archive")).setExecutor(new ScoreArchiveCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-archive-list"))
|
||||||
|
.setExecutor(new ScoreArchiveListCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-bucket")).setExecutor(new ScoreBucketCommand(this));
|
||||||
|
Objects.requireNonNull(getCommand("score-run")).setExecutor(new ScoreRunCommand(this));
|
||||||
|
|
||||||
|
_buckets.put("points", new ScoreBucket("points", "point", "points", 0));
|
||||||
|
_bucketScores.put("points", new LinkedHashMap<>());
|
||||||
|
loadScores();
|
||||||
|
loadArchives();
|
||||||
|
checkHighScoreRuns();
|
||||||
|
getServer().getScheduler().runTaskTimer(this, this::checkHighScoreRuns, 20L, 20L);
|
||||||
|
|
||||||
|
logInfo(
|
||||||
|
getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// region Commands
|
||||||
|
public void addScore(Player player, int amount) {
|
||||||
|
addScore(player, getPlayerBucket(player), amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScore(Player player, String bucketId, int amount) {
|
||||||
|
setScore(player, bucketId, getScore(player, bucketId) + amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void archiveScore(Player player) {
|
||||||
|
archivePlayerScore(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String archivePlayerScore(Player player) {
|
||||||
|
String bucketId = getPlayerBucket(player);
|
||||||
|
return createScoreArchive(
|
||||||
|
"player " + player.getName() + " in " + bucketId, List.of(bucketId), player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String archiveBucketScores(String bucketId) {
|
||||||
|
requireBucket(bucketId);
|
||||||
|
return createScoreArchive("bucket " + bucketId, List.of(bucketId), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String archiveAllScores() {
|
||||||
|
return createScoreArchive("all buckets", new ArrayList<>(_buckets.keySet()), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ScoreArchive> getScoreArchives() {
|
||||||
|
return List.copyOf(_scoreArchives.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreArchive getScoreArchive(String archiveId) {
|
||||||
|
return _scoreArchives.get(archiveId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScore(Player player) {
|
||||||
|
return getScore(player, getPlayerBucket(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScore(Player player, String bucketId) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
return _bucketScores
|
||||||
|
.get(bucketId)
|
||||||
|
.computeIfAbsent(player.getUniqueId(), uuid -> bucket.getInitialValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetScore(Player player) {
|
||||||
|
resetScore(player, getPlayerBucket(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetScore(Player player, String bucketId) {
|
||||||
|
setScore(player, bucketId, requireBucket(bucketId).getInitialValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(Player player, int score) {
|
||||||
|
setScore(player, getPlayerBucket(player), score);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(Player player, String bucketId, int score) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
int oldScore = getScore(player, bucketId);
|
||||||
|
_bucketScores.get(bucketId).put(player.getUniqueId(), score);
|
||||||
|
if (oldScore != score) {
|
||||||
|
HighScoreRun run = _highScoreRuns.get(bucketId);
|
||||||
|
if (run == null) {
|
||||||
|
reportScoreChange(player, bucket, score);
|
||||||
|
} else {
|
||||||
|
reportHighScoreRunChange(player, bucket, run, score);
|
||||||
|
if (run.lifetime == HighScoreLifetime.TARGET_SCORE && score >= run.targetScore) {
|
||||||
|
finishHighScoreRun(bucketId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtractScore(Player player, int amount) {
|
||||||
|
subtractScore(player, getPlayerBucket(player), amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtractScore(Player player, String bucketId, int amount) {
|
||||||
|
setScore(player, bucketId, getScore(player, bucketId) - amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreBucket createBucket(String id, String singular, String plural, int initialValue) {
|
||||||
|
return createBucket(id, singular, plural, initialValue, ScoreReporting.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreBucket createBucket(
|
||||||
|
String id, String singular, String plural, int initialValue, ScoreReporting reporting) {
|
||||||
|
ScoreBucket bucket = new ScoreBucket(id, singular, plural, initialValue, reporting);
|
||||||
|
if (_buckets.containsKey(id)) {
|
||||||
|
throw new IllegalArgumentException("A score bucket with ID " + id + " already exists");
|
||||||
|
}
|
||||||
|
_buckets.put(id, bucket);
|
||||||
|
_bucketScores.put(id, new LinkedHashMap<>());
|
||||||
|
return bucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreBucket getBucket(String bucketId) {
|
||||||
|
return _buckets.get(bucketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ScoreBucket> getBuckets() {
|
||||||
|
return Map.copyOf(_buckets);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerBucket(Player player) {
|
||||||
|
return _playerBuckets.getOrDefault(player.getUniqueId(), _defaultBucketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchPlayerBucket(Player player, String bucketId) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
UUID playerId = player.getUniqueId();
|
||||||
|
String previousBucketId = getPlayerBucket(player);
|
||||||
|
if (bucketId.equals(_defaultBucketId)) {
|
||||||
|
_playerBuckets.remove(playerId);
|
||||||
|
} else {
|
||||||
|
_playerBuckets.put(playerId, bucketId);
|
||||||
|
}
|
||||||
|
if (!previousBucketId.equals(bucketId)) {
|
||||||
|
sendBucketChangeMessage(player, bucket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchAllPlayers(String bucketId) {
|
||||||
|
requireBucket(bucketId);
|
||||||
|
Map<UUID, String> previousBuckets = new LinkedHashMap<>();
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
previousBuckets.put(Objects.requireNonNull(player).getUniqueId(), getPlayerBucket(player));
|
||||||
|
}
|
||||||
|
_defaultBucketId = bucketId;
|
||||||
|
_playerBuckets.clear();
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
if (!bucketId.equals(previousBuckets.get(Objects.requireNonNull(player).getUniqueId()))) {
|
||||||
|
sendBucketChangeMessage(player, bucket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startTargetScoreRun(String bucketId, int topN, boolean resetScores, int targetScore) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
if (resetScores && targetScore <= bucket.getInitialValue()) {
|
||||||
|
throw new IllegalArgumentException("Target score must exceed the bucket's initial value");
|
||||||
|
}
|
||||||
|
startHighScoreRun(bucketId, topN, resetScores, HighScoreLifetime.TARGET_SCORE, targetScore, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startTimedScoreRun(
|
||||||
|
String bucketId, int topN, boolean resetScores, Duration duration) {
|
||||||
|
if (duration == null || duration.isNegative() || duration.isZero()) {
|
||||||
|
throw new IllegalArgumentException("Run duration must be positive");
|
||||||
|
}
|
||||||
|
long durationMillis;
|
||||||
|
long expiresAtMillis;
|
||||||
|
try {
|
||||||
|
durationMillis = duration.toMillis();
|
||||||
|
expiresAtMillis = Math.addExact(System.currentTimeMillis(), durationMillis);
|
||||||
|
} catch (ArithmeticException ex) {
|
||||||
|
throw new IllegalArgumentException("Run duration is too large", ex);
|
||||||
|
}
|
||||||
|
if (durationMillis <= 0) {
|
||||||
|
throw new IllegalArgumentException("Run duration must be at least one millisecond");
|
||||||
|
}
|
||||||
|
startHighScoreRun(bucketId, topN, resetScores, HighScoreLifetime.DURATION, 0, expiresAtMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startUntilDisabledScoreRun(String bucketId, int topN, boolean resetScores) {
|
||||||
|
startHighScoreRun(bucketId, topN, resetScores, HighScoreLifetime.UNTIL_DISABLED, 0, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopHighScoreRun(String bucketId) {
|
||||||
|
if (!_highScoreRuns.containsKey(bucketId)) {
|
||||||
|
throw new IllegalArgumentException("No high-score run is active for bucket " + bucketId);
|
||||||
|
}
|
||||||
|
finishHighScoreRun(bucketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasActiveHighScoreRun(String bucketId) {
|
||||||
|
return _highScoreRuns.containsKey(bucketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Utiilty Methods
|
||||||
|
public void sendMessage(CommandSender reciever, Component message) {
|
||||||
|
reciever.sendMessage(_messagePrefix.append(Objects.requireNonNull(message)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoreBucket requireBucket(String bucketId) {
|
||||||
|
ScoreBucket bucket = _buckets.get(bucketId);
|
||||||
|
if (bucket == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown score bucket: " + bucketId);
|
||||||
|
}
|
||||||
|
return bucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendBucketChangeMessage(Player player, ScoreBucket bucket) {
|
||||||
|
int score = getScore(player, bucket.getId());
|
||||||
|
String unit = score == 1 ? bucket.getSingular() : bucket.getPlural();
|
||||||
|
sendMessage(
|
||||||
|
player,
|
||||||
|
Component.text(
|
||||||
|
"You are now tracking " + bucket.getId() + ". You have " + score + " " + unit + "."));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createScoreArchive(String scope, List<String> bucketIds, Player player) {
|
||||||
|
for (String bucketId : bucketIds) {
|
||||||
|
if (_highScoreRuns.containsKey(bucketId)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Stop the active high-score run for " + bucketId + " before archiving it");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Map<UUID, Integer>> archivedScores = new LinkedHashMap<>();
|
||||||
|
UUID playerId = player == null ? null : player.getUniqueId();
|
||||||
|
for (String bucketId : bucketIds) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
Map<UUID, Integer> bucketScores = _bucketScores.get(bucketId);
|
||||||
|
if (playerId == null) {
|
||||||
|
archivedScores.put(bucketId, new LinkedHashMap<>(bucketScores));
|
||||||
|
bucketScores.replaceAll((uuid, score) -> bucket.getInitialValue());
|
||||||
|
} else {
|
||||||
|
int score = getScore(player, bucketId);
|
||||||
|
archivedScores.put(bucketId, Map.of(playerId, score));
|
||||||
|
bucketScores.put(playerId, bucket.getInitialValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String archiveId = UUID.randomUUID().toString();
|
||||||
|
_scoreArchives.put(
|
||||||
|
archiveId, new ScoreArchive(archiveId, scope, System.currentTimeMillis(), archivedScores));
|
||||||
|
return archiveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startHighScoreRun(
|
||||||
|
String bucketId,
|
||||||
|
int topN,
|
||||||
|
boolean resetScores,
|
||||||
|
HighScoreLifetime lifetime,
|
||||||
|
int targetScore,
|
||||||
|
long expiresAtMillis) {
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
if (topN < 1) {
|
||||||
|
throw new IllegalArgumentException("Top N must be at least 1");
|
||||||
|
}
|
||||||
|
if (_highScoreRuns.containsKey(bucketId)) {
|
||||||
|
throw new IllegalArgumentException("A high-score run is already active for " + bucketId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<UUID, Integer> bucketScores = _bucketScores.get(bucketId);
|
||||||
|
Map<UUID, Integer> previousScores = resetScores ? new LinkedHashMap<>(bucketScores) : Map.of();
|
||||||
|
if (resetScores) {
|
||||||
|
bucketScores.replaceAll((playerId, score) -> bucket.getInitialValue());
|
||||||
|
}
|
||||||
|
_highScoreRuns.put(
|
||||||
|
bucketId,
|
||||||
|
new HighScoreRun(
|
||||||
|
bucketId, topN, resetScores, lifetime, targetScore, expiresAtMillis, previousScores));
|
||||||
|
checkHighScoreRuns();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkHighScoreRuns() {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
List<String> finishedRuns = new ArrayList<>();
|
||||||
|
for (HighScoreRun run : _highScoreRuns.values()) {
|
||||||
|
boolean expired = run.lifetime == HighScoreLifetime.DURATION && now >= run.expiresAtMillis;
|
||||||
|
boolean targetReached =
|
||||||
|
run.lifetime == HighScoreLifetime.TARGET_SCORE
|
||||||
|
&& _bucketScores.get(run.bucketId).values().stream()
|
||||||
|
.anyMatch(score -> score >= run.targetScore);
|
||||||
|
if (expired || targetReached) {
|
||||||
|
finishedRuns.add(run.bucketId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String bucketId : finishedRuns) {
|
||||||
|
finishHighScoreRun(bucketId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportHighScoreRunChange(
|
||||||
|
Player player, ScoreBucket bucket, HighScoreRun run, int score) {
|
||||||
|
String message = scoreMessage(player.getName(), bucket, score);
|
||||||
|
sendMessage(player, Component.text(Objects.requireNonNull(message)));
|
||||||
|
List<ScoreEntry> standings = getRankedScores(bucket.getId());
|
||||||
|
for (int place = 0; place < Math.min(run.topN, standings.size()); place++) {
|
||||||
|
if (standings.get(place).playerId.equals(player.getUniqueId())) {
|
||||||
|
for (Player recipient : getServer().getOnlinePlayers()) {
|
||||||
|
if (recipient != player) {
|
||||||
|
sendMessage(recipient, Component.text(Objects.requireNonNull(message)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishHighScoreRun(String bucketId) {
|
||||||
|
HighScoreRun run = _highScoreRuns.remove(bucketId);
|
||||||
|
if (run == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreBucket bucket = requireBucket(bucketId);
|
||||||
|
List<ScoreEntry> standings = getRankedScores(bucketId);
|
||||||
|
StringBuilder table =
|
||||||
|
new StringBuilder("High-score run for ").append(bucketId).append(" finished.");
|
||||||
|
int places = Math.min(run.topN, standings.size());
|
||||||
|
if (places == 0) {
|
||||||
|
table.append("\nNo scores were recorded.");
|
||||||
|
}
|
||||||
|
for (int place = 0; place < places; place++) {
|
||||||
|
ScoreEntry entry = standings.get(place);
|
||||||
|
table
|
||||||
|
.append("\n")
|
||||||
|
.append(place + 1)
|
||||||
|
.append(". ")
|
||||||
|
.append(entry.playerName)
|
||||||
|
.append(" - ")
|
||||||
|
.append(entry.score)
|
||||||
|
.append(" ")
|
||||||
|
.append(scoreUnit(bucket, entry.score));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (run.resetScores) {
|
||||||
|
Map<UUID, Integer> bucketScores = _bucketScores.get(bucketId);
|
||||||
|
bucketScores.clear();
|
||||||
|
bucketScores.putAll(run.previousScores);
|
||||||
|
}
|
||||||
|
logInfo(table.toString().replace('\n', ' '));
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
ScoreEntry personalEntry = null;
|
||||||
|
int personalPlace = -1;
|
||||||
|
for (int place = 0; place < standings.size(); place++) {
|
||||||
|
if (standings.get(place).playerId.equals(Objects.requireNonNull(player).getUniqueId())) {
|
||||||
|
personalEntry = standings.get(place);
|
||||||
|
personalPlace = place + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int personalScore = personalEntry == null ? bucket.getInitialValue() : personalEntry.score;
|
||||||
|
String personalResult =
|
||||||
|
personalPlace < 0
|
||||||
|
? "Your place: unranked; score: "
|
||||||
|
+ personalScore
|
||||||
|
+ " "
|
||||||
|
+ scoreUnit(bucket, personalScore)
|
||||||
|
: "Your place: "
|
||||||
|
+ personalPlace
|
||||||
|
+ "; score: "
|
||||||
|
+ personalScore
|
||||||
|
+ " "
|
||||||
|
+ scoreUnit(bucket, personalScore);
|
||||||
|
sendMessage(player, Component.text(table + "\n" + personalResult));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ScoreEntry> getRankedScores(String bucketId) {
|
||||||
|
List<ScoreEntry> standings = new ArrayList<>();
|
||||||
|
for (var entry : _bucketScores.get(bucketId).entrySet()) {
|
||||||
|
String playerName = getServer().getOfflinePlayer(entry.getKey()).getName();
|
||||||
|
if (playerName == null || playerName.isBlank()) {
|
||||||
|
playerName = entry.getKey().toString();
|
||||||
|
}
|
||||||
|
standings.add(new ScoreEntry(entry.getKey(), playerName, entry.getValue()));
|
||||||
|
}
|
||||||
|
standings.sort(
|
||||||
|
Comparator.comparingInt((ScoreEntry entry) -> entry.score)
|
||||||
|
.reversed()
|
||||||
|
.thenComparing(entry -> entry.playerName, String.CASE_INSENSITIVE_ORDER)
|
||||||
|
.thenComparing(entry -> entry.playerId.toString()));
|
||||||
|
return standings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String scoreMessage(String playerName, ScoreBucket bucket, int score) {
|
||||||
|
return playerName
|
||||||
|
+ "'s "
|
||||||
|
+ bucket.getId()
|
||||||
|
+ " score is now "
|
||||||
|
+ score
|
||||||
|
+ " "
|
||||||
|
+ scoreUnit(bucket, score)
|
||||||
|
+ ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String scoreUnit(ScoreBucket bucket, int score) {
|
||||||
|
return score == 1 ? bucket.getSingular() : bucket.getPlural();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadScores() {
|
||||||
|
File scoreFile = new File(getDataFolder(), "scores.yml");
|
||||||
|
if (!scoreFile.isFile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration scores = YamlConfiguration.loadConfiguration(scoreFile);
|
||||||
|
ConfigurationSection bucketSection = scores.getConfigurationSection("buckets");
|
||||||
|
if (bucketSection == null) {
|
||||||
|
loadLegacyScores(scores);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_buckets.clear();
|
||||||
|
_bucketScores.clear();
|
||||||
|
for (String id : bucketSection.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
ScoreReporting reporting =
|
||||||
|
parseReporting(bucketSection.getString(id + ".reporting", "none"), id);
|
||||||
|
createBucket(
|
||||||
|
id,
|
||||||
|
bucketSection.getString(id + ".singular", id),
|
||||||
|
bucketSection.getString(id + ".plural", id),
|
||||||
|
bucketSection.getInt(id + ".initial-value"),
|
||||||
|
reporting);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning("Ignoring invalid score bucket " + id + ": " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!_buckets.containsKey("points")) {
|
||||||
|
createBucket("points", "point", "points", 0);
|
||||||
|
}
|
||||||
|
_defaultBucketId = scores.getString("default-bucket", "points");
|
||||||
|
if (!_buckets.containsKey(_defaultBucketId)) {
|
||||||
|
logWarning("Unknown default score bucket; using points instead.");
|
||||||
|
_defaultBucketId = "points";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String id : _buckets.keySet()) {
|
||||||
|
ConfigurationSection bucketScores =
|
||||||
|
scores.getConfigurationSection("buckets." + id + ".scores");
|
||||||
|
if (bucketScores != null) {
|
||||||
|
loadPlayerScores(bucketScores, _bucketScores.get(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConfigurationSection playerBuckets = scores.getConfigurationSection("player-buckets");
|
||||||
|
if (playerBuckets != null) {
|
||||||
|
for (String key : playerBuckets.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
UUID playerId = UUID.fromString(key);
|
||||||
|
String bucketId = playerBuckets.getString(key);
|
||||||
|
if (_buckets.containsKey(bucketId) && !bucketId.equals(_defaultBucketId)) {
|
||||||
|
_playerBuckets.put(playerId, bucketId);
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning("Ignoring invalid player bucket UUID: " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadHighScoreRuns(scores);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadArchives() {
|
||||||
|
File archiveFile = new File(getDataFolder(), "archives.yml");
|
||||||
|
if (!archiveFile.isFile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
YamlConfiguration archives = YamlConfiguration.loadConfiguration(archiveFile);
|
||||||
|
ConfigurationSection archiveSection = archives.getConfigurationSection("archives");
|
||||||
|
if (archiveSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String archiveId : archiveSection.getKeys(false)) {
|
||||||
|
String path = "archives." + archiveId;
|
||||||
|
Map<String, Map<UUID, Integer>> bucketScores = new LinkedHashMap<>();
|
||||||
|
ConfigurationSection buckets = archives.getConfigurationSection(path + ".buckets");
|
||||||
|
if (buckets != null) {
|
||||||
|
for (String bucketId : buckets.getKeys(false)) {
|
||||||
|
Map<UUID, Integer> playerScores = new LinkedHashMap<>();
|
||||||
|
ConfigurationSection savedScores =
|
||||||
|
archives.getConfigurationSection(path + ".buckets." + bucketId + ".scores");
|
||||||
|
if (savedScores != null) {
|
||||||
|
loadPlayerScores(savedScores, playerScores);
|
||||||
|
}
|
||||||
|
bucketScores.put(bucketId, playerScores);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_scoreArchives.put(
|
||||||
|
archiveId,
|
||||||
|
new ScoreArchive(
|
||||||
|
archiveId,
|
||||||
|
archives.getString(path + ".scope", "unknown"),
|
||||||
|
archives.getLong(path + ".created-at"),
|
||||||
|
bucketScores));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveArchives() {
|
||||||
|
YamlConfiguration archives = new YamlConfiguration();
|
||||||
|
for (ScoreArchive archive : _scoreArchives.values()) {
|
||||||
|
String path = "archives." + archive.getId();
|
||||||
|
archives.set(path + ".scope", archive.getScope());
|
||||||
|
archives.set(path + ".created-at", archive.getCreatedAtMillis());
|
||||||
|
for (var bucketEntry : archive.getBucketScores().entrySet()) {
|
||||||
|
for (var scoreEntry : bucketEntry.getValue().entrySet()) {
|
||||||
|
archives.set(
|
||||||
|
path + ".buckets." + bucketEntry.getKey() + ".scores." + scoreEntry.getKey(),
|
||||||
|
scoreEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
archives.save(new File(getDataFolder(), "archives.yml"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logError(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLegacyScores(YamlConfiguration scores) {
|
||||||
|
loadPlayerScores(scores, _bucketScores.get("points"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadPlayerScores(ConfigurationSection scores, Map<UUID, Integer> target) {
|
||||||
|
for (String key : scores.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
target.put(UUID.fromString(key), scores.getInt(key));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning("Ignoring score with invalid player UUID: " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoreReporting parseReporting(String value, String bucketId) {
|
||||||
|
try {
|
||||||
|
return ScoreReporting.fromString(value);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning("Ignoring invalid reporting policy for bucket " + bucketId + "; using none.");
|
||||||
|
return ScoreReporting.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadHighScoreRuns(YamlConfiguration scores) {
|
||||||
|
ConfigurationSection runs = scores.getConfigurationSection("high-score-runs");
|
||||||
|
if (runs == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String bucketId : runs.getKeys(false)) {
|
||||||
|
if (!_buckets.containsKey(bucketId)) {
|
||||||
|
logWarning("Ignoring high-score run for unknown bucket " + bucketId + ".");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String path = "high-score-runs." + bucketId;
|
||||||
|
int topN = scores.getInt(path + ".top-n");
|
||||||
|
if (topN < 1) {
|
||||||
|
throw new IllegalArgumentException("Top N must be at least 1");
|
||||||
|
}
|
||||||
|
HighScoreLifetime lifetime =
|
||||||
|
HighScoreLifetime.valueOf(
|
||||||
|
scores.getString(path + ".lifetime", "until_disabled").toUpperCase(Locale.ROOT));
|
||||||
|
Map<UUID, Integer> previousScores = new LinkedHashMap<>();
|
||||||
|
ConfigurationSection savedScores =
|
||||||
|
scores.getConfigurationSection(path + ".previous-scores");
|
||||||
|
if (savedScores != null) {
|
||||||
|
loadPlayerScores(savedScores, previousScores);
|
||||||
|
}
|
||||||
|
_highScoreRuns.put(
|
||||||
|
bucketId,
|
||||||
|
new HighScoreRun(
|
||||||
|
bucketId,
|
||||||
|
topN,
|
||||||
|
scores.getBoolean(path + ".reset-scores"),
|
||||||
|
lifetime,
|
||||||
|
scores.getInt(path + ".target-score"),
|
||||||
|
scores.getLong(path + ".expires-at"),
|
||||||
|
previousScores));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning(
|
||||||
|
"Ignoring invalid high-score run for bucket " + bucketId + ": " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportScoreChange(Player player, ScoreBucket bucket, int score) {
|
||||||
|
ScoreReporting reporting = bucket.getReporting();
|
||||||
|
if (reporting == ScoreReporting.NONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String text = scoreMessage(player.getName(), bucket, score);
|
||||||
|
Component message = Component.text(Objects.requireNonNull(text));
|
||||||
|
if (reporting == ScoreReporting.PLAYER) {
|
||||||
|
sendMessage(player, message);
|
||||||
|
} else if (reporting == ScoreReporting.GLOBAL) {
|
||||||
|
for (Player recipient : getServer().getOnlinePlayers()) {
|
||||||
|
sendMessage(recipient, message);
|
||||||
|
}
|
||||||
|
} else if (reporting == ScoreReporting.ADMIN) {
|
||||||
|
logInfo(text);
|
||||||
|
for (Player recipient : getServer().getOnlinePlayers()) {
|
||||||
|
if (Objects.requireNonNull(recipient).isOp()
|
||||||
|
|| recipient.hasPermission("scorekeeper.admin")) {
|
||||||
|
sendMessage(recipient, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum HighScoreLifetime {
|
||||||
|
TARGET_SCORE,
|
||||||
|
DURATION,
|
||||||
|
UNTIL_DISABLED
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class HighScoreRun {
|
||||||
|
private final String bucketId;
|
||||||
|
private final int topN;
|
||||||
|
private final boolean resetScores;
|
||||||
|
private final HighScoreLifetime lifetime;
|
||||||
|
private final int targetScore;
|
||||||
|
private final long expiresAtMillis;
|
||||||
|
private final Map<UUID, Integer> previousScores;
|
||||||
|
|
||||||
|
private HighScoreRun(
|
||||||
|
String bucketId,
|
||||||
|
int topN,
|
||||||
|
boolean resetScores,
|
||||||
|
HighScoreLifetime lifetime,
|
||||||
|
int targetScore,
|
||||||
|
long expiresAtMillis,
|
||||||
|
Map<UUID, Integer> previousScores) {
|
||||||
|
this.bucketId = bucketId;
|
||||||
|
this.topN = topN;
|
||||||
|
this.resetScores = resetScores;
|
||||||
|
this.lifetime = lifetime;
|
||||||
|
this.targetScore = targetScore;
|
||||||
|
this.expiresAtMillis = expiresAtMillis;
|
||||||
|
this.previousScores = new LinkedHashMap<>(previousScores);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record ScoreEntry(UUID playerId, String playerName, int score) {}
|
||||||
|
|
||||||
|
public static final class ScoreArchive {
|
||||||
|
private final String _id;
|
||||||
|
private final String _scope;
|
||||||
|
private final long _createdAtMillis;
|
||||||
|
private final Map<String, Map<UUID, Integer>> _bucketScores;
|
||||||
|
|
||||||
|
private ScoreArchive(
|
||||||
|
String id,
|
||||||
|
String scope,
|
||||||
|
long createdAtMillis,
|
||||||
|
Map<String, Map<UUID, Integer>> bucketScores) {
|
||||||
|
_id = id;
|
||||||
|
_scope = scope;
|
||||||
|
_createdAtMillis = createdAtMillis;
|
||||||
|
Map<String, Map<UUID, Integer>> copiedScores = new LinkedHashMap<>();
|
||||||
|
for (var entry : bucketScores.entrySet()) {
|
||||||
|
copiedScores.put(entry.getKey(), Map.copyOf(entry.getValue()));
|
||||||
|
}
|
||||||
|
_bucketScores = Collections.unmodifiableMap(copiedScores);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return _scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreatedAtMillis() {
|
||||||
|
return _createdAtMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Map<UUID, Integer>> getBucketScores() {
|
||||||
|
return _bucketScores;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Logging
|
||||||
|
public void logError(Exception ex) {
|
||||||
|
getLogger().log(Level.SEVERE, _logPrefix + ex.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logInfo(String message) {
|
||||||
|
getLogger().info(_logPrefix + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logWarning(String message) {
|
||||||
|
getLogger().warning(_logPrefix + message);
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public enum ScoreReporting {
|
||||||
|
ADMIN,
|
||||||
|
GLOBAL,
|
||||||
|
PLAYER,
|
||||||
|
NONE;
|
||||||
|
|
||||||
|
public static ScoreReporting fromString(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalArgumentException("Reporting policy cannot be null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return valueOf(value.toUpperCase(Locale.ROOT));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
throw new IllegalArgumentException("Reporting must be admin, global, player or none", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,75 +1,103 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
import org.bukkit.command.CommandExecutor;
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.command.CommandSender;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.entity.Player;
|
(at your option) any later version.
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
public class ScoreAddCommand implements CommandExecutor {
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
private final ScoreKeeperPlugin _plugin;
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
public ScoreAddCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
You should have received a copy of the GNU Affero General Public License
|
||||||
_plugin = scoreKeeperPlugin;
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
public boolean onCommand(
|
|
||||||
CommandSender sender,
|
import java.util.Objects;
|
||||||
Command command,
|
|
||||||
String label,
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
String[] split
|
|
||||||
) {
|
import net.kyori.adventure.text.Component;
|
||||||
boolean rcon = !(sender instanceof Player);
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
int amount = 0;
|
|
||||||
Player targetPlayer = null;
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
if(split.length == 1){
|
import org.bukkit.command.CommandSender;
|
||||||
if(rcon){
|
import org.bukkit.entity.Player;
|
||||||
echoUsage(sender, rcon);
|
|
||||||
return true;
|
public class ScoreAddCommand implements CommandExecutor {
|
||||||
}else{
|
private final ScoreKeeperPlugin _plugin;
|
||||||
targetPlayer = (Player)sender;
|
|
||||||
try{
|
public ScoreAddCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
amount = Integer.parseInt(split[0]);
|
_plugin = scoreKeeperPlugin;
|
||||||
}catch(NumberFormatException ex){
|
}
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||||
}
|
boolean rcon = !(sender instanceof Player);
|
||||||
}else if(split.length == 2){
|
int amount = 0;
|
||||||
targetPlayer = _plugin.getServer().getPlayer(split[0]);
|
Player targetPlayer = null;
|
||||||
if(targetPlayer == null){
|
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
if (split.length == 1) {
|
||||||
return true;
|
if (rcon) {
|
||||||
}
|
echoUsage(sender, rcon);
|
||||||
|
return true;
|
||||||
try{
|
} else {
|
||||||
amount = Integer.parseInt(split[1]);
|
targetPlayer = (Player) sender;
|
||||||
}catch(NumberFormatException ex){
|
try {
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
amount = Integer.parseInt(split[0]);
|
||||||
return true;
|
} catch (NumberFormatException ex) {
|
||||||
}
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
}else{
|
return true;
|
||||||
echoUsage(sender, rcon);
|
}
|
||||||
return true;
|
}
|
||||||
}
|
} else if (split.length == 2) {
|
||||||
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
_plugin.addScore(targetPlayer, amount);
|
if (targetPlayer == null) {
|
||||||
return true;
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
|
||||||
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
|
try {
|
||||||
}
|
amount = Integer.parseInt(split[1]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
private void echoUsage(CommandSender sender, boolean rcon) {
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
if(rcon){
|
return true;
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-add " + ChatColor.GREEN + "<playername> <amount>");
|
}
|
||||||
}else{
|
} else {
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-add " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>");
|
echoUsage(sender, rcon);
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
_plugin.addScore(targetPlayer, amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoError(CommandSender sender, boolean rcon, String string) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(string)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
|
if (rcon) {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": score-add ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("<playerName> <amount>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
} else {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": /score-add ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("[playerName] ").color(NamedTextColor.YELLOW))
|
||||||
|
.append(Component.text("<amount>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,36 +1,83 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
import org.bukkit.command.CommandExecutor;
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.command.CommandSender;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.entity.Player;
|
(at your option) any later version.
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
public class ScoreArchiveCommand implements CommandExecutor {
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
private final ScoreKeeperPlugin _plugin;
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
public ScoreArchiveCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
You should have received a copy of the GNU Affero General Public License
|
||||||
_plugin = scoreKeeperPlugin;
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
public boolean onCommand(
|
|
||||||
CommandSender sender,
|
import java.util.Objects;
|
||||||
Command command,
|
|
||||||
String label,
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
String[] split
|
|
||||||
) {
|
import net.kyori.adventure.text.Component;
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
if(sender instanceof Player){
|
import org.bukkit.command.Command;
|
||||||
Player player = (Player) sender;
|
import org.bukkit.command.CommandExecutor;
|
||||||
int score = _plugin.getPlayerScore(player);
|
import org.bukkit.command.CommandSender;
|
||||||
player.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score);
|
import org.bukkit.entity.Player;
|
||||||
return true;
|
|
||||||
}else{
|
public class ScoreArchiveCommand implements CommandExecutor {
|
||||||
return false;
|
private final ScoreKeeperPlugin _plugin;
|
||||||
}
|
|
||||||
}
|
public ScoreArchiveCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
}
|
_plugin = scoreKeeperPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||||
|
if (!sender.hasPermission("scorekeeper.admin")) {
|
||||||
|
sendError(sender, "You do not have permission to archive scores");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String archiveId;
|
||||||
|
if (split.length == 1 && split[0].equalsIgnoreCase("all")) {
|
||||||
|
archiveId = _plugin.archiveAllScores();
|
||||||
|
} else if (split.length == 2 && split[0].equalsIgnoreCase("bucket")) {
|
||||||
|
archiveId = _plugin.archiveBucketScores(split[1]);
|
||||||
|
} else if (split.length == 0 && sender instanceof Player player) {
|
||||||
|
archiveId = _plugin.archivePlayerScore(player);
|
||||||
|
} else if (split.length == 1) {
|
||||||
|
Player target = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
|
if (target == null) {
|
||||||
|
sendError(sender, "Can't find a player with that name");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
archiveId = _plugin.archivePlayerScore(target);
|
||||||
|
} else {
|
||||||
|
sendUsage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_plugin.sendMessage(sender, Component.text("Saved score archive " + archiveId + "."));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendError(CommandSender sender, String message) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(message)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendUsage(CommandSender sender) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text("Usage: /score-archive [playerName|all] | /score-archive bucket <bucketId>")
|
||||||
|
.color(NamedTextColor.YELLOW));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreBucket;
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class ScoreArchiveListCommand implements CommandExecutor {
|
||||||
|
private final ScoreKeeperPlugin _plugin;
|
||||||
|
|
||||||
|
public ScoreArchiveListCommand(ScoreKeeperPlugin plugin) {
|
||||||
|
_plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
var archives = _plugin.getScoreArchives();
|
||||||
|
if (archives.isEmpty()) {
|
||||||
|
_plugin.sendMessage(sender, Component.text("No score archives have been saved."));
|
||||||
|
} else {
|
||||||
|
archives.stream()
|
||||||
|
.sorted(
|
||||||
|
Comparator.comparingLong(
|
||||||
|
(ScoreKeeperPlugin.ScoreArchive archive) -> archive.getCreatedAtMillis())
|
||||||
|
.reversed())
|
||||||
|
.forEach(
|
||||||
|
archive ->
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
archive.getId()
|
||||||
|
+ " | "
|
||||||
|
+ archive.getScope()
|
||||||
|
+ " | "
|
||||||
|
+ Instant.ofEpochMilli(archive.getCreatedAtMillis()))));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
sendUsage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ScoreKeeperPlugin.ScoreArchive archive = _plugin.getScoreArchive(args[0]);
|
||||||
|
if (archive == null) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text("No score archive exists with ID " + args[0] + ".")
|
||||||
|
.color(NamedTextColor.RED));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
"Archive "
|
||||||
|
+ archive.getId()
|
||||||
|
+ " ("
|
||||||
|
+ archive.getScope()
|
||||||
|
+ ", "
|
||||||
|
+ Instant.ofEpochMilli(archive.getCreatedAtMillis())
|
||||||
|
+ ")"));
|
||||||
|
for (var bucketEntry : archive.getBucketScores().entrySet()) {
|
||||||
|
ScoreBucket bucket = _plugin.getBucket(bucketEntry.getKey());
|
||||||
|
_plugin.sendMessage(sender, Component.text("Bucket " + bucketEntry.getKey() + ":"));
|
||||||
|
bucketEntry.getValue().entrySet().stream()
|
||||||
|
.sorted(
|
||||||
|
Map.Entry.<UUID, Integer>comparingByValue()
|
||||||
|
.reversed()
|
||||||
|
.thenComparing(entry -> entry.getKey().toString()))
|
||||||
|
.forEach(
|
||||||
|
entry ->
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
displayName(entry.getKey())
|
||||||
|
+ " - "
|
||||||
|
+ entry.getValue()
|
||||||
|
+ " "
|
||||||
|
+ scoreUnit(bucket, entry.getValue()))));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String displayName(UUID playerId) {
|
||||||
|
OfflinePlayer player = _plugin.getServer().getOfflinePlayer(playerId);
|
||||||
|
return player.getName() == null ? playerId.toString() : player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String scoreUnit(ScoreBucket bucket, int score) {
|
||||||
|
if (bucket == null) {
|
||||||
|
return "scores";
|
||||||
|
}
|
||||||
|
return score == 1 ? bucket.getSingular() : bucket.getPlural();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendUsage(CommandSender sender) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text("Usage: /score-archive-list [archiveId]").color(NamedTextColor.YELLOW));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreBucket;
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreReporting;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ScoreBucketCommand implements CommandExecutor {
|
||||||
|
private final ScoreKeeperPlugin _plugin;
|
||||||
|
|
||||||
|
public ScoreBucketCommand(ScoreKeeperPlugin plugin) {
|
||||||
|
_plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
String bucketId = _plugin.getPlayerBucket(player);
|
||||||
|
ScoreBucket bucket = _plugin.getBucket(bucketId);
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
"You are tracking " + bucket.getId() + " (" + bucket.getPlural() + ")."));
|
||||||
|
} else {
|
||||||
|
sendUsage(sender);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((args.length == 5 || args.length == 6) && args[0].equalsIgnoreCase("create")) {
|
||||||
|
if (!requireAdmin(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ScoreReporting reporting =
|
||||||
|
args.length == 6 ? ScoreReporting.fromString(args[5]) : ScoreReporting.NONE;
|
||||||
|
_plugin.createBucket(args[1], args[2], args[3], Integer.parseInt(args[4]), reporting);
|
||||||
|
_plugin.sendMessage(sender, Component.text("Created score bucket " + args[1] + "."));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 1 && sender instanceof Player player) {
|
||||||
|
switchPlayerBucket(sender, player, args[0]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2) {
|
||||||
|
if (!requireAdmin(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
|
try {
|
||||||
|
_plugin.switchAllPlayers(args[1]);
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text("All players are now tracking " + args[1] + "."));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player target = _plugin.getServer().getPlayerExact(args[0]);
|
||||||
|
if (target == null) {
|
||||||
|
sendError(sender, "Can't find a player with that name");
|
||||||
|
} else {
|
||||||
|
switchPlayerBucket(sender, target, args[1]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendUsage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void switchPlayerBucket(CommandSender sender, Player target, String bucketId) {
|
||||||
|
try {
|
||||||
|
_plugin.switchPlayerBucket(target, bucketId);
|
||||||
|
if (sender != target) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(target.getName() + " is now tracking " + bucketId + "."));
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requireAdmin(CommandSender sender) {
|
||||||
|
if (sender.hasPermission("scorekeeper.admin")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sendError(sender, "You do not have permission to manage score buckets");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendError(CommandSender sender, String message) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(message)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendUsage(CommandSender sender) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
"Usage: /score-bucket [bucketId] | create <id> <singular> <plural> <initialValue>"
|
||||||
|
+ " | <player|all> <bucketId>")
|
||||||
|
.color(NamedTextColor.YELLOW));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,75 +1,110 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
import org.bukkit.command.CommandExecutor;
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.command.CommandSender;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.entity.Player;
|
(at your option) any later version.
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
public class ScoreGetCommand implements CommandExecutor {
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
private final ScoreKeeperPlugin _plugin;
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
public ScoreGetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
You should have received a copy of the GNU Affero General Public License
|
||||||
_plugin = scoreKeeperPlugin;
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
public boolean onCommand(
|
|
||||||
CommandSender sender,
|
import java.util.Objects;
|
||||||
Command command,
|
|
||||||
String label,
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
String[] split
|
|
||||||
) {
|
import net.kyori.adventure.text.Component;
|
||||||
boolean rcon = !(sender instanceof Player);
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
Player targetPlayer = null;
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
if(split.length == 0){
|
import org.bukkit.command.CommandExecutor;
|
||||||
if(!rcon){
|
import org.bukkit.command.CommandSender;
|
||||||
targetPlayer = (Player)sender;
|
import org.bukkit.entity.Player;
|
||||||
}else{
|
|
||||||
echoUsage(sender, rcon);
|
public class ScoreGetCommand implements CommandExecutor {
|
||||||
return true; //false;
|
private final ScoreKeeperPlugin _plugin;
|
||||||
}
|
|
||||||
}else if(split.length == 1){
|
public ScoreGetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
targetPlayer = _plugin.getServer().getPlayer(split[0]);
|
_plugin = scoreKeeperPlugin;
|
||||||
}else if(split.length > 1){
|
}
|
||||||
echoUsage(sender, rcon);
|
|
||||||
return true; //false;
|
@Override
|
||||||
}
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||||
|
boolean rcon = !(sender instanceof Player);
|
||||||
if(targetPlayer == null){
|
Player targetPlayer = null;
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
|
||||||
return true;
|
if (split.length == 0) {
|
||||||
}
|
if (!rcon) {
|
||||||
|
targetPlayer = (Player) sender;
|
||||||
int score = _plugin.getPlayerScore(targetPlayer);
|
} else {
|
||||||
|
echoUsage(sender, rcon);
|
||||||
if(!rcon){
|
return true; // false;
|
||||||
if(sender == targetPlayer){
|
}
|
||||||
targetPlayer.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score);
|
} else if (split.length == 1) {
|
||||||
}else{
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score);
|
} else if (split.length > 1) {
|
||||||
}
|
echoUsage(sender, rcon);
|
||||||
|
return true; // false;
|
||||||
return true;
|
}
|
||||||
}else{
|
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score);
|
if (targetPlayer == null) {
|
||||||
return true;
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
int score = _plugin.getScore(targetPlayer);
|
||||||
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
|
|
||||||
}
|
if (!rcon) {
|
||||||
|
if (sender == targetPlayer) {
|
||||||
private void echoUsage(CommandSender sender, boolean rcon) {
|
_plugin.sendMessage(
|
||||||
if(rcon){
|
targetPlayer,
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-get " + ChatColor.GREEN + "<playername>");
|
Component.text("Your score is ")
|
||||||
}else{
|
.append(Component.text(score).color(NamedTextColor.GREEN)));
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-get " + ChatColor.YELLOW + "[playername]");
|
} else {
|
||||||
}
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
}
|
Component.text(targetPlayer.getName() + "'s score is ")
|
||||||
}
|
.append(Component.text(score).color(NamedTextColor.GREEN)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(targetPlayer.getName() + "'s score is ")
|
||||||
|
.append(Component.text(score).color(NamedTextColor.GREEN)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoError(CommandSender sender, boolean rcon, String string) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(string)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
|
if (rcon) {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": score-get ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
} else {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": /score-get ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("[playerName]").color(NamedTextColor.YELLOW));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,76 +1,88 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
import org.bukkit.command.CommandExecutor;
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.command.CommandSender;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.entity.Player;
|
(at your option) any later version.
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
public class ScoreResetCommand implements CommandExecutor {
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
private final ScoreKeeperPlugin _plugin;
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
public ScoreResetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
You should have received a copy of the GNU Affero General Public License
|
||||||
_plugin = scoreKeeperPlugin;
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
public boolean onCommand(
|
|
||||||
CommandSender sender,
|
import java.util.Objects;
|
||||||
Command command,
|
|
||||||
String label,
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
String[] split
|
|
||||||
) {
|
import net.kyori.adventure.text.Component;
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
boolean rcon = !(sender instanceof Player);
|
import org.bukkit.command.Command;
|
||||||
Player targetPlayer = null;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
if(split.length == 1){
|
import org.bukkit.entity.Player;
|
||||||
if(rcon){
|
|
||||||
echoUsage(sender, rcon);
|
public class ScoreResetCommand implements CommandExecutor {
|
||||||
return true;
|
private final ScoreKeeperPlugin _plugin;
|
||||||
}else{
|
|
||||||
targetPlayer = (Player)sender;
|
public ScoreResetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
try{
|
_plugin = scoreKeeperPlugin;
|
||||||
|
}
|
||||||
}catch(NumberFormatException ex){
|
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
@Override
|
||||||
return true;
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||||
}
|
boolean rcon = !(sender instanceof Player);
|
||||||
}
|
Player targetPlayer = null;
|
||||||
}else if(split.length == 2){
|
|
||||||
targetPlayer = _plugin.getServer().getPlayer(split[0]);
|
if (split.length == 0) {
|
||||||
if(targetPlayer == null){
|
if (rcon) {
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
echoUsage(sender, rcon);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
targetPlayer = (Player) sender;
|
||||||
try{
|
}
|
||||||
|
} else if (split.length == 1) {
|
||||||
}catch(NumberFormatException ex){
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
if (targetPlayer == null) {
|
||||||
return true;
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
}
|
return true;
|
||||||
}else{
|
}
|
||||||
echoUsage(sender, rcon);
|
} else {
|
||||||
return true;
|
echoUsage(sender, rcon);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
_plugin.resetPlayerScore(targetPlayer);
|
|
||||||
return true;
|
_plugin.resetScore(targetPlayer);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
|
||||||
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
|
private void echoError(CommandSender sender, boolean rcon, String string) {
|
||||||
}
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(string)).color(NamedTextColor.RED));
|
||||||
private void echoUsage(CommandSender sender, boolean rcon) {
|
}
|
||||||
if(rcon){
|
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-reset " + ChatColor.GREEN + "<playername>");
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
}else{
|
if (rcon) {
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-reset " + ChatColor.YELLOW + "[playername]");
|
Component message =
|
||||||
}
|
Component.text("Usage")
|
||||||
}
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
}
|
.append(Component.text(": score-reset ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
} else {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": /score-reset ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("[playerName]").color(NamedTextColor.YELLOW));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
|
|
||||||
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class ScoreRunCommand implements CommandExecutor {
|
||||||
|
private final ScoreKeeperPlugin _plugin;
|
||||||
|
|
||||||
|
public ScoreRunCommand(ScoreKeeperPlugin plugin) {
|
||||||
|
_plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!sender.hasPermission("scorekeeper.admin")) {
|
||||||
|
sendError(sender, "You do not have permission to manage high-score runs");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2 && args[0].equalsIgnoreCase("stop")) {
|
||||||
|
try {
|
||||||
|
_plugin.stopHighScoreRun(args[1]);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length < 5 || !args[0].equalsIgnoreCase("start")) {
|
||||||
|
sendUsage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String bucketId = args[1];
|
||||||
|
try {
|
||||||
|
int topN = Integer.parseInt(args[2]);
|
||||||
|
boolean resetScores = parseBoolean(args[3]);
|
||||||
|
String lifetime = args[4].toLowerCase();
|
||||||
|
if (lifetime.equals("target") && args.length == 6) {
|
||||||
|
_plugin.startTargetScoreRun(bucketId, topN, resetScores, Integer.parseInt(args[5]));
|
||||||
|
} else if (lifetime.equals("duration") && args.length == 6) {
|
||||||
|
_plugin.startTimedScoreRun(bucketId, topN, resetScores, parseDuration(args[5]));
|
||||||
|
} else if (lifetime.equals("until-disabled") && args.length == 5) {
|
||||||
|
_plugin.startUntilDisabledScoreRun(bucketId, topN, resetScores);
|
||||||
|
} else {
|
||||||
|
sendUsage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_plugin.sendMessage(sender, Component.text("Started a high-score run for " + bucketId + "."));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
sendError(sender, ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean parseBoolean(String value) {
|
||||||
|
if (value.equalsIgnoreCase("true")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (value.equalsIgnoreCase("false")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Reset scores must be true or false");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Duration parseDuration(String value) {
|
||||||
|
if (!value.matches("[0-9]+[smhdw]")) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Duration must use seconds, minutes, hours, days or weeks (e.g. 4h)");
|
||||||
|
}
|
||||||
|
long amount = Long.parseLong(value.substring(0, value.length() - 1));
|
||||||
|
try {
|
||||||
|
return switch (value.charAt(value.length() - 1)) {
|
||||||
|
case 's' -> Duration.ofSeconds(amount);
|
||||||
|
case 'm' -> Duration.ofMinutes(amount);
|
||||||
|
case 'h' -> Duration.ofHours(amount);
|
||||||
|
case 'd' -> Duration.ofDays(amount);
|
||||||
|
case 'w' -> Duration.ofDays(Math.multiplyExact(amount, 7));
|
||||||
|
default -> throw new IllegalArgumentException("Unsupported duration unit");
|
||||||
|
};
|
||||||
|
} catch (ArithmeticException ex) {
|
||||||
|
throw new IllegalArgumentException("Duration is too large", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendError(CommandSender sender, String message) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(message)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendUsage(CommandSender sender) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender,
|
||||||
|
Component.text(
|
||||||
|
"Usage: /score-run start <bucket> <topN> <reset:true|false> "
|
||||||
|
+ "<target <score>|duration <time>|until-disabled> | /score-run stop <bucket>")
|
||||||
|
.color(NamedTextColor.YELLOW));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,75 +1,103 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
/*
|
||||||
|
This file is part of Score Keeper.
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
Score Keeper is free software: you can redistribute it and/or modify
|
||||||
import org.bukkit.command.CommandExecutor;
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
import org.bukkit.command.CommandSender;
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
import org.bukkit.entity.Player;
|
(at your option) any later version.
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
Score Keeper is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
public class ScoreSubtractCommand implements CommandExecutor {
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
private final ScoreKeeperPlugin _plugin;
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
You should have received a copy of the GNU Affero General Public License
|
||||||
_plugin = scoreKeeperPlugin;
|
along with Score Keeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
||||||
public boolean onCommand(
|
|
||||||
CommandSender sender,
|
import java.util.Objects;
|
||||||
Command command,
|
|
||||||
String label,
|
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
||||||
String[] split
|
|
||||||
) {
|
import net.kyori.adventure.text.Component;
|
||||||
boolean rcon = !(sender instanceof Player);
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
int amount = 0;
|
|
||||||
Player targetPlayer = null;
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
if(split.length == 1){
|
import org.bukkit.command.CommandSender;
|
||||||
if(rcon){
|
import org.bukkit.entity.Player;
|
||||||
echoUsage(sender, rcon);
|
|
||||||
return true;
|
public class ScoreSubtractCommand implements CommandExecutor {
|
||||||
}else{
|
private final ScoreKeeperPlugin _plugin;
|
||||||
targetPlayer = (Player)sender;
|
|
||||||
try{
|
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
amount=Integer.parseInt(split[0]);
|
_plugin = scoreKeeperPlugin;
|
||||||
}catch(NumberFormatException ex){
|
}
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||||
}
|
boolean rcon = !(sender instanceof Player);
|
||||||
}else if(split.length == 2){
|
int amount = 0;
|
||||||
targetPlayer = _plugin.getServer().getPlayer(split[0]);
|
Player targetPlayer = null;
|
||||||
if(targetPlayer == null){
|
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
if (split.length == 1) {
|
||||||
return true;
|
if (rcon) {
|
||||||
}
|
echoUsage(sender, rcon);
|
||||||
|
return true;
|
||||||
try{
|
} else {
|
||||||
amount = Integer.parseInt(split[1]);
|
targetPlayer = (Player) sender;
|
||||||
}catch(NumberFormatException ex){
|
try {
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
amount = Integer.parseInt(split[0]);
|
||||||
return true;
|
} catch (NumberFormatException ex) {
|
||||||
}
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
}else{
|
return true;
|
||||||
echoUsage(sender, rcon);
|
}
|
||||||
return true;
|
}
|
||||||
}
|
} else if (split.length == 2) {
|
||||||
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
_plugin.subtractScore(targetPlayer, amount);
|
if (targetPlayer == null) {
|
||||||
return true;
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
|
||||||
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
|
try {
|
||||||
}
|
amount = Integer.parseInt(split[1]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
private void echoUsage(CommandSender sender, boolean rcon) {
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
if(rcon){
|
return true;
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-subtract " + ChatColor.GREEN + "<playername> <amount>");
|
}
|
||||||
}else{
|
} else {
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-subtract " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>");
|
echoUsage(sender, rcon);
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
_plugin.subtractScore(targetPlayer, amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoError(CommandSender sender, boolean rcon, String string) {
|
||||||
|
_plugin.sendMessage(
|
||||||
|
sender, Component.text(Objects.requireNonNull(string)).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
|
if (rcon) {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": score-subtract ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("<playerName> <amount>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
} else {
|
||||||
|
Component message =
|
||||||
|
Component.text("Usage")
|
||||||
|
.color(NamedTextColor.DARK_PURPLE)
|
||||||
|
.append(Component.text(": /score-subtract ").color(NamedTextColor.WHITE))
|
||||||
|
.append(Component.text("[playerName] ").color(NamedTextColor.YELLOW))
|
||||||
|
.append(Component.text("<amount>").color(NamedTextColor.GREEN));
|
||||||
|
_plugin.sendMessage(sender, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,21 +1,34 @@
|
|||||||
name: ScoreKeeper
|
name: ScoreKeeper
|
||||||
main: com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin
|
main: com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin
|
||||||
version: ${version}
|
version: ${version}
|
||||||
api-version: 1.21
|
api-version: '26.2'
|
||||||
commands:
|
commands:
|
||||||
score-get:
|
score-get:
|
||||||
description: Displays the player's score.
|
description: Displays the player's score.
|
||||||
usage: /score-get [playername]
|
usage: /score-get [playername]
|
||||||
score-add:
|
score-add:
|
||||||
description: Adds point to the player's score.
|
description: Adds point to the player's score.
|
||||||
usage: /score-add [playername] <amount>
|
usage: /score-add [playername] <amount>
|
||||||
score-subtract:
|
score-subtract:
|
||||||
description: Subtracts points from the player's score.
|
description: Subtracts points from the player's score.
|
||||||
usage: /score-subtract [playername] <amount>
|
usage: /score-subtract [playername] <amount>
|
||||||
score-reset:
|
score-reset:
|
||||||
description: Resets the player's score
|
description: Resets the player's score
|
||||||
usage: /score-reset [playername]
|
usage: /score-reset [playername]
|
||||||
score-archive:
|
score-archive:
|
||||||
description: Archives and resets the player's score
|
description: Archives and resets the player's score
|
||||||
usage: /score-archive [playername]
|
usage: /score-archive [playername]
|
||||||
|
score-archive-list:
|
||||||
|
description: Lists saved score archives or displays one archive.
|
||||||
|
usage: /score-archive-list [archiveId]
|
||||||
|
score-bucket:
|
||||||
|
description: Selects or manages score buckets.
|
||||||
|
usage: /score-bucket [bucketId] | create <id> <singular> <plural> <initialValue> [admin|global|player|none] | <player|all> <bucketId>
|
||||||
|
score-run:
|
||||||
|
description: Starts or stops a high-score run.
|
||||||
|
usage: /score-run start <bucket> <topN> <reset:true|false> <target <score>|duration <time>|until-disabled> | /score-run stop <bucket>
|
||||||
|
permissions:
|
||||||
|
scorekeeper.admin:
|
||||||
|
description: Allows managing score buckets.
|
||||||
|
default: op
|
||||||
|
|
||||||
103
tools/backup-server.sh
Executable file
103
tools/backup-server.sh
Executable file
@@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Backs up plugins, config, worlds, and settings from MINECRAFT_SERVER_PATH
|
||||||
|
# to MINECRAFT_BACKUP_PATH/backup-<timestamp>[-label].tar.bz2.
|
||||||
|
#
|
||||||
|
# Usage: backup-server.sh [-f|--force] [label]
|
||||||
|
# -f Back up even if the server is running (worlds may be inconsistent).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
TOOLS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$TOOLS_DIR/.." && pwd)"
|
||||||
|
if [[ ! -r "$PROJECT_ROOT/.env" ]]; then
|
||||||
|
echo "Error: $PROJECT_ROOT/.env is missing or unreadable. Copy .env.example to .env and set its values." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
load_project_env() {
|
||||||
|
local env_line env_key env_value first_char last_char
|
||||||
|
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||||
|
env_line="${env_line%$'\r'}"
|
||||||
|
[[ "$env_line" =~ ^[[:space:]]*(#|$) ]] && continue
|
||||||
|
[[ "$env_line" == *=* ]] || continue
|
||||||
|
|
||||||
|
env_key="${env_line%%=*}"
|
||||||
|
env_value="${env_line#*=}"
|
||||||
|
env_key="${env_key#"${env_key%%[![:space:]]*}"}"
|
||||||
|
env_key="${env_key%"${env_key##*[![:space:]]}"}"
|
||||||
|
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
env_value="${env_value#"${env_value%%[![:space:]]*}"}"
|
||||||
|
env_value="${env_value%"${env_value##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
if (( ${#env_value} >= 2 )); then
|
||||||
|
first_char="${env_value:0:1}"
|
||||||
|
last_char="${env_value:$((${#env_value} - 1)):1}"
|
||||||
|
if [[ "$first_char" == "$last_char" && ( "$first_char" == '"' || "$first_char" == "'" ) ]]; then
|
||||||
|
env_value="${env_value:1:$((${#env_value} - 2))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${!env_key:-}" ]]; then
|
||||||
|
export "$env_key=$env_value"
|
||||||
|
fi
|
||||||
|
done < "$PROJECT_ROOT/.env"
|
||||||
|
}
|
||||||
|
load_project_env
|
||||||
|
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH:-MCServer}"
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_SERVER_PATH" == /* ]] || MINECRAFT_SERVER_PATH="$PROJECT_ROOT/$MINECRAFT_SERVER_PATH"
|
||||||
|
MINECRAFT_BACKUP_PATH="${MINECRAFT_BACKUP_PATH:-backups}"
|
||||||
|
MINECRAFT_BACKUP_PATH="${MINECRAFT_BACKUP_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_BACKUP_PATH" == /* ]] || MINECRAFT_BACKUP_PATH="$PROJECT_ROOT/$MINECRAFT_BACKUP_PATH"
|
||||||
|
|
||||||
|
FORCE=false
|
||||||
|
LABEL=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
-f|--force) FORCE=true ;;
|
||||||
|
-h|--help) sed -n '2,7p' "$0"; exit 0 ;;
|
||||||
|
-*) echo "Unknown option: $arg" >&2; exit 1 ;;
|
||||||
|
*) LABEL="$arg" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -d "$MINECRAFT_SERVER_PATH" ]] || { echo "Error: $MINECRAFT_SERVER_PATH does not exist." >&2; exit 1; }
|
||||||
|
|
||||||
|
if pgrep -f "java.*paper-.*\.jar" >/dev/null && ! $FORCE; then
|
||||||
|
echo "Error: the server is running. Stop it first (tools/stop-server.sh) or pass --force." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$MINECRAFT_SERVER_PATH"
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
ITEMS=()
|
||||||
|
[[ -d plugins ]] && ITEMS+=(plugins)
|
||||||
|
[[ -d config ]] && ITEMS+=(config)
|
||||||
|
for dir in */; do
|
||||||
|
dir="${dir%/}"
|
||||||
|
[[ -f "$dir/level.dat" ]] && ITEMS+=("$dir")
|
||||||
|
done
|
||||||
|
for f in *.yml *.yaml *.json *.properties eula.txt; do
|
||||||
|
ITEMS+=("$f")
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( ${#ITEMS[@]} == 0 )); then
|
||||||
|
echo "Error: nothing to back up in $MINECRAFT_SERVER_PATH." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Keep labels filename-safe.
|
||||||
|
LABEL="${LABEL//[^A-Za-z0-9._-]/_}"
|
||||||
|
NAME="backup-$(date +%Y%m%d-%H%M%S)${LABEL:+-$LABEL}.tar.bz2"
|
||||||
|
mkdir -p "$MINECRAFT_BACKUP_PATH"
|
||||||
|
ARCHIVE="$MINECRAFT_BACKUP_PATH/$NAME"
|
||||||
|
|
||||||
|
echo "Backing up: ${ITEMS[*]}"
|
||||||
|
trap 'rm -f "$ARCHIVE.part"' EXIT
|
||||||
|
tar --exclude 'plugins/.paper-remapped' --exclude '*/session.lock' \
|
||||||
|
-cjf "$ARCHIVE.part" "${ITEMS[@]}"
|
||||||
|
mv "$ARCHIVE.part" "$ARCHIVE"
|
||||||
|
trap - EXIT
|
||||||
|
|
||||||
|
echo "Created $ARCHIVE ($(du -h "$ARCHIVE" | awk '{print $1}'))"
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Find project root (two directories above this script)
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
||||||
|
|
||||||
cd "$PROJECT_ROOT"
|
|
||||||
|
|
||||||
./gradlew build
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [[ -z "$MINECRAFT_SERVER_PATH" ]]; then
|
|
||||||
echo "Error: MINECRAFT_SERVER_PATH environment variable is not set."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
||||||
|
|
||||||
PLUGIN_JAR=$(ls -t "$PROJECT_ROOT"/build/libs/*.jar 2>/dev/null | head -n1)
|
|
||||||
if [[ ! -f "$PLUGIN_JAR" ]]; then
|
|
||||||
echo "Error: No plugin jar found in $PROJECT_ROOT/build/libs. Build the plugin first."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Optional: Warn if jar is older than any source file
|
|
||||||
if find "$PROJECT_ROOT/src/main/java" "$PROJECT_ROOT/src/main/resources" -type f -newer "$PLUGIN_JAR" | grep -q .; then
|
|
||||||
echo "Warning: The built plugin jar is older than some source files. Consider rebuilding."
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "$MINECRAFT_SERVER_PATH/plugins"
|
|
||||||
cp "$PLUGIN_JAR" "$MINECRAFT_SERVER_PATH/plugins/"
|
|
||||||
echo "Deployed $PLUGIN_JAR to $MINECRAFT_SERVER_PATH/plugins/"
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Check required environment variables
|
|
||||||
if [[ -z "$MINECRAFT_SERVER_PATH" || -z "$MINECRAFT_SERVER_JAR" ]]; then
|
|
||||||
echo "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$MINECRAFT_SERVER_PATH"
|
|
||||||
|
|
||||||
# Find running server process (java with the server jar)
|
|
||||||
SERVER_PID=$(pgrep -f "java.*$MINECRAFT_SERVER_JAR" || true)
|
|
||||||
|
|
||||||
if [[ -n "$SERVER_PID" ]]; then
|
|
||||||
echo "Minecraft server is running (PID: $SERVER_PID). Stopping it..."
|
|
||||||
kill "$SERVER_PID"
|
|
||||||
sleep 5
|
|
||||||
else
|
|
||||||
echo "Minecraft server is not running."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start the server (in a detached screen session)
|
|
||||||
pushd "${MINECRAFT_SERVER_PATH}"
|
|
||||||
java -jar "${MINECRAFT_SERVER_JAR}"
|
|
||||||
popd
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [[ -z "$MINECRAFT_SERVER_PATH" || -z "$MINECRAFT_SERVER_JAR" ]]; then
|
|
||||||
echo "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$MINECRAFT_SERVER_PATH"
|
|
||||||
|
|
||||||
SERVER_PID=$(pgrep -f "java.*$MINECRAFT_SERVER_JAR" || true)
|
|
||||||
|
|
||||||
if [[ -n "$SERVER_PID" ]]; then
|
|
||||||
echo "Minecraft server is running (PID: $SERVER_PID). Stopping it..."
|
|
||||||
kill "$SERVER_PID"
|
|
||||||
sleep 5
|
|
||||||
echo "Minecraft server stopped."
|
|
||||||
else
|
|
||||||
echo "Minecraft server is not running."
|
|
||||||
fi
|
|
||||||
44
tools/build-plugin.sh
Executable file
44
tools/build-plugin.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
export GRADLE_USER_HOME="${GRADLE_USER_HOME:-$PROJECT_ROOT/.gradle/user-home}"
|
||||||
|
mkdir -p "$GRADLE_USER_HOME/jdks"
|
||||||
|
|
||||||
|
ensure_java_25() {
|
||||||
|
local version="25"
|
||||||
|
local os arch archive java_bin actual_home
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin) os="mac" ;;
|
||||||
|
Linux) os="linux" ;;
|
||||||
|
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$(uname -m)" in
|
||||||
|
arm64|aarch64) arch="aarch64" ;;
|
||||||
|
x86_64|amd64) arch="x64" ;;
|
||||||
|
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
java_bin=$(find "$GRADLE_USER_HOME/jdks" -path '*/bin/java' -type f 2>/dev/null | head -n 1 || true)
|
||||||
|
if [[ -z "$java_bin" ]]; then
|
||||||
|
echo "Downloading Temurin JDK $version into $GRADLE_USER_HOME/jdks..."
|
||||||
|
archive="$GRADLE_USER_HOME/jdks/temurin-$version.tar.gz"
|
||||||
|
curl -fsSL "https://api.adoptium.net/v3/binary/latest/$version/ga/${os}/${arch}/jdk/hotspot/normal/eclipse" -o "$archive"
|
||||||
|
tar -xzf "$archive" -C "$GRADLE_USER_HOME/jdks"
|
||||||
|
rm -f "$archive"
|
||||||
|
java_bin=$(find "$GRADLE_USER_HOME/jdks" -path '*/bin/java' -type f 2>/dev/null | head -n 1 || true)
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$java_bin" ]] || { echo "Error: could not locate installed JDK 25." >&2; exit 1; }
|
||||||
|
actual_home="$(dirname "$(dirname "$java_bin")")"
|
||||||
|
export JAVA_HOME="$actual_home"
|
||||||
|
export PATH="$JAVA_HOME/bin:$PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_java_25
|
||||||
|
cd "$PROJECT_ROOT"
|
||||||
|
./gradlew build "$@"
|
||||||
63
tools/deploy-plugin.sh
Executable file
63
tools/deploy-plugin.sh
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
if [[ ! -r "$PROJECT_ROOT/.env" ]]; then
|
||||||
|
echo "Error: $PROJECT_ROOT/.env is missing or unreadable. Copy .env.example to .env and set its values." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
load_project_env() {
|
||||||
|
local env_line env_key env_value first_char last_char
|
||||||
|
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||||
|
env_line="${env_line%$'\r'}"
|
||||||
|
[[ "$env_line" =~ ^[[:space:]]*(#|$) ]] && continue
|
||||||
|
[[ "$env_line" == *=* ]] || continue
|
||||||
|
|
||||||
|
env_key="${env_line%%=*}"
|
||||||
|
env_value="${env_line#*=}"
|
||||||
|
env_key="${env_key#"${env_key%%[![:space:]]*}"}"
|
||||||
|
env_key="${env_key%"${env_key##*[![:space:]]}"}"
|
||||||
|
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
env_value="${env_value#"${env_value%%[![:space:]]*}"}"
|
||||||
|
env_value="${env_value%"${env_value##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
if (( ${#env_value} >= 2 )); then
|
||||||
|
first_char="${env_value:0:1}"
|
||||||
|
last_char="${env_value:$((${#env_value} - 1)):1}"
|
||||||
|
if [[ "$first_char" == "$last_char" && ( "$first_char" == '"' || "$first_char" == "'" ) ]]; then
|
||||||
|
env_value="${env_value:1:$((${#env_value} - 2))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${!env_key:-}" ]]; then
|
||||||
|
export "$env_key=$env_value"
|
||||||
|
fi
|
||||||
|
done < "$PROJECT_ROOT/.env"
|
||||||
|
}
|
||||||
|
load_project_env
|
||||||
|
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH:-MCServer}"
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_SERVER_PATH" == /* ]] || MINECRAFT_SERVER_PATH="$PROJECT_ROOT/$MINECRAFT_SERVER_PATH"
|
||||||
|
|
||||||
|
if [[ -z "$MINECRAFT_SERVER_PATH" ]]; then
|
||||||
|
echo "Error: MINECRAFT_SERVER_PATH environment variable is not set."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
PLUGIN_JAR=$(ls -t "$PROJECT_ROOT"/build/libs/*.jar 2>/dev/null | grep -v -- '-all\.jar$' | head -n1)
|
||||||
|
if [[ ! -f "$PLUGIN_JAR" ]]; then
|
||||||
|
echo "Error: No plugin jar found in $PROJECT_ROOT/build/libs. Build the plugin first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Optional: Warn if jar is older than any source file
|
||||||
|
if find "$PROJECT_ROOT/src/main/java" "$PROJECT_ROOT/src/main/resources" -type f -newer "$PLUGIN_JAR" | grep -q .; then
|
||||||
|
echo "Warning: The built plugin jar is older than some source files. Consider rebuilding."
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$MINECRAFT_SERVER_PATH/plugins"
|
||||||
|
cp "$PLUGIN_JAR" "$MINECRAFT_SERVER_PATH/plugins/"
|
||||||
|
echo "Deployed $PLUGIN_JAR to $MINECRAFT_SERVER_PATH/plugins/"
|
||||||
20
tools/powershell/Build-Plugin.ps1
Normal file
20
tools/powershell/Build-Plugin.ps1
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Find project root (two directories above this script)
|
||||||
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
||||||
|
|
||||||
|
# Save current location and change to project root
|
||||||
|
Push-Location $ProjectRoot
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Build the project using Gradle
|
||||||
|
& ".\gradlew.bat" build
|
||||||
|
} finally {
|
||||||
|
# Always restore the original location
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
49
tools/powershell/Deploy-Plugin.ps1
Normal file
49
tools/powershell/Deploy-Plugin.ps1
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variable
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH environment variable is not set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find project root (two directories above this script)
|
||||||
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
||||||
|
|
||||||
|
# Find the most recent plugin jar file
|
||||||
|
$LibsPath = Join-Path $ProjectRoot "build\libs"
|
||||||
|
$PluginJar = Get-ChildItem -Path "$LibsPath\*.jar" -ErrorAction SilentlyContinue |
|
||||||
|
Sort-Object LastWriteTime -Descending |
|
||||||
|
Select-Object -First 1
|
||||||
|
|
||||||
|
if (-not $PluginJar) {
|
||||||
|
Write-Error "Error: No plugin jar found in $LibsPath. Build the plugin first."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optional: Warn if jar is older than any source file
|
||||||
|
$SourcePaths = @(
|
||||||
|
(Join-Path $ProjectRoot "src\main\java"),
|
||||||
|
(Join-Path $ProjectRoot "src\main\resources")
|
||||||
|
)
|
||||||
|
|
||||||
|
$NewerSourceFiles = Get-ChildItem -Path $SourcePaths -Recurse -File -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.LastWriteTime -gt $PluginJar.LastWriteTime }
|
||||||
|
|
||||||
|
if ($NewerSourceFiles) {
|
||||||
|
Write-Host "Warning: The built plugin jar is older than some source files. Consider rebuilding." -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create plugins directory if it doesn't exist
|
||||||
|
$PluginsPath = Join-Path $env:MINECRAFT_SERVER_PATH "plugins"
|
||||||
|
if (-not (Test-Path $PluginsPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $PluginsPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy the plugin jar to the plugins directory
|
||||||
|
Copy-Item -Path $PluginJar.FullName -Destination $PluginsPath -Force
|
||||||
|
Write-Host "Deployed $($PluginJar.Name) to $PluginsPath\"
|
||||||
34
tools/powershell/Start-Server.ps1
Normal file
34
tools/powershell/Start-Server.ps1
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH -or -not $env:MINECRAFT_SERVER_JAR) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Push-Location $env:MINECRAFT_SERVER_PATH
|
||||||
|
|
||||||
|
# Find running server process (java with the server jar)
|
||||||
|
$ServerProcess = Get-Process -Name "java" -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.CommandLine -like "*$($env:MINECRAFT_SERVER_JAR)*"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ServerProcess) {
|
||||||
|
Write-Host "Minecraft server is running (PID: $($ServerProcess.Id)). Stopping it..."
|
||||||
|
Stop-Process -Id $ServerProcess.Id -Force
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
} else {
|
||||||
|
Write-Host "Minecraft server is not running."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start the server in a new window
|
||||||
|
try {
|
||||||
|
$ServerJob = Start-Process -FilePath "java" -ArgumentList "-jar", $env:MINECRAFT_SERVER_JAR -PassThru
|
||||||
|
Write-Host "Minecraft server started in new window with PID: $($ServerJob.Id)"
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
25
tools/powershell/Stop-Server.ps1
Normal file
25
tools/powershell/Stop-Server.ps1
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH -or -not $env:MINECRAFT_SERVER_JAR) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find running server process (java with the server jar)
|
||||||
|
$ServerProcess = Get-Process -Name "java" -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.CommandLine -like "*$($env:MINECRAFT_SERVER_JAR)*"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ServerProcess) {
|
||||||
|
Write-Host "Minecraft server is running (PID: $($ServerProcess.Id)). Stopping it..."
|
||||||
|
Stop-Process -Id $ServerProcess.Id -Force
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
Write-Host "Minecraft server stopped."
|
||||||
|
} else {
|
||||||
|
Write-Host "Minecraft server is not running."
|
||||||
|
}
|
||||||
44
tools/publish-local.sh
Executable file
44
tools/publish-local.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
export GRADLE_USER_HOME="${GRADLE_USER_HOME:-$PROJECT_ROOT/.gradle/user-home}"
|
||||||
|
mkdir -p "$GRADLE_USER_HOME/jdks"
|
||||||
|
|
||||||
|
ensure_java_25() {
|
||||||
|
local version="25"
|
||||||
|
local os arch archive java_bin actual_home
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin) os="mac" ;;
|
||||||
|
Linux) os="linux" ;;
|
||||||
|
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$(uname -m)" in
|
||||||
|
arm64|aarch64) arch="aarch64" ;;
|
||||||
|
x86_64|amd64) arch="x64" ;;
|
||||||
|
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
java_bin=$(find "$GRADLE_USER_HOME/jdks" -path '*/bin/java' -type f 2>/dev/null | head -n 1 || true)
|
||||||
|
if [[ -z "$java_bin" ]]; then
|
||||||
|
echo "Downloading Temurin JDK $version into $GRADLE_USER_HOME/jdks..."
|
||||||
|
archive="$GRADLE_USER_HOME/jdks/temurin-$version.tar.gz"
|
||||||
|
curl -fsSL "https://api.adoptium.net/v3/binary/latest/$version/ga/${os}/${arch}/jdk/hotspot/normal/eclipse" -o "$archive"
|
||||||
|
tar -xzf "$archive" -C "$GRADLE_USER_HOME/jdks"
|
||||||
|
rm -f "$archive"
|
||||||
|
java_bin=$(find "$GRADLE_USER_HOME/jdks" -path '*/bin/java' -type f 2>/dev/null | head -n 1 || true)
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$java_bin" ]] || { echo "Error: could not locate installed JDK 25." >&2; exit 1; }
|
||||||
|
actual_home="$(dirname "$(dirname "$java_bin")")"
|
||||||
|
export JAVA_HOME="$actual_home"
|
||||||
|
export PATH="$JAVA_HOME/bin:$PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_java_25
|
||||||
|
cd "$PROJECT_ROOT"
|
||||||
|
./gradlew publishToMavenLocal "$@"
|
||||||
195
tools/publish-modrinth.sh
Executable file
195
tools/publish-modrinth.sh
Executable file
@@ -0,0 +1,195 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
|
load_project_env() {
|
||||||
|
local env_line env_key env_value first_char last_char
|
||||||
|
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||||
|
env_line="${env_line%$'\r'}"
|
||||||
|
[[ "$env_line" =~ ^[[:space:]]*(#|$) ]] && continue
|
||||||
|
[[ "$env_line" == *=* ]] || continue
|
||||||
|
|
||||||
|
env_key="${env_line%%=*}"
|
||||||
|
env_value="${env_line#*=}"
|
||||||
|
env_key="${env_key#"${env_key%%[![:space:]]*}"}"
|
||||||
|
env_key="${env_key%"${env_key##*[![:space:]]}"}"
|
||||||
|
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
env_value="${env_value#"${env_value%%[![:space:]]*}"}"
|
||||||
|
env_value="${env_value%"${env_value##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
if (( ${#env_value} >= 2 )); then
|
||||||
|
first_char="${env_value:0:1}"
|
||||||
|
last_char="${env_value:$((${#env_value} - 1)):1}"
|
||||||
|
if [[ "$first_char" == "$last_char" && ( "$first_char" == '"' || "$first_char" == "'" ) ]]; then
|
||||||
|
env_value="${env_value:1:$((${#env_value} - 2))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${!env_key:-}" ]]; then
|
||||||
|
export "$env_key=$env_value"
|
||||||
|
fi
|
||||||
|
done < "$PROJECT_ROOT/.env"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -r "$PROJECT_ROOT/.env" ]]; then
|
||||||
|
load_project_env
|
||||||
|
elif [[ -z "${MODRINTH_TOKEN:-}" ]]; then
|
||||||
|
echo "Error: $PROJECT_ROOT/.env is missing or unreadable and MODRINTH_TOKEN is not set. Copy .env.example to .env and set its values." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
MODRINTH_TOKEN="${MODRINTH_TOKEN:-}"
|
||||||
|
MODRINTH_PROJECT_ID="${MODRINTH_PROJECT_ID:-5NYwxysp}"
|
||||||
|
MODRINTH_VERSION="${MODRINTH_VERSION:-${VERSION:-}}"
|
||||||
|
if [[ -z "$MODRINTH_VERSION" ]]; then
|
||||||
|
MODRINTH_VERSION=$(
|
||||||
|
"$PROJECT_ROOT/gradlew" -q -p "$PROJECT_ROOT" properties --property version \
|
||||||
|
| sed -n 's/^version: //p'
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
generate_changelog() {
|
||||||
|
local current_tag previous_tag range commits
|
||||||
|
current_tag="${TAG:-$(git -C "$PROJECT_ROOT" describe --tags --exact-match HEAD 2>/dev/null || true)}"
|
||||||
|
if [[ -n "$current_tag" ]]; then
|
||||||
|
previous_tag=$(git -C "$PROJECT_ROOT" describe --tags --abbrev=0 "${current_tag}^" 2>/dev/null || true)
|
||||||
|
range="${previous_tag:+$previous_tag..}$current_tag"
|
||||||
|
else
|
||||||
|
previous_tag=$(git -C "$PROJECT_ROOT" describe --tags --abbrev=0 2>/dev/null || true)
|
||||||
|
range="${previous_tag:+$previous_tag..}HEAD"
|
||||||
|
fi
|
||||||
|
commits=$(git -C "$PROJECT_ROOT" log --no-merges --format='- %s (%h)' "$range" 2>/dev/null || true)
|
||||||
|
if [[ -z "$commits" ]]; then
|
||||||
|
commits='- No commit messages found for this release.'
|
||||||
|
fi
|
||||||
|
printf '%s\n\n%s\n' "## What's Changed" "$commits"
|
||||||
|
}
|
||||||
|
|
||||||
|
MODRINTH_CHANGELOG="${MODRINTH_CHANGELOG:-$(generate_changelog)}"
|
||||||
|
MODRINTH_GAME_VERSIONS="${MODRINTH_GAME_VERSIONS:-26.2,26.3}"
|
||||||
|
MODRINTH_LOADERS="${MODRINTH_LOADERS:-paper}"
|
||||||
|
MODRINTH_VERSION_TYPE="${MODRINTH_VERSION_TYPE:-}"
|
||||||
|
MODRINTH_FILE="${MODRINTH_FILE:-}"
|
||||||
|
MODRINTH_DEPENDENCIES="${MODRINTH_DEPENDENCIES:-}"
|
||||||
|
MODRINTH_SYNC_BODY="${MODRINTH_SYNC_BODY:-true}"
|
||||||
|
MODRINTH_DESCRIPTION_FILE="${MODRINTH_DESCRIPTION_FILE:-$PROJECT_ROOT/docs/modrinth-description.md}"
|
||||||
|
if [[ ! -f "$MODRINTH_DESCRIPTION_FILE" ]]; then
|
||||||
|
MODRINTH_DESCRIPTION_FILE="$PROJECT_ROOT/README.md"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$MODRINTH_VERSION" ]]; then
|
||||||
|
echo "Error: could not determine the project version from Gradle." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ -z "$MODRINTH_VERSION_TYPE" ]]; then
|
||||||
|
if [[ "$MODRINTH_VERSION" == *-* ]]; then
|
||||||
|
MODRINTH_VERSION_TYPE="beta"
|
||||||
|
else
|
||||||
|
MODRINTH_VERSION_TYPE="release"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
case "$MODRINTH_VERSION_TYPE" in
|
||||||
|
release|beta|alpha) ;;
|
||||||
|
*) echo "Error: MODRINTH_VERSION_TYPE must be release, beta, or alpha." >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
MODRINTH_VERSION_NAME="Score Keeper $MODRINTH_VERSION"
|
||||||
|
|
||||||
|
if [[ -n "$MODRINTH_FILE" && "$MODRINTH_FILE" != /* ]]; then
|
||||||
|
MODRINTH_FILE="$PROJECT_ROOT/$MODRINTH_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$MODRINTH_TOKEN" ]]; then
|
||||||
|
echo "Error: MODRINTH_TOKEN is not set (check $PROJECT_ROOT/.env or environment variable)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$MODRINTH_FILE" ]]; then
|
||||||
|
MODRINTH_FILE=$(ls -t "$PROJECT_ROOT"/build/libs/*.jar 2>/dev/null | grep -v -- '-all\.jar$' | head -n1 || true)
|
||||||
|
fi
|
||||||
|
if [[ -z "$MODRINTH_FILE" || ! -f "$MODRINTH_FILE" ]]; then
|
||||||
|
echo "Error: no jar found for Modrinth upload. Build the project first or set MODRINTH_FILE." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v unzip >/dev/null; then
|
||||||
|
echo "Error: 'unzip' is required to verify the plugin version in the jar." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
JAR_VERSION=$(unzip -p "$MODRINTH_FILE" plugin.yml 2>/dev/null | sed -n 's/^version: //p' | head -n1 || true)
|
||||||
|
if [[ -z "$JAR_VERSION" ]]; then
|
||||||
|
echo "Error: could not read the plugin version from $MODRINTH_FILE." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "$JAR_VERSION" != "$MODRINTH_VERSION" ]]; then
|
||||||
|
echo "Error: jar version $JAR_VERSION does not match Gradle version $MODRINTH_VERSION. Rebuild the plugin and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
csv_to_json_array() {
|
||||||
|
jq -cn --arg csv "$1" '$csv | split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0))'
|
||||||
|
}
|
||||||
|
MODRINTH_GAME_VERSIONS_JSON=$(csv_to_json_array "$MODRINTH_GAME_VERSIONS")
|
||||||
|
MODRINTH_LOADERS_JSON=$(csv_to_json_array "$MODRINTH_LOADERS")
|
||||||
|
if [[ -n "$MODRINTH_DEPENDENCIES" ]]; then
|
||||||
|
if ! MODRINTH_DEPENDENCIES_JSON=$(jq -ce 'if type == "array" then . else error("dependencies must be a JSON array") end' <<<"$MODRINTH_DEPENDENCIES"); then
|
||||||
|
echo "Error: MODRINTH_DEPENDENCIES must be a JSON array." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
MODRINTH_DEPENDENCIES_JSON='[]'
|
||||||
|
fi
|
||||||
|
|
||||||
|
MODRINTH_DATA=$(jq -cn \
|
||||||
|
--arg project_id "$MODRINTH_PROJECT_ID" \
|
||||||
|
--arg name "$MODRINTH_VERSION_NAME" \
|
||||||
|
--arg version_number "$MODRINTH_VERSION" \
|
||||||
|
--arg version_type "$MODRINTH_VERSION_TYPE" \
|
||||||
|
--arg changelog "$MODRINTH_CHANGELOG" \
|
||||||
|
--argjson featured false \
|
||||||
|
--argjson dependencies "$MODRINTH_DEPENDENCIES_JSON" \
|
||||||
|
--argjson game_versions "$MODRINTH_GAME_VERSIONS_JSON" \
|
||||||
|
--argjson loaders "$MODRINTH_LOADERS_JSON" \
|
||||||
|
'{project_id: $project_id, name: $name, version_number: $version_number, version_type: $version_type, featured: $featured, changelog: $changelog, dependencies: $dependencies, game_versions: $game_versions, loaders: $loaders, file_parts: ["file"], primary_file: "file"}')
|
||||||
|
|
||||||
|
CURL_ARGS=(
|
||||||
|
-X POST "https://api.modrinth.com/v2/version"
|
||||||
|
-H "Authorization: $MODRINTH_TOKEN"
|
||||||
|
-F "data=$MODRINTH_DATA;type=application/json"
|
||||||
|
-F "file=@$MODRINTH_FILE"
|
||||||
|
)
|
||||||
|
|
||||||
|
HTTP_RESPONSE=$(curl -sS -w $'\n%{http_code}' "${CURL_ARGS[@]}")
|
||||||
|
HTTP_STATUS="${HTTP_RESPONSE##*$'\n'}"
|
||||||
|
HTTP_BODY="${HTTP_RESPONSE%$'\n'*}"
|
||||||
|
if [[ "$HTTP_STATUS" != 2?? ]]; then
|
||||||
|
echo "Error: Modrinth API returned HTTP $HTTP_STATUS:" >&2
|
||||||
|
if ! printf '%s\n' "$HTTP_BODY" | jq -r '.description // .error // .' >&2; then
|
||||||
|
printf '%s\n' "$HTTP_BODY" >&2
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
printf '%s\n' "$HTTP_BODY" | jq .
|
||||||
|
|
||||||
|
if [[ "$MODRINTH_SYNC_BODY" == "true" && -f "$MODRINTH_DESCRIPTION_FILE" ]]; then
|
||||||
|
echo "Syncing project description to Modrinth from $MODRINTH_DESCRIPTION_FILE..."
|
||||||
|
BODY_CONTENT=$(cat "$MODRINTH_DESCRIPTION_FILE")
|
||||||
|
PATCH_DATA=$(jq -cn --arg body "$BODY_CONTENT" '{body: $body}')
|
||||||
|
|
||||||
|
PATCH_RESPONSE=$(curl -sS -w $'\n%{http_code}' \
|
||||||
|
-X PATCH "https://api.modrinth.com/v2/project/$MODRINTH_PROJECT_ID" \
|
||||||
|
-H "Authorization: $MODRINTH_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$PATCH_DATA")
|
||||||
|
|
||||||
|
PATCH_STATUS="${PATCH_RESPONSE##*$'\n'}"
|
||||||
|
PATCH_BODY="${PATCH_RESPONSE%$'\n'*}"
|
||||||
|
if [[ "$PATCH_STATUS" != 2?? ]]; then
|
||||||
|
echo "Warning: Modrinth project description update returned HTTP $PATCH_STATUS:" >&2
|
||||||
|
if ! printf '%s\n' "$PATCH_BODY" | jq -r '.description // .error // .' >&2; then
|
||||||
|
printf '%s\n' "$PATCH_BODY" >&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Successfully updated Modrinth project description."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
107
tools/restore-server.sh
Executable file
107
tools/restore-server.sh
Executable file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Restores a backup made by backup-server.sh into MINECRAFT_SERVER_PATH.
|
||||||
|
# Each top-level item in the archive (plugins, config, worlds, settings) is
|
||||||
|
# replaced; a "pre-restore" backup of the current state is taken first.
|
||||||
|
#
|
||||||
|
# Usage: restore-server.sh [-y|--yes] [--no-backup] [backup-file|name]
|
||||||
|
# Defaults to the newest backup in MINECRAFT_BACKUP_PATH.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
TOOLS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$TOOLS_DIR/.." && pwd)"
|
||||||
|
if [[ ! -r "$PROJECT_ROOT/.env" ]]; then
|
||||||
|
echo "Error: $PROJECT_ROOT/.env is missing or unreadable. Copy .env.example to .env and set its values." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
load_project_env() {
|
||||||
|
local env_line env_key env_value first_char last_char
|
||||||
|
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||||
|
env_line="${env_line%$'\r'}"
|
||||||
|
[[ "$env_line" =~ ^[[:space:]]*(#|$) ]] && continue
|
||||||
|
[[ "$env_line" == *=* ]] || continue
|
||||||
|
|
||||||
|
env_key="${env_line%%=*}"
|
||||||
|
env_value="${env_line#*=}"
|
||||||
|
env_key="${env_key#"${env_key%%[![:space:]]*}"}"
|
||||||
|
env_key="${env_key%"${env_key##*[![:space:]]}"}"
|
||||||
|
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
env_value="${env_value#"${env_value%%[![:space:]]*}"}"
|
||||||
|
env_value="${env_value%"${env_value##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
if (( ${#env_value} >= 2 )); then
|
||||||
|
first_char="${env_value:0:1}"
|
||||||
|
last_char="${env_value:$((${#env_value} - 1)):1}"
|
||||||
|
if [[ "$first_char" == "$last_char" && ( "$first_char" == '"' || "$first_char" == "'" ) ]]; then
|
||||||
|
env_value="${env_value:1:$((${#env_value} - 2))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${!env_key:-}" ]]; then
|
||||||
|
export "$env_key=$env_value"
|
||||||
|
fi
|
||||||
|
done < "$PROJECT_ROOT/.env"
|
||||||
|
}
|
||||||
|
load_project_env
|
||||||
|
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH:-MCServer}"
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_SERVER_PATH" == /* ]] || MINECRAFT_SERVER_PATH="$PROJECT_ROOT/$MINECRAFT_SERVER_PATH"
|
||||||
|
MINECRAFT_BACKUP_PATH="${MINECRAFT_BACKUP_PATH:-backups}"
|
||||||
|
MINECRAFT_BACKUP_PATH="${MINECRAFT_BACKUP_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_BACKUP_PATH" == /* ]] || MINECRAFT_BACKUP_PATH="$PROJECT_ROOT/$MINECRAFT_BACKUP_PATH"
|
||||||
|
|
||||||
|
ASSUME_YES=false
|
||||||
|
SAFETY_BACKUP=true
|
||||||
|
ARCHIVE=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
-y|--yes) ASSUME_YES=true ;;
|
||||||
|
--no-backup) SAFETY_BACKUP=false ;;
|
||||||
|
-h|--help) sed -n '2,8p' "$0"; exit 0 ;;
|
||||||
|
-*) echo "Unknown option: $arg" >&2; exit 1 ;;
|
||||||
|
*) ARCHIVE="$arg" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$ARCHIVE" ]]; then
|
||||||
|
ARCHIVE=$(ls -t "$MINECRAFT_BACKUP_PATH"/backup-*.tar.bz2 2>/dev/null | head -n1 || true)
|
||||||
|
[[ -n "$ARCHIVE" ]] || { echo "Error: no backups found in $MINECRAFT_BACKUP_PATH." >&2; exit 1; }
|
||||||
|
elif [[ ! -f "$ARCHIVE" && -f "$MINECRAFT_BACKUP_PATH/$ARCHIVE" ]]; then
|
||||||
|
ARCHIVE="$MINECRAFT_BACKUP_PATH/$ARCHIVE"
|
||||||
|
fi
|
||||||
|
[[ -f "$ARCHIVE" ]] || { echo "Error: backup not found: $ARCHIVE" >&2; exit 1; }
|
||||||
|
ARCHIVE="$(cd "$(dirname "$ARCHIVE")" && pwd)/$(basename "$ARCHIVE")"
|
||||||
|
|
||||||
|
if pgrep -f "java.*paper-.*\.jar" >/dev/null; then
|
||||||
|
echo "Error: the server is running. Stop it first (tools/stop-server.sh)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ENTRIES=$(tar -tjf "$ARCHIVE")
|
||||||
|
if grep -qE '^/|(^|/)\.\.(/|$)' <<<"$ENTRIES"; then
|
||||||
|
echo "Error: archive contains absolute or '..' paths; refusing to restore." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
TOP_LEVEL=$(sed -E 's#^\./##; s#/.*##' <<<"$ENTRIES" | { grep -vE '^\.?$' || true; } | sort -u)
|
||||||
|
[[ -n "$TOP_LEVEL" ]] || { echo "Error: backup is empty." >&2; exit 1; }
|
||||||
|
|
||||||
|
echo "Restore $(basename "$ARCHIVE") into $MINECRAFT_SERVER_PATH"
|
||||||
|
echo "These items will be replaced:"
|
||||||
|
sed 's/^/ /' <<<"$TOP_LEVEL"
|
||||||
|
if ! $ASSUME_YES; then
|
||||||
|
read -r -p "Continue? [y/N] " reply
|
||||||
|
[[ "$reply" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 1; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$MINECRAFT_SERVER_PATH"
|
||||||
|
if $SAFETY_BACKUP && [[ -n "$(ls -A "$MINECRAFT_SERVER_PATH")" ]]; then
|
||||||
|
"$TOOLS_DIR/backup-server.sh" pre-restore
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r item; do
|
||||||
|
rm -rf "${MINECRAFT_SERVER_PATH:?}/$item"
|
||||||
|
done <<<"$TOP_LEVEL"
|
||||||
|
|
||||||
|
tar -xjf "$ARCHIVE" -C "$MINECRAFT_SERVER_PATH"
|
||||||
|
echo "Restored $(basename "$ARCHIVE")."
|
||||||
131
tools/start-server.sh
Executable file
131
tools/start-server.sh
Executable file
@@ -0,0 +1,131 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Downloads (if missing) and runs a Paper server via the Fill v3 API.
|
||||||
|
# Server settings come from the project .env file.
|
||||||
|
#
|
||||||
|
# Env vars:
|
||||||
|
# JAVA_OPTS Extra JVM args (default: -Xms2G -Xmx2G)
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
TOOLS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_ROOT="$(cd "$TOOLS_DIR/.." && pwd)"
|
||||||
|
if [[ ! -r "$PROJECT_ROOT/.env" ]]; then
|
||||||
|
echo "Error: $PROJECT_ROOT/.env is missing or unreadable. Copy .env.example to .env and set its values." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
load_project_env() {
|
||||||
|
local env_line env_key env_value first_char last_char
|
||||||
|
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||||
|
env_line="${env_line%$'\r'}"
|
||||||
|
[[ "$env_line" =~ ^[[:space:]]*(#|$) ]] && continue
|
||||||
|
[[ "$env_line" == *=* ]] || continue
|
||||||
|
|
||||||
|
env_key="${env_line%%=*}"
|
||||||
|
env_value="${env_line#*=}"
|
||||||
|
env_key="${env_key#"${env_key%%[![:space:]]*}"}"
|
||||||
|
env_key="${env_key%"${env_key##*[![:space:]]}"}"
|
||||||
|
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||||
|
env_value="${env_value#"${env_value%%[![:space:]]*}"}"
|
||||||
|
env_value="${env_value%"${env_value##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
if (( ${#env_value} >= 2 )); then
|
||||||
|
first_char="${env_value:0:1}"
|
||||||
|
last_char="${env_value:$((${#env_value} - 1)):1}"
|
||||||
|
if [[ "$first_char" == "$last_char" && ( "$first_char" == '"' || "$first_char" == "'" ) ]]; then
|
||||||
|
env_value="${env_value:1:$((${#env_value} - 2))}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${!env_key:-}" ]]; then
|
||||||
|
export "$env_key=$env_value"
|
||||||
|
fi
|
||||||
|
done < "$PROJECT_ROOT/.env"
|
||||||
|
}
|
||||||
|
load_project_env
|
||||||
|
|
||||||
|
PAPER_VERSION="${PAPER_VERSION:-}"
|
||||||
|
PAPER_BUILD="${PAPER_BUILD:-}"
|
||||||
|
MINECRAFT_SERVER_JAR="${MINECRAFT_SERVER_JAR:-}"
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH:-MCServer}"
|
||||||
|
MINECRAFT_SERVER_PATH="${MINECRAFT_SERVER_PATH/#\~/$HOME}"
|
||||||
|
[[ "$MINECRAFT_SERVER_PATH" == /* ]] || MINECRAFT_SERVER_PATH="$PROJECT_ROOT/$MINECRAFT_SERVER_PATH"
|
||||||
|
|
||||||
|
[[ -n "$PAPER_VERSION" ]] || { echo "Error: PAPER_VERSION is not set (see .env)." >&2; exit 1; }
|
||||||
|
|
||||||
|
PAPER_PROJECT="paper"
|
||||||
|
JAVA_OPTS="${JAVA_OPTS:--Xms2G -Xmx2G}"
|
||||||
|
FILL_API="https://fill.papermc.io/v3/projects/${PAPER_PROJECT}/versions/${PAPER_VERSION}"
|
||||||
|
# Fill requires a non-generic User-Agent with contact info.
|
||||||
|
USER_AGENT="${PAPER_USER_AGENT:-majinnaibu-plugin-dev/1.0 (https://github.com/majinnaibu)}"
|
||||||
|
|
||||||
|
for cmd in curl jq java shasum; do
|
||||||
|
command -v "$cmd" >/dev/null || { echo "Error: '$cmd' is required." >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
api_get() {
|
||||||
|
curl -fsSL -H "User-Agent: $USER_AGENT" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir -p "$MINECRAFT_SERVER_PATH"
|
||||||
|
cd "$MINECRAFT_SERVER_PATH"
|
||||||
|
|
||||||
|
JAR_BUILD="${MINECRAFT_SERVER_JAR:-}"
|
||||||
|
JAR_BUILD="${JAR_BUILD#paper-"$PAPER_VERSION"-}"; JAR_BUILD="${JAR_BUILD%.jar}"
|
||||||
|
if [[ -z "$PAPER_BUILD" && "$JAR_BUILD" =~ ^[0-9]+$ ]]; then
|
||||||
|
PAPER_BUILD="$JAR_BUILD"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$PAPER_BUILD" ]]; then
|
||||||
|
echo "Resolving latest stable build for Paper $PAPER_VERSION..."
|
||||||
|
PAPER_BUILD=$(api_get "$FILL_API/builds" \
|
||||||
|
| jq -r 'map(select(.channel == "STABLE")) | max_by(.id) | .id // empty') || true
|
||||||
|
if [[ -z "$PAPER_BUILD" ]]; then
|
||||||
|
# Offline or no stable build: fall back to the newest local jar for this version.
|
||||||
|
for f in paper-"$PAPER_VERSION"-*.jar; do
|
||||||
|
b="${f#paper-"$PAPER_VERSION"-}"; b="${b%.jar}"
|
||||||
|
[[ "$b" =~ ^[0-9]+$ ]] && (( b > ${PAPER_BUILD:-0} )) && PAPER_BUILD="$b"
|
||||||
|
done
|
||||||
|
[[ -n "$PAPER_BUILD" ]] || { echo "Error: no stable build found for $PAPER_VERSION." >&2; exit 1; }
|
||||||
|
echo "Could not resolve from API; using local build $PAPER_BUILD."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
EXPECTED_JAR="paper-${PAPER_VERSION}-${PAPER_BUILD}.jar"
|
||||||
|
if [[ -n "${MINECRAFT_SERVER_JAR:-}" && "$MINECRAFT_SERVER_JAR" != "$EXPECTED_JAR" ]]; then
|
||||||
|
echo "Error: MINECRAFT_SERVER_JAR=$MINECRAFT_SERVER_JAR does not match PAPER_VERSION/PAPER_BUILD ($EXPECTED_JAR)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
MINECRAFT_SERVER_JAR="$EXPECTED_JAR"
|
||||||
|
|
||||||
|
if [[ ! -f "$MINECRAFT_SERVER_JAR" ]]; then
|
||||||
|
echo "Downloading $MINECRAFT_SERVER_JAR..."
|
||||||
|
BUILD_JSON=$(api_get "$FILL_API/builds/$PAPER_BUILD")
|
||||||
|
DOWNLOAD_URL=$(jq -r '.downloads."server:default".url // empty' <<<"$BUILD_JSON")
|
||||||
|
EXPECTED_SHA=$(jq -r '.downloads."server:default".checksums.sha256 // empty' <<<"$BUILD_JSON")
|
||||||
|
[[ -n "$DOWNLOAD_URL" ]] || { echo "Error: no download for $PAPER_VERSION build $PAPER_BUILD." >&2; exit 1; }
|
||||||
|
|
||||||
|
TMP_JAR="$MINECRAFT_SERVER_JAR.part"
|
||||||
|
trap 'rm -f "$TMP_JAR"' EXIT
|
||||||
|
curl -fL --progress-bar -H "User-Agent: $USER_AGENT" -o "$TMP_JAR" "$DOWNLOAD_URL"
|
||||||
|
|
||||||
|
ACTUAL_SHA=$(shasum -a 256 "$TMP_JAR" | awk '{print $1}')
|
||||||
|
if [[ -n "$EXPECTED_SHA" && "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then
|
||||||
|
echo "Error: checksum mismatch (expected $EXPECTED_SHA, got $ACTUAL_SHA)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mv "$TMP_JAR" "$MINECRAFT_SERVER_JAR"
|
||||||
|
trap - EXIT
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MINECRAFT_SERVER_PATH MINECRAFT_SERVER_JAR
|
||||||
|
|
||||||
|
"$TOOLS_DIR/stop-server.sh"
|
||||||
|
|
||||||
|
if ! grep -qs '^eula=true' eula.txt; then
|
||||||
|
echo "Note: accept the EULA by setting eula=true in $MINECRAFT_SERVER_PATH/eula.txt (server will exit until then)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting $MINECRAFT_SERVER_JAR in $MINECRAFT_SERVER_PATH..."
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
exec java $JAVA_OPTS -jar "$MINECRAFT_SERVER_JAR" --nogui
|
||||||
|
|
||||||
34
tools/stop-server.sh
Executable file
34
tools/stop-server.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Stops any running Paper server (java process running a paper-*.jar).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
STOP_TIMEOUT="${STOP_TIMEOUT:-60}"
|
||||||
|
|
||||||
|
SERVER_PIDS=$(pgrep -f "java.*paper-.*\.jar" || true)
|
||||||
|
|
||||||
|
if [[ -z "$SERVER_PIDS" ]]; then
|
||||||
|
echo "Minecraft server is not running."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for pid in $SERVER_PIDS; do
|
||||||
|
echo "Stopping Minecraft server (PID: $pid)..."
|
||||||
|
# SIGTERM lets Paper run its shutdown hook and save worlds.
|
||||||
|
kill "$pid"
|
||||||
|
done
|
||||||
|
|
||||||
|
for ((i = 0; i < STOP_TIMEOUT; i++)); do
|
||||||
|
remaining=""
|
||||||
|
for pid in $SERVER_PIDS; do
|
||||||
|
kill -0 "$pid" 2>/dev/null && remaining="$remaining $pid"
|
||||||
|
done
|
||||||
|
if [[ -z "$remaining" ]]; then
|
||||||
|
echo "Minecraft server stopped."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Server did not stop within ${STOP_TIMEOUT}s; forcing:$remaining"
|
||||||
|
kill -9 $remaining
|
||||||
Reference in New Issue
Block a user