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
*/
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
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
.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);
}
@ -437,7 +434,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
/**
* 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) {

View File

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

View File

@ -132,15 +132,13 @@ public class GreenhouseEvents implements Listener {
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());
}
@ -164,7 +162,9 @@ public class GreenhouseEvents implements Listener {
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);
});
}

View File

@ -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;
@ -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 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);
@ -125,7 +122,7 @@ public class SnowTracker implements Listener {
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)

View File

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

View File

@ -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;
@ -252,7 +249,7 @@ public class GreenhouseManager implements Listener {
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);
}
}
}
@ -262,7 +259,7 @@ public class GreenhouseManager implements Listener {
* Result of the greenhouse make effort
*
*/
public class GhResult {
public static class GhResult {
private Set<GreenhouseResult> results;
private GreenhouseFinder finder;

View File

@ -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;
@ -68,6 +63,7 @@ public class RecipeManager {
}
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
@ -82,6 +78,7 @@ public class RecipeManager {
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);
@ -124,7 +121,7 @@ public class RecipeManager {
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);
}
@ -178,7 +175,7 @@ public class RecipeManager {
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]);

View File

@ -587,25 +587,6 @@ public class BiomeRecipeTest {
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()}.
*/

View File

@ -99,7 +99,7 @@ public class WallsTest {
*/
@Test
public void testLookAround() {
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.lookAround(location, wf, roof);
assertTrue(wf.stopMaxX);
assertTrue(wf.stopMaxZ);
@ -116,7 +116,7 @@ public class WallsTest {
*/
@Test
public void testAnalyzeFindings() {
WallFinder wf = walls.new WallFinder();
WallFinder wf = new WallFinder();
walls.analyzeFindings(wf, roof);
assertFalse(wf.stopMaxX);
assertFalse(wf.stopMaxZ);
@ -137,7 +137,7 @@ public class WallsTest {
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);
@ -154,7 +154,7 @@ public class WallsTest {
*/
@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);
@ -168,7 +168,7 @@ public class WallsTest {
@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);

View File

@ -95,7 +95,7 @@ public class GreenhouseFinderTest {
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
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());