mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Added javadoc to event
also remove extra Event in one of the event
This commit is contained in:
parent
6029193f6e
commit
87e837a4b1
8 changed files with 198 additions and 26 deletions
|
|
@ -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.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>
|
||||
* If you want to listen this event
|
||||
* you will need to register the listener on your plugin onEnable or earlier
|
||||
* <p>
|
||||
* Custom enchantments may be registered later but may cause issue if registered too later
|
||||
* (after configuration loading phase. see {@link CAConfigReadyEvent})
|
||||
* <p>
|
||||
* 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();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This event being cancelled will make CustomAnvil abort the click on result process.
|
||||
* <p>
|
||||
* Most of the time you would likely need {@link CAPreAnvilBypassEvent} or {@link CAEarlyPreAnvilBypassEvent}
|
||||
* for this event to be useful.
|
||||
* <p>
|
||||
* 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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>
|
||||
* This event will always get called when CustomAnvil need to handle
|
||||
* <p>
|
||||
* This event being cancelled will make CustomAnvil abort the anvil process.
|
||||
* <p>
|
||||
* You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This event being cancelled will make CustomAnvil abort the anvil process.
|
||||
* <p>
|
||||
* You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful.
|
||||
* <p>
|
||||
* 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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>
|
||||
* You may also want to check {@link CAClickResultBypassEvent},
|
||||
* {@link CAPreAnvilBypassEvent}
|
||||
* and {@link CAEarlyPreAnvilBypassEvent} for your use case
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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.
|
||||
* <h3>Important note:</h3>
|
||||
* the final price are re calculated on click for the following use case:
|
||||
* <ul>
|
||||
* <li>Custom craft</li>
|
||||
* <li>Unit repair</li>
|
||||
* <li>Lore edit</li>
|
||||
* </ul>
|
||||
* This value will be used as final price for:
|
||||
* <li>Item merge</li>
|
||||
* <li>Item rename</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return The current cost.
|
||||
*/
|
||||
public int getLevelCost() {
|
||||
return levelCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level cost displayed on the anvil.
|
||||
* <h3>Important note:</h3>
|
||||
* the final price are re calculated on click for the following use case:
|
||||
* <ul>
|
||||
* <li>Custom craft</li>
|
||||
* <li>Unit repair</li>
|
||||
* <li>Lore edit</li>
|
||||
* </ul>
|
||||
* This value will be used as final price for:
|
||||
* <li>Item merge</li>
|
||||
* <li>Item rename</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param levelCost The new cost.
|
||||
*/
|
||||
public void setLevelCost(int levelCost) {
|
||||
this.levelCost = levelCost;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue