Only use paper + code cleanup

This commit is contained in:
alexcrea 2025-07-09 10:18:55 +02:00
parent 6ede990987
commit c12e70ca54
Signed by: alexcrea
GPG key ID: E346CD16413450E3
28 changed files with 132 additions and 352 deletions

View file

@ -14,7 +14,7 @@ plugins {
signing signing
id("cn.lalaki.central").version("1.2.8") id("cn.lalaki.central").version("1.2.8")
// Paper // Paper
id("io.papermc.paperweight.userdev") version "2.0.0-beta.17" apply false id("io.papermc.paperweight.userdev") version "2.0.0-beta.17"
} }
group = "xyz.alexcrea" group = "xyz.alexcrea"
@ -29,11 +29,14 @@ repositories {
// ExcellentEnchants // ExcellentEnchants
maven(url = "https://repo.nightexpressdev.com/releases") maven(url = "https://repo.nightexpressdev.com/releases")
// ProtocoLib
maven(url = "https://repo.dmulloy2.net/repository/public/")
} }
dependencies { dependencies {
// Spigot api // Paper
compileOnly("org.spigotmc:spigot-api:1.21.5-R0.1-SNAPSHOT") paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
// Gui library // Gui library
val inventoryFramework = "xyz.alexcrea.cuanvil.inventoryframework:IF-CustomAnvil:0.10.18.2" val inventoryFramework = "xyz.alexcrea.cuanvil.inventoryframework:IF-CustomAnvil:0.10.18.2"
@ -61,16 +64,19 @@ dependencies {
// ToolStats // ToolStats
compileOnly(files("libs/toolstats-1.9.6-stripped.jar")) compileOnly(files("libs/toolstats-1.9.6-stripped.jar"))
// Protocolib
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
// AxPlayerWarps // AxPlayerWarps
compileOnly(files("libs/AxPlayerWarps-1.10.3.jar")) compileOnly(files("libs/AxPlayerWarps-1.10.3.jar"))
// Include nms // Include nms
implementation(project(":nms:nms-common")) implementation(project(":nms:nms-common"))
implementation(project(":nms:v1_21R1", configuration = "reobf")) implementation(project(":nms:v1_21R1"))
implementation(project(":nms:v1_21R2", configuration = "reobf")) implementation(project(":nms:v1_21R2"))
implementation(project(":nms:v1_21R3", configuration = "reobf")) implementation(project(":nms:v1_21R3"))
implementation(project(":nms:v1_21R4", configuration = "reobf")) implementation(project(":nms:v1_21R4"))
implementation(project(":nms:v1_21R5", configuration = "reobf")) implementation(project(":nms:v1_21R5"))
// include kotlin for the offline jar // include kotlin for the offline jar
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
@ -154,6 +160,11 @@ tasks {
) )
} }
// paper mapping
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
// Process resource for plugin.yml // Process resource for plugin.yml
dependsOn(processResources) dependsOn(processResources)
} }
@ -186,6 +197,11 @@ tasks {
// Add custom anvil compiled // Add custom anvil compiled
from(sourceSets.main.get().output) from(sourceSets.main.get().output)
// paper mapping
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
dependsOn(processResources) dependsOn(processResources)
}) })

View file

@ -1,10 +1,12 @@
group = rootProject.group group = rootProject.group
version = rootProject.version version = rootProject.version
dependencies { plugins {
// Spigot api id("io.papermc.paperweight.userdev")
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") }
// Protocolib dependencies {
compileOnly("net.dmulloy2:ProtocolLib:5.4.0") // Paper
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
} }

View file

@ -1,14 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet
import org.bukkit.entity.Player
class NoPacketManager: PacketManager {
override val canSetInstantBuild: Boolean
get() = false
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
// ProtocoLib not installed and not in a supported version: We do nothing
}
}

View file

@ -1,17 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet
import org.bukkit.entity.Player
interface PacketManager {
/**
* If the provided packet manager if able to set instant build.
*/
val canSetInstantBuild: Boolean
/**
* Try to set instant build properties
*/
fun setInstantBuild(player: Player, instantBuild: Boolean)
}

View file

@ -1,14 +1,13 @@
package xyz.alexcrea.cuanvil.dependency.packet package xyz.alexcrea.cuanvil.dependency.packet
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.event.Listener
abstract class PacketManagerBase() : PacketManager, Listener { open class PacketManagerBase {
override val canSetInstantBuild: Boolean open val canSetInstantBuild: Boolean
get() = false get() = false
override fun setInstantBuild(player: Player, instantBuild: Boolean) { open fun setInstantBuild(player: Player, instantBuild: Boolean) {
// Default implementation is empty. // Default implementation is empty.
} }

View file

@ -1,13 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.datapack
import io.papermc.paper.datapack.Datapack
import org.bukkit.Bukkit
object DataPackTester {
val enabledPacks: List<String>
get() {
return Bukkit.getDatapackManager().enabledPacks
.stream().map { obj: Datapack -> obj.name }
.toList()
}
}

View file

@ -1,33 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet.versions
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
import net.minecraft.world.entity.player.Abilities
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class V1_21R1_PacketManager : PacketManagerBase(), PacketManager {
override val canSetInstantBuild: Boolean
get() = true
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
val nmsPlayer = (player as CraftPlayer).handle
val playerAbilities = nmsPlayer.abilities
val sendedAbilities: Abilities
if (playerAbilities.instabuild == instantBuild) {
sendedAbilities = playerAbilities
} else {
sendedAbilities = Abilities()
sendedAbilities.invulnerable = playerAbilities.invulnerable
sendedAbilities.flying = playerAbilities.flying
sendedAbilities.mayfly = playerAbilities.mayfly
sendedAbilities.instabuild = instantBuild
sendedAbilities.mayBuild = playerAbilities.mayBuild
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
}
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
nmsPlayer.connection.send(packet)
}
}

View file

@ -1,33 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet.versions
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
import net.minecraft.world.entity.player.Abilities
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class V1_21R3_PacketManager : PacketManagerBase(), PacketManager {
override val canSetInstantBuild: Boolean
get() = true
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
val nmsPlayer = (player as CraftPlayer).handle
val playerAbilities = nmsPlayer.abilities
val sendedAbilities: Abilities
if (playerAbilities.instabuild == instantBuild) {
sendedAbilities = playerAbilities
} else {
sendedAbilities = Abilities()
sendedAbilities.invulnerable = playerAbilities.invulnerable
sendedAbilities.flying = playerAbilities.flying
sendedAbilities.mayfly = playerAbilities.mayfly
sendedAbilities.instabuild = instantBuild
sendedAbilities.mayBuild = playerAbilities.mayBuild
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
}
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
nmsPlayer.connection.send(packet)
}
}

View file

@ -1,33 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet.versions
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
import net.minecraft.world.entity.player.Abilities
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class V1_21R4_PacketManager : PacketManagerBase(), PacketManager {
override val canSetInstantBuild: Boolean
get() = true
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
val nmsPlayer = (player as CraftPlayer).handle
val playerAbilities = nmsPlayer.abilities
val sendedAbilities: Abilities
if (playerAbilities.instabuild == instantBuild) {
sendedAbilities = playerAbilities
} else {
sendedAbilities = Abilities()
sendedAbilities.invulnerable = playerAbilities.invulnerable
sendedAbilities.flying = playerAbilities.flying
sendedAbilities.mayfly = playerAbilities.mayfly
sendedAbilities.instabuild = instantBuild
sendedAbilities.mayBuild = playerAbilities.mayBuild
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
}
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
nmsPlayer.connection.send(packet)
}
}

View file

