mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Only use paper + code cleanup
This commit is contained in:
parent
6ede990987
commit
c12e70ca54
28 changed files with 132 additions and 352 deletions
|
|
@ -14,7 +14,7 @@ plugins {
|
|||
signing
|
||||
id("cn.lalaki.central").version("1.2.8")
|
||||
// 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"
|
||||
|
|
@ -29,11 +29,14 @@ repositories {
|
|||
|
||||
// ExcellentEnchants
|
||||
maven(url = "https://repo.nightexpressdev.com/releases")
|
||||
|
||||
// ProtocoLib
|
||||
maven(url = "https://repo.dmulloy2.net/repository/public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
compileOnly("org.spigotmc:spigot-api:1.21.5-R0.1-SNAPSHOT")
|
||||
// Paper
|
||||
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
|
||||
|
||||
// Gui library
|
||||
val inventoryFramework = "xyz.alexcrea.cuanvil.inventoryframework:IF-CustomAnvil:0.10.18.2"
|
||||
|
|
@ -61,16 +64,19 @@ dependencies {
|
|||
// ToolStats
|
||||
compileOnly(files("libs/toolstats-1.9.6-stripped.jar"))
|
||||
|
||||
// Protocolib
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
|
||||
|
||||
// AxPlayerWarps
|
||||
compileOnly(files("libs/AxPlayerWarps-1.10.3.jar"))
|
||||
|
||||
// Include nms
|
||||
implementation(project(":nms:nms-common"))
|
||||
implementation(project(":nms:v1_21R1", configuration = "reobf"))
|
||||
implementation(project(":nms:v1_21R2", configuration = "reobf"))
|
||||
implementation(project(":nms:v1_21R3", configuration = "reobf"))
|
||||
implementation(project(":nms:v1_21R4", configuration = "reobf"))
|
||||
implementation(project(":nms:v1_21R5", configuration = "reobf"))
|
||||
implementation(project(":nms:v1_21R1"))
|
||||
implementation(project(":nms:v1_21R2"))
|
||||
implementation(project(":nms:v1_21R3"))
|
||||
implementation(project(":nms:v1_21R4"))
|
||||
implementation(project(":nms:v1_21R5"))
|
||||
|
||||
// include kotlin for the offline jar
|
||||
implementation(kotlin("stdlib"))
|
||||
|
|
@ -154,6 +160,11 @@ tasks {
|
|||
)
|
||||
}
|
||||
|
||||
// paper mapping
|
||||
manifest {
|
||||
attributes["paperweight-mappings-namespace"] = "mojang"
|
||||
}
|
||||
|
||||
// Process resource for plugin.yml
|
||||
dependsOn(processResources)
|
||||
}
|
||||
|
|
@ -186,6 +197,11 @@ tasks {
|
|||
// Add custom anvil compiled
|
||||
from(sourceSets.main.get().output)
|
||||
|
||||
// paper mapping
|
||||
manifest {
|
||||
attributes["paperweight-mappings-namespace"] = "mojang"
|
||||
}
|
||||
|
||||
dependsOn(processResources)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
group = rootProject.group
|
||||
version = rootProject.version
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
||||
|
||||
// Protocolib
|
||||
compileOnly("net.dmulloy2:ProtocolLib:5.4.0")
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Paper
|
||||
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet
|
||||
|
||||
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
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
open fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
// Default implementation is empty.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,8 @@ public class EnchantmentApi {
|
|||
|
||||
private static Object saveChangeTask = null;
|
||||
|
||||
private EnchantmentApi() {}
|
||||
private EnchantmentApi() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an enchantment.
|
||||
|
|
@ -116,7 +117,7 @@ public class EnchantmentApi {
|
|||
* @return True if successful.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return An immutable map of enchantment key as map key and custom anvil enchantment as value.
|
||||
*/
|
||||
@NotNull
|
||||
|
|
@ -164,6 +166,7 @@ public class EnchantmentApi {
|
|||
|
||||
/**
|
||||
* Write the default level and rarity configuration of the enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment to write default configuration
|
||||
* @param override If it should override old configuration
|
||||
* @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.
|
||||
*
|
||||
* @param operation An optimised get enchantments operation
|
||||
*/
|
||||
public static void addBulkGet(@NotNull BulkGetEnchantOperation operation) {
|
||||
|
|
@ -225,6 +229,7 @@ public class EnchantmentApi {
|
|||
|
||||
/**
|
||||
* Add a bulk clean operator.
|
||||
*
|
||||
* @param operation An optimised clean enchantments operation
|
||||
*/
|
||||
public static void addBulkClean(@NotNull BulkCleanEnchantOperation operation) {
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public class MaterialGroupApi {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ public class BukkitEnchantBulkOperation implements BulkGetEnchantOperation, Bulk
|
|||
}
|
||||
|
||||
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) {
|
||||
CustomAnvil.instance.getLogger().warning("Enchantment of key " + enchantment.getKeyOrThrow() +
|
||||
CustomAnvil.instance.getLogger().warning("Enchantment of key " + enchantment.getKey() +
|
||||
" somehow not found in CustomAnvil ?");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
|
|||
public final @NotNull Enchantment bukkit;
|
||||
|
||||
public CABukkitEnchantment(@NotNull Enchantment bukkit, @Nullable EnchantmentRarity rarity) {
|
||||
super(bukkit.getKeyOrThrow(),
|
||||
super(bukkit.getKey(),
|
||||
rarity,
|
||||
bukkit.getMaxLevel());
|
||||
this.bukkit = bukkit;
|
||||
|
|
@ -103,7 +103,7 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
|
|||
@NotNull
|
||||
public static EnchantmentRarity getRarity(Enchantment enchantment) {
|
||||
try {
|
||||
return EnchantmentProperties.valueOf(enchantment.getKeyOrThrow().getKey().toUpperCase(Locale.ENGLISH)).getRarity();
|
||||
return EnchantmentProperties.valueOf(enchantment.getKey().getKey().toUpperCase(Locale.ENGLISH)).getRarity();
|
||||
} catch (Exception ignored) {
|
||||
return findRarity(enchantment);
|
||||
}
|
||||
|
|
@ -114,22 +114,8 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
|
|||
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<>();
|
||||
|
||||
static {
|
||||
targetToGroup.put(EnchantmentTarget.ARMOR, "armors");
|
||||
targetToGroup.put(EnchantmentTarget.ARMOR_HEAD, "helmets");
|
||||
|
|
@ -148,18 +134,8 @@ public class CABukkitEnchantment extends CAEnchantmentBase {
|
|||
}
|
||||
|
||||
private static EnchantmentRarity findRarity(Enchantment enchantment) {
|
||||
if (getAnvilCostMethod == null) return EnchantmentRarity.COMMON;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//TODO use non deprecated value
|
||||
return EnchantmentRarity.getRarity(enchantment.getRarity().getWeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import io.delilaheve.CustomAnvil;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
|
@ -27,7 +27,7 @@ public class MainConfigGui extends ChestGui {
|
|||
super(3, "§8Anvil Config", CustomAnvil.instance);
|
||||
}
|
||||
|
||||
public void init(PacketManager packetManager) {
|
||||
public void init(PacketManagerBase packetManager) {
|
||||
Pattern pattern = new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
"012345678",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
|
|
@ -41,11 +41,12 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final PacketManager packetManager;
|
||||
private final PacketManagerBase packetManager;
|
||||
|
||||
/**
|
||||
* Constructor of this Global gui for basic settings.
|
||||
*/
|
||||
public BasicConfigGui(PacketManager packetManager) {
|
||||
public BasicConfigGui(PacketManagerBase packetManager) {
|
||||
super(4, "§8Basic Config", CustomAnvil.instance);
|
||||
if (INSTANCE == null) INSTANCE = this;
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ open class CustomAnvil : JavaPlugin() {
|
|||
try {
|
||||
val configReader = FileReader(resourceFile)
|
||||
yamlConfig.load(configReader)
|
||||
} catch (test: Exception) {
|
||||
} catch (_: Exception) {
|
||||
if (hardFailSafe) {
|
||||
// This is important and may impact gameplay if it does not load.
|
||||
// Failsafe is to stop the plugin
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
|
|||
import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
|
||||
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.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
|
||||
|
|
@ -34,7 +32,7 @@ object DependencyManager {
|
|||
|
||||
var isFolia: Boolean = false
|
||||
lateinit var scheduler: TaskScheduler
|
||||
lateinit var packetManager: PacketManager
|
||||
lateinit var packetManager: PacketManagerBase
|
||||
private var externGuiTester: ExternGuiTester? = null
|
||||
|
||||
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
|
||||
|
|
@ -53,11 +51,9 @@ object DependencyManager {
|
|||
|
||||
// Bukkit or Paper scheduler ?
|
||||
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.")
|
||||
|
||||
FoliaScheduler()
|
||||
} else BukkitScheduler()
|
||||
}
|
||||
|
||||
// Packet Manager
|
||||
val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.datapack
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import io.papermc.paper.datapack.Datapack
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.configuration.file.FileConfiguration
|
||||
|
|
@ -17,7 +19,6 @@ import xyz.alexcrea.cuanvil.update.Version
|
|||
import java.io.InputStreamReader
|
||||
|
||||
object DataPackDependency {
|
||||
private val START_DETECT_VERSION = Version(1, 19, 0)
|
||||
|
||||
/**
|
||||
* Map of the latest CustomAnvil update related to the pack
|
||||
|
|
@ -30,10 +31,9 @@ object DataPackDependency {
|
|||
|
||||
private val enabledDatapacks: List<String>
|
||||
get() {
|
||||
val version: Version = UpdateUtils.currentMinecraftVersion()
|
||||
if (version.lesserThan(START_DETECT_VERSION)) return emptyList()
|
||||
|
||||
return DataPackTester.enabledPacks
|
||||
return Bukkit.getDatapackManager().enabledPacks
|
||||
.stream().map { obj: Datapack -> obj.name }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun handleDatapackConfigs() {
|
||||
|
|
@ -44,7 +44,8 @@ object DataPackDependency {
|
|||
if (!packName.startsWith("file/")) continue
|
||||
|
||||
if (packName.contains("bp_post_scarcity", ignoreCase = true)
|
||||
|| packName.contains("bracken", ignoreCase = true)) {
|
||||
|| packName.contains("bracken", ignoreCase = true)
|
||||
) {
|
||||
handlePack("bracken")
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.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_21R2_PacketManager : PacketManagerBase(), PacketManager {
|
||||
class PacketManager : PacketManagerBase() {
|
||||
override val canSetInstantBuild: Boolean
|
||||
get() = true
|
||||
|
||||
|
|
@ -1,45 +1,24 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet
|
||||
|
||||
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 {
|
||||
fun selectPacketManager(forceProtocolib: Boolean): PacketManager {
|
||||
fun selectPacketManager(forceProtocolib: Boolean): PacketManagerBase {
|
||||
// Try to find version
|
||||
return if (forceProtocolib)
|
||||
protocolibIfPresent
|
||||
else
|
||||
versionSpecificManager ?: protocolibIfPresent
|
||||
versionSpecificManager
|
||||
}
|
||||
|
||||
private val protocolibIfPresent: PacketManager
|
||||
private val protocolibIfPresent: PacketManagerBase
|
||||
get() =
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"))
|
||||
ProtocoLibWrapper()
|
||||
else
|
||||
NoPacketManager()
|
||||
private val versionSpecificManager: PacketManagerBase?
|
||||
PacketManagerBase()
|
||||
private val versionSpecificManager: PacketManagerBase
|
||||
get() {
|
||||
val versionParts = UpdateUtils.currentMinecraftVersionArray()
|
||||
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
|
||||
}
|
||||
return PacketManager()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import com.comphenix.protocol.events.PacketContainer
|
|||
import org.bukkit.entity.Player
|
||||
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
|
||||
get() = true
|
||||
|
|
@ -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.
|
||||
for (enchantment in V5EnchantRegistry.getRegistered()) {
|
||||
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.keyOrThrow)
|
||||
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key)
|
||||
EnchantmentApi.registerEnchantment(CAEEV5Enchantment(enchantment))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Entity
|
|||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class FoliaScheduler : TaskScheduler {
|
||||
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
if (time < 1) {
|
||||
return Bukkit.getGlobalRegionScheduler().run(
|
||||
|
|
@ -35,5 +36,4 @@ class FoliaScheduler : TaskScheduler {
|
|||
time
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ class EnchantConflictManager {
|
|||
// 1.20.5 compatibility TODO better update system
|
||||
private val SWEEPING_EDGE_ENCHANT = Collections.singletonList<CAEnchantment>(
|
||||
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
|
||||
): ConflictType {
|
||||
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
|
||||
|
||||
var result = ConflictType.NO_CONFLICT
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import org.bukkit.event.EventHandler
|
|||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
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
|
||||
fun onAnvilClose(event: InventoryCloseEvent) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class PrepareAnvilListener : Listener {
|
|||
// Test if custom anvil is bypassed before immutability test
|
||||
if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class PrepareAnvilListener : Listener {
|
|||
// Test if the event should bypass custom anvil.
|
||||
if (DependencyManager.tryEventPreAnvilBypass(event, player)) {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ class PrepareAnvilListener : Listener {
|
|||
if (!meta.hasEnchants()) return false
|
||||
|
||||
for (enchant in meta.enchants.keys) {
|
||||
if (ConfigOptions.isImmutable(enchant.keyOrThrow)) return true
|
||||
if (ConfigOptions.isImmutable(enchant.key)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class PrepareAnvilListener : Listener {
|
|||
if (meta !is EnchantmentStorageMeta || !meta.hasStoredEnchants()) return false
|
||||
|
||||
for (enchant in meta.storedEnchants.keys) {
|
||||
if (ConfigOptions.isImmutable(enchant.keyOrThrow)) return true
|
||||
if (ConfigOptions.isImmutable(enchant.key)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue