Conde clean up from IntelliJ

This commit is contained in:
tastybento 2021-09-18 10:33:48 -07:00
parent 4708a70e24
commit 8a3e0eb403
11 changed files with 42 additions and 73 deletions

View File

@ -220,7 +220,7 @@ public class Greenhouse implements DataObject {
* @return true if inside the greenhouse * @return true if inside the greenhouse
*/ */
public boolean contains(Location location2) { 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());
} }
/** /**
@ -253,7 +253,7 @@ public class Greenhouse implements DataObject {
*/ */
@NonNull @NonNull
public Map<Material, Integer> getMissingBlocks() { public Map<Material, Integer> getMissingBlocks() {
return Objects.requireNonNullElseGet(missingBlocks, () -> new HashMap<>()); return Objects.requireNonNullElseGet(missingBlocks, HashMap::new);
} }
/** /**

View File

@ -362,22 +362,19 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
// If spawn occurs, check if it can fit inside greenhouse // If spawn occurs, check if it can fit inside greenhouse
.map(m -> { .map(m -> {
Entity entity = b.getWorld().spawnEntity(spawnLoc, m.mobType()); Entity entity = b.getWorld().spawnEntity(spawnLoc, m.mobType());
if (entity != null) { preventZombie(entity);
preventZombie(entity); return addon
return addon .getManager()
.getManager() .getMap()
.getMap() .getGreenhouse(b.getLocation()).map(gh -> {
.getGreenhouse(b.getLocation()).map(gh -> { BoundingBox interior = gh.getBoundingBox().clone();
BoundingBox interior = gh.getBoundingBox().clone(); interior.expand(-1, -1, -1);
interior.expand(-1, -1, -1); if (!interior.contains(entity.getBoundingBox())) {
if (!interior.contains(entity.getBoundingBox())) { entity.remove();
entity.remove(); return false;
return false; }
} return true;
return true; }).orElse(false);
}).orElse(false);
}
return false;
}).orElse(false); }).orElse(false);
} }
@ -437,7 +434,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
/** /**
* Plants a plant on block bl if it makes sense. * 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 * @return true if successful
*/ */
public boolean growPlant(GrowthBlock block) { public boolean growPlant(GrowthBlock block) {

View File

@ -28,7 +28,7 @@ public class Walls extends MinMaxXZ {
private final AsyncWorldCache cache; private final AsyncWorldCache cache;
class WallFinder { static class WallFinder {
int radiusMinX; int radiusMinX;
int radiusMaxX; int radiusMaxX;
int radiusMinZ; int radiusMinZ;

View File

@ -132,15 +132,13 @@ public class GreenhouseEvents implements Listener {
return; return;
} }
// from is a greenhouse // from is a greenhouse
if (from.isPresent() && to.isEmpty()) { if (from.isPresent()) {
// Exiting // Exiting
user.sendMessage("greenhouses.event.leaving", BIOME, from.get().getBiomeRecipe().getFriendlyName()); user.sendMessage("greenhouses.event.leaving", BIOME, from.get().getBiomeRecipe().getFriendlyName());
return; return;
} }
if (from.isEmpty()) { // Entering
// Entering user.sendMessage("greenhouses.event.entering", BIOME, to.get().getBiomeRecipe().getFriendlyName());
user.sendMessage("greenhouses.event.entering", BIOME, to.get().getBiomeRecipe().getFriendlyName());
}
} }
@ -164,7 +162,9 @@ public class GreenhouseEvents implements Listener {
addon.getManager().getMap().getGreenhouse(e.getBlock().getLocation()) addon.getManager().getMap().getGreenhouse(e.getBlock().getLocation())
.filter(g -> g.isRoofOrWallBlock(e.getBlock().getLocation())) .filter(g -> g.isRoofOrWallBlock(e.getBlock().getLocation()))
.ifPresent(g -> { .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); addon.getManager().removeGreenhouse(g);
}); });
} }

View File

