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
|
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)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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")
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Paper
|
||||||
|
paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
// Protocolib
|
|
||||||
compileOnly("net.dmulloy2:ProtocolLib:5.4.0")
|
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
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.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 static Object saveChangeTask = null;
|
||||||
|
|
||||||
private EnchantmentApi() {}
|
private EnchantmentApi() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register an enchantment.
|
* Register an enchantment.
|
||||||
|
|
@ -37,14 +38,14 @@ public class EnchantmentApi {
|
||||||
* @param enchantment The enchantment to register
|
* @param enchantment The enchantment to register
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){
|
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment) {
|
||||||
if(!CAEnchantmentRegistry.getInstance().register(enchantment)) return false;
|
if (!CAEnchantmentRegistry.getInstance().register(enchantment)) return false;
|
||||||
|
|
||||||
// Add enchantment to gui.
|
// Add enchantment to gui.
|
||||||
if(EnchantCostConfigGui.getInstance() != null){
|
if (EnchantCostConfigGui.getInstance() != null) {
|
||||||
EnchantCostConfigGui.getInstance().updateValueForGeneric(enchantment, true);
|
EnchantCostConfigGui.getInstance().updateValueForGeneric(enchantment, true);
|
||||||
}
|
}
|
||||||
if(EnchantLimitConfigGui.getInstance() != null){
|
if (EnchantLimitConfigGui.getInstance() != null) {
|
||||||
EnchantLimitConfigGui.getInstance().updateValueForGeneric(enchantment, true);
|
EnchantLimitConfigGui.getInstance().updateValueForGeneric(enchantment, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,8 +62,8 @@ public class EnchantmentApi {
|
||||||
* @param defaultRarity The default rarity of the provided enchantment
|
* @param defaultRarity The default rarity of the provided enchantment
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity){
|
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity) {
|
||||||
if(defaultRarity == null)
|
if (defaultRarity == null)
|
||||||
return registerEnchantment(new CABukkitEnchantment(enchantment));
|
return registerEnchantment(new CABukkitEnchantment(enchantment));
|
||||||
|
|
||||||
return registerEnchantment(new CABukkitEnchantment(enchantment, defaultRarity));
|
return registerEnchantment(new CABukkitEnchantment(enchantment, defaultRarity));
|
||||||
|
|
@ -76,7 +77,7 @@ public class EnchantmentApi {
|
||||||
* @param enchantment The enchantment to register
|
* @param enchantment The enchantment to register
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean registerEnchantment(@NotNull Enchantment enchantment){
|
public static boolean registerEnchantment(@NotNull Enchantment enchantment) {
|
||||||
return registerEnchantment(new CABukkitEnchantment(enchantment));
|
return registerEnchantment(new CABukkitEnchantment(enchantment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,12 +87,12 @@ public class EnchantmentApi {
|
||||||
* @param enchantment The enchantment to unregister
|
* @param enchantment The enchantment to unregister
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean unregisterEnchantment(@Nullable CAEnchantment enchantment){
|
public static boolean unregisterEnchantment(@Nullable CAEnchantment enchantment) {
|
||||||
// Remove from gui
|
// Remove from gui
|
||||||
if(EnchantCostConfigGui.getInstance() != null){
|
if (EnchantCostConfigGui.getInstance() != null) {
|
||||||
EnchantCostConfigGui.getInstance().removeGeneric(enchantment);
|
EnchantCostConfigGui.getInstance().removeGeneric(enchantment);
|
||||||
}
|
}
|
||||||
if(EnchantLimitConfigGui.getInstance() != null){
|
if (EnchantLimitConfigGui.getInstance() != null) {
|
||||||
EnchantLimitConfigGui.getInstance().removeGeneric(enchantment);
|
EnchantLimitConfigGui.getInstance().removeGeneric(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +105,7 @@ public class EnchantmentApi {
|
||||||
* @param key The enchantment key to unregister
|
* @param key The enchantment key to unregister
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean unregisterEnchantment(@NotNull NamespacedKey key){
|
public static boolean unregisterEnchantment(@NotNull NamespacedKey key) {
|
||||||
CAEnchantment enchantment = CAEnchantment.getByKey(key);
|
CAEnchantment enchantment = CAEnchantment.getByKey(key);
|
||||||
return unregisterEnchantment(enchantment);
|
return unregisterEnchantment(enchantment);
|
||||||
}
|
}
|
||||||
|
|
@ -115,8 +116,8 @@ public class EnchantmentApi {
|
||||||
* @param enchantment The enchantment to unregister
|
* @param enchantment The enchantment to unregister
|
||||||
* @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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -126,7 +127,7 @@ public class EnchantmentApi {
|
||||||
* @return The custom anvil enchantment of this key. null if not found.
|
* @return The custom anvil enchantment of this key. null if not found.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CAEnchantment getByKey(@NotNull NamespacedKey key){
|
public static CAEnchantment getByKey(@NotNull NamespacedKey key) {
|
||||||
return CAEnchantment.getByKey(key);
|
return CAEnchantment.getByKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +140,7 @@ public class EnchantmentApi {
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "1.6.3")
|
@Deprecated(since = "1.6.3")
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CAEnchantment getByName(@NotNull String name){
|
public static CAEnchantment getByName(@NotNull String name) {
|
||||||
return CAEnchantment.getByName(name);
|
return CAEnchantment.getByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,29 +150,31 @@ public class EnchantmentApi {
|
||||||
* @param name The name used to fetch
|
* @param name The name used to fetch
|
||||||
* @return List of custom anvil enchantments of this name. May be empty if not found.
|
* @return List of custom anvil enchantments of this name. May be empty if not found.
|
||||||
*/
|
*/
|
||||||
public static List<CAEnchantment> getListByName(@NotNull String name){
|
public static List<CAEnchantment> getListByName(@NotNull String name) {
|
||||||
return CAEnchantment.getListByName(name);
|
return CAEnchantment.getListByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
public static Map<NamespacedKey, CAEnchantment> getRegisteredEnchantments(){
|
public static Map<NamespacedKey, CAEnchantment> getRegisteredEnchantments() {
|
||||||
return Collections.unmodifiableMap(CAEnchantmentRegistry.getInstance().registeredEnchantments());
|
return Collections.unmodifiableMap(CAEnchantmentRegistry.getInstance().registeredEnchantments());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override){
|
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override) {
|
||||||
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||||
|
|
||||||
if(tryWriteDefaultConfig(config, enchantment, override)){
|
if (tryWriteDefaultConfig(config, enchantment, override)) {
|
||||||
prepareSaveTask();
|
prepareSaveTask();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -181,7 +184,7 @@ public class EnchantmentApi {
|
||||||
boolean hasChange = false;
|
boolean hasChange = false;
|
||||||
|
|
||||||
String levelPath = "enchant_limits." + enchantment.getKey();
|
String levelPath = "enchant_limits." + enchantment.getKey();
|
||||||
if(override || !defaultConfig.isSet(levelPath)){
|
if (override || !defaultConfig.isSet(levelPath)) {
|
||||||
defaultConfig.set(levelPath, enchantment.defaultMaxLevel());
|
defaultConfig.set(levelPath, enchantment.defaultMaxLevel());
|
||||||
hasChange = true;
|
hasChange = true;
|
||||||
}
|
}
|
||||||
|
|
@ -191,11 +194,11 @@ public class EnchantmentApi {
|
||||||
|
|
||||||
String itemPath = basePath + ".item";
|
String itemPath = basePath + ".item";
|
||||||
String bookPath = basePath + ".book";
|
String bookPath = basePath + ".book";
|
||||||
if(override || !defaultConfig.isSet(itemPath)){
|
if (override || !defaultConfig.isSet(itemPath)) {
|
||||||
defaultConfig.set(itemPath, rarity.getItemValue());
|
defaultConfig.set(itemPath, rarity.getItemValue());
|
||||||
hasChange = true;
|
hasChange = true;
|
||||||
}
|
}
|
||||||
if(override || !defaultConfig.isSet(bookPath)){
|
if (override || !defaultConfig.isSet(bookPath)) {
|
||||||
defaultConfig.set(bookPath, rarity.getBookValue());
|
defaultConfig.set(bookPath, rarity.getBookValue());
|
||||||
hasChange = true;
|
hasChange = true;
|
||||||
}
|
}
|
||||||
|
|
@ -207,9 +210,9 @@ public class EnchantmentApi {
|
||||||
* Prepare a task to save custom recipe configuration.
|
* Prepare a task to save custom recipe configuration.
|
||||||
*/
|
*/
|
||||||
private static void prepareSaveTask() {
|
private static void prepareSaveTask() {
|
||||||
if(saveChangeTask != null) return;
|
if (saveChangeTask != null) return;
|
||||||
|
|
||||||
saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{
|
saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> {
|
||||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||||
saveChangeTask = null;
|
saveChangeTask = null;
|
||||||
});
|
});
|
||||||
|
|
@ -217,17 +220,19 @@ 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) {
|
||||||
CAEnchantmentRegistry.getInstance().getOptimisedGetOperators().add(operation);
|
CAEnchantmentRegistry.getInstance().getOptimisedGetOperators().add(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
||||||
CAEnchantmentRegistry.getInstance().getOptimisedCleanOperators().add(operation);
|
CAEnchantmentRegistry.getInstance().getOptimisedCleanOperators().add(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class BukkitEnchantBulkOperation implements BulkGetEnchantOperation, Bulk
|
||||||
addEnchantment(enchantmentMap, enchantment, level)
|
addEnchantment(enchantmentMap, enchantment, level)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if(!isBook || ConfigOptions.INSTANCE.getAddBookEnchantmentAsStoredEnchantment()){
|
if (!isBook || ConfigOptions.INSTANCE.getAddBookEnchantmentAsStoredEnchantment()) {
|
||||||
item.getEnchantments().forEach((enchantment, level) ->
|
item.getEnchantments().forEach((enchantment, level) ->
|
||||||
addEnchantment(enchantmentMap, enchantment, level)
|
addEnchantment(enchantmentMap, enchantment, level)
|
||||||
);
|
);
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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,13 +41,14 @@ 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;
|
||||||
|
|
||||||
this.packetManager = packetManager;
|
this.packetManager = packetManager;
|
||||||
init();
|
init();
|
||||||
|
|
@ -282,7 +283,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||||
lore.add("§7Even if cost is displayed as §aGreen§7:");
|
lore.add("§7Even if cost is displayed as §aGreen§7:");
|
||||||
lore.add("§7If the player do not have the required xp level, the action will not be completable.");
|
lore.add("§7If the player do not have the required xp level, the action will not be completable.");
|
||||||
|
|
||||||
if(!this.packetManager.getCanSetInstantBuild()){
|
if (!this.packetManager.getCanSetInstantBuild()) {
|
||||||
lore.add("");
|
lore.add("");
|
||||||
lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a newer version of this plugin for this to work.");
|
lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a newer version of this plugin for this to work.");
|
||||||
lore.add("§cCurrently ProtocoLib is not detected.");
|
lore.add("§cCurrently ProtocoLib is not detected.");
|
||||||
|
|
@ -346,7 +347,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||||
pane.bindItem('h', allowHexColorItem);
|
pane.bindItem('h', allowHexColorItem);
|
||||||
|
|
||||||
// True if player could place color
|
// True if player could place color
|
||||||
if(ConfigOptions.INSTANCE.getRenameColorPossible()){
|
if (ConfigOptions.INSTANCE.getRenameColorPossible()) {
|
||||||
// use permission for color
|
// use permission for color
|
||||||
GuiItem permissionNeededItem = this.permissionNeededForColor.getItem();
|
GuiItem permissionNeededItem = this.permissionNeededForColor.getItem();
|
||||||
pane.bindItem('p', permissionNeededItem);
|
pane.bindItem('p', permissionNeededItem);
|
||||||
|
|
@ -354,7 +355,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||||
// using color cost
|
// using color cost
|
||||||
GuiItem useColorCostItem = this.useOfColorCost.getItem(Material.EXPERIENCE_BOTTLE, "Use color");
|
GuiItem useColorCostItem = this.useOfColorCost.getItem(Material.EXPERIENCE_BOTTLE, "Use color");
|
||||||
pane.bindItem('P', useColorCostItem);
|
pane.bindItem('P', useColorCostItem);
|
||||||
}else{
|
} else {
|
||||||
pane.bindItem('p', this.noPermissionNeededItem);
|
pane.bindItem('p', this.noPermissionNeededItem);
|
||||||
pane.bindItem('P', this.noColorCostItem);
|
pane.bindItem('P', this.noColorCostItem);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
// Load default configuration
|
// Load default configuration
|
||||||
if (!ConfigHolder.loadDefaultConfig()) {
|
if (!ConfigHolder.loadDefaultConfig()) {
|
||||||
logger.log(Level.SEVERE,"could not load default config.")
|
logger.log(Level.SEVERE, "could not load default config.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,10 +122,10 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
// Load other thing later.
|
// Load other thing later.
|
||||||
// It is so other dependent plugins can implement there event listener before we fire them.
|
// It is so other dependent plugins can implement there event listener before we fire them.
|
||||||
DependencyManager.scheduler.scheduleGlobally(this, {loadEnchantmentSystem()})
|
DependencyManager.scheduler.scheduleGlobally(this, { loadEnchantmentSystem() })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadEnchantmentSystem(){
|
private fun loadEnchantmentSystem() {
|
||||||
// Register enchantments
|
// Register enchantments
|
||||||
CAEnchantmentRegistry.getInstance().registerBukkit()
|
CAEnchantmentRegistry.getInstance().registerBukkit()
|
||||||
DependencyManager.registerEnchantments()
|
DependencyManager.registerEnchantments()
|
||||||
|
|
@ -135,7 +135,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
if (!ConfigHolder.loadNonDefaultConfig()) {
|
if (!ConfigHolder.loadNonDefaultConfig()) {
|
||||||
logger.log(Level.SEVERE,"could not load non default config.")
|
logger.log(Level.SEVERE, "could not load non default config.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
@ -41,10 +41,11 @@ object DataPackDependency {
|
||||||
for (packName in enabledDatapack) {
|
for (packName in enabledDatapack) {
|
||||||
// Handling of pack name is horrible: it is based on file name
|
// Handling of pack name is horrible: it is based on file name
|
||||||
// So if someone rename a datapack it will make me sad
|
// So if someone rename a datapack it will make me sad
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +63,7 @@ object DataPackDependency {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handlePack(pack: String){
|
private fun handlePack(pack: String) {
|
||||||
CustomAnvil.instance.logger.info("trying to handle datapack $pack")
|
CustomAnvil.instance.logger.info("trying to handle datapack $pack")
|
||||||
handlePackInitialConfig(pack)
|
handlePackInitialConfig(pack)
|
||||||
writeDefaultByNamespace(pack)
|
writeDefaultByNamespace(pack)
|
||||||
|
|
@ -72,7 +73,7 @@ object DataPackDependency {
|
||||||
private fun handlePackInitialConfig(pack: String) {
|
private fun handlePackInitialConfig(pack: String) {
|
||||||
val defConfig = ConfigHolder.DEFAULT_CONFIG
|
val defConfig = ConfigHolder.DEFAULT_CONFIG
|
||||||
val version = LATEST_VERSION[pack]
|
val version = LATEST_VERSION[pack]
|
||||||
if(version == null) {
|
if (version == null) {
|
||||||
throw RuntimeException("The pack $pack has no latest version hard coded in the plugin")
|
throw RuntimeException("The pack $pack has no latest version hard coded in the plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,7 +258,7 @@ object DataPackDependency {
|
||||||
val conflict = manager.conflictList.find {
|
val conflict = manager.conflictList.find {
|
||||||
it.name.equals(group, ignoreCase = true)
|
it.name.equals(group, ignoreCase = true)
|
||||||
}
|
}
|
||||||
if(conflict == null) {
|
if (conflict == null) {
|
||||||
// This should not happen as configuration section
|
// This should not happen as configuration section
|
||||||
CustomAnvil.instance.logger.severe("Could not find $group while its configuration section exist... this should NOT happen")
|
CustomAnvil.instance.logger.severe("Could not find $group while its configuration section exist... this should NOT happen")
|
||||||
return false
|
return false
|
||||||
|
|
@ -265,7 +266,7 @@ object DataPackDependency {
|
||||||
|
|
||||||
val key = NamespacedKey.fromString(ench)!!
|
val key = NamespacedKey.fromString(ench)!!
|
||||||
val enchant = EnchantmentApi.getByKey(key)
|
val enchant = EnchantmentApi.getByKey(key)
|
||||||
if (enchant == null){
|
if (enchant == null) {
|
||||||
CustomAnvil.instance.logger.severe("Could not find enchantment $ench while configuring pack a datapack")
|
CustomAnvil.instance.logger.severe("Could not find enchantment $ench while configuring pack a datapack")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -294,7 +295,7 @@ object DataPackDependency {
|
||||||
|
|
||||||
private fun writeDefaultByNamespace(namespace: String) {
|
private fun writeDefaultByNamespace(namespace: String) {
|
||||||
for (enchantment in EnchantmentApi.getRegisteredEnchantments().values) {
|
for (enchantment in EnchantmentApi.getRegisteredEnchantments().values) {
|
||||||
if(!enchantment.key.namespace.equals(namespace, ignoreCase = true)) continue
|
if (!enchantment.key.namespace.equals(namespace, ignoreCase = true)) continue
|
||||||
|
|
||||||
CustomAnvil.log("Writing default for ${enchantment.key}")
|
CustomAnvil.log("Writing default for ${enchantment.key}")
|
||||||
EnchantmentApi.writeDefaultConfig(enchantment, false)
|
EnchantmentApi.writeDefaultConfig(enchantment, false)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -36,4 +36,4 @@ class ProtocoLibWrapper: PacketManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@ 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) {
|
||||||
val player = event.player
|
val player = event.player
|
||||||
if(event.inventory !is AnvilInventory) return
|
if (event.inventory !is AnvilInventory) return
|
||||||
if(player is Player && GameMode.CREATIVE != player.gameMode){
|
if (player is Player && GameMode.CREATIVE != player.gameMode) {
|
||||||
packetManager.setInstantBuild(player, false)
|
packetManager.setInstantBuild(player, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue