We only need one ModifyEvent

Move PotionColor into its own Class
This commit is contained in:
Sn0wStorm
2019-10-14 21:02:59 +02:00
parent b761e83882
commit 595df50ca5
9 changed files with 315 additions and 286 deletions
@@ -1,50 +0,0 @@
package com.dre.brewery.api.events.brew;
import com.dre.brewery.Brew;
import com.dre.brewery.lore.BrewLore;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
/*
* A Brew has been created or modified
* Usually happens on Filling from cauldron, distilling and aging.
* Final Modifications to the Brew or the PotionMeta can be done now
*/
public class BrewModifiedEvent extends BrewEvent {
private static final HandlerList handlers = new HandlerList();
private final Type type;
public BrewModifiedEvent(Brew brew, ItemMeta meta, Type type) {
super(brew, meta);
this.type = type;
}
public Type getType() {
return type;
}
public BrewLore getLore() {
return new BrewLore(getBrew(), (PotionMeta) getItemMeta());
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public enum Type {
CREATE, // A new Brew is created with arbitrary ways, like the create command
FILL, // Filled from a Cauldron into a new Brew
DISTILL, // Distilled in the Brewing stand
AGE, // Aged in a Barrel
UNLABEL, // Unlabeling Brew with command
STATIC, // Making Brew static with command
UNKNOWN // Unknown modification, unused
}
}
@@ -1,20 +1,25 @@
package com.dre.brewery.api.events.brew;
import com.dre.brewery.Brew;
import com.dre.brewery.lore.BrewLore;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
/*
* A Brew is starting to be created or modified
* A Brew has been created or modified
* Usually happens on Filling from cauldron, distilling and aging.
* Modifications to the Brew or the PotionMeta can be done now
* Cancelling reverts the Brew to the state it was before the modification
*/
public class BrewBeginModifyEvent extends BrewEvent implements Cancellable {
public class BrewModifyEvent extends BrewEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Type type;
private boolean cancelled;
public BrewBeginModifyEvent(Brew brew, ItemMeta meta, Type type) {
public BrewModifyEvent(Brew brew, ItemMeta meta, Type type) {
super(brew, meta);
this.type = type;
}
@@ -23,11 +28,19 @@ public class BrewBeginModifyEvent extends BrewEvent implements Cancellable {
return type;
}
public BrewLore getLore() {
return new BrewLore(getBrew(), (PotionMeta) getItemMeta());
}
@Override
public boolean isCancelled() {
return cancelled;
}
/*
* Setting the Event cancelled cancels all modificatons to the brew.
* Modifications to the Brew or ItemMeta will not be applied
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;