Skip to content

Commit

Permalink
add resource pack build
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Oct 3, 2023
1 parent f598ff2 commit babe76d
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 14 deletions.
33 changes: 33 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
Binary file modified .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions plugin/src/main/java/kor/toxicity/questadder/QuestAdderBukkit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
private set
var animator: PlayerAnimator? = null
private set

var reloaded = false
private set

private lateinit var plugin: QuestAdderBukkit

private val playerThreadMap = ConcurrentHashMap<UUID,PlayerThread>()
Expand Down Expand Up @@ -167,6 +171,7 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
LocationManager,
GuiManager,
ItemManager,
ShopManager,
SkinManager,
EntityManager,
GestureManager,
Expand Down Expand Up @@ -200,6 +205,8 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
private set
var questSuffix = listOf<Component>()
private set
var zipResourcePack = true
private set
fun getPlayerGuiButton(type: PlayerGuiButtonType) = playerGuiButton[type]
internal fun reload(section: ConfigurationSection) {
defaultTypingSpeed = section.getLong("default-typing-speed",1L)
Expand Down Expand Up @@ -261,6 +268,7 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
s.colored()
}
}
zipResourcePack = section.getBoolean("zip-resource-pack", true)
}
}
object Prefix {
Expand Down Expand Up @@ -533,8 +541,14 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
} while (task != null)
}
private fun reloadSync() {
if (reloaded) {
warn("plugin is still on reload.")
return
}
reloaded = true
loadDatabase()
load()
reloaded = false
}
private fun loadDatabase() {
loadFile("database")?.let { database ->
Expand All @@ -545,8 +559,7 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
ReloadStartEvent().callEvent()
asyncTask {
var time = System.currentTimeMillis()
loadDatabase()
load()
reloadSync()
time = System.currentTimeMillis() - time
task {
callback(time)
Expand Down Expand Up @@ -677,4 +690,4 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
addEvent("customblockplace", EventCustomBlockPlace::class.java)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import org.zeroturnaround.zip.ZipUtil
import ru.beykerykt.minecraft.lightapi.common.LightAPI
import java.io.*
import java.util.*
import java.util.zip.Deflater
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import javax.imageio.ImageIO
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
Expand Down Expand Up @@ -422,6 +425,44 @@ object ResourcePackManager: QuestAdderManager {
materialMap.forEach {
saveCustomModelData(it.key,it.value.entries)
}
val buildPath = build.path
if (QuestAdderBukkit.Config.zipResourcePack) ZipOutputStream(FileOutputStream(File(resource,"build.zip").apply {
if (!exists()) delete()
}).buffered()).use {
fun zip(file: File) {
if (file.isFile) {
val byte = file.readBytes()
val entry = ZipEntry(file.path.substring(buildPath.length + 1).replace('\\','/'))
it.putNextEntry(entry)
it.write(byte)
it.closeEntry()
} else {
file.listFiles()?.forEach { f ->
zip(f)
}
}
}
it.setLevel(Deflater.BEST_COMPRESSION)
it.setComment("This is an example zip file.")
build.listFiles()?.forEach { f ->
zip(f)
}
adder.getResource("pack.png")?.buffered()?.let { png ->
val entry = ZipEntry("pack.png")
it.putNextEntry(entry)
it.write(png.readBytes())
it.closeEntry()
}
val entry = ZipEntry("pack.mcmeta")
it.putNextEntry(entry)
it.write(gson.toJson(JsonObject().apply {
add("pack",JsonObject().apply {
addProperty("pack_format", QuestAdderBukkit.nms.getVersion().mcmetaVersion)
addProperty("description","QuestAdder's example resource pack.")
})
}).toByteArray())
it.closeEntry()
}
} catch (ex: Exception) {
ex.printStackTrace()
QuestAdderBukkit.warn("unable to make a resource pack.")
Expand Down Expand Up @@ -578,4 +619,4 @@ object ResourcePackManager: QuestAdderManager {

override fun end(adder: QuestAdderBukkit) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kor.toxicity.questadder.manager

import kor.toxicity.questadder.QuestAdderBukkit

object ShopManager: QuestAdderManager {
override fun start(adder: QuestAdderBukkit) {
}

override fun reload(adder: QuestAdderBukkit) {
}

override fun end(adder: QuestAdderBukkit) {
}
}
20 changes: 10 additions & 10 deletions plugin/src/main/java/kor/toxicity/questadder/nms/NMSVersion.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kor.toxicity.questadder.nms

enum class NMSVersion(val version: Int, val subVersion: Int) {
V1_17_R1(17,1),
V1_18_R1(18,1),
V1_18_R2(18,2),
V1_19_R1(19,1),
V1_19_R2(19,2),
V1_19_R3(19,3),
V1_20_R1(20,1),
V1_20_R2(20,2)
}
enum class NMSVersion(val version: Int, val subVersion: Int, val mcmetaVersion: Int) {
V1_17_R1(17,1, 7),
V1_18_R1(18,1, 8),
V1_18_R2(18,2, 8),
V1_19_R1(19,1, 9),
V1_19_R2(19,2, 12),
V1_19_R3(19,3, 13),
V1_20_R1(20,1, 15),
V1_20_R2(20,2, 18)
}
Binary file added plugin/src/main/resources/pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit babe76d

Please sign in to comment.