Add linting + fix warnings

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2020-11-07 18:27:39 -05:00
parent de4eb8cb73
commit dc46e4596d
31 changed files with 233 additions and 206 deletions

View File

@@ -35,6 +35,7 @@ public class Terra extends GaeaPlugin {
TerraChunkGenerator.saveAll();
}
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
instance = this;
@@ -54,7 +55,6 @@ public class Terra extends GaeaPlugin {
locatePl.setTabCompleter(locate);
saveDefaultConfig();
//noinspection deprecation
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, ConfigUtil.dataSave, ConfigUtil.dataSave);
Bukkit.getPluginManager().registerEvents(new EventListener(this), this);
PaperUtil.checkPaper(this);

View File

@@ -6,6 +6,7 @@ import org.bukkit.configuration.InvalidConfigurationException;
* Thrown when a config item is not valid.
*/
public class ConfigException extends InvalidConfigurationException {
private static final long serialVersionUID = -4342864317005935979L;
private final String message;
private final String id;

View File

@@ -4,6 +4,8 @@ package com.dfsek.terra.config.exception;
* Thrown when a required config item is not found.
*/
public class NotFoundException extends ConfigException {
private static final long serialVersionUID = -3763471113262357426L;
public NotFoundException(String item, String itemName, String id) {
super(item + " \"" + itemName + "\" cannot be found!", id);
}

View File

@@ -61,8 +61,8 @@ public class OreConfig extends TerraConfig {
}
}
private int randomInRange(Random r) {
return r.nextInt(max - min + 1) + min;
public String getID() {
return id;
}
public void doVein(Vector l, Chunk chunk, Random r) {
@@ -91,6 +91,10 @@ public class OreConfig extends TerraConfig {
}
}
private int randomInRange(Random r) {
return r.nextInt(max - min + 1) + min;
}
public void doVeinSingle(Vector l, Chunk chunk, Random r) {
FastNoiseLite ore = new FastNoiseLite(r.nextInt());
ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
@@ -117,10 +121,6 @@ public class OreConfig extends TerraConfig {
return "Ore with ID " + getID();
}
public String getID() {
return id;
}
public boolean crossChunks() {
return crossChunks;
}

View File

@@ -15,6 +15,7 @@ import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
public class DebugFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 9133084939622854303L;
private final int x;
private final int z;
private final BufferedImage img;

View File

@@ -25,7 +25,7 @@ public class UserDefinedGenerator extends Generator {
private final Variable xVar = s.getVariable("x");
private final Variable yVar = s.getVariable("y");
private final Variable zVar = s.getVariable("z");
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
private final Palette<BlockData>[] palettes = new Palette[256];
private final NoiseFunction2 n2 = new NoiseFunction2();
private final NoiseFunction3 n3 = new NoiseFunction3();

View File

@@ -28,6 +28,7 @@ public class CavePopulator extends BlockPopulator {
private static final Map<Material, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
private static final BlockData AIR = Material.AIR.createBlockData();
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
if(ConfigUtil.masterDisableCaves) return;

View File

@@ -30,6 +30,7 @@ import java.util.Random;
* Populates Flora and Trees
*/
public class FloraPopulator extends GaeaBlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {

View File

@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Random;
public class OrePopulator extends GaeaBlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
@@ -44,7 +45,7 @@ public class OrePopulator extends GaeaBlockPopulator {
Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) {
if(ore.crossChunks()) ore.doVein(v, chunk, random);
else ore.doVeinSingleChunk(new Vector(x, y, z), chunk, random);
else ore.doVeinSingle(new Vector(x, y, z), chunk, random);
}
}
}

View File

@@ -44,6 +44,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
Bukkit.getLogger().info("Added " + blacklistSpawn.size() + " materials to snow blacklist");
}
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("SnowTime")) {

View File

@@ -25,6 +25,7 @@ import java.util.Random;
public class StructurePopulator extends BlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {

View File

@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
@SuppressWarnings("unused")
public class InitializationException extends Exception {
private static final long serialVersionUID = -3817726044758088486L;
private final Location worldLoc;
public InitializationException(String message, @Nullable Location worldLoc) {

View File

@@ -163,46 +163,6 @@ public class Structure implements Serializable {
this.executeForBlocksInRange(xRange, getRange(Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
}
public boolean checkSpawns(Location origin, Rotation r) {
for(StructureContainedBlock b : spawns) {
Vector2 rot = getRotatedCoords(new Vector2(b.getX() - structureInfo.getCenterX(), b.getZ() - structureInfo.getCenterZ()), r);
if(!b.getRequirement().matches(origin.getWorld(), (int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
return false;
}
return true;
}
public HashSet<StructureContainedInventory> getInventories() {
return inventories;
}
/**
* Get GaeaStructureInfo object
*
* @return Structure Info
*/
@NotNull
public StructureInfo getStructureInfo() {
return structureInfo;
}
/**
* Paste structure at an origin location, confined to a single chunk.
*
* @param origin Origin location
* @param chunk Chunk to confine pasting to
* @param r Rotation
*/
public void paste(Location origin, Chunk chunk, Rotation r) {
int xOr = (chunk.getX() << 4);
int zOr = (chunk.getZ() << 4);
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
if(intersectX == null || intersectZ == null) return;
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
}
/**
* Paste a single StructureDefinedBlock at an origin location, offset by its coordinates.
*
@@ -298,6 +258,16 @@ public class Structure implements Serializable {
}
}
/**
* Get GaeaStructureInfo object
*
* @return Structure Info
*/
@NotNull
public StructureInfo getStructureInfo() {
return structureInfo;
}
/**
* Test whether a set of coordinates is within the current structure
*
@@ -339,6 +309,36 @@ public class Structure implements Serializable {
}
}
public boolean checkSpawns(Location origin, Rotation r) {
for(StructureContainedBlock b : spawns) {
Vector2 rot = getRotatedCoords(new Vector2(b.getX() - structureInfo.getCenterX(), b.getZ() - structureInfo.getCenterZ()), r);
if(!b.getRequirement().matches(origin.getWorld(), (int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
return false;
}
return true;
}
public HashSet<StructureContainedInventory> getInventories() {
return inventories;
}
/**
* Paste structure at an origin location, confined to a single chunk.
*
* @param origin Origin location
* @param chunk Chunk to confine pasting to
* @param r Rotation
*/
public void paste(Location origin, Chunk chunk, Rotation r) {
int xOr = (chunk.getX() << 4);
int zOr = (chunk.getZ() << 4);
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
if(intersectX == null || intersectZ == null) return;
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
}
/**
* From an origin location (First bound) fetch the second bound.
*

View File

@@ -32,6 +32,7 @@ public class SerializableBanner implements SerializableBlockState {
}
private static final class Pattern implements Serializable {
private static final long serialVersionUID = -7802163816361757171L;
private final DyeColor color;
private final PatternType type;

View File

@@ -157,6 +157,7 @@ public final class RotationUtil {
* @param r Rotate
* @return Rotated/mirrored shape
*/
@SuppressWarnings("fallthrough")
public static Rail.Shape getRotatedRail(Rail.Shape orig, Structure.Rotation r) {
switch(r) {
case CCW_90:

View File

@@ -36,6 +36,13 @@ public final class WorldEditUtil {
return new Location[] {l1, l2};
}
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
public static Location[] getSelectionPositions(Player sender) {
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
if(we == null) {
@@ -59,11 +66,4 @@ public final class WorldEditUtil {
Location l2 = new Location(sender.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
return new Location[] {l1, l2};
}
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
}