-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add permissions, reload command and workflows (#7)
- Loading branch information
Showing
11 changed files
with
223 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "maven" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Java CI with Maven | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive | ||
- name: Submit Dependency Snapshot | ||
uses: advanced-security/maven-dependency-submission-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
name: Maven Release | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
package-and-upload: | ||
name: Build and Upload JARs | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: Build and package Maven project | ||
run: mvn clean package | ||
|
||
- name: Upload to release | ||
uses: JasonEtco/upload-to-release@master | ||
with: | ||
args: target/EnchantBookPlus-${{ github.event.release.tag_name }}.jar application/java-archive | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
package-and-upload: | ||
name: Build and Upload JARs | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Set project version | ||
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false | ||
|
||
- name: Build and package Maven project | ||
run: mvn clean package | ||
|
||
- name: Upload to release | ||
uses: JasonEtco/upload-to-release@master | ||
with: | ||
args: target/EnchantBookPlus-${{ github.event.release.tag_name }}.jar application/java-archive | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Upload to Modrinth | ||
uses: cloudnode-pro/[email protected] | ||
with: | ||
token: '${{ secrets.MODRINTH_TOKEN }}' | ||
project: '${{ github.event.repository.custom_properties.modrinth_id }}' | ||
file: target/EnchantBookPlus-${{ github.event.release.tag_name }}.jar | ||
changelog: ${{ github.event.release.body }} | ||
loaders: paper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/pro/cloudnode/smp/enchantbookplus/MainCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package pro.cloudnode.smp.enchantbookplus; | ||
|
||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public final class MainCommand implements CommandExecutor, TabCompleter { | ||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) { | ||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) reload(sender, command); | ||
return overview(sender); | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) { | ||
return null; | ||
} | ||
|
||
/** | ||
* Plugin overview | ||
*/ | ||
public static boolean overview(final @NotNull CommandSender sender) { | ||
final @NotNull EnchantBookPlus plugin = EnchantBookPlus.getInstance(); | ||
sender.sendMessage(MiniMessage.miniMessage() | ||
.deserialize("<green><name></green> <white>v<version> by</white> <gray><author></gray>", Placeholder.unparsed("name", plugin | ||
.getPluginMeta().getName()), Placeholder.unparsed("version", plugin.getPluginMeta() | ||
.getVersion()), Placeholder.unparsed("author", String.join(", ", plugin.getPluginMeta() | ||
.getAuthors())))); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Reload plugin configuration | ||
*/ | ||
public static boolean reload(final @NotNull CommandSender sender, final @NotNull Command command) { | ||
if (!sender.hasPermission(Permissions.RELOAD)) { | ||
sender.sendMessage(Optional.ofNullable(command.permissionMessage()).orElse(sender.getServer().permissionMessage())); | ||
return true; | ||
} | ||
EnchantBookPlus.getInstance().reload(); | ||
sender.sendMessage(MiniMessage.miniMessage().deserialize("<green>(!) Plugin configuration reloaded.")); | ||
return true; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/pro/cloudnode/smp/enchantbookplus/Permissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package pro.cloudnode.smp.enchantbookplus; | ||
|
||
import org.bukkit.enchantments.Enchantment; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class Permissions { | ||
public static @NotNull String enchant(final @NotNull Enchantment enchantment) { | ||
return "enchantbookplus.enchant." + enchantment.getKey().getKey(); | ||
} | ||
|
||
public static @NotNull String RELOAD = "enchantbookplus.reload"; | ||
} |
Oops, something went wrong.