11package br .minilambda .event ;
22
3+ import org .bukkit .Bukkit ;
34import org .bukkit .Material ;
45import org .bukkit .block .Block ;
56import org .bukkit .block .data .Directional ;
1112import org .bukkit .event .block .BlockPlaceEvent ;
1213import org .bukkit .event .player .PlayerBucketEmptyEvent ;
1314
15+ import br .minilambda .utils .GetDirtAroundBlockGenerator ;
16+
1417public class DirtToMudUsingWater implements Listener {
1518 @ EventHandler
1619 public void onPlayerBucketEmptyEvent (PlayerBucketEmptyEvent event ){
@@ -25,21 +28,13 @@ public void onPlayerBucketEmptyEvent(PlayerBucketEmptyEvent event){
2528 // Get block occupied by water.
2629 Block blockOccupiedByWater = event .getBlock ();
2730
28- // Iterating block direction weights.
29- for (Integer [] weight : this .blockDirections ){
30- // Getting block.
31- Block block = blockOccupiedByWater .getWorld ().getBlockAt (
32- blockOccupiedByWater .getX () + weight [0 ],
33- blockOccupiedByWater .getY () + weight [1 ],
34- blockOccupiedByWater .getZ () + weight [2 ]
35- );
36-
37- // Jump to next loop if block is different of dirt.
38- if (block .getType () != Material .DIRT ){
39- continue ;
40- }
41-
42- // Else, set block type to mud block.
31+ // To get dirt blocks around.
32+ GetDirtAroundBlockGenerator dirtBlocks = new GetDirtAroundBlockGenerator (blockOccupiedByWater );
33+ Block block ;
34+
35+ // Iterating dirt blocks around.
36+ while ((block = dirtBlocks .next ()) != null ){
37+ // Set block type to mud block.
4338 block .setType (Material .MUD );
4439 }
4540 }
@@ -113,21 +108,13 @@ public void onDispenseWater(BlockDispenseEvent event){
113108 ((Directional ) dispenseBlock .getBlockData ()).getFacing ()
114109 );
115110
116- // Iterating block direction weights.
117- for (Integer [] weight : this .blockDirections ){
118- // Getting block.
119- Block block = facedBlock .getWorld ().getBlockAt (
120- facedBlock .getX () + weight [0 ],
121- facedBlock .getY () + weight [1 ],
122- facedBlock .getZ () + weight [2 ]
123- );
124-
125- // Jump to next loop if block is different of dirt.
126- if (block .getType () != Material .DIRT ){
127- continue ;
128- }
129-
130- // Else, set block type to mud block.
111+ // To get dirt blocks around.
112+ GetDirtAroundBlockGenerator dirtBlocks = new GetDirtAroundBlockGenerator (facedBlock );
113+ Block block ;
114+
115+ // Iterating dirt blocks around.
116+ while ((block = dirtBlocks .next ()) != null ){
117+ // Set block type to mud block.
131118 block .setType (Material .MUD );
132119 }
133120 }
@@ -144,21 +131,13 @@ public void onBlockFadeToWater(BlockFadeEvent event){
144131 return ;
145132 }
146133
147- // Iterating block direction weights.
148- for (Integer [] weight : this .blockDirections ){
149- // Getting block.
150- Block block = fadedBlock .getWorld ().getBlockAt (
151- fadedBlock .getX () + weight [0 ],
152- fadedBlock .getY () + weight [1 ],
153- fadedBlock .getZ () + weight [2 ]
154- );
155-
156- // Jump to next loop if block is different of dirt.
157- if (block .getType () != Material .DIRT ){
158- continue ;
159- }
160-
161- // Else, set block type to mud block.
134+ // To get dirt blocks around.
135+ GetDirtAroundBlockGenerator dirtBlocks = new GetDirtAroundBlockGenerator (fadedBlock );
136+ Block block ;
137+
138+ // Iterating dirt blocks around.
139+ while ((block = dirtBlocks .next ()) != null ){
140+ // Set block type to mud block.
162141 block .setType (Material .MUD );
163142 }
164143 }
0 commit comments