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
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)
})

View file

@ -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")
}

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
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.
}

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 EnchantmentApi() {}
private EnchantmentApi() {
}
/**
* Register an enchantment.
@ -37,14 +38,14 @@ public class EnchantmentApi {
* @param enchantment The enchantment to register
* @return True if successful.
*/
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){
if(!CAEnchantmentRegistry.getInstance().register(enchantment)) return false;
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment) {
if (!CAEnchantmentRegistry.getInstance().register(enchantment)) return false;
// Add enchantment to gui.
if(EnchantCostConfigGui.getInstance() != null){
if (EnchantCostConfigGui.getInstance() != null) {
EnchantCostConfigGui.getInstance().updateValueForGeneric(enchantment, true);
}
if(EnchantLimitConfigGui.getInstance() != null){
if (EnchantLimitConfigGui.getInstance() != null) {
EnchantLimitConfigGui.getInstance().updateValueForGeneric(enchantment, true);
}
@ -61,8 +62,8 @@ public class EnchantmentApi {
* @param defaultRarity The default rarity of the provided enchantment
* @return True if successful.
*/
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity){
if(defaultRarity == null)
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity) {
if (defaultRarity == null)
return registerEnchantment(new CABukkitEnchantment(enchantment));
return registerEnchantment(new CABukkitEnchantment(enchantment, defaultRarity));
@ -76,7 +77,7 @@ public class EnchantmentApi {
* @param enchantment The enchantment to register
* @return True if successful.
*/
public static boolean registerEnchantment(@NotNull Enchantment enchantment){
public static boolean registerEnchantment(@NotNull Enchantment enchantment) {
return registerEnchantment(new CABukkitEnchantment(enchantment));
}
@ -86,12 +87,12 @@ public class EnchantmentApi {
* @param enchantment The enchantment to unregister
* @return True if successful.
*/
public static boolean unregisterEnchantment(@Nullable CAEnchantment enchantment){
public static boolean unregisterEnchantment(@Nullable CAEnchantment enchantment) {
// Remove from gui
if(EnchantCostConfigGui.getInstance() != null){
if (EnchantCostConfigGui.getInstance() != null) {
EnchantCostConfigGui.getInstance().removeGeneric(enchantment);
}
if(EnchantLimitConfigGui.getInstance() != null){
if (EnchantLimitConfigGui.getInstance() != null) {
EnchantLimitConfigGui.getInstance().removeGeneric(enchantment);
}
@ -104,7 +105,7 @@ public class EnchantmentApi {
* @param key The enchantment key to unregister
* @return True if successful.
*/
public static boolean unregisterEnchantment(@NotNull NamespacedKey key){
public static boolean unregisterEnchantment(@NotNull NamespacedKey key) {
CAEnchantment enchantment = CAEnchantment.getByKey(key);
return unregisterEnchantment(enchantment);
}
@ -115,8 +116,8 @@ public class EnchantmentApi {
* @param enchantment The enchantment to unregister
* @return True if successful.
*/
public static boolean unregisterEnchantment(@NotNull Enchantment enchantment){
return unregisterEnchantment(enchantment.getKeyOrThrow());
public static boolean unregisterEnchantment(@NotNull Enchantment enchantment) {
return unregisterEnchantment(enchantment.getKey());
}
/**
@ -126,7 +127,7 @@ public class EnchantmentApi {
* @return The custom anvil enchantment of this key. null if not found.
*/
@Nullable
public static CAEnchantment getByKey(@NotNull NamespacedKey key){
public static CAEnchantment getByKey(@NotNull NamespacedKey key) {
return CAEnchantment.getByKey(key);
}
@ -139,7 +140,7 @@ public class EnchantmentApi {
*/
@Deprecated(since = "1.6.3")
@Nullable
public static CAEnchantment getByName(@NotNull String name){
public static CAEnchantment getByName(@NotNull String name) {
return CAEnchantment.getByName(name);
}
@ -149,29 +150,31 @@ public class EnchantmentApi {
* @param name The name used to fetch
* @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);
}
/**
* Get every registered custom anvil enchantments.
*
* @return An immutable map of enchantment key as map key and custom anvil enchantment as value.
*/
@NotNull
public static Map<NamespacedKey, CAEnchantment> getRegisteredEnchantments(){
public static Map<NamespacedKey, CAEnchantment> getRegisteredEnchantments() {
return Collections.unmodifiableMap(CAEnchantmentRegistry.getInstance().registeredEnchantments());
}
/**
* 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.
*/
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override){
public static boolean writeDefaultConfig(CAEnchantment enchantment, boolean override) {
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
if(tryWriteDefaultConfig(config, enchantment, override)){
if (tryWriteDefaultConfig(config, enchantment, override)) {
prepareSaveTask();
}
return true;
@ -181,7 +184,7 @@ public class EnchantmentApi {
boolean hasChange = false;
String levelPath = "enchant_limits." + enchantment.getKey();
if(override || !defaultConfig.isSet(levelPath)){
if (override || !defaultConfig.isSet(levelPath)) {
defaultConfig.set(levelPath, enchantment.defaultMaxLevel());
hasChange = true;
}
@ -191,11 +194,11 @@ public class EnchantmentApi {
String itemPath = basePath + ".item";
String bookPath = basePath + ".book";
if(override || !defaultConfig.isSet(itemPath)){
if (override || !defaultConfig.isSet(itemPath)) {
defaultConfig.set(itemPath, rarity.getItemValue());
hasChange = true;
}
if(override || !defaultConfig.isSet(bookPath)){
if (override || !defaultConfig.isSet(bookPath)) {
defaultConfig.set(bookPath, rarity.getBookValue());
hasChange = true;
}
@ -207,9 +210,9 @@ public class EnchantmentApi {
* Prepare a task to save custom recipe configuration.
*/
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);
saveChangeTask = null;
});
@ -217,17 +220,19 @@ public class EnchantmentApi {
/**
* Add a bulk get operator.
*
* @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);
}
/**
* Add a bulk clean operator.
*
* @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);
}

View file

@ -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) {

View file

@ -25,7 +25,7 @@ public class BukkitEnchantBulkOperation implements BulkGetEnchantOperation, Bulk
addEnchantment(enchantmentMap, enchantment, level)
);
}
if(!isBook || ConfigOptions.INSTANCE.getAddBookEnchantmentAsStoredEnchantment()){
if (!isBook || ConfigOptions.INSTANCE.getAddBookEnchantmentAsStoredEnchantment()) {
item.getEnchantments().forEach((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) {
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;
}

View file

@ -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

View file

@ -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",

View file

@ -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,13 +41,14 @@ 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;
if (INSTANCE == null) INSTANCE = this;
this.packetManager = packetManager;
init();
@ -282,7 +283,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
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.");
if(!this.packetManager.getCanSetInstantBuild()){
if (!this.packetManager.getCanSetInstantBuild()) {
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("§cCurrently ProtocoLib is not detected.");
@ -346,7 +347,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
pane.bindItem('h', allowHexColorItem);
// True if player could place color
if(ConfigOptions.INSTANCE.getRenameColorPossible()){
if (ConfigOptions.INSTANCE.getRenameColorPossible()) {
// use permission for color
GuiItem permissionNeededItem = this.permissionNeededForColor.getItem();
pane.bindItem('p', permissionNeededItem);
@ -354,7 +355,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
// using color cost
GuiItem useColorCostItem = this.useOfColorCost.getItem(Material.EXPERIENCE_BOTTLE, "Use color");
pane.bindItem('P', useColorCostItem);
}else{
} else {
pane.bindItem('p', this.noPermissionNeededItem);
pane.bindItem('P', this.noColorCostItem);
}

View file

@ -105,7 +105,7 @@ open class CustomAnvil : JavaPlugin() {
// Load default configuration
if (!ConfigHolder.loadDefaultConfig()) {
logger.log(Level.SEVERE,"could not load default config.")
logger.log(Level.SEVERE, "could not load default config.")
return
}
@ -122,10 +122,10 @@ open class CustomAnvil : JavaPlugin() {
// Load other thing later.
// 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
CAEnchantmentRegistry.getInstance().registerBukkit()
DependencyManager.registerEnchantments()
@ -135,7 +135,7 @@ open class CustomAnvil : JavaPlugin() {
// Load config
if (!ConfigHolder.loadNonDefaultConfig()) {
logger.log(Level.SEVERE,"could not load non default config.")
logger.log(Level.SEVERE, "could not load non default config.")
return
}
@ -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

View file

@ -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)

View file

@ -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() {
@ -41,10 +41,11 @@ object DataPackDependency {
for (packName in enabledDatapack) {
// Handling of pack name is horrible: it is based on file name
// 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)
|| packName.contains("bracken", ignoreCase = true)) {
|| packName.contains("bracken", ignoreCase = true)
) {
handlePack("bracken")
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")
handlePackInitialConfig(pack)
writeDefaultByNamespace(pack)
@ -72,7 +73,7 @@ object DataPackDependency {
private fun handlePackInitialConfig(pack: String) {
val defConfig = ConfigHolder.DEFAULT_CONFIG
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")
}
@ -257,7 +258,7 @@ object DataPackDependency {
val conflict = manager.conflictList.find {
it.name.equals(group, ignoreCase = true)
}
if(conflict == null) {
if (conflict == null) {
// This should not happen as configuration section
CustomAnvil.instance.logger.severe("Could not find $group while its configuration section exist... this should NOT happen")
return false
@ -265,7 +266,7 @@ object DataPackDependency {
val key = NamespacedKey.fromString(ench)!!
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")
return false
}
@ -294,7 +295,7 @@ object DataPackDependency {
private fun writeDefaultByNamespace(namespace: String) {
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}")
EnchantmentApi.writeDefaultConfig(enchantment, false)

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.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

View file

@ -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()
}
}

View file

@ -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

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.
for (enchantment in V5EnchantRegistry.getRegistered()) {
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.keyOrThrow)
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key)
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
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
)
}
}

View file

@ -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

View file

@ -6,15 +6,15 @@ 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){
fun onAnvilClose(event: InventoryCloseEvent) {
val player = event.player
if(event.inventory !is AnvilInventory) return
if(player is Player && GameMode.CREATIVE != player.gameMode){
if (event.inventory !is AnvilInventory) return
if (player is Player && GameMode.CREATIVE != player.gameMode) {
packetManager.setInstantBuild(player, false)
}

View file

@ -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
}