@ -1,9 +1,6 @@
package world.bentobox.greenhouses.listeners; package world.bentobox.greenhouses.listeners;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -55,7 +52,7 @@ public class SnowTracker implements Listener {
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX() -1; x++) { 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 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--) { 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(); Material type = b.getType();
if (type.equals(Material.AIR) || type.equals(Material.SNOW)) { if (type.equals(Material.AIR) || type.equals(Material.SNOW)) {
b.getWorld().spawnParticle(Particle.SNOWBALL, b.getLocation(), 5); b.getWorld().spawnParticle(Particle.SNOWBALL, b.getLocation(), 5);
@ -125,7 +122,7 @@ public class SnowTracker implements Listener {
private void shakeGlobes(World world) { private void shakeGlobes(World world) {
addon.getManager().getMap().getGreenhouses().stream().filter(g -> g.getBiomeRecipe().getIceCoverage() > 0) 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.getLocation().getWorld().equals(world))
.filter(g -> !g.isBroken()) .filter(g -> !g.isBroken())
.filter(g -> g.getRoofHopperLocation() != null) .filter(g -> g.getRoofHopperLocation() != null)

View File

@ -33,7 +33,7 @@ public class GreenhouseFinder {
*/ */
private CounterCheck cc = new CounterCheck(); private CounterCheck cc = new CounterCheck();
class CounterCheck { static class CounterCheck {
int doorCount; int doorCount;
int hopperCount; int hopperCount;
boolean airHole; boolean airHole;

View File

@ -1,9 +1,6 @@
package world.bentobox.greenhouses.managers; package world.bentobox.greenhouses.managers;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -252,7 +249,7 @@ public class GreenhouseManager implements Listener {
for (int x = (int)gh.getBoundingBox().getMinX(); x < gh.getBoundingBox().getMaxX(); x+=4) { 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 z = (int)gh.getBoundingBox().getMinZ(); z < gh.getBoundingBox().getMaxZ(); z+=4) {
for (int y = (int)gh.getBoundingBox().getMinY(); y < gh.getBoundingBox().getMaxY(); y+=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);
} }
} }
} }
@ -262,7 +259,7 @@ public class GreenhouseManager implements Listener {
* Result of the greenhouse make effort * Result of the greenhouse make effort
* *
*/ */
public class GhResult { public static class GhResult {
private Set<GreenhouseResult> results; private Set<GreenhouseResult> results;
private GreenhouseFinder finder; private GreenhouseFinder finder;

View File

@ -1,13 +1,8 @@
package world.bentobox.greenhouses.managers; package world.bentobox.greenhouses.managers;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -68,6 +63,7 @@ public class RecipeManager {
} }
ConfigurationSection biomeSection = biomeConfig.getConfigurationSection("biomes"); ConfigurationSection biomeSection = biomeConfig.getConfigurationSection("biomes");
// Loop through all the entries // Loop through all the entries
assert biomeSection != null;
for (String type: biomeSection.getValues(false).keySet()) { for (String type: biomeSection.getValues(false).keySet()) {
processEntries(type, biomeSection); processEntries(type, biomeSection);
// Check maximum number // Check maximum number
@ -82,6 +78,7 @@ public class RecipeManager {
private void processEntries(String biomeType, ConfigurationSection biomeSection) { private void processEntries(String biomeType, ConfigurationSection biomeSection) {
try { try {
ConfigurationSection biomeRecipeConfig = biomeSection.getConfigurationSection(biomeType); ConfigurationSection biomeRecipeConfig = biomeSection.getConfigurationSection(biomeType);
assert biomeRecipeConfig != null;
Biome thisBiome = loadBiome(biomeType, biomeRecipeConfig); Biome thisBiome = loadBiome(biomeType, biomeRecipeConfig);
if (thisBiome == null) return; if (thisBiome == null) return;
int priority = biomeRecipeConfig.getInt("priority", 0); int priority = biomeRecipeConfig.getInt("priority", 0);
@ -124,7 +121,7 @@ public class RecipeManager {
addon.logError("No biome defined in the biome reciepe " + biomeType + ". Skipping..."); addon.logError("No biome defined in the biome reciepe " + biomeType + ". Skipping...");
return null; 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()) { if (Enums.getIfPresent(Biome.class, name).isPresent()) {
return Biome.valueOf(name); return Biome.valueOf(name);
} }
@ -178,7 +175,7 @@ public class RecipeManager {
try { try {
Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH)); Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH));
String conversions = conversionSec.getString(oldMat); String conversions = conversionSec.getString(oldMat);
if (!conversions.isEmpty()) { if (!Objects.requireNonNull(conversions).isEmpty()) {
String[] split = conversions.split(":"); String[] split = conversions.split(":");
double convChance = Double.parseDouble(split[0]); double convChance = Double.parseDouble(split[0]);
Material newMaterial = Material.valueOf(split[1]); Material newMaterial = Material.valueOf(split[1]);

View File

@ -587,25 +587,6 @@ public class BiomeRecipeTest {
verify(world, never()).spawnEntity(eq(location), eq(EntityType.CAT)); 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()}. * Test method for {@link world.bentobox.greenhouses.greenhouse.BiomeRecipe#getRecipeBlocks()}.
*/ */

View File

@ -99,7 +99,7 @@ public class WallsTest {
*/ */
@Test @Test
public void testLookAround() { public void testLookAround() {
WallFinder wf = walls.new WallFinder(); WallFinder wf = new WallFinder();
walls.lookAround(location, wf, roof); walls.lookAround(location, wf, roof);
assertTrue(wf.stopMaxX); assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ); assertTrue(wf.stopMaxZ);
@ -116,7 +116,7 @@ public class WallsTest {
*/ */
@Test @Test
public void testAnalyzeFindings() { public void testAnalyzeFindings() {
WallFinder wf = walls.new WallFinder(); WallFinder wf = new WallFinder();
walls.analyzeFindings(wf, roof); walls.analyzeFindings(wf, roof);
assertFalse(wf.stopMaxX); assertFalse(wf.stopMaxX);
assertFalse(wf.stopMaxZ); assertFalse(wf.stopMaxZ);
@ -137,7 +137,7 @@ public class WallsTest {
walls.maxX = 1; walls.maxX = 1;
walls.minZ = -1; walls.minZ = -1;
walls.maxZ = 1; walls.maxZ = 1;
WallFinder wf = walls.new WallFinder(); WallFinder wf = new WallFinder();
walls.analyzeFindings(wf, roof); walls.analyzeFindings(wf, roof);
assertTrue(wf.stopMaxX); assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ); assertTrue(wf.stopMaxZ);
@ -154,7 +154,7 @@ public class WallsTest {
*/ */
@Test @Test
public void testLookAtBlockFaces() { public void testLookAtBlockFaces() {
WallFinder wf = walls.new WallFinder(); WallFinder wf = new WallFinder();
walls.lookAtBlockFaces(wf, 0, 5, -1); walls.lookAtBlockFaces(wf, 0, 5, -1);
assertTrue(wf.stopMaxX); assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ); assertTrue(wf.stopMaxZ);
@ -168,7 +168,7 @@ public class WallsTest {
@Test @Test
public void testLookAtBlockFacesNoGlass() { public void testLookAtBlockFacesNoGlass() {
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR); when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR);
WallFinder wf = walls.new WallFinder(); WallFinder wf = new WallFinder();
walls.lookAtBlockFaces(wf, 0, 5, -1); walls.lookAtBlockFaces(wf, 0, 5, -1);
assertFalse(wf.stopMaxX); assertFalse(wf.stopMaxX);
assertFalse(wf.stopMaxZ); assertFalse(wf.stopMaxZ);

View File

@ -95,7 +95,7 @@ public class GreenhouseFinderTest {
gf = new GreenhouseFinder(); gf = new GreenhouseFinder();
cc = gf.new CounterCheck(); cc = new CounterCheck();
} }
/** /**
@ -232,7 +232,7 @@ public class GreenhouseFinderTest {
// Set the greenhouse so the world is known // Set the greenhouse so the world is known
gf.setGh(gh); gf.setGh(gh);
when(Tag.DOORS.isTagged(any(Material.class))).thenReturn(false); 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.checkDoorsHoppers(cc, Material.HOPPER, new Vector(5,14,25)));
assertTrue(gf.getRedGlass().isEmpty()); assertTrue(gf.getRedGlass().isEmpty());
assertEquals(5, gf.getGh().getRoofHopperLocation().getBlockX()); assertEquals(5, gf.getGh().getRoofHopperLocation().getBlockX());