Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Uni0305 committed Oct 24, 2024
2 parents d388d7e + c3a3fc2 commit ab93a50
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle
run: ./gradlew build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
path: build/libs/*.jar
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/libs/*.jar
generate_release_notes: true
26 changes: 26 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
The MIT License (MIT)
=====================

Copyright © 2024 Uni0305

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OraxenExtras

[![GitHub License](https://img.shields.io/github/license/Uni0305/OraxenExtras?style=for-the-badge)](LICENSE.md)
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Uni0305/OraxenExtras/build.yml?style=for-the-badge)](https://github.com/Uni0305/OraxenExtras/actions)
[![GitHub Release](https://img.shields.io/github/v/release/Uni0305/OraxenExtras?style=for-the-badge)](https://github.com/Uni0305/OraxenExtras/releases)

A plugin that adds extra features to Oraxen
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "me.uni0305"
version = "1.0-SNAPSHOT"
version = "0.1.0"

repositories {
mavenCentral()
Expand All @@ -22,7 +22,7 @@ dependencies {
}

kotlin {
jvmToolchain(17)
jvmToolchain(21)
}

bukkitPluginYaml {
Expand Down
64 changes: 64 additions & 0 deletions src/main/kotlin/me/uni0305/oraxen/OraxenExtrasCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package me.uni0305.oraxen

import io.th0rgal.oraxen.api.OraxenPack
import org.bukkit.command.CommandSender
import org.bukkit.command.defaults.BukkitCommand
import org.bukkit.plugin.java.JavaPlugin

class OraxenExtrasCommand(private val plugin: JavaPlugin) : BukkitCommand("oraxen-extras") {
init {
this.permission = "op"
plugin.server.commandMap.register("uni0305", this)
}

override fun execute(sender: CommandSender, label: String, args: Array<String>): Boolean {
if (args.isEmpty()) {
sender.sendRichMessage("<yellow>Usage: <white>/$label reload")
sender.sendRichMessage("<yellow>Usage: <white>/$label pack <reload|upload>")
return true
}

when (args[0].lowercase()) {
"reload" -> {
plugin.saveDefaultConfig()
plugin.reloadConfig()
sender.sendRichMessage("<gold>Configuration reloaded.")
return true
}
"pack" -> {
if (args.size < 2) {
sender.sendRichMessage("<yellow>Usage: <white>/$label pack <reload|upload>")
return false
}

when (args[1].lowercase()) {
"reload" -> {
OraxenExtrasPlugin.externalPackImportService.importPacks()
OraxenPack.reloadPack()
sender.sendRichMessage("<gold>Reloaded Oraxen pack.")
return true
}
"upload" -> {
OraxenPack.uploadPack()
sender.sendRichMessage("<gold>Uploaded Oraxen pack.")
return true
}
else -> {
sender.sendRichMessage("<red>Unknown subcommand: ${args[1]}")
return false
}
}
}
else -> {
sender.sendRichMessage("<red>Unknown subcommand: ${args[0]}")
return false
}
}
}

override fun tabComplete(sender: CommandSender, label: String, args: Array<String>): List<String> {
return if (args.size <= 1 || args[0].isEmpty()) listOf("reload", "pack")
else if (args.size == 2 && args[0].lowercase() == "pack") listOf("reload", "upload")
else emptyList()
}
}
21 changes: 20 additions & 1 deletion src/main/kotlin/me/uni0305/oraxen/OraxenExtrasPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package me.uni0305.oraxen

import me.uni0305.oraxen.config.ExternalPackImportConfig
import me.uni0305.oraxen.service.ExternalPackImportService
import org.bukkit.plugin.java.JavaPlugin

class OraxenExtrasPlugin : JavaPlugin()
class OraxenExtrasPlugin : JavaPlugin() {
companion object {
lateinit var externalPackImportService: ExternalPackImportService private set
}

override fun onEnable() {
saveDefaultConfig()
reloadConfig()

val externalPackImportConfig = ExternalPackImportConfig(config)
externalPackImportService = ExternalPackImportService(externalPackImportConfig)
OraxenExtrasCommand(this)
}

override fun onDisable() {
saveConfig()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.uni0305.oraxen.config

import org.bukkit.Bukkit
import org.bukkit.configuration.file.FileConfiguration
import java.io.File

class ExternalPackImportConfig(private val config: FileConfiguration) {
companion object {
private const val SECTION_PATH = "import-external-packs"
}

fun isEnabled() = config.getBoolean("$SECTION_PATH.enabled", false)

fun getPacks(): List<File> = config.getStringList("$SECTION_PATH.packs")
.map { File(Bukkit.getServer().pluginsFolder, it).resolve("assets") }
.filter { it.exists() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.uni0305.oraxen.service

import io.th0rgal.oraxen.api.OraxenPack
import me.uni0305.oraxen.config.ExternalPackImportConfig
import org.slf4j.LoggerFactory

class ExternalPackImportService(private val config: ExternalPackImportConfig) {
private val logger = LoggerFactory.getLogger(this.javaClass)

fun getPacks() = if (config.isEnabled()) config.getPacks() else emptyList()

fun importPacks() {
if (!config.isEnabled()) {
logger.warn("External pack import is disabled")
return
}

val packs = config.getPacks()
if (packs.isEmpty()) {
logger.warn("No external packs to import")
return
}

try {
OraxenPack.addFilesToPack(packs.toTypedArray())
logger.info("Imported ${packs.size} external packs")
} catch (e: Exception) {
logger.error("Failed to import external packs", e)
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import-external-packs:
enabled: false
packs:
- ModelEngine/resource pack

0 comments on commit ab93a50

Please sign in to comment.