3434import org .bukkit .event .EventPriority ;
3535import org .bukkit .event .inventory .BrewEvent ;
3636import org .bukkit .event .inventory .InventoryClickEvent ;
37+ import org .bukkit .event .inventory .InventoryMoveItemEvent ;
3738import org .bukkit .event .inventory .InventoryType ;
3839
39- import java .util .HashSet ;
40+ import java .util .HashMap ;
4041import java .util .Iterator ;
41- import java .util .Set ;
42+ import java .util .Map ;
4243
4344
4445public class BrewingSuperHeated extends SimpleAdaptation <BrewingSuperHeated .Config > {
45- private final Set <Block > activeStands = new HashSet <>();
46+
47+ private static final int MAX_CHECKS_BEFORE_REMOVE = 20 ;
48+ private final Map <Block , Integer > activeStands = new HashMap <>();
4649
4750 public BrewingSuperHeated () {
4851 super ("brewing-super-heated" );
@@ -71,14 +74,26 @@ public double getFireBoost(double factor) {
7174 return (getConfig ().fireMultiplier ) * (getConfig ().multiplierFactor * factor );
7275 }
7376
77+ @ EventHandler (priority = EventPriority .HIGHEST )
78+ public void on (InventoryMoveItemEvent e ) {
79+ if (e .isCancelled ()) {
80+ return ;
81+ }
82+ J .s (() -> {
83+ if (e .getDestination ().getType ().equals (InventoryType .BREWING )) {
84+ activeStands .put (e .getDestination ().getLocation ().getBlock (), MAX_CHECKS_BEFORE_REMOVE );
85+ }
86+ });
87+ }
88+
7489 @ EventHandler (priority = EventPriority .HIGHEST )
7590 public void on (BrewEvent e ) {
7691 if (e .isCancelled ()) {
7792 return ;
7893 }
7994 J .s (() -> {
8095 if (((BrewingStand ) e .getBlock ().getState ()).getBrewingTime () > 0 ) {
81- activeStands .add (e .getBlock ());
96+ activeStands .put (e .getBlock (), MAX_CHECKS_BEFORE_REMOVE );
8297 }
8398 });
8499 }
@@ -89,7 +104,7 @@ public void on(InventoryClickEvent e) {
89104 return ;
90105 }
91106 if (e .getView ().getTopInventory ().getType ().equals (InventoryType .BREWING )) {
92- activeStands .add (e .getView ().getTopInventory ().getLocation ().getBlock ());
107+ activeStands .put (e .getView ().getTopInventory ().getLocation ().getBlock (), MAX_CHECKS_BEFORE_REMOVE );
93108 }
94109 }
95110
@@ -100,7 +115,7 @@ public void onTick() {
100115 return ;
101116 }
102117
103- Iterator <Block > it = activeStands .iterator ();
118+ Iterator <Block > it = activeStands .keySet (). iterator ();
104119
105120 J .s (() -> {
106121 while (it .hasNext ()) {
@@ -110,9 +125,13 @@ public void onTick() {
110125 if (b .getBrewingTime () <= 0 ) {
111126 J .s (() -> {
112127 BrewingStand bb = (BrewingStand ) s .getBlock ().getState ();
113-
114128 if (bb .getBrewingTime () <= 0 ) {
115- activeStands .remove (b .getBlock ());
129+ if (activeStands .get (b .getBlock ()) == 0 ) {
130+ activeStands .remove (b .getBlock ());
131+ }
132+ if (activeStands .containsKey (b .getBlock ())) {
133+ activeStands .put (b .getBlock (), activeStands .get (b .getBlock ()) - 1 );
134+ }
116135 }
117136 });
118137 continue ;
0 commit comments