@ -1,33 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.packet.versions
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
import net.minecraft.world.entity.player.Abilities
import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class V1_21R5_PacketManager : PacketManagerBase(), PacketManager {
override val canSetInstantBuild: Boolean
get() = true
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
val nmsPlayer = (player as CraftPlayer).handle
val playerAbilities = nmsPlayer.abilities
val sendedAbilities: Abilities
if (playerAbilities.instabuild == instantBuild) {
sendedAbilities = playerAbilities
} else {
sendedAbilities = Abilities()
sendedAbilities.invulnerable = playerAbilities.invulnerable
sendedAbilities.flying = playerAbilities.flying
sendedAbilities.mayfly = playerAbilities.mayfly
sendedAbilities.instabuild = instantBuild
sendedAbilities.mayBuild = playerAbilities.mayBuild
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
}
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
nmsPlayer.connection.send(packet)
}
}

View file

@ -29,7 +29,8 @@ public class EnchantmentApi {
private static Object saveChangeTask = null; private static Object saveChangeTask = null;
private EnchantmentApi() {} private EnchantmentApi() {
}
/** /**
* Register an enchantment. * Register an enchantment.
@ -116,7 +117,7 @@ public class EnchantmentApi {
* @return True if successful. * @return True if successful.
*/ */
public static boolean unregisterEnchantment(@NotNull Enchantment enchantment) { public static boolean unregisterEnchantment(@NotNull Enchantment enchantment) {
return unregisterEnchantment(enchantment.getKeyOrThrow()); return unregisterEnchantment(enchantment.getKey());
} }
/** /**
@ -155,6 +156,7 @@ public class EnchantmentApi {
/** /**
* Get every registered custom anvil enchantments. * Get every registered custom anvil enchantments.
*
* @return An immutable map of enchantment key as map key and custom anvil enchantment as value. * @return An immutable map of enchantment key as map key and custom anvil enchantment as value.
*/ */
@NotNull @NotNull
@ -164,6 +166,7 @@ public class EnchantmentApi {
/** /**
* Write the default level and rarity configuration of the enchantment. * Write the default level and rarity configuration of the enchantment.
*
* @param enchantment The enchantment to write default configuration * @param enchantment The enchantment to write default configuration
* @param override If it should override old configuration * @param override If it should override old configuration
* @return Return false if override is false and a configuration exist. true otherwise. * @return Return false if override is false and a configuration exist. true otherwise.
@ -217,6 +220,7 @@ public class EnchantmentApi {
/** /**
* Add a bulk get operator. * Add a bulk get operator.
*
* @param operation An optimised get enchantments operation * @param operation An optimised get enchantments operation
*/ */
public static void addBulkGet(@NotNull BulkGetEnchantOperation operation) { public static void addBulkGet(@NotNull BulkGetEnchantOperation operation) {
@ -225,6 +229,7 @@ public class EnchantmentApi {
/** /**
* Add a bulk clean operator. * Add a bulk clean operator.
*
* @param operation An optimised clean enchantments operation * @param operation An optimised clean enchantments operation
*/ */
public static void addBulkClean(@NotNull BulkCleanEnchantOperation operation) { public static void addBulkClean(@NotNull BulkCleanEnchantOperation operation) {

View file

@ -164,7 +164,7 @@ public class MaterialGroupApi {
} }
public static List<String> materialSetToStringList(@NotNull Set<Material> materials) { public static List<String> materialSetToStringList(@NotNull Set<Material> materials) {
return materials.stream().map(material -> material.getKeyOrThrow().getKey().toLowerCase()).toList(); return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList();
} }
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) { public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) {

View file

@ -33,9 +33,9 @@ public class BukkitEnchantBulkOperation implements BulkGetEnchantOperation, Bulk
} }
public void addEnchantment(@NotNull Map<CAEnchantment, Integer> enchantmentMap, @NotNull Enchantment enchantment, int level) { public void addEnchantment(@NotNull Map<CAEnchantment, Integer> enchantmentMap, @NotNull Enchantment enchantment, int level) {
CAEnchantment enchant = EnchantmentApi.getByKey(enchantment.getKeyOrThrow()); CAEnchantment enchant = EnchantmentApi.getByKey(enchantment.getKey());
if (enchant == null) { if (enchant == null) {
CustomAnvil.instance.getLogger().warning("Enchantment of key " + enchantment.getKeyOrThrow() + CustomAnvil.instance.getLogger().warning("Enchantment of key " + enchantment.getKey() +
" somehow not found in CustomAnvil ?"); " somehow not found in CustomAnvil ?");
return; return;
} }

View file

@ -30,7 +30,7 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
public final @NotNull Enchantment bukkit; public final @NotNull Enchantment bukkit;
public CABukkitEnchantment(@NotNull Enchantment bukkit, @Nullable EnchantmentRarity rarity) { public CABukkitEnchantment(@NotNull Enchantment bukkit, @Nullable EnchantmentRarity rarity) {
super(bukkit.getKeyOrThrow(), super(bukkit.getKey(),
rarity, rarity,
bukkit.getMaxLevel()); bukkit.getMaxLevel());
this.bukkit = bukkit; this.bukkit = bukkit;
@ -103,7 +103,7 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
@NotNull @NotNull
public static EnchantmentRarity getRarity(Enchantment enchantment) { public static EnchantmentRarity getRarity(Enchantment enchantment) {
try { try {
return EnchantmentProperties.valueOf(enchantment.getKeyOrThrow().getKey().toUpperCase(Locale.ENGLISH)).getRarity(); return EnchantmentProperties.valueOf(enchantment.getKey().getKey().toUpperCase(Locale.ENGLISH)).getRarity();
} catch (Exception ignored) { } catch (Exception ignored) {
return findRarity(enchantment); return findRarity(enchantment);
} }
@ -114,22 +114,8 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
return this.bukkit; return this.bukkit;
} }
private static Method getAnvilCostMethod;
static {
Class<Enchantment> clazz = Enchantment.class;
try {
getAnvilCostMethod = clazz.getDeclaredMethod("getAnvilCost");
getAnvilCostMethod.setAccessible(true);
CustomAnvil.Companion.log("Detected getAnvilCost method");
} catch (NoSuchMethodException e) {
getAnvilCostMethod = null;
}
}
private static final Map<EnchantmentTarget, String> targetToGroup = new HashMap<>(); private static final Map<EnchantmentTarget, String> targetToGroup = new HashMap<>();
static { static {
targetToGroup.put(EnchantmentTarget.ARMOR, "armors"); targetToGroup.put(EnchantmentTarget.ARMOR, "armors");
targetToGroup.put(EnchantmentTarget.ARMOR_HEAD, "helmets"); targetToGroup.put(EnchantmentTarget.ARMOR_HEAD, "helmets");
@ -148,18 +134,8 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
} }
private static EnchantmentRarity findRarity(Enchantment enchantment) { private static EnchantmentRarity findRarity(Enchantment enchantment) {
if (getAnvilCostMethod == null) return EnchantmentRarity.COMMON; //TODO use non deprecated value
return EnchantmentRarity.getRarity(enchantment.getRarity().getWeight());
try {
int itemCost = (int) getAnvilCostMethod.invoke(enchantment);
return EnchantmentRarity.getRarity(itemCost);
} catch (IllegalAccessException | InvocationTargetException e) {
CustomAnvil.instance.getLogger().log(Level.SEVERE, "could not find cost for enchantment " + enchantment.getKey(), e);
return EnchantmentRarity.COMMON;
}
} }
@Override @Override

View file

@ -8,7 +8,7 @@ import io.delilaheve.CustomAnvil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager; import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase;
import xyz.alexcrea.cuanvil.gui.config.global.*; import xyz.alexcrea.cuanvil.gui.config.global.*;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -27,7 +27,7 @@ public class MainConfigGui extends ChestGui {
super(3, "§8Anvil Config", CustomAnvil.instance); super(3, "§8Anvil Config", CustomAnvil.instance);
} }
public void init(PacketManager packetManager) { public void init(PacketManagerBase packetManager) {
Pattern pattern = new Pattern( Pattern pattern = new Pattern(
GuiSharedConstant.EMPTY_GUI_FULL_LINE, GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"012345678", "012345678",

View file

@ -14,7 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager; import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui; import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
@ -41,11 +41,12 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
return INSTANCE; return INSTANCE;
} }
private final PacketManager packetManager; private final PacketManagerBase packetManager;
/** /**
* Constructor of this Global gui for basic settings. * Constructor of this Global gui for basic settings.
*/ */
public BasicConfigGui(PacketManager packetManager) { public BasicConfigGui(PacketManagerBase packetManager) {
super(4, "§8Basic Config", CustomAnvil.instance); super(4, "§8Basic Config", CustomAnvil.instance);
if (INSTANCE == null) INSTANCE = this; if (INSTANCE == null) INSTANCE = this;

View file

@ -189,7 +189,7 @@ open class CustomAnvil : JavaPlugin() {
try { try {
val configReader = FileReader(resourceFile) val configReader = FileReader(resourceFile)
yamlConfig.load(configReader) yamlConfig.load(configReader)
} catch (test: Exception) { } catch (_: Exception) {
if (hardFailSafe) { if (hardFailSafe) {
// This is important and may impact gameplay if it does not load. // This is important and may impact gameplay if it does not load.
// Failsafe is to stop the plugin // Failsafe is to stop the plugin

View file

@ -18,11 +18,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
import xyz.alexcrea.cuanvil.dependency.gui.GuiTesterSelector import xyz.alexcrea.cuanvil.dependency.gui.GuiTesterSelector
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerSelector import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerSelector
import xyz.alexcrea.cuanvil.dependency.plugins.* 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.dependency.scheduler.TaskScheduler
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
import xyz.alexcrea.cuanvil.util.AnvilUseType import xyz.alexcrea.cuanvil.util.AnvilUseType
@ -34,7 +32,7 @@ object DependencyManager {
var isFolia: Boolean = false var isFolia: Boolean = false
lateinit var scheduler: TaskScheduler lateinit var scheduler: TaskScheduler
lateinit var packetManager: PacketManager lateinit var packetManager: PacketManagerBase
private var externGuiTester: ExternGuiTester? = null private var externGuiTester: ExternGuiTester? = null
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
@ -53,11 +51,9 @@ object DependencyManager {
// Bukkit or Paper scheduler ? // Bukkit or Paper scheduler ?
isFolia = testIsFolia() isFolia = testIsFolia()
scheduler = if (isFolia) { if (isFolia) {
CustomAnvil.instance.logger.info("Folia detected... Custom Anvil Folia support is experimental. issues are more likely to happens.") CustomAnvil.instance.logger.info("Folia detected... Custom Anvil Folia support is experimental. issues are more likely to happens.")
}
FoliaScheduler()
} else BukkitScheduler()
// Packet Manager // Packet Manager
val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false) val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false)

View file

@ -1,6 +1,8 @@
package xyz.alexcrea.cuanvil.dependency.datapack package xyz.alexcrea.cuanvil.dependency.datapack
import io.delilaheve.CustomAnvil import io.delilaheve.CustomAnvil
import io.papermc.paper.datapack.Datapack
import org.bukkit.Bukkit
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.NamespacedKey import org.bukkit.NamespacedKey
import org.bukkit.configuration.file.FileConfiguration import org.bukkit.configuration.file.FileConfiguration
@ -17,7 +19,6 @@ import xyz.alexcrea.cuanvil.update.Version
import java.io.InputStreamReader import java.io.InputStreamReader
object DataPackDependency { object DataPackDependency {
private val START_DETECT_VERSION = Version(1, 19, 0)
/** /**
* Map of the latest CustomAnvil update related to the pack * Map of the latest CustomAnvil update related to the pack
@ -30,10 +31,9 @@ object DataPackDependency {
private val enabledDatapacks: List<String> private val enabledDatapacks: List<String>
get() { get() {
val version: Version = UpdateUtils.currentMinecraftVersion() return Bukkit.getDatapackManager().enabledPacks
if (version.lesserThan(START_DETECT_VERSION)) return emptyList() .stream().map { obj: Datapack -> obj.name }
.toList()
return DataPackTester.enabledPacks
} }
fun handleDatapackConfigs() { fun handleDatapackConfigs() {
@ -44,7 +44,8 @@ object DataPackDependency {
if (!packName.startsWith("file/")) continue if (!packName.startsWith("file/")) continue
if (packName.contains("bp_post_scarcity", ignoreCase = true) if (packName.contains("bp_post_scarcity", ignoreCase = true)
|| packName.contains("bracken", ignoreCase = true)) { || packName.contains("bracken", ignoreCase = true)
) {
handlePack("bracken") handlePack("bracken")
continue continue
} }

View file

@ -1,13 +1,11 @@
package xyz.alexcrea.cuanvil.dependency.packet.versions package xyz.alexcrea.cuanvil.dependency.packet
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
import net.minecraft.world.entity.player.Abilities import net.minecraft.world.entity.player.Abilities
import org.bukkit.craftbukkit.entity.CraftPlayer import org.bukkit.craftbukkit.entity.CraftPlayer
import org.bukkit.entity.Player import org.bukkit.entity.Player
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class V1_21R2_PacketManager : PacketManagerBase(), PacketManager { class PacketManager : PacketManagerBase() {
override val canSetInstantBuild: Boolean override val canSetInstantBuild: Boolean
get() = true get() = true

View file

@ -1,45 +1,24 @@
package xyz.alexcrea.cuanvil.dependency.packet package xyz.alexcrea.cuanvil.dependency.packet
import org.bukkit.Bukkit import org.bukkit.Bukkit
import xyz.alexcrea.cuanvil.dependency.packet.versions.V1_21R1_PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.versions.V1_21R2_PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.versions.V1_21R3_PacketManager
import xyz.alexcrea.cuanvil.dependency.packet.versions.V1_21R4_PacketManager
import xyz.alexcrea.cuanvil.update.UpdateUtils
object PacketManagerSelector { object PacketManagerSelector {
fun selectPacketManager(forceProtocolib: Boolean): PacketManager { fun selectPacketManager(forceProtocolib: Boolean): PacketManagerBase {
// Try to find version // Try to find version
return if (forceProtocolib) return if (forceProtocolib)
protocolibIfPresent protocolibIfPresent
else else
versionSpecificManager ?: protocolibIfPresent versionSpecificManager
} }
private val protocolibIfPresent: PacketManager private val protocolibIfPresent: PacketManagerBase
get() = get() =
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"))
ProtocoLibWrapper() ProtocoLibWrapper()
else else
NoPacketManager() PacketManagerBase()
private val versionSpecificManager: PacketManagerBase? private val versionSpecificManager: PacketManagerBase
get() { get() {
val versionParts = UpdateUtils.currentMinecraftVersionArray() return PacketManager()
if (versionParts[0] != 1) return null
return when (versionParts[1]) {
// Can't support 1.16.5 bc 1.16.5 paper userdev do not exist
21 -> when (versionParts[2]) {
0, 1 -> V1_21R1_PacketManager()
2, 3 -> V1_21R2_PacketManager()
4 -> V1_21R3_PacketManager()
5 -> V1_21R4_PacketManager()
6, 7, 8 -> V1_21R5_PacketManager()
else -> null
}
else -> null
}
} }
} }

View file

@ -7,9 +7,9 @@ import com.comphenix.protocol.events.PacketContainer
import org.bukkit.entity.Player import org.bukkit.entity.Player
import java.lang.reflect.InvocationTargetException import java.lang.reflect.InvocationTargetException
class ProtocoLibWrapper: PacketManager { class ProtocoLibWrapper : PacketManagerBase() {
private val protocolManager: ProtocolManager = ProtocolLibrary.getProtocolManager(); private val protocolManager: ProtocolManager = ProtocolLibrary.getProtocolManager()
override val canSetInstantBuild: Boolean override val canSetInstantBuild: Boolean
get() = true get() = true

View file

@ -24,7 +24,7 @@ class ExcellentEnchantsDependency {
// As excellent enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant. // As excellent enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
for (enchantment in V5EnchantRegistry.getRegistered()) { for (enchantment in V5EnchantRegistry.getRegistered()) {
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.keyOrThrow) EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key)
EnchantmentApi.registerEnchantment(CAEEV5Enchantment(enchantment)) EnchantmentApi.registerEnchantment(CAEEV5Enchantment(enchantment))
} }

View file

@ -1,17 +0,0 @@
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)
}
}

View file

@ -6,6 +6,7 @@ import org.bukkit.entity.Entity
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
class FoliaScheduler : TaskScheduler { class FoliaScheduler : TaskScheduler {
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any { override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
if (time < 1) { if (time < 1) {
return Bukkit.getGlobalRegionScheduler().run( return Bukkit.getGlobalRegionScheduler().run(
@ -35,5 +36,4 @@ class FoliaScheduler : TaskScheduler {
time time
) )
} }
} }

View file

@ -32,7 +32,7 @@ class EnchantConflictManager {
// 1.20.5 compatibility TODO better update system // 1.20.5 compatibility TODO better update system
private val SWEEPING_EDGE_ENCHANT = Collections.singletonList<CAEnchantment>( private val SWEEPING_EDGE_ENCHANT = Collections.singletonList<CAEnchantment>(
CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge"))
?: CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.keyOrThrow) ?: CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key)
) )
} }
@ -176,7 +176,7 @@ class EnchantConflictManager {
newEnchant: CAEnchantment newEnchant: CAEnchantment
): ConflictType { ): ConflictType {
val mat = item.type val mat = item.type
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.keyOrThrow}") CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
val conflictList = newEnchant.conflicts val conflictList = newEnchant.conflicts
var result = ConflictType.NO_CONFLICT var result = ConflictType.NO_CONFLICT

View file

@ -6,9 +6,9 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.event.inventory.InventoryCloseEvent
import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.AnvilInventory
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
class AnvilCloseListener(private val packetManager: PacketManager) : Listener { class AnvilCloseListener(private val packetManager: PacketManagerBase) : Listener {
@EventHandler @EventHandler
fun onAnvilClose(event: InventoryCloseEvent) { fun onAnvilClose(event: InventoryCloseEvent) {

View file

@ -52,7 +52,7 @@ class PrepareAnvilListener : Listener {
// Test if custom anvil is bypassed before immutability test // Test if custom anvil is bypassed before immutability test
if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) { if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) {
// even if we got bypassed we still want to set price // even if we got bypassed we still want to set price
AnvilXpUtil.setAnvilInvXp(event.view, player, event.inventory.repairCost) AnvilXpUtil.setAnvilInvXp(event.view, player, event.view.repairCost)
return return
} }
@ -69,7 +69,7 @@ class PrepareAnvilListener : Listener {
// Test if the event should bypass custom anvil. // Test if the event should bypass custom anvil.
if (DependencyManager.tryEventPreAnvilBypass(event, player)) { if (DependencyManager.tryEventPreAnvilBypass(event, player)) {
// even if we got bypassed we still want to set price // even if we got bypassed we still want to set price
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, event.inventory.repairCost) AnvilXpUtil.setAnvilInvXp(event.view, player, event.view.repairCost)
return return
} }
@ -113,7 +113,7 @@ class PrepareAnvilListener : Listener {
if (!meta.hasEnchants()) return false if (!meta.hasEnchants()) return false
for (enchant in meta.enchants.keys) { for (enchant in meta.enchants.keys) {
if (ConfigOptions.isImmutable(enchant.keyOrThrow)) return true if (ConfigOptions.isImmutable(enchant.key)) return true
} }
return false return false
} }
@ -122,7 +122,7 @@ class PrepareAnvilListener : Listener {
if (meta !is EnchantmentStorageMeta || !meta.hasStoredEnchants()) return false if (meta !is EnchantmentStorageMeta || !meta.hasStoredEnchants()) return false
for (enchant in meta.storedEnchants.keys) { for (enchant in meta.storedEnchants.keys) {
if (ConfigOptions.isImmutable(enchant.keyOrThrow)) return true if (ConfigOptions.isImmutable(enchant.key)) return true
} }
return false return false
} }