More features for BrewModifyEvent

This commit is contained in:
Sn0wStorm
2019-10-12 16:07:02 +02:00
parent d355966d42
commit b761e83882
10 changed files with 116 additions and 34 deletions
@@ -3,19 +3,19 @@ package com.dre.brewery.api.events.brew;
import com.dre.brewery.Brew;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
/*
* A Brew is created or modified
* A Brew is starting to be created or modified
* Usually happens on Filling from cauldron, distilling and aging.
*/
public class BrewModifyEvent extends BrewEvent implements Cancellable {
public class BrewBeginModifyEvent extends BrewEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Type type;
private boolean cancelled;
//private List<Consumer<Brew>> fcts;
public BrewModifyEvent(Brew brew, Type type) {
super(brew);
public BrewBeginModifyEvent(Brew brew, ItemMeta meta, Type type) {
super(brew, meta);
this.type = type;
}
@@ -23,10 +23,6 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
return type;
}
/*public void addModification(Consumer<Brew> predicate) {
fcts.add(predicate);
}*/
@Override
public boolean isCancelled() {
return cancelled;
@@ -47,7 +43,7 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable {
}
public enum Type {
//CREATE, // A new Brew is created with arbitrary ways, like the create command
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
@@ -1,14 +1,11 @@
package com.dre.brewery.api.events.brew;
import com.dre.brewery.BEffect;
import com.dre.brewery.BPlayer;
import com.dre.brewery.Brew;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.potion.PotionEffect;
import java.util.List;
import org.bukkit.inventory.meta.ItemMeta;
/*
* A Player Drinks a Brew
@@ -23,8 +20,8 @@ public class BrewDrinkEvent extends BrewEvent implements Cancellable {
private int quality;
private boolean cancelled;
public BrewDrinkEvent(Brew brew, Player player, BPlayer bPlayer) {
super(brew);
public BrewDrinkEvent(Brew brew, ItemMeta meta, Player player, BPlayer bPlayer) {
super(brew, meta);
this.player = player;
this.bPlayer = bPlayer;
alc = brew.calcAlcohol();
@@ -2,16 +2,22 @@ package com.dre.brewery.api.events.brew;
import com.dre.brewery.Brew;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.ItemMeta;
public abstract class BrewEvent extends Event {
protected final Brew brew;
protected final ItemMeta meta;
public BrewEvent(Brew brew) {
public BrewEvent(Brew brew, ItemMeta meta) {
this.brew = brew;
this.meta = meta;
}
public Brew getBrew() {
return brew;
}
public ItemMeta getItemMeta() {
return meta;
}
}
@@ -0,0 +1,50 @@
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
}
}