Skip to content

Commit 80a8fd6

Browse files
committed
Add javadoc and sources
1 parent a2824a3 commit 80a8fd6

File tree

4 files changed

+180
-142
lines changed

4 files changed

+180
-142
lines changed

.github/workflows/publish.yml

Lines changed: 106 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -6,126 +6,128 @@ on:
66
pull_request:
77
branches: [ "main" ]
88
release:
9-
types: [created]
9+
types: [ created ]
1010

1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v4
18-
19-
- name: Set up JDK 8
20-
uses: actions/setup-java@v3
21-
with:
22-
distribution: 'temurin'
23-
java-version: '8'
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
2418

25-
- name: Build with Maven
26-
run: mvn clean package
19+
- name: Set up JDK 8
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: '8'
2724

28-
- name: Upload plugin artifact
29-
uses: actions/upload-artifact@v4
30-
with:
31-
name: Plugin
32-
path: target/${{ github.event.repository.name }}-*.jar
25+
- name: Build with Maven
26+
run: mvn clean package javadoc:jar source:jar
3327

34-
- name: Get Plugin Version
35-
id: version
36-
run: echo "VERSION=$(basename $(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/${{ github.event.repository.name }}-//')" >> $GITHUB_ENV
28+
- name: Upload plugin artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: Plugin
32+
path: target/${{ github.event.repository.name }}-*.jar
3733

38-
- name: Delete existing GitHub release (if exists)
39-
run: |
40-
RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "")
41-
if [ -n "$RELEASE_ID" ]; then
42-
echo "Deleting existing release..."
43-
gh release delete ${{ env.VERSION }} --yes
44-
fi
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Get Plugin Version
35+
id: version
36+
run: echo "VERSION=$(basename $(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/${{ github.event.repository.name }}-//')" >> $GITHUB_ENV
4737

48-
- name: Delete existing tag (if exists)
49-
run: |
50-
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
51-
echo "Deleting existing tag..."
52-
git tag -d ${{ env.VERSION }}
53-
git push origin :refs/tags/${{ env.VERSION }}
54-
fi
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
- name: Delete existing GitHub release (if exists)
39+
run: |
40+
RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "")
41+
if [ -n "$RELEASE_ID" ]; then
42+
echo "Deleting existing release..."
43+
gh release delete ${{ env.VERSION }} --yes
44+
fi
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5747

58-
- name: Rename & Upload Latest Release
59-
run: |
60-
JAR_FILE=$(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1)
61-
cp "$JAR_FILE" target/${{ github.event.repository.name }}-latest.jar
48+
- name: Delete existing tag (if exists)
49+
run: |
50+
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
51+
echo "Deleting existing tag..."
52+
git tag -d ${{ env.VERSION }}
53+
git push origin :refs/tags/${{ env.VERSION }}
54+
fi
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6257

