Skip to content

Commit b65dddc

Browse files
committed
Better use guards here
1 parent 0e6b3d6 commit b65dddc

File tree

1 file changed

+21
-19
lines changed
  • src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids

1 file changed

+21
-19
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.bukkit.Material;
1212
import org.bukkit.OfflinePlayer;
1313
import org.bukkit.Particle;
14+
import org.bukkit.World;
1415
import org.bukkit.block.Block;
1516
import org.bukkit.block.BlockFace;
1617
import org.bukkit.inventory.ItemStack;
@@ -134,37 +135,38 @@ protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block)
134135

135136
@ParametersAreNonnullByDefault
136137
private void breakBlock(BlockMenu menu, Collection<ItemStack> drops, Block block) {
137-
138-
if (!block.getWorld().getWorldBorder().isInside(block.getLocation())) {
138+
World world = block.getWorld();
139+
if (!world.getWorldBorder().isInside(block.getLocation())) {
139140
return;
140141
}
141142

142-
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
143+
world.playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
143144

144145
// Push our drops to the inventory
145146
for (ItemStack drop : drops) {
146147
menu.pushItem(drop, getOutputSlots());
147148
}
148149

149150
// Check if Block Generator optimizations should be applied.
150-
if (applyOptimizations.getValue()) {
151-
InfiniteBlockGenerator generator = InfiniteBlockGenerator.findAt(block);
152-
153-
// If we found a generator, continue.
154-
if (generator != null) {
155-
if (firesEvent.getValue()) {
156-
generator.callEvent(block);
157-
}
158-
159-
// "poof" a "new" block was generated
160-
SoundEffect.MINER_ANDROID_BLOCK_GENERATION_SOUND.playAt(block);
161-
block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, block.getX() + 0.5, block.getY() + 1.25, block.getZ() + 0.5, 8, 0.5, 0.5, 0.5, 0.015);
162-
} else {
163-
block.setType(Material.AIR);
164-
}
165-
} else {
151+
if (!applyOptimizations.getValue()) {
166152
block.setType(Material.AIR);
153+
return;
167154
}
155+
156+
// If we didn't find a generator ignore the block.
157+
InfiniteBlockGenerator generator = InfiniteBlockGenerator.findAt(block);
158+
if (generator == null) {
159+
block.setType(Material.AIR);
160+
return;
161+
}
162+
163+
if (firesEvent.getValue()) {
164+
generator.callEvent(block);
165+
}
166+
167+
// "poof" a "new" block was generated
168+
SoundEffect.MINER_ANDROID_BLOCK_GENERATION_SOUND.playAt(block);
169+
world.spawnParticle(Particle.SMOKE_NORMAL, block.getX() + 0.5, block.getY() + 1.25, block.getZ() + 0.5, 8, 0.5, 0.5, 0.5, 0.015);
168170
}
169171

170172
}

0 commit comments

Comments
 (0)