Skip to content

Commit

Permalink
Merge branch 'main' into custom-enchantments
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Jun 27, 2023
2 parents 5080686 + 165a4f4 commit a3706b6
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = 0.14.1
version = 0.14.2
kotlin.daemon.jvmargs=-Xmx2g
org.gradle.jvmargs=-Xmx2g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
@Hook(plugins = ["Oraxen"])
internal object OraxenUploadService : UploadService {

override val name = "oraxen"
override val names = listOf("oraxen")

override suspend fun upload(file: File): String {
val polymath = Polymath(Settings.POLYMATH_SERVER.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import xyz.xenondevs.nova.data.config.configReloadable
import xyz.xenondevs.nova.data.resources.ResourceGeneration
import xyz.xenondevs.nova.data.resources.builder.ResourcePackBuilder
import xyz.xenondevs.nova.data.resources.upload.service.CustomMultiPart
import xyz.xenondevs.nova.data.resources.upload.service.ResourcePackDotHost
import xyz.xenondevs.nova.data.resources.upload.service.S3
import xyz.xenondevs.nova.data.resources.upload.service.SelfHost
import xyz.xenondevs.nova.data.resources.upload.service.Xenondevs
import xyz.xenondevs.nova.integration.HooksLoader
import xyz.xenondevs.nova.initialize.DisableFun
import xyz.xenondevs.nova.initialize.InitFun
import xyz.xenondevs.nova.initialize.InternalInitStage
import xyz.xenondevs.nova.initialize.InternalInit
import xyz.xenondevs.nova.integration.HooksLoader
import xyz.xenondevs.nova.util.data.hash
import xyz.xenondevs.nova.util.data.http.ConnectionUtils
import java.io.File
Expand All @@ -29,9 +30,10 @@ import java.util.logging.Level
)
internal object AutoUploadManager {

internal val services = arrayListOf(Xenondevs, SelfHost, CustomMultiPart, S3)
internal val services = arrayListOf(Xenondevs, SelfHost, CustomMultiPart, S3, ResourcePackDotHost)

private val config by configReloadable { DEFAULT_CONFIG.getConfigurationSection("resource_pack.auto_upload")!! }
private val resourcePackCfg by configReloadable { DEFAULT_CONFIG.getConfigurationSection("resource_pack")!! }
private val autoUploadCfg by configReloadable { DEFAULT_CONFIG.getConfigurationSection("resource_pack.auto_upload")!! }

var enabled = false
private set
Expand Down Expand Up @@ -62,12 +64,17 @@ internal object AutoUploadManager {
SelfHost.startedLatch.await()
}

fun reload() {
disable()
reloadForceResourcePackSettings()
enable(fromReload = true)
}

private fun enable(fromReload: Boolean) {
val packConfig = DEFAULT_CONFIG.getConfigurationSection("resource_pack")!!
enabled = config.getBoolean("enabled")
enabled = autoUploadCfg.getBoolean("enabled")

if (packConfig.contains("url")) {
val url = packConfig.getString("url")
if (resourcePackCfg.contains("url")) {
val url = resourcePackCfg.getString("url")
if (!url.isNullOrEmpty()) {
if (enabled)
LOGGER.warning("The resource pack url is set in the config, but the auto upload is also enabled. Defaulting to the url in the config.")
Expand All @@ -86,19 +93,19 @@ internal object AutoUploadManager {
return
}

val serviceName = config.getString("service")
val serviceName = autoUploadCfg.getString("service")?.lowercase()
if (serviceName != null) {
val service = services.find { it.name.equals(serviceName, ignoreCase = true) }
val service = services.find { serviceName in it.names }
checkNotNull(service) { "Service $serviceName not found!" }
service.loadConfig(config)
service.loadConfig(autoUploadCfg)

selectedService = service
} else {
LOGGER.warning("No uploading service specified! Available: " + services.joinToString(transform = UploadService::name))
LOGGER.warning("No uploading service specified! Available: " + services.joinToString { it.names[0] })
return
}

val configHash = config.hash()
val configHash = autoUploadCfg.hash()
if (wasRegenerated || lastConfig != configHash) {
wasRegenerated = false
runBlocking {
Expand All @@ -119,12 +126,6 @@ internal object AutoUploadManager {
selectedService = null
}

fun reload() {
disable()
reloadForceResourcePackSettings()
enable(fromReload = true)
}

suspend fun uploadPack(pack: File): String? {
try {
if (selectedService == SelfHost)
Expand All @@ -141,7 +142,6 @@ internal object AutoUploadManager {
return url
}

@Suppress("LiftReturnOrAssignment")
private fun reloadForceResourcePackSettings() {
ForceResourcePack.getInstance().apply {
setPrompt(TextComponent.fromLegacyText(DEFAULT_CONFIG.getString("resource_pack.prompt.message")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.File

interface UploadService {

val name: String
val names: List<String>

fun loadConfig(cfg: ConfigurationSection)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@ import xyz.xenondevs.nova.HTTP_CLIENT
import xyz.xenondevs.nova.data.resources.upload.UploadService
import java.io.File

internal object CustomMultiPart : UploadService {
internal abstract class MultiPart : UploadService {

override val name = "CustomMultiPart"

private lateinit var url: String
private lateinit var filePartName: String
var urlRegex: Regex? = null
private val extraParams = HashMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) {
url = cfg.getString("url")
?: throw IllegalArgumentException("No url specified for CustomMultiPart")
filePartName = cfg.getString("filePartName")
?: throw IllegalArgumentException("No filePartName specified for CustomMultiPart")
urlRegex = cfg.getString("urlRegex")?.let(::Regex)
val extraParams = cfg.getConfigurationSection("extraParams")
?: return
extraParams.getValues(false).forEach { (key, value) ->
this.extraParams[key] = value.toString()
}
}
protected abstract val url: String
protected abstract val filePartName: String
protected abstract val urlRegex: Regex?
protected abstract val extraParams: Map<String, String>

override suspend fun upload(file: File): String {
val response = HTTP_CLIENT.submitFormWithBinaryData(url, formData {
Expand All @@ -46,4 +31,40 @@ internal object CustomMultiPart : UploadService {

override fun disable() = Unit

}

internal object CustomMultiPart : MultiPart() {

override val names = listOf("custom_multi_part", "custommultipart")

override lateinit var url: String
override lateinit var filePartName: String
public override var urlRegex: Regex? = null
override val extraParams = HashMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) {
url = cfg.getString("url")
?: throw IllegalArgumentException("No url specified for CustomMultiPart")
filePartName = cfg.getString("filePartName")
?: throw IllegalArgumentException("No filePartName specified for CustomMultiPart")
urlRegex = cfg.getString("urlRegex")?.let(::Regex)
val extraParams = cfg.getConfigurationSection("extraParams")
?: return
extraParams.getValues(false).forEach { (key, value) ->
this.extraParams[key] = value.toString()
}
}

}

internal object ResourcePackDotHost : MultiPart() {

override val names = listOf("resourcepack.host")
override val url = "https://resourcepack.host/index.php"
override var filePartName = "pack"
override var urlRegex = Regex("""(http://resourcepack\.host/dl/[^"]+)""")
override val extraParams = emptyMap<String, String>()

override fun loadConfig(cfg: ConfigurationSection) = Unit

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.net.URI

internal object S3 : UploadService {

override val name = "S3"
override val names = listOf("amazon_s3", "s3")

private var client: S3Client? = null
private lateinit var bucket: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import io.ktor.server.engine.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import org.bukkit.configuration.ConfigurationSection
import xyz.xenondevs.nova.data.config.DEFAULT_CONFIG
import xyz.xenondevs.nova.data.config.configReloadable
import xyz.xenondevs.nova.data.resources.builder.ResourcePackBuilder
import xyz.xenondevs.nova.data.resources.upload.UploadService
import xyz.xenondevs.nova.util.StringUtils
Expand All @@ -23,7 +21,7 @@ import kotlin.concurrent.thread
@Suppress("HttpUrlsUsage", "ExtractKtorModule")
internal object SelfHost : UploadService {

override val name = "SelfHost"
override val names = listOf("self_host", "selfhost")
internal val startedLatch = Latch()

private lateinit var server: CIOApplicationEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal object Xenondevs : UploadService {

private const val API_URL = "https://api.xenondevs.xyz/nova/rp/patreon/upload"

override val name = "xenondevs"
override val names = listOf("xenondevs")
private lateinit var key: String

override fun loadConfig(cfg: ConfigurationSection) {
Expand Down
3 changes: 2 additions & 1 deletion nova/src/main/resources/assets/nova/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"command.nova.advanced_tooltips.nova.success": "已为Nova的物品开启高级提示框。",
"command.nova.advanced_tooltips.nova.failure": "Nova物品的高级提示框已经处于开启状态。",
"command.nova.advanced_tooltips.all.failure": "所有物品的高级提示框已经处于开启状态。",
"command.nova.list_blocks.success": "共计:%s"
"command.nova.list_blocks.success": "共计:%s",
"command.nova.invalidate_char_sizes.success": "已成功使所有字符大小无效。它们将在下次创建资源包时重新计算。"
}
3 changes: 2 additions & 1 deletion nova/src/main/resources/configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ resource_pack:
# The auto uploader automatically uploads the resource pack after generation.
# READ SETUP GUIDE: https://xenondevs.xyz/docs/nova/admin/setup/#automatic-resource-pack-hosting
auto_upload:
enabled: false
enabled: true
service: resourcepack.host

# Settings affecting the resource pack prompt
prompt:
Expand Down

0 comments on commit a3706b6

Please sign in to comment.