Skip to content

Commit

Permalink
Conde clean up from IntelliJ
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 18, 2021
1 parent 4708a70 commit 8a3e0eb
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/greenhouses/data/Greenhouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public World getWorld() {
* @return true if inside the greenhouse
*/
public boolean contains(Location location2) {
return location.getWorld().equals(location2.getWorld()) && boundingBox.contains(location2.toVector());
return location.getWorld() != null && location.getWorld().equals(location2.getWorld()) && boundingBox.contains(location2.toVector());
}

/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public void setMissingBlocks(Map<Material, Integer> missingBlocks) {
*/
@NonNull
public Map<Material, Integer> getMissingBlocks() {
return Objects.requireNonNullElseGet(missingBlocks, () -> new HashMap<>());
return Objects.requireNonNullElseGet(missingBlocks, HashMap::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,22 +362,19 @@ public boolean spawnMob(Block b) {
// If spawn occurs, check if it can fit inside greenhouse
.map(m -> {
Entity entity = b.getWorld().spawnEntity(spawnLoc, m.mobType());
if (entity != null) {
preventZombie(entity);
return addon
.getManager()
.getMap()
.getGreenhouse(b.getLocation()).map(gh -> {
BoundingBox interior = gh.getBoundingBox().clone();
interior.expand(-1, -1, -1);
if (!interior.contains(entity.getBoundingBox())) {
entity.remove();
return false;
}
return true;
}).orElse(false);
}
return false;
preventZombie(entity);
return addon
.getManager()
.getMap()
.getGreenhouse(b.getLocation()).map(gh -> {
BoundingBox interior = gh.getBoundingBox().clone();
interior.expand(-1, -1, -1);
if (!interior.contains(entity.getBoundingBox())) {
entity.remove();
return false;
}
return true;
}).orElse(false);
}).orElse(false);

}
Expand Down Expand Up @@ -437,7 +434,7 @@ public int getWaterCoverage() {

/**
* Plants a plant on block bl if it makes sense.
* @param bl - block that can have growth
* @param block - block that can have growth
* @return true if successful
*/
public boolean growPlant(GrowthBlock block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Walls extends MinMaxXZ {

private final AsyncWorldCache cache;

class WallFinder {
static class WallFinder {
int radiusMinX;
int radiusMaxX;
int radiusMinZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ private void handleTransition(User user, Location toLoc, Location fromLoc) {
return;
}
// from is a greenhouse
if (from.isPresent() && to.isEmpty()) {
if (from.isPresent()) {
// Exiting
user.sendMessage("greenhouses.event.leaving", BIOME, from.get().getBiomeRecipe().getFriendlyName());
return;
}
if (from.isEmpty()) {
// Entering
user.sendMessage("greenhouses.event.entering", BIOME, to.get().getBiomeRecipe().getFriendlyName());
}
// Entering
user.sendMessage("greenhouses.event.entering", BIOME, to.get().getBiomeRecipe().getFriendlyName());

}

Expand All @@ -164,7 +162,9 @@ public void onBlockBreak(final BlockBreakEvent e) {
addon.getManager().getMap().getGreenhouse(e.getBlock().getLocation())
.filter(g -> g.isRoofOrWallBlock(e.getBlock().getLocation()))
.ifPresent(g -> {
user.sendMessage("greenhouses.event.broke", BIOME, Util.prettifyText(g.getOriginalBiome().name()));
if (g.getOriginalBiome() != null) {
user.sendMessage("greenhouses.event.broke", BIOME, Util.prettifyText(g.getOriginalBiome().name()));
}
addon.getManager().removeGreenhouse(g);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package world.bentobox.greenhouses.listeners;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand Down Expand Up @@ -55,7 +52,7 @@ private boolean getAirBlocks(Greenhouse gh) {
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX() -1; x++) {
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ() - 1; z++) {
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
Block b = Objects.requireNonNull(gh.getLocation().getWorld()).getBlockAt(x, y, z);
Material type = b.getType();
if (type.equals(Material.AIR) || type.equals(Material.SNOW)) {
b.getWorld().spawnParticle(Particle.SNOWBALL, b.getLocation(), 5);
Expand Down Expand Up @@ -125,7 +122,7 @@ private void removeWaterBucketAndShake(Greenhouse g) {

private void shakeGlobes(World world) {
addon.getManager().getMap().getGreenhouses().stream().filter(g -> g.getBiomeRecipe().getIceCoverage() > 0)
.filter(g -> (g.getLocation().getWorld().isChunkLoaded(((int) g.getBoundingBox().getMaxX()) >> 4, ((int) g.getBoundingBox().getMaxZ()) >> 4) && g.getLocation().getWorld().isChunkLoaded(((int) g.getBoundingBox().getMinX()) >> 4, ((int) g.getBoundingBox().getMinZ()) >> 4)))
.filter(g -> (Objects.requireNonNull(Objects.requireNonNull(g.getLocation()).getWorld()).isChunkLoaded(((int) g.getBoundingBox().getMaxX()) >> 4, ((int) g.getBoundingBox().getMaxZ()) >> 4) && g.getLocation().getWorld().isChunkLoaded(((int) g.getBoundingBox().getMinX()) >> 4, ((int) g.getBoundingBox().getMinZ()) >> 4)))
.filter(g -> g.getLocation().getWorld().equals(world))
.filter(g -> !g.isBroken())
.filter(g -> g.getRoofHopperLocation() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GreenhouseFinder {
*/
private CounterCheck cc = new CounterCheck();

class CounterCheck {
static class CounterCheck {
int doorCount;
int hopperCount;
boolean airHole;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package world.bentobox.greenhouses.managers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -252,7 +249,7 @@ private void activateGreenhouse(Greenhouse gh) {
for (int x = (int)gh.getBoundingBox().getMinX(); x < gh.getBoundingBox().getMaxX(); x+=4) {
for (int z = (int)gh.getBoundingBox().getMinZ(); z < gh.getBoundingBox().getMaxZ(); z+=4) {
for (int y = (int)gh.getBoundingBox().getMinY(); y < gh.getBoundingBox().getMaxY(); y+=4) {
gh.getWorld().setBiome(x, y, z, ghBiome);
Objects.requireNonNull(gh.getWorld()).setBiome(x, y, z, ghBiome);
}
}
}
Expand All @@ -262,7 +259,7 @@ private void activateGreenhouse(Greenhouse gh) {
* Result of the greenhouse make effort
*
*/
public class GhResult {
public static class GhResult {
private Set<GreenhouseResult> results;
private GreenhouseFinder finder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package world.bentobox.greenhouses.managers;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

import org.bukkit.ChatColor;
Expand Down Expand Up @@ -68,6 +63,7 @@ private void loadBiomeRecipes() throws IOException, InvalidConfigurationExceptio
}
ConfigurationSection biomeSection = biomeConfig.getConfigurationSection("biomes");
// Loop through all the entries
assert biomeSection != null;
for (String type: biomeSection.getValues(false).keySet()) {
processEntries(type, biomeSection);
// Check maximum number
Expand All @@ -82,6 +78,7 @@ private void loadBiomeRecipes() throws IOException, InvalidConfigurationExceptio
private void processEntries(String biomeType, ConfigurationSection biomeSection) {
try {
ConfigurationSection biomeRecipeConfig = biomeSection.getConfigurationSection(biomeType);
assert biomeRecipeConfig != null;
Biome thisBiome = loadBiome(biomeType, biomeRecipeConfig);
if (thisBiome == null) return;
int priority = biomeRecipeConfig.getInt("priority", 0);
Expand Down Expand Up @@ -124,7 +121,7 @@ private Biome loadBiome(String biomeType, ConfigurationSection biomeRecipeConfig
addon.logError("No biome defined in the biome reciepe " + biomeType + ". Skipping...");
return null;
}
String name = biomeRecipeConfig.getString("biome").toUpperCase(Locale.ENGLISH);
String name = Objects.requireNonNull(biomeRecipeConfig.getString("biome")).toUpperCase(Locale.ENGLISH);
if (Enums.getIfPresent(Biome.class, name).isPresent()) {
return Biome.valueOf(name);
}
Expand Down Expand Up @@ -178,7 +175,7 @@ private void loadBlockConversions(ConfigurationSection biomeRecipeConfig, BiomeR
try {
Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH));
String conversions = conversionSec.getString(oldMat);
if (!conversions.isEmpty()) {
if (!Objects.requireNonNull(conversions).isEmpty()) {
String[] split = conversions.split(":");
double convChance = Double.parseDouble(split[0]);
Material newMaterial = Material.valueOf(split[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,25 +587,6 @@ public void testSpawnMobWrongSurface() {
verify(world, never()).spawnEntity(eq(location), eq(EntityType.CAT));
}

/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#spawnMob(org.bukkit.block.Block)}.
*/
@Test
public void testSpawnMobFailToSpawn() {
when(block.getY()).thenReturn(10);
when(block.getType()).thenReturn(Material.GRASS_BLOCK);
when(block.getRelative(any())).thenReturn(block);

EntityType mobType = EntityType.CAT;
int mobProbability = 100;
Material mobSpawnOn = Material.GRASS_BLOCK;

br.addMobs(mobType, mobProbability, mobSpawnOn);
assertFalse(br.spawnMob(block));
verify(world).spawnEntity(eq(location), eq(EntityType.CAT));
}


/**
* Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#getRecipeBlocks()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void testFindWalls() {
*/
@Test
public void testLookAround() {
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.lookAround(location, wf, roof);
assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ);
Expand All @@ -116,7 +116,7 @@ public void testLookAround() {
*/
@Test
public void testAnalyzeFindings() {
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.analyzeFindings(wf, roof);
assertFalse(wf.stopMaxX);
assertFalse(wf.stopMaxZ);
Expand All @@ -137,7 +137,7 @@ public void testAnalyzeFindingsStop() {
walls.maxX = 1;
walls.minZ = -1;
walls.maxZ = 1;
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.analyzeFindings(wf, roof);
assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ);
Expand All @@ -154,7 +154,7 @@ public void testAnalyzeFindingsStop() {
*/
@Test
public void testLookAtBlockFaces() {
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.lookAtBlockFaces(wf, 0, 5, -1);
assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ);
Expand All @@ -168,7 +168,7 @@ public void testLookAtBlockFaces() {
@Test
public void testLookAtBlockFacesNoGlass() {
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR);
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.lookAtBlockFaces(wf, 0, 5, -1);
assertFalse(wf.stopMaxX);
assertFalse(wf.stopMaxZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setUp() {


gf = new GreenhouseFinder();
cc = gf.new CounterCheck();
cc = new CounterCheck();
}

/**
Expand Down Expand Up @@ -232,7 +232,7 @@ public void testCheckDoorsHoppersHopper() {
// Set the greenhouse so the world is known
gf.setGh(gh);
when(Tag.DOORS.isTagged(any(Material.class))).thenReturn(false);
CounterCheck cc = gf.new CounterCheck();
CounterCheck cc = new CounterCheck();
assertTrue(gf.checkDoorsHoppers(cc, Material.HOPPER, new Vector(5,14,25)));
assertTrue(gf.getRedGlass().isEmpty());
assertEquals(5, gf.getGh().getRoofHopperLocation().getBlockX());
Expand Down

0 comments on commit 8a3e0eb

Please sign in to comment.