mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
big cleanup & update legacy code
This commit is contained in:
parent
c8597986a2
commit
39cbc640ef
38 changed files with 285 additions and 314 deletions
|
|
@ -2,37 +2,12 @@ package xyz.alexcrea.cuanvil.dependency.datapack
|
|||
|
||||
import io.papermc.paper.datapack.Datapack
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.packs.DataPack
|
||||
import java.util.*
|
||||
|
||||
object DataPackTester {
|
||||
val legacyNames: List<String>
|
||||
get() = Bukkit.getDataPackManager().dataPacks
|
||||
.stream().filter { obj -> obj.isEnabled }
|
||||
.map { pack -> pack.key.key }
|
||||
.toList()
|
||||
|
||||
val enabledPacks: List<String>
|
||||
get() {
|
||||
try {
|
||||
// will throw error if do not exist
|
||||
Bukkit::class.java.getDeclaredMethod("getDatapackManager")
|
||||
|
||||
return Bukkit.getDatapackManager().enabledPacks
|
||||
.stream().map { obj: Datapack -> obj.name }
|
||||
.toList()
|
||||
} catch (e: NoSuchMethodException) {
|
||||
try {
|
||||
DataPack::class.java.getDeclaredMethod("getKey")
|
||||
} catch (e: NoSuchMethodException) {
|
||||
System.err.println("Could not find compatible datapack manager")
|
||||
System.err.println("If you are using a datapack that should be compatible with CustomAnvil. It will not get detected...")
|
||||
return emptyList()
|
||||
}
|
||||
return legacyNames
|
||||
} catch (e: Exception){
|
||||
// Assume cause UnimplementedOperationException on mock server
|
||||
return Collections.emptyList()
|
||||
}
|
||||
return Bukkit.getDatapackManager().enabledPacks
|
||||
.stream().map { obj: Datapack -> obj.name }
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryView
|
|||
import org.bukkit.inventory.InventoryView
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
|
||||
|
||||
class v1_21R1_ExternGuiTester: ExternGuiTester {
|
||||
class v1_21R1_ExternGuiTester : ExternGuiTester {
|
||||
override val wesjdAnvilGuiName = "Wrapper1_21_R1"
|
||||
|
||||
override fun getContainerClass(view: InventoryView): Class<Any>? {
|
||||
if(view !is CraftInventoryView<*, *>) return null
|
||||
if (view !is CraftInventoryView<*, *>) return null
|
||||
val container = view.handle
|
||||
|
||||
return container.javaClass
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import io.papermc.paper.threadedregions.scheduler.ScheduledTask
|
|||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.util.function.Consumer
|
||||
|
||||
class FoliaScheduler : TaskScheduler {
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any? {
|
||||
if(time < 1){
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
if (time < 1) {
|
||||
return Bukkit.getGlobalRegionScheduler().run(
|
||||
plugin
|
||||
) { scheduledTask: ScheduledTask? -> task.run() }
|
||||
|
|
@ -22,7 +21,7 @@ class FoliaScheduler : TaskScheduler {
|
|||
|
||||
|
||||
override fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any? {
|
||||
if(time < 1){
|
||||
if (time < 1) {
|
||||
return entity.scheduler.run(
|
||||
plugin,
|
||||
{ scheduledTask: ScheduledTask? -> task.run() },
|
||||
|
|
@ -36,5 +35,5 @@ class FoliaScheduler : TaskScheduler {
|
|||
time
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue