A round of FindBugs, and fix red interceptor not working at all

This commit is contained in:
Vincent Lee committed 2016-04-11 22:47:24 -05:00
1 parent e73feae688
commit effd07129c
24 files changed
+71 -61

No files matched your search

@@ -115,11 +115,11 @@ public final class BotaniaAPI {
public static final EnumRarity rarityRelic = EnumHelper.addRarity("RELIC", TextFormatting.GOLD, "Relic");
public static KnowledgeType basicKnowledge;
public static KnowledgeType elvenKnowledge;
public static final KnowledgeType basicKnowledge;
public static final KnowledgeType elvenKnowledge;
// This is here for completeness sake, but you shouldn't use it
public static KnowledgeType relicKnowledge;
public static final KnowledgeType relicKnowledge;
// All of these categories are initialized during botania's PreInit stage.
public static LexiconCategory categoryBasics;
@@ -133,7 +133,7 @@ public final class BotaniaAPI {
public static LexiconCategory categoryAlfhomancy;
public static LexiconCategory categoryMisc;
public static Brew fallbackBrew = new Brew("fallback", "botania.brew.fallback", 0, 0);
public static final Brew fallbackBrew = new Brew("fallback", "botania.brew.fallback", 0, 0);
static {
registerSubTile("", DummySubTile.class);
@@ -10,7 +10,9 @@
*/
package vazkii.botania.client.core.handler;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -199,11 +201,12 @@ public final class ContributorFancinessHandler implements LayerRenderer<EntityPl
try {
URL url = new URL("https://raw.githubusercontent.com/Vazkii/Botania/master/contributors.properties");
Properties props = new Properties();
props.load(new InputStreamReader(url.openStream()));
load(props);
} catch(Exception e) {
try (InputStreamReader reader = new InputStreamReader(url.openStream())) {
props.load(reader);
load(props);
}
} catch (IOException e) {
FMLLog.info("[Botania] Could not load contributors list. Either you're offline or github is down. Nothing to worry about, carry on~");
e.printStackTrace();
}
VersionChecker.doneChecking = true;
}
@@ -194,7 +194,7 @@ public class LightningHandler {
private World world;
private Entity source;
public static ConcurrentLinkedQueue<LightningBolt> boltlist = new ConcurrentLinkedQueue<>();
public static final ConcurrentLinkedQueue<LightningBolt> boltlist = new ConcurrentLinkedQueue<>();
public float speed = 1.5F;
public static final int fadetime = 20;
@@ -205,7 +205,7 @@ public class LightningHandler {
public int colorOuter;
public int colorInner;
public class BoltPoint {
public static class BoltPoint {
public BoltPoint(Vector3 basepoint, Vector3 offsetvec) {
point = basepoint.copy().add(offsetvec);
@@ -20,6 +20,7 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import net.minecraft.client.Minecraft;
@@ -73,7 +74,7 @@ public class GuiLexicon extends GuiScreen {
public static GuiLexicon currentOpenLexicon = new GuiLexicon();
public static ItemStack stackUsed;
public static HashMap<String, String> notes = new HashMap<>();
public static final Map<String, String> notes = new HashMap<>();
private static final String TAG_TYPE = "type";
@@ -82,11 +83,11 @@ public class GuiLexicon extends GuiScreen {
public static final int BOOKMARK_START = 1337;
public static final int NOTES_BUTTON_ID = 1336; // random button tho
public static final int MAX_BOOKMARK_COUNT = 8;
public static List<GuiLexicon> bookmarks = new ArrayList<>();
public static List<String> bookmarkKeys = new ArrayList<>();
boolean bookmarksNeedPopulation = false;
public static final List<GuiLexicon> bookmarks = new ArrayList<>();
public static final List<String> bookmarkKeys = new ArrayList<>();
private boolean bookmarksNeedPopulation = false;
public static Queue<LexiconEntry> tutorial = new ArrayDeque<>();
public static final Queue<LexiconEntry> tutorial = new ArrayDeque<>();
public static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_LEXICON);
public static final ResourceLocation textureToff = new ResourceLocation(LibResources.GUI_TOFF);
@@ -20,7 +20,7 @@ import vazkii.botania.api.lexicon.LexiconEntry;
public class GuiLexiconHistory extends GuiLexiconIndex {
public static List<LexiconEntry> history = new ArrayList<>();
public static final List<LexiconEntry> history = new ArrayList<>();
public GuiLexiconHistory() {
super(null);
@@ -25,13 +25,13 @@ import vazkii.botania.common.entity.EntityDoppleganger;
public class RenderDoppleganger extends RenderBiped<EntityDoppleganger> {
public static float DEFAULT_GRAIN_INTENSITY = 0.05F;
public static float DEFAULT_DISFIGURATION = 0.025F;
public static final float DEFAULT_GRAIN_INTENSITY = 0.05F;
public static final float DEFAULT_DISFIGURATION = 0.025F;
public static float grainIntensity = DEFAULT_GRAIN_INTENSITY;
public static float disfiguration = DEFAULT_DISFIGURATION;
public static ShaderCallback callback = shader -> {
public static final ShaderCallback callback = shader -> {
// Frag Uniforms
int disfigurationUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "disfiguration");
ARBShaderObjects.glUniform1fARB(disfigurationUniform, disfiguration);
@@ -41,7 +41,7 @@ public class RenderDoppleganger extends RenderBiped<EntityDoppleganger> {
ARBShaderObjects.glUniform1fARB(grainIntensityUniform, grainIntensity);
};
public static ShaderCallback defaultCallback = shader -> {
public static final ShaderCallback defaultCallback = shader -> {
// Frag Uniforms
int disfigurationUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "disfiguration");
ARBShaderObjects.glUniform1fARB(disfigurationUniform, DEFAULT_DISFIGURATION);
@@ -21,7 +21,7 @@ import vazkii.botania.api.item.IRelic;
public class AchievementMod extends Achievement {
public static List<Achievement> achievements = new ArrayList<>();
public static final List<Achievement> achievements = new ArrayList<>();
public AchievementMod(String name, int x, int y, ItemStack icon, Achievement parent) {
super("achievement.botania:" + name, "botania:" + name, x, y, icon, parent);
@@ -26,7 +26,7 @@ public class SubTileSolegnolia extends SubTileFunctional {
private static final double RANGE = 5;
private static final double RANGE_MINI = 1;
public static Set<SubTileSolegnolia> existingFlowers = Collections.newSetFromMap(new WeakHashMap<>());
public static final Set<SubTileSolegnolia> existingFlowers = Collections.newSetFromMap(new WeakHashMap<>());
private static boolean registered = false;
@Override
@@ -28,7 +28,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class SubTileVinculotus extends SubTileFunctional {
public static Set<SubTileVinculotus> existingFlowers = Collections.newSetFromMap(new WeakHashMap<>());
public static final Set<SubTileVinculotus> existingFlowers = Collections.newSetFromMap(new WeakHashMap<>());
private static boolean registered = false;
private static final int RANGE = 64;
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.google.common.base.Predicates;
import net.minecraft.block.state.IBlockState;
@@ -323,9 +324,9 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
itemToEnchant.writeToNBT(itemCmp);
cmp.setTag(TAG_ITEM, itemCmp);
String enchStr = "";
for(EnchantmentData data : enchants)
enchStr = enchStr + Enchantment.enchantmentRegistry.getNameForObject(data.enchantmentobj) + ":" + data.enchantmentLevel + ",";
String enchStr = enchants.stream()
.map(e -> Enchantment.enchantmentRegistry.getNameForObject(e.enchantmentobj) + ":" + e.enchantmentLevel)
.collect(Collectors.joining(","));
cmp.setString(TAG_ENCHANTS, enchStr.isEmpty() ? enchStr : enchStr.substring(0, enchStr.length() - 1));
}
@@ -315,7 +315,7 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
long least = cmp.getLong(TAG_UUID_LEAST);
UUID identity = getIdentifierUnsafe();
if(identity == null || most != identity.getMostSignificantBits() || least != identity.getLeastSignificantBits())
identity = new UUID(most, least);
this.identity = new UUID(most, least);
} else getIdentifier();
mana = cmp.getInteger(TAG_MANA);
@@ -11,7 +11,9 @@
package vazkii.botania.common.block.tile.string;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@@ -24,12 +26,12 @@ import vazkii.botania.api.state.BotaniaStateProps;
public class TileRedStringInterceptor extends TileRedString {
public static List<TileRedStringInterceptor> interceptors = new ArrayList<>();
private static final ThreadLocal<Set<TileRedStringInterceptor>> interceptors = ThreadLocal.withInitial(HashSet::new);;
@Override
public void updateEntity() {
if(!interceptors.contains(this))
interceptors.add(this);
super.updateEntity();
interceptors.get().add(this);
}
@Override
@@ -37,19 +39,17 @@ public class TileRedStringInterceptor extends TileRedString {
return worldObj.getTileEntity(pos) != null;
}
public boolean removeFromList() {
return !tileEntityInvalid && worldObj.getTileEntity(pos) == this;
private boolean saneState() {
return !isInvalid() && worldObj.getTileEntity(pos) == this;
}
public static void onInteract(EntityPlayer player, World world, BlockPos pos, EnumHand hand) {
List<TileRedStringInterceptor> remove = new ArrayList<>();
boolean did = false;
// CMEs are amazing
List<TileRedStringInterceptor> interceptorsCopy = new ArrayList<>(interceptors);
for(TileRedStringInterceptor inter : interceptorsCopy) {
if(!inter.removeFromList()) {
for(TileRedStringInterceptor inter : interceptors.get()) {
if(!inter.saneState()) {
remove.add(inter);
continue;
}
@@ -68,7 +68,7 @@ public class TileRedStringInterceptor extends TileRedString {
}
}
interceptors.removeAll(remove);
interceptors.get().removeAll(remove);
if(did) {
if(world.isRemote)
player.swingArm(hand);
@@ -27,7 +27,7 @@ import vazkii.botania.common.lib.LibMisc;
public final class BotaniaCreativeTab extends CreativeTabs {
public static BotaniaCreativeTab INSTANCE = new BotaniaCreativeTab();
public static final BotaniaCreativeTab INSTANCE = new BotaniaCreativeTab();
List<ItemStack> list;
public BotaniaCreativeTab() {
@@ -11,6 +11,7 @@
package vazkii.botania.common.core.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.entity.Entity;
@@ -37,8 +38,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public final class SheddingHandler {
public static ArrayList<ShedPattern> patterns = new ArrayList<>();
public static ArrayList<ShedPattern> defaultPatterns = new ArrayList<>();
public static final List<ShedPattern> patterns = new ArrayList<>();
public static final List<ShedPattern> defaultPatterns = new ArrayList<>();
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
@@ -108,8 +108,8 @@ public class Quat {
public String toString() {
StringBuilder stringbuilder = new StringBuilder();
Formatter formatter = new Formatter(stringbuilder, Locale.US);
formatter.format("Quaternion:\n");
formatter.format(" < %f %f %f %f >\n", s, x, y, z);
formatter.format("Quaternion:%n");
formatter.format(" < %f %f %f %f >%n", s, x, y, z);
formatter.close();
return stringbuilder.toString();
}
@@ -30,9 +30,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class Vector3
{
public static Vector3 zero = new Vector3();
public static Vector3 one = new Vector3(1, 1, 1);
public static Vector3 center = new Vector3(0.5, 0.5, 0.5);
public static final Vector3 zero = new Vector3();
public static final Vector3 one = new Vector3(1, 1, 1);
public static final Vector3 center = new Vector3(0.5, 0.5, 0.5);
public double x;
public double y;
@@ -12,9 +12,11 @@ package vazkii.botania.common.core.version;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import net.minecraft.client.Minecraft;
@@ -58,7 +60,7 @@ public class ThreadDownloadMod extends Thread {
try {
url.openStream().close(); // Add to DL Counter
} catch(IOException e) { }
} catch(IOException ignored) {}
url = new URL(base + "files/" + file);
webReader = url.openStream();
@@ -87,15 +89,9 @@ public class ThreadDownloadMod extends Thread {
Desktop.getDesktop().open(dir);
VersionChecker.downloadedFile = true;
finalize();
} catch(Throwable e) {
} catch (IOException e) {
e.printStackTrace();
sendError();
try {
finalize();
} catch(Throwable e1) {
e1.printStackTrace();
}
}
}
@@ -79,7 +79,7 @@ public class ItemFlightTiara extends ItemBauble implements IManaUsingItem, IBaub
private static final String TAG_DASH_COOLDOWN = "dashCooldown";
private static final String TAG_IS_SPRINTING = "isSprinting";
public static List<String> playersWithFlight = new ArrayList();
public static final List<String> playersWithFlight = new ArrayList();
private static final int COST = 35;
private static final int COST_OVERKILL = COST * 3;
private static final int MAX_FLY_TIME = 1200;
@@ -39,7 +39,7 @@ import baubles.api.BaubleType;
public class ItemIcePendant extends ItemBauble implements IBaubleRender {
public static Map<String, List<IceRemover>> playerIceBlocks = new HashMap<>();
public static final Map<String, List<IceRemover>> playerIceBlocks = new HashMap<>();
public ItemIcePendant() {
super(LibItemNames.ICE_PENDANT);
@@ -121,7 +121,7 @@ public class ItemIcePendant extends ItemBauble implements IBaubleRender {
}
}
class IceRemover {
private static class IceRemover {
int time = 30;
final BlockPos coords;
@@ -45,7 +45,7 @@ public class ItemTravelBelt extends ItemBauble implements IBaubleRender, IManaUs
private static final int COST = 1;
private static final int COST_INTERVAL = 10;
public static List<String> playersWithStepup = new ArrayList<>();
public static final List<String> playersWithStepup = new ArrayList<>();
final float speed;
final float jump;
@@ -16,6 +16,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Set;
@@ -386,6 +387,11 @@ public class ItemTerraAxe extends ItemManasteelAxe implements ISequentialBreaker
SwapCandidate cand = (SwapCandidate) other;
return coordinates.equals(cand.coordinates) && range == cand.range;
}
@Override
public int hashCode() {
return Objects.hash(coordinates, range);
}
}
}
@@ -42,7 +42,7 @@ public class ItemSmeltRod extends ItemMod implements IManaUsingItem {
private static final int COST = 300;
private static final int COST_PER_TICK = COST / TIME;
public static Map<EntityPlayer, SmeltData> playerData = new WeakHashMap<>();
public static final Map<EntityPlayer, SmeltData> playerData = new WeakHashMap<>();
public ItemSmeltRod() {
super(LibItemNames.SMELT_ROD);
@@ -159,7 +159,7 @@ public class ItemTerraformRod extends ItemMod implements IManaUsingItem, IBlockP
return true;
}
private class CoordsWithBlock extends BlockPos {
private static class CoordsWithBlock extends BlockPos {
private final Block block;
@@ -11,7 +11,9 @@
package vazkii.botania.common.lexicon.page;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.text.translation.I18n;
@@ -43,7 +45,7 @@ public class PageGuide extends PageText {
Desktop.getDesktop().browse(new URI("https://www.youtube.com/watch?v=rx0xyejC6fI"));
if(Math.random() < 0.01)
Desktop.getDesktop().browse(new URI("https://www.youtube.com/watch?v=dQw4w9WgXcQ"));
} catch(Exception e) { }
} catch(IOException | URISyntaxException ignored) { }
}
}