mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
bring back bukkit scheduler for mockbukkit
also other mockbukkit fixes
This commit is contained in:
parent
2f2923e910
commit
ee569ed7de
8 changed files with 78 additions and 20 deletions
|
|
@ -129,6 +129,11 @@ allprojects {
|
|||
|
||||
}
|
||||
|
||||
// Stupid paperweight workaround
|
||||
paperweight {
|
||||
addServerDependencyTo = configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).map { setOf(it) }
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
// Online jar (use of libraries)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
|
|||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerSelector
|
||||
import xyz.alexcrea.cuanvil.dependency.plugins.*
|
||||
import xyz.alexcrea.cuanvil.dependency.scheduler.BukkitScheduler
|
||||
import xyz.alexcrea.cuanvil.dependency.scheduler.FoliaScheduler
|
||||
import xyz.alexcrea.cuanvil.dependency.scheduler.TaskScheduler
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import java.util.logging.Level
|
||||
|
|
@ -29,7 +31,8 @@ import java.util.logging.Level
|
|||
object DependencyManager {
|
||||
|
||||
var isFolia: Boolean = false
|
||||
lateinit var scheduler: FoliaScheduler
|
||||
var isMockbukkit: Boolean = false
|
||||
lateinit var scheduler: TaskScheduler
|
||||
lateinit var packetManager: PacketManagerBase
|
||||
|
||||
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
|
||||
|
|
@ -48,10 +51,15 @@ object DependencyManager {
|
|||
|
||||
// Bukkit or Paper scheduler ?
|
||||
isFolia = testIsFolia()
|
||||
isMockbukkit = testIsMockbukkit()
|
||||
|
||||
if (isFolia) {
|
||||
CustomAnvil.instance.logger.info("Folia detected... Custom Anvil Folia support is experimental. issues are more likely to happens.")
|
||||
}
|
||||
scheduler = FoliaScheduler()
|
||||
|
||||
scheduler =
|
||||
if (isMockbukkit) BukkitScheduler()
|
||||
else FoliaScheduler()
|
||||
|
||||
// Packet Manager
|
||||
val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false)
|
||||
|
|
@ -101,6 +109,15 @@ object DependencyManager {
|
|||
|
||||
}
|
||||
|
||||
private fun testIsMockbukkit(): Boolean {
|
||||
try {
|
||||
Class.forName("org.mockbukkit.mockbukkit.exception.UnimplementedOperationException")
|
||||
return true
|
||||
} catch (e: ClassNotFoundException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
fun handleCompatibilityConfig() {
|
||||
enchantmentSquaredCompatibility?.registerPluginConfiguration()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import xyz.alexcrea.cuanvil.api.ConflictBuilder
|
|||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||
import xyz.alexcrea.cuanvil.api.MaterialGroupApi
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAIncompatibleAllEnchant
|
||||
import xyz.alexcrea.cuanvil.group.IncludeGroup
|
||||
|
|
@ -37,6 +38,8 @@ object DataPackDependency {
|
|||
}
|
||||
|
||||
fun handleDatapackConfigs() {
|
||||
if (DependencyManager.isMockbukkit) return
|
||||
|
||||
val enabledDatapack = enabledDatapacks
|
||||
for (packName in enabledDatapack) {
|
||||
// Handling of pack name is horrible: it is based on file name
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.dependency.gui
|
|||
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView
|
||||
import org.bukkit.inventory.InventoryView
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
|
||||
object ExternGuiTester {
|
||||
|
||||
|
|
@ -13,10 +14,7 @@ object ExternGuiTester {
|
|||
}
|
||||
|
||||
fun testIfGui(view: InventoryView): Boolean {
|
||||
// this mean we are on test
|
||||
//TODO review why needed knowing previous mitigations should works
|
||||
if(view.javaClass.name.endsWith("AnvilViewMock")) return false
|
||||
|
||||
if (DependencyManager.isMockbukkit) return false
|
||||
val clazz = getContainerClass(view) ?: return false
|
||||
|
||||
val clazzName = clazz.name
|
||||
|
|
@ -30,7 +28,7 @@ object ExternGuiTester {
|
|||
|
||||
fun expectWesjd(name: String): Boolean {
|
||||
val spigotVer = GuiTesterSelector.spigotVersionString
|
||||
if(spigotVer == null) return false
|
||||
if (spigotVer == null) return false
|
||||
|
||||
val expectedWesjdGuiPath = "anvilgui.version.Wrapper${spigotVer}"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.scheduler
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class BukkitScheduler : TaskScheduler {
|
||||
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
return Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, time)
|
||||
}
|
||||
|
||||
|
||||
override fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any {
|
||||
return Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, time)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,11 @@ import org.bukkit.Bukkit
|
|||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
//TODO first, add to mockbukkit theses then do next todo
|
||||
//TODO replace usage of this to in code correct version
|
||||
class FoliaScheduler {
|
||||
class FoliaScheduler: TaskScheduler {
|
||||
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
if (time < 1) {
|
||||
return Bukkit.getGlobalRegionScheduler().run(
|
||||
plugin
|
||||
|
|
@ -21,11 +22,7 @@ class FoliaScheduler {
|
|||
)
|
||||
}
|
||||
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable): Any?{
|
||||
return scheduleGlobally(plugin, task, 0L)
|
||||
}
|
||||
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any? {
|
||||
override fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any? {
|
||||
if (time < 1) {
|
||||
return entity.scheduler.run(
|
||||
plugin,
|
||||
|
|
@ -41,7 +38,4 @@ class FoliaScheduler {
|
|||
)
|
||||
}
|
||||
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable): Any?{
|
||||
return scheduleOnEntity(plugin, entity, task, 0L)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.scheduler
|
||||
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
interface TaskScheduler {
|
||||
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any?
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable): Any?{
|
||||
return scheduleGlobally(plugin, task, 0L)
|
||||
}
|
||||
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any?
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable): Any?{
|
||||
return scheduleOnEntity(plugin, entity, task, 0L)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeAll;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockbukkit.mockbukkit.MockBukkit;
|
||||
import org.mockbukkit.mockbukkit.ServerMock;
|
||||
import org.mockbukkit.mockbukkit.exception.UnimplementedOperationException;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
|
||||
|
||||
|
|
@ -26,9 +27,14 @@ public abstract class DefaultCustomAnvilTest {
|
|||
@BeforeEach
|
||||
public void setUp() {
|
||||
// Load your plugin
|
||||
plugin = MockBukkit.load(CustomAnvil.class);
|
||||
// Continue initialization of the plugin
|
||||
server.getScheduler().performOneTick();
|
||||
try {
|
||||
plugin = MockBukkit.load(CustomAnvil.class);
|
||||
|
||||
// Continue initialization of the plugin
|
||||
server.getScheduler().performOneTick();
|
||||
} catch (UnimplementedOperationException exception) {
|
||||
throw new IllegalStateException("unimplemented on plugin startup", exception);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue