diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/CAConfigReadyEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/CAConfigReadyEvent.java index 24691db..67d27a8 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/CAConfigReadyEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/CAConfigReadyEvent.java @@ -3,6 +3,23 @@ package xyz.alexcrea.cuanvil.api.event; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +/** + * Called when the configuration of CustomAnvil is ready. + * It is called either on the plugin startup or on the plugin config reload. + *

+ * If you want to listen to the first trigger of this event (first configuration load. aka plugin load) + * you will need to register the listener on your plugin onEnable or earlier + *

+ * This event indicate that can start to register your recipes, item groups and conflicts. + * The vanilla and custom enchantments should already have been provided to CustomAnvil. + * Configuration can be changed any time after this event is triggered but never before. + *

+ * use {@link xyz.alexcrea.cuanvil.api.ConflictAPI ConflictApi}, + * {@link xyz.alexcrea.cuanvil.gui.config.global.CustomRecipeConfigGui CustomRecipeConfigGui}, + * {@link xyz.alexcrea.cuanvil.api.MaterialGroupApi MaterialGroupApi} + * and {@link xyz.alexcrea.cuanvil.api.UnitRepairApi UnitRepairApi} + * to add/remove/edit configurations + */ public class CAConfigReadyEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/CAEnchantRegistryReadyEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/CAEnchantRegistryReadyEvent.java index 3e2fdf8..3ffe372 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/CAEnchantRegistryReadyEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/CAEnchantRegistryReadyEvent.java @@ -3,6 +3,17 @@ package xyz.alexcrea.cuanvil.api.event; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +/** + * Called when custom anvil is ready to accept registration on custom enchantment. + *

+ * If you want to listen this event + * you will need to register the listener on your plugin onEnable or earlier + *

+ * Custom enchantments may be registered later but may cause issue if registered too later + * (after configuration loading phase. see {@link CAConfigReadyEvent}) + *

+ * use {@link xyz.alexcrea.cuanvil.api.EnchantmentApi EnchantmentApi} to register and unregister your custom enchantments + */ public class CAEnchantRegistryReadyEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java index 968b1bf..a27c65e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java @@ -6,6 +6,19 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; +/** + * Called before custom anvil process the click on the result on the anvil inventory. + *

+ * This event is called after checking that the inventory is an anvil inventory and that the click is on the result slot + * but before checking if the player has the custom anvil affected permission. + *

+ * This event being cancelled will make CustomAnvil abort the click on result process. + *

+ * Most of the time you would likely need {@link CAPreAnvilBypassEvent} or {@link CAEarlyPreAnvilBypassEvent} + * for this event to be useful. + *

+ * There is also {@link CATreatAnvilResultEvent} that may be better for some use case. + */ public class CAClickResultBypassEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); @@ -34,6 +47,11 @@ public class CAClickResultBypassEvent extends Event implements Cancellable { @NotNull private final InventoryClickEvent event; + /** + * Get the bukkit inventory click event causing to this event + * + * @return The click event causing to this event + */ @NotNull public InventoryClickEvent getEvent() { return event; diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java new file mode 100644 index 0000000..2fbd275 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java @@ -0,0 +1,63 @@ +package xyz.alexcrea.cuanvil.api.event.listener; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.jetbrains.annotations.NotNull; + +/** + * Called before custom anvil process the prepare anvil event. + *

+ * This event will always get called when CustomAnvil need to handle + *

+ * This event being cancelled will make CustomAnvil abort the anvil process. + *

+ * You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. + *

+ * It is also recommended that you read about {@link CAPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} + * as your use case may be more prone to use theses. + */ +public class CAEarlyPreAnvilBypassEvent extends Event implements Cancellable { + + private static final HandlerList HANDLERS = new HandlerList(); + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + private boolean cancelled = false; + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + private final PrepareAnvilEvent event; + + /** + * Get the bukkit pre anvil event causing this event + * + * @return The pre anvil event causing to this event + */ + @NotNull + public PrepareAnvilEvent getEvent() { + return event; + } + + public CAEarlyPreAnvilBypassEvent(@NotNull PrepareAnvilEvent event) { + this.event = event; + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEventEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEventEvent.java deleted file mode 100644 index 1213c80..0000000 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEventEvent.java +++ /dev/null @@ -1,24 +0,0 @@ -package xyz.alexcrea.cuanvil.api.event.listener; - -import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.PrepareAnvilEvent; -import org.jetbrains.annotations.NotNull; - -public class CAEarlyPreAnvilBypassEventEvent extends CAPreAnvilBypassEvent { - - private static final HandlerList HANDLERS = new HandlerList(); - - public static HandlerList getHandlerList() { - return HANDLERS; - } - - @Override - public @NotNull HandlerList getHandlers() { - return HANDLERS; - } - - public CAEarlyPreAnvilBypassEventEvent(@NotNull PrepareAnvilEvent event) { - super(event); - } - -} diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java index 43dfbb9..18334e3 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java @@ -6,6 +6,21 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.inventory.PrepareAnvilEvent; import org.jetbrains.annotations.NotNull; +/** + * Called before custom anvil process the prepare anvil event. + *

+ * This event is called after {@link CAEarlyPreAnvilBypassEvent}, + * after checking that there is at least an item on the left slot + * and after checking if any of the 2 item is marked as immutable + * but before checking if the player has the custom anvil affected permission. + *

+ * This event being cancelled will make CustomAnvil abort the anvil process. + *

+ * You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. + *

+ * It is also recommended that you read about {@link CAEarlyPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} + * as your use case may be more prone to use theses. + */ public class CAPreAnvilBypassEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); @@ -34,6 +49,11 @@ public class CAPreAnvilBypassEvent extends Event implements Cancellable { @NotNull private final PrepareAnvilEvent event; + /** + * Get the bukkit pre anvil event causing this event + * + * @return The pre anvil event causing this event + */ @NotNull public PrepareAnvilEvent getEvent() { return event; diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java index c2e8fcd..1675d1a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java @@ -8,6 +8,17 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.util.AnvilUseType; +/** + * Called after custom anvil processed the click on the result on the anvil inventory. + * This event should be used to modify the result of an anvil use. + *

+ * You may also want to check {@link CAClickResultBypassEvent}, + * {@link CAPreAnvilBypassEvent} + * and {@link CAEarlyPreAnvilBypassEvent} for your use case + *

+ * A null result will cancel this pre anvil event + */ +@SuppressWarnings("unused") public class CATreatAnvilResultEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,26 +49,82 @@ public class CATreatAnvilResultEvent extends Event { this.levelCost = levelCost; } + /** + * Get the bukkit inventory click event causing to this event. + * + * @return The click event causing to this event. + */ public @NotNull PrepareAnvilEvent getEvent() { return event; } + /** + * Get the type of use source of the result. + * + * @return The craft use type. + */ public AnvilUseType getUseType() { return useType; } + /** + * Get the current result + *

+ * note that it will not be null unless another listener previously set it to null. + * + * @return The current result. + */ public @Nullable ItemStack getResult() { return result; } + /** + * Set the current result + *

+ * note that a null result will cancel this anvil use. + * + * @param result The new result + */ public void setResult(@Nullable ItemStack result) { this.result = result; } + /** + * Get the level cost displayed on the anvil. + *

Important note:

+ * the final price are re calculated on click for the following use case: + * + * This value will be used as final price for: + *
  • Item merge
  • + *
  • Item rename
  • + * + * + * @return The current cost. + */ public int getLevelCost() { return levelCost; } + /** + * Set the level cost displayed on the anvil. + *

    Important note:

    + * the final price are re calculated on click for the following use case: + * + * This value will be used as final price for: + *
  • Item merge
  • + *
  • Item rename
  • + * + * + * @param levelCost The new cost. + */ public void setLevelCost(int levelCost) { this.levelCost = levelCost; } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index cb895bf..09980b5 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -9,7 +9,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent -import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEventEvent +import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAPreAnvilBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResultEvent import xyz.alexcrea.cuanvil.config.ConfigHolder @@ -145,7 +145,7 @@ object DependencyManager { private fun earlyUnsafeTryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean { // Run the event - val bypassEvent = CAEarlyPreAnvilBypassEventEvent(event) + val bypassEvent = CAEarlyPreAnvilBypassEvent(event) Bukkit.getPluginManager().callEvent(bypassEvent) var bypass = bypassEvent.isCancelled