Skip to content

Commit

Permalink
bug fix, add papi function.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 5, 2023
1 parent 4718c21 commit 82fc0bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 105 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

val questAdderGroup = "kor.toxicity.questadder"
val questAdderVersion = "1.1.5"
val questAdderVersion = "1.1.6"

val adventureVersion = "4.14.0"
val platformVersion = "4.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import java.util.concurrent.ThreadLocalRandom
class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
companion object: QuestAdder {

const val VERSION = "1.1.5"
const val VERSION = "1.1.6"

private val listener = object : Listener {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ object ResourcePackManager: QuestAdderManager {
build.listFiles()?.forEach { f ->
zip(f)
}
adder.getResource("pack.png")?.buffered()?.let { png ->
adder.getResource("pack.png")?.buffered()?.use { png ->
val entry = ZipEntry("pack.png")
it.putNextEntry(entry)
it.write(png.readBytes())
Expand Down Expand Up @@ -762,108 +762,6 @@ object ResourcePackManager: QuestAdderManager {
}
}
}
// private fun writeToolTipFont(targetFont: Font, data: FontBlueprint, fontTargetDir: File, jsonTargetDir: File): ToolTipFontData? {
//
//
// val parsedUTF8 = (Char.MIN_VALUE..Char.MAX_VALUE).filter {
// targetFont.canDisplay(it)
// }.toCharArray().run {
// copyOf(size - size % 16)
// }
// val name = data.name
// val key = "${name}_${abs(data.ascent)}_${abs(data.height)}"
// if (parsedUTF8.isEmpty()) return null
// val fontSize = 16 shl data.size
//
// var i = 0
// var num = 1
// val array = JsonArray().apply {
// add(JsonObject().apply {
// addProperty("type","space")
// add("advances",JsonObject().apply {
// addProperty(" ", 4)
// })
// })
// }
// val pow = fontSize shl 4
//
// val folder = File(fontTargetDir,data.name)
// val exists = folder.exists()
// val newFont = targetFont.deriveFont(fontSize.toFloat() * 0.75F)
// if (!exists) {
// folder.mkdir()
// }
//
// val spriteMap = HashMap<Int, CharSprite>()
//
// val multiplier = data.height.toDouble() / fontSize
// while (i < parsedUTF8.size) {
// val finalName = "${name}_${num++}"
// val utf = parsedUTF8.copyOfRange(i, (i + 256).coerceAtMost(parsedUTF8.size))
// val json = JsonArray()
//
// if (!exists) {
// val image = BufferedImage(pow, pow, BufferedImage.TYPE_INT_ARGB)
// val graphics = image.createGraphics().apply {
// composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER)
//
// font = newFont
// setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
// setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON)
// }
// for (i2 in 0 until 16.coerceAtMost(utf.size / 16)) {
// val str = String(utf.copyOfRange(i2 * 16, ((i2 + 1) * 16).coerceAtMost(utf.size)))
// if (str.isNotEmpty()) {
// str.forEachIndexed { index, c ->
// val s = c.toString()
// val bound = newFont.getStringBounds(s, fontRenderContent)
//
// val draw = newFont.createGlyphVector(fontRenderContent, s).getPixelBounds(fontRenderContent, 0F, 0F)
// spriteMap[c.code] = CharSprite(ceil(draw.width * multiplier).toInt(), ceil(draw.height * multiplier).toInt())
//
// graphics.drawString(
// s,
// index * fontSize.toFloat(),
// (i2 + 1) * fontSize.toFloat() + min(fontSize - bound.height, -bound.y - fontSize).toFloat() * 0.75F
// )
// }
// json.add(str)
// }
// }
// graphics.dispose()
// ImageIO.write(image, "png", File(folder, "$finalName.png"))
// } else {
// for (i2 in 0 until 16.coerceAtMost(utf.size / 16)) {
// val str = String(utf.copyOfRange(i2 * 16, ((i2 + 1) * 16).coerceAtMost(utf.size)))
// if (str.isNotEmpty()) {
// json.add(str)
// str.forEach {
// val draw = newFont.createGlyphVector(fontRenderContent, it.toString()).getPixelBounds(fontRenderContent, 0F, 0F)
// spriteMap[it.code] = CharSprite(ceil(draw.width * multiplier).toInt(), ceil(draw.height * multiplier).toInt())
// }
// }
// }
// }
// i += 256
// array.add(JsonObject().apply {
// addProperty("type","bitmap")
// addProperty("file","questadder:font/tooltip/$name/$finalName.png")
// addProperty("ascent",data.ascent)
// addProperty("height",data.height)
// add("chars",json)
// })
// }
// JsonWriter(File(jsonTargetDir,"$key.json").bufferedWriter()).use {
// gson.toJson(JsonObject().apply {
// add("providers", array)
// },it)
// }
// return ToolTipFontData(
// Key.key("questadder:tooltip/$key"),
// data.fontOffset,
// spriteMap
// )
// }

fun getToolTip(name: String) = tooltipMap[name]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kor.toxicity.questadder.util.function.ArgumentFunction
import kor.toxicity.questadder.util.function.QuestOperator
import kor.toxicity.questadder.util.function.WrappedFunction
import kor.toxicity.questadder.util.reflect.PrimitiveType
import me.clip.placeholderapi.PlaceholderAPI
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
Expand Down Expand Up @@ -318,6 +319,27 @@ object FunctionBuilder {
addFunction("region") { e: RegionEvent, _ ->
e.region.id
}
addFunction("papiStrOf", listOf(Player::class.java, String::class.java)) { _: Null, args ->
try {
PlaceholderAPI.setPlaceholders(args[0] as Player, args[1] as String)
} catch (ex: Throwable) {
"<none>"
}
}
addFunction("papiNumOf", listOf(Player::class.java, String::class.java)) { _: Null, args ->
try {
PlaceholderAPI.setPlaceholders(args[0] as Player, args[1] as String).toInt()
} catch (ex: Throwable) {
0
}
}
addFunction("papiBoolOf", listOf(Player::class.java, String::class.java)) { _: Null, args ->
try {
PlaceholderAPI.setPlaceholders(args[0] as Player, args[1] as String).toBoolean()
} catch (ex: Throwable) {
false
}
}
}
inline fun <reified T, reified R : Any> addOperation(name: String, priority: Int, noinline operate: (T, T) -> R) {
addOperation(name,priority,T::class.java,R::class.java,operate)
Expand Down

0 comments on commit 82fc0bb

Please sign in to comment.