Skip to content

Commit

Permalink
feat(plugin): 1.20.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Apr 29, 2024
1 parent 1cdaf7e commit c8a03c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'me.gabytm.minecraft'
version '2.3.1-SNAPSHOT'
version '2.3.2-SNAPSHOT'

subprojects {
if (project.name != 'comet') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package me.gabytm.minecraft.arcanevouchers

import org.bukkit.Bukkit
import org.bukkit.Server
import java.util.regex.Pattern

/**
* @author [Matt (@ipsk)](https://github.com/ipsk)
* @author [Matt (@LichtHund)](https://github.com/LichtHund)
*/
object ServerVersion {

private val VERSION = getCurrentVersion()
private val NMS_VERSION = Bukkit.getServer().javaClass.`package`.name.substringAfterLast('.')

private const val V_1_8 = 1_8_0
private const val V_1_9 = 1_9_0
private const val V_1_13 = 1_13_0

val CURRENT = getCurrentVersionAsString()

val IS_VERY_OLD = VERSION.toString().startsWith("17")
val IS_VERY_OLD = CURRENT.startsWith("1.7")
val IS_ANCIENT = VERSION <= V_1_8

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ object ServerVersion {
*/
private fun getCurrentVersion(): Int {
// No need to cache since will only run once
val matcher = Pattern.compile("(?<version>\\d+\\.\\d+)(?<patch>\\.\\d+)?").matcher(Bukkit.getBukkitVersion())
val matcher = Pattern.compile("(?<version>\\d+\\.\\d+)(?<patch>\\.\\d+)?").matcher(getMinecraftVersion())

return buildString {
if (matcher.find()) {
Expand All @@ -72,18 +72,28 @@ object ServerVersion {
}

private fun getCurrentVersionAsString(): String {
val matcher = Pattern.compile("\\d+\\.\\d+(?:\\.\\d+)?").matcher(Bukkit.getBukkitVersion())
val matcher = Pattern.compile("\\d+\\.\\d+(?:\\.\\d+)?").matcher(getMinecraftVersion())
return if (matcher.find()) matcher.group() else "unknown"
}

private fun getMinecraftVersion(): String {
try {
// Paper method
val method = Server::class.java.getDeclaredMethod("getMinecraftVersion")
return method.invoke(Bukkit.getServer()) as String
} catch (ignored: NoSuchMethodError) {
return Bukkit.getServer().javaClass.`package`.name.substringAfterLast('.');
}
}

/**
* Gets a NMS class by its name
* @return class
* @throws ClassNotFoundException if the class wasn't found
*/
@Throws(ClassNotFoundException::class)
fun getCraftClass(name: String): Class<*> {
return Class.forName("org.bukkit.craftbukkit.$NMS_VERSION.$name")
return Class.forName("${Bukkit.getServer().javaClass.`package`.name}.$name")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ fun String.replace(placeholders: Array<String>, values: Array<String>): String {
return StringUtils.replaceEach(this, placeholders, values)
}

fun String.mini(removeItalic: Boolean = false, vararg tagResolver: TagResolver): Component {
fun String.mini(removeItalic: Boolean = false, customTagResolvers: Set<TagResolver> = emptySet()): Component {
val allTagResolvers = TagResolver.builder()
.resolvers(TagResolver.standard())
.resolvers(customTagResolvers)
.build()

return try {
if (removeItalic) {
EMPTY_COMPONENT_WITHOUT_ITALIC.append(Constant.MINI.deserialize(this, *tagResolver))
EMPTY_COMPONENT_WITHOUT_ITALIC.append(Constant.MINI.deserialize(this, allTagResolvers))
} else {
Constant.MINI.deserialize(this, *tagResolver)
Constant.MINI.deserialize(this, allTagResolvers)
}
} catch (e: ParsingException) {
exception("Could not parse '$this'", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class VoucherManager(private val plugin: ArcaneVouchers) {
val transformer: (String) -> Component = {
it.replace(arguments, values) // Replace arguments
.papi(player) // Set PAPI placeholders
.mini(true, PapiMiniMessageTag(player)) // Parse mini tags
.mini(true, setOf(PapiMiniMessageTag(player))) // Parse mini tags
}

if (voucher.itemName.isNotBlank()) {
Expand Down

0 comments on commit c8a03c4

Please sign in to comment.