63-
- name: Create GitHub Release
64-
uses: softprops/action-gh-release@v1
65-
with:
66-
tag_name: ${{ env.VERSION }}
67-
name: Release ${{ env.VERSION }}
68-
draft: false
69-
prerelease: false
70-
files: |
71-
target/${{ github.event.repository.name }}-latest.jar
72-
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
- name: Rename & Upload Latest Release
59+
run: |
60+
JAR_FILE=$(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1)
61+
cp "$JAR_FILE" target/${{ github.event.repository.name }}-latest.jar
7462
75-
- name: Checkout Maven repository
76-
uses: actions/checkout@v4
77-
with:
78-
repository: CroaBeast/repo
79-
path: maven-repo
80-
token: ${{ secrets.MAVEN_DEPLOY_TOKEN }}
81-
82-
- name: Configure Git
83-
run: |
84-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
85-
git config --global user.name "github-actions[bot]"
86-
87-
- name: Deploy to Maven repository
88-
run: |
89-
# Create directory structure
90-
mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}
91-
92-
# Copy JAR file
93-
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
94-
95-
# Create POM file
96-
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF
97-
<?xml version="1.0" encoding="UTF-8"?>
98-
<project>
99-
<modelVersion>4.0.0</modelVersion>
63+
- name: Create GitHub Release
64+
uses: softprops/action-gh-release@v1
65+
with:
66+
tag_name: ${{ env.VERSION }}
67+
name: Release ${{ env.VERSION }}
68+
draft: false
69+
prerelease: false
70+
files: |
71+
target/${{ github.event.repository.name }}-latest.jar
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Checkout Maven repository
76+
uses: actions/checkout@v4
77+
with:
78+
repository: CroaBeast/repo
79+
path: maven-repo
80+
token: ${{ secrets.MAVEN_DEPLOY_TOKEN }}
81+
82+
- name: Configure Git
83+
run: |
84+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
85+
git config --global user.name "github-actions[bot]"
86+
87+
- name: Deploy to Maven repository
88+
run: |
89+
# Create directory structure
90+
mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}
91+
92+
# Copy JAR files
93+
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
94+
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}-javadoc.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
95+
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}-sources.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
96+
97+
# Create POM file
98+
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF
99+
<?xml version="1.0" encoding="UTF-8"?>
100+
<project>
101+
<modelVersion>4.0.0</modelVersion>
102+
<groupId>me.croabeast</groupId>
103+
<artifactId>${{ github.event.repository.name }}</artifactId>
104+
<version>${{ env.VERSION }}</version>
105+
<packaging>jar</packaging>
106+
</project>
107+
EOF
108+
109+
# Update or create maven-metadata.xml
110+
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF
111+
<?xml version="1.0" encoding="UTF-8"?>
112+
<metadata>
100113
<groupId>me.croabeast</groupId>
101114
<artifactId>${{ github.event.repository.name }}</artifactId>
102-
<version>${{ env.VERSION }}</version>
103-
<packaging>jar</packaging>
104-
</project>
105-
EOF
106-
107-
# Update or create maven-metadata.xml
108-
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF
109-
<?xml version="1.0" encoding="UTF-8"?>
110-
<metadata>
111-
<groupId>me.croabeast</groupId>
112-
<artifactId>${{ github.event.repository.name }}</artifactId>
113-
<versioning>
114-
<latest>${{ env.VERSION }}</latest>
115-
<release>${{ env.VERSION }}</release>
116-
<versions>
117-
<version>${{ env.VERSION }}</version>
118-
</versions>
119-
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
120-
</versioning>
121-
</metadata>
122-
EOF
123-
124-
# Commit and push changes
125-
cd maven-repo
126-
git add .
127-
git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}"
128-
git push
115+
<versioning>
116+
<latest>${{ env.VERSION }}</latest>
117+
<release>${{ env.VERSION }}</release>
118+
<versions>
119+
<version>${{ env.VERSION }}</version>
120+
</versions>
121+
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
122+
</versioning>
123+
</metadata>
124+
EOF
125+
126+
# Commit and push changes
127+
cd maven-repo
128+
git add .
129+
git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}"
130+
git push
129131
130132
env:
131133
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/main/java/me/croabeast/command/BukkitCommand.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,14 @@ private static class Entry {
117117
*/
118118
private Entry(org.bukkit.command.@NotNull Command command) {
119119
this.command = command;
120-
this.plugin = fromCommand(command);
120+
this.plugin = command instanceof PluginIdentifiableCommand ?
121+
((PluginIdentifiableCommand) command).getPlugin() : null;
122+
121123
if (plugin != null) {
122124
fallbackPrefix = pluginName(plugin);
123125
return;
124126
}
127+
125128
Set<String> names = new HashSet<>();
126129
knownCommands().forEach((k, v) -> {
127130
if (command.equals(v)) names.add(k);
@@ -133,17 +136,6 @@ private Entry(org.bukkit.command.@NotNull Command command) {
133136
fallbackPrefix = prefix;
134137
}
135138

136-
/**
137-
* Retrieves the plugin associated with the command.
138-
*
139-
* @param command the command instance.
140-
* @return the plugin if the command implements {@link PluginIdentifiableCommand}; {@code null} otherwise.
141-
*/
142-
static Plugin fromCommand(org.bukkit.command.Command command) {
143-
return command instanceof PluginIdentifiableCommand ?
144-
((PluginIdentifiableCommand) command).getPlugin() : null;
145-
}
146-
147139
/**
148140
* Converts the plugin's name to lower case.
149141
*
@@ -514,18 +506,7 @@ static void syncCommands() {
514506
method.invoke(server);
515507
}
516508

517-
/**
518-
* Registers this command with the Bukkit command map.
519-
* <p>
520-
* If the command is set to override an existing command, the existing command is unregistered and stored
521-
* for later re-registration upon unregistration of this command. Permissions for this command and its sub-commands
522-
* are also managed accordingly.
523-
* </p>
524-
*
525-
* @return {@code true} if the command was successfully registered; {@code false} otherwise.
526-
*/
527-
@Override
528-
public boolean register() {
509+
public boolean register(boolean sync) {
529510
if (registered || !isEnabled()) return false;
530511

531512
org.bukkit.command.Command c = knownCommands().get(getName());
@@ -535,21 +516,27 @@ public boolean register() {
535516
loadCommandPermissions(true);
536517
getMap().register(Entry.pluginName(plugin), this);
537518

538-
syncCommands();
519+
if (sync) syncCommands();
539520
return registered = true;
540521
}
541522

542523
/**
543-
* Unregisters this command from the Bukkit command map.
524+
* Registers this command with the Bukkit command map.
544525
* <p>
545-
* If a previous command was overridden, it is re-registered after this command is unregistered.
526+
* If the command is set to override an existing command, the existing command is unregistered and stored
527+
* for later re-registration upon unregistration of this command. Permissions for this command and its sub-commands
528+
* are also managed accordingly.
546529
* </p>
547530
*
548-
* @return {@code true} if the command was successfully unregistered; {@code false} otherwise.
531+
* @return {@code true} if the command was successfully registered; {@code false} otherwise.
549532
*/
550-
@SuppressWarnings("all")
551533
@Override
552-
public boolean unregister() {
534+
public boolean register() {
535+
return register(true);
536+
}
537+
538+
@SuppressWarnings("all")
539+
public boolean unregister(boolean sync) {
553540
if (!registered || isEnabled()) return false;
554541

555542
org.bukkit.command.Command c = knownCommands().get(getName());
@@ -565,10 +552,23 @@ public boolean unregister() {
565552
loadedCommand = null;
566553
}
567554

568-
syncCommands();
555+
if (sync) syncCommands();
569556
return !(registered = false);
570557
}
571558

559+
/**
560+
* Unregisters this command from the Bukkit command map.
561+
* <p>
562+
* If a previous command was overridden, it is re-registered after this command is unregistered.
563+
* </p>
564+
*
565+
* @return {@code true} if the command was successfully unregistered; {@code false} otherwise.
566+
*/
567+
@Override
568+
public boolean unregister() {
569+
return unregister(true);
570+
}
571+
572572
/**
573573
* Checks if this command is equal to another object based on its unique key.
574574
*

src/main/java/me/croabeast/command/Command.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.croabeast.command;
22

3+
import me.croabeast.common.Registrable;
34
import org.bukkit.Keyed;
45
import org.bukkit.command.PluginIdentifiableCommand;
56
import org.jetbrains.annotations.NotNull;
@@ -17,6 +18,7 @@
1718
* <li>{@link BaseCommand} for basic command properties (name, aliases, and executable action).</li>
1819
* <li>{@link Completable} for generating tab-completion suggestions.</li>
1920
* <li>{@link PluginIdentifiableCommand} and {@link Keyed} for associating the command with a plugin.</li>
21+
* <li>{@link Registrable} for handling command registration.</li>
2022
* </ul>
2123
* </p>
2224
* <p>
@@ -74,8 +76,9 @@
7476
* @see Completable
7577
* @see PluginIdentifiableCommand
7678
* @see Keyed
79+
* @see Registrable
7780
*/
78-
public interface Command extends BaseCommand, Completable, PluginIdentifiableCommand, Keyed {
81+
public interface Command extends BaseCommand, Completable, PluginIdentifiableCommand, Keyed, Registrable {
7982

8083
/**
8184
* Checks if the command is currently enabled.
@@ -91,12 +94,6 @@ public interface Command extends BaseCommand, Completable, PluginIdentifiableCom
9194
*/
9295
boolean isOverriding();
9396

94-
boolean isRegistered();
95-
96-
boolean register();
97-
98-
boolean unregister();
99-
10097
/**
10198
* Retrieves the set of sub-commands associated with this command.
10299
*

0 commit comments

Comments
 (0)