22
33import codes .biscuit .genbucket .GenBucket ;
44import codes .biscuit .genbucket .timers .GenningTimer ;
5+ import codes .biscuit .genbucket .utils .Bucket ;
56import org .bukkit .Location ;
67import org .bukkit .Material ;
78import org .bukkit .block .Block ;
@@ -39,9 +40,10 @@ public void onBlockPlace(BlockPlaceEvent e) {
3940 return ;
4041 }
4142 }
42- if (main .getUtils ().matchBucket (e .getItemInHand ()) != null ) { // Sorry, you can't use it with offhand atm.
43+ Bucket matchedBucket = main .getBucketManager ().matchBucket (e .getItemInHand ());
44+ if (matchedBucket != null ) { // Sorry, you can't use it with offhand atm.
4345 e .setCancelled (true );
44- startGenBucket (main . getUtils (). matchBucket ( e . getItemInHand ()) , e .getPlayer (), e .getBlock (), e .getBlockAgainst ().getFace (e .getBlock ()), e .getItemInHand ());
46+ startGenBucket (matchedBucket , e .getPlayer (), e .getBlock (), e .getBlockAgainst ().getFace (e .getBlock ()), e .getItemInHand ());
4547 }
4648 }
4749
@@ -53,9 +55,12 @@ public void onBucketPlace(PlayerInteractEvent e) {
5355 }
5456 }
5557 if (e .getAction ().equals (Action .RIGHT_CLICK_BLOCK ) && e .getItem () != null && (e .getItem ().getType ().equals (Material .LAVA_BUCKET ) ||
56- e .getItem ().getType ().equals (Material .WATER_BUCKET )) && main .getUtils ().matchBucket (e .getItem ()) != null ) {
57- e .setCancelled (true );
58- startGenBucket (main .getUtils ().matchBucket (e .getItem ()), e .getPlayer (), e .getClickedBlock ().getRelative (e .getBlockFace ()), e .getBlockFace (), e .getItem ());
58+ e .getItem ().getType ().equals (Material .WATER_BUCKET ))) {
59+ Bucket bucket = main .getBucketManager ().matchBucket (e .getItem ());
60+ if (bucket != null ) {
61+ e .setCancelled (true );
62+ startGenBucket (bucket , e .getPlayer (), e .getClickedBlock ().getRelative (e .getBlockFace ()), e .getBlockFace (), e .getItem ());
63+ }
5964 }
6065 }
6166
@@ -79,57 +84,53 @@ private boolean noPlayersNearby(Player p) {
7984 @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
8085 public void onItemDrop (PlayerDropItemEvent e ) {
8186 if (main .getConfigValues ().bucketsDisappearDrop ()) {
82- String bucket = main .getUtils ().matchBucket (e .getItemDrop ().getItemStack ());
83- if (bucket != null && main . getConfigValues (). isBucketInfinite ( bucket )) {
87+ Bucket bucket = main .getBucketManager ().matchBucket (e .getItemDrop ().getItemStack ());
88+ if (bucket != null && bucket . isInfinite ( )) {
8489 e .getItemDrop ().remove ();
8590 }
8691 }
8792 }
8893
89- private void startGenBucket (String bucket , Player p , Block block , BlockFace direction , ItemStack removeItem ) {
94+ private void startGenBucket (Bucket bucket , Player p , Block block , BlockFace direction , ItemStack removeItem ) {
9095 if (main .getHookUtils ().canPlaceHere (p , block .getLocation ()) && noPlayersNearby (p ) && main .getHookUtils ().takeBucketPlaceCost (p , bucket )) {
91- if (( main . getConfigValues (). getBucketDirection ( bucket ). equals ( "HORIZONTAL" ) || main . getConfigValues (). getBucketDirection ( bucket ). equals ( "HORIZONTAL_BY_CHUNK" )) &&
96+ if (bucket . getDirection () == Bucket . Direction . HORIZONTAL &&
9297 (direction .equals (BlockFace .UP ) || direction .equals (BlockFace .DOWN ))) {
9398 if (!main .getConfigValues ().getWrongDirectionMessage ().equals ("" )) {
9499 p .sendMessage (main .getConfigValues ().getWrongDirectionMessage ());
95100 }
96101 return ;
97102 }
98- boolean chunkLimited = false ;
99- switch (main .getConfigValues ().getBucketDirection (bucket )) {
100- case "UPWARDS" :
103+ switch (bucket .getDirection ()) {
104+ case UPWARDS :
101105 direction = BlockFace .UP ;
102106 break ;
103- case " DOWNWARDS" :
107+ case DOWNWARDS :
104108 direction = BlockFace .DOWN ;
105109 break ;
106- case "HORIZONTAL_BY_CHUNK" : case "ANY_BY_CHUNK" :
107- chunkLimited = true ;
108- break ;
109110 }
110111 int limit = main .getConfigValues ().getVerticalTravel ();
111112 if (direction != BlockFace .UP && direction != BlockFace .DOWN ) {
112113 limit = main .getConfigValues ().getHorizontalTravel ();
113114 }
114- GenningTimer genningTimer = new GenningTimer (p , main . getConfigValues (). getBucketBlockMaterial ( bucket ) , block , direction , main , limit , chunkLimited );
115+ GenningTimer genningTimer = new GenningTimer (p , bucket , block , direction , main , limit );
115116 genningTimer .runTaskTimer (main , 0L , main .getConfigValues ().getBlockSpeedDelay ());
116117 if (main .getConfigValues ().cancellingEnabled ()) {
117118 main .getUtils ().getCurrentGens ().put (block .getLocation (), genningTimer );
118119 }
119- if (main . getConfigValues (). isNotInfinite ( bucket )) {
120+ if (! bucket . isInfinite ( )) {
120121 if (!main .getHookUtils ().getBypassPlayers ().contains (p )) {
121122 if (removeItem .getAmount () <= 1 ) {
122123 p .setItemInHand (null );
123124 } else {
124125 removeItem .setAmount (removeItem .getAmount () - 1 );
125126 }
126127 }
127- if (!main .getConfigValues ().getPlaceNormalMessage (main . getConfigValues (). getBucketPlaceCost ( bucket )) .equals ("" ) && main . getConfigValues (). getBucketPlaceCost ( bucket ) > 0 ) {
128- p .sendMessage (main .getConfigValues ().getPlaceNormalMessage (main . getConfigValues (). getBucketPlaceCost ( bucket )));
128+ if (!main .getConfigValues ().getPlaceNormalMessage (bucket . getPlacePrice ()) .equals ("" ) && bucket . getPlacePrice ( ) > 0 ) {
129+ p .sendMessage (main .getConfigValues ().getPlaceNormalMessage (bucket . getPlacePrice ( )));
129130 }
130131 } else {
131- if (!main .getConfigValues ().getPlaceInfiniteMessage (main . getConfigValues (). getBucketPlaceCost ( bucket )) .equals ("" ) && main . getConfigValues (). getBucketPlaceCost ( bucket ) > 0 ) {
132- p .sendMessage (main .getConfigValues ().getPlaceInfiniteMessage (main . getConfigValues (). getBucketPlaceCost ( bucket )));
132+ if (!main .getConfigValues ().getPlaceInfiniteMessage (bucket . getPlacePrice ()) .equals ("" ) && bucket . getPlacePrice ( ) > 0 ) {
133+ p .sendMessage (main .getConfigValues ().getPlaceInfiniteMessage (bucket . getPlacePrice ( )));
133134 }
134135 }
135136 }
@@ -141,17 +142,18 @@ public void onShopClick(InventoryClickEvent e) {
141142 e .getClickedInventory ().getName ().equals (main .getConfigValues ().getGUITitle ())) {
142143 e .setCancelled (true );
143144 Player p = (Player ) e .getWhoClicked ();
144- if (e .getCurrentItem () != null && e .getCurrentItem ().hasItemMeta () && e .getCurrentItem ().getItemMeta ().hasDisplayName ())
145- if ( main .getConfigValues ().getBucketFromShopName (e .getCurrentItem ().getItemMeta ().getDisplayName ()) != null ) {
146- String bucket = main . getConfigValues (). getBucketFromShopName ( e . getCurrentItem (). getItemMeta (). getDisplayName ());
147- double price = main . getConfigValues (). getBucketBuyPrice ( bucket );
145+ if (e .getCurrentItem () != null && e .getCurrentItem ().hasItemMeta () && e .getCurrentItem ().getItemMeta ().hasDisplayName ()) {
146+ Bucket bucket = main .getBucketManager ().fromShopName (e .getCurrentItem ().getItemMeta ().getDisplayName ());
147+ if ( bucket != null ) {
148+ double price = bucket . getBuyPrice ( );
148149 int amount = 1 ;
149150 if (e .getClick ().equals (ClickType .SHIFT_LEFT ) || e .getClick ().equals (ClickType .SHIFT_RIGHT )) {
150151 amount = 16 ;
151152 price *= main .getConfigValues ().getBulkBuyAmount ();
152153 }
153154 if (main .getHookUtils ().takeShopMoney (p , price )) {
154- ItemStack item = main .getUtils ().getBucketItemStack (bucket , amount );
155+ ItemStack item = bucket .getItem ();
156+ item .setAmount (amount );
155157 Map excessItems ;
156158 if (!main .getConfigValues ().shopShouldDropItem ()) {
157159 if (p .getInventory ().firstEmpty () == -1 ) {
@@ -163,15 +165,15 @@ public void onShopClick(InventoryClickEvent e) {
163165 }
164166 excessItems = p .getInventory ().addItem (item );
165167 for (Object excessItem : excessItems .values ()) {
166- int itemCount = ((ItemStack )excessItem ).getAmount ();
168+ int itemCount = ((ItemStack ) excessItem ).getAmount ();
167169 while (itemCount > 64 ) {
168170 ((ItemStack ) excessItem ).setAmount (64 );
169- p .getWorld ().dropItemNaturally (p .getLocation (), (ItemStack )excessItem );
171+ p .getWorld ().dropItemNaturally (p .getLocation (), (ItemStack ) excessItem );
170172 itemCount = itemCount - 64 ;
171173 }
172174 if (itemCount > 0 ) {
173175 ((ItemStack ) excessItem ).setAmount (itemCount );
174- p .getWorld ().dropItemNaturally (p .getLocation (), (ItemStack )excessItem );
176+ p .getWorld ().dropItemNaturally (p .getLocation (), (ItemStack ) excessItem );
175177 }
176178 }
177179 if (!main .getConfigValues ().getBuyConfirmationMessage (amount ).equals ("" )) {
@@ -181,6 +183,7 @@ public void onShopClick(InventoryClickEvent e) {
181183 } else if (main .getConfigValues ().getExitName ().equals (e .getCurrentItem ().getItemMeta ().getDisplayName ())) {
182184 p .closeInventory ();
183185 }
186+ }
184187 }
185188 }
186189
0 commit comments