Fix issues pointed out by the FindBugs plugin

This commit is contained in:
TfT_02 2014-01-19 11:49:30 +01:00
parent 79155887b0
commit a1c1271d21
8 changed files with 35 additions and 26 deletions

View File

@ -61,7 +61,6 @@ public final class LocaleLoader {
string = formatter.format(messageArguments);
}
string.replaceAll("\'", "''");
string = addColors(string);
return string;

View File

@ -328,11 +328,15 @@ public class mcMMO extends JavaPlugin {
File oldModPath = new File(mainDirectory + "ModConfigs" + File.separator);
if (oldFlatfilePath.exists()) {
oldFlatfilePath.renameTo(new File(flatFileDirectory));
if (!oldFlatfilePath.renameTo(new File(flatFileDirectory))) {
getLogger().warning("Failed to rename FlatFileStuff to flatfile !");
}
}
if (oldModPath.exists()) {
oldModPath.renameTo(new File(modDirectory));
if (!oldModPath.renameTo(new File(modDirectory))) {
getLogger().warning("Failed to rename ModConfigs to mods !");
}
}
}
@ -422,7 +426,7 @@ public class mcMMO extends JavaPlugin {
new BleedTimerTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
// Old & Powerless User remover
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
if (purgeIntervalTicks == 0) {
new UserPurgeTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
@ -432,7 +436,7 @@ public class mcMMO extends JavaPlugin {
}
// Automatically remove old members from parties
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60 * 60 * Misc.TICK_CONVERSION_FACTOR;
long kickIntervalTicks = Config.getInstance().getAutoPartyKickInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
if (kickIntervalTicks == 0) {
new PartyAutoKickTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.

View File

@ -521,7 +521,10 @@ public final class PartyManager {
*/
public static void saveParties() {
if (partyFile.exists()) {
partyFile.delete();
if (!partyFile.delete()) {
mcMMO.p.getLogger().warning("Could not delete party file. Party saving failed!");
return;
}
}
YamlConfiguration partiesFile = new YamlConfiguration();

View File

@ -87,8 +87,9 @@ public class CleanBackupsTask extends BukkitRunnable {
mcMMO.p.getLogger().info("Cleaned backup files. Deleted " + amountDeleted + " of " + amountTotal + " files.");
for (File file : toDelete) {
mcMMO.p.debug("Deleted: " + file.getName());
file.delete();
if (file.delete()) {
mcMMO.p.debug("Deleted: " + file.getName());
}
}
}

View File

@ -18,8 +18,8 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
public class AlchemyBrewTask extends BukkitRunnable {
private final double DEFAULT_BREW_SPEED = 1.0;
private final int DEFAULT_BREW_TICKS = 400;
private static double DEFAULT_BREW_SPEED = 1.0;
private static int DEFAULT_BREW_TICKS = 400;
private Block brewingStand;
private double brewSpeed;

View File

@ -69,7 +69,8 @@ public class AlchemyManager extends SkillManager {
}
public String getIngredientList() {
String list = "";
StringBuilder list = new StringBuilder();
for (ItemStack ingredient : getIngredients()) {
String string = StringUtils.getPrettyItemString(ingredient.getType()) + (ingredient.getDurability() != 0 ? ":" + ingredient.getDurability() : "");
if (string.equals("Long Grass:2")) {
@ -79,7 +80,7 @@ public class AlchemyManager extends SkillManager {
string = "Pufferfish";
}
list += ", " + string;
list.append(", " + string);
}
return list.substring(2);
}

View File

@ -30,9 +30,9 @@ import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList;
public final class HolidayManager {
private static ArrayList<String> hasCelebrated;
private static int CURRENT_YEAR;
private static int START_YEAR = 2011;
private ArrayList<String> hasCelebrated;
private int currentYear;
private final int startYear = 2011;
private static final List<Color> ALL_COLORS;
private static final List<ChatColor> ALL_CHAT_COLORS;
@ -67,9 +67,9 @@ public final class HolidayManager {
// This gets called onEnable
public HolidayManager() {
CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
currentYear = Calendar.getInstance().get(Calendar.YEAR);
File anniversaryFile = new File(mcMMO.getFlatFileDirectory(), "anniversary." + CURRENT_YEAR + ".yml");
File anniversaryFile = new File(mcMMO.getFlatFileDirectory(), "anniversary." + currentYear + ".yml");
if (!anniversaryFile.exists()) {
try {
@ -113,7 +113,7 @@ public final class HolidayManager {
Pattern pattern = Pattern.compile("anniversary\\.(?:.+)\\.yml");
for (String fileName : FlatFileDir.list()) {
if (!pattern.matcher(fileName).matches() || fileName.equals("anniversary." + CURRENT_YEAR + ".yml")) {
if (!pattern.matcher(fileName).matches() || fileName.equals("anniversary." + currentYear + ".yml")) {
continue;
}
@ -127,15 +127,16 @@ public final class HolidayManager {
}
for (File file : toDelete) {
mcMMO.p.debug("Deleted: " + file.getName());
file.delete();
if (file.delete()) {
mcMMO.p.debug("Deleted: " + file.getName());
}
}
}
// This gets called onDisable
public void saveAnniversaryFiles() {
mcMMO.p.debug("Saving anniversary files...");
String anniversaryFilePath = mcMMO.getFlatFileDirectory() + "anniversary." + CURRENT_YEAR + ".yml";
String anniversaryFilePath = mcMMO.getFlatFileDirectory() + "anniversary." + currentYear + ".yml";
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(anniversaryFilePath));
@ -152,8 +153,8 @@ public final class HolidayManager {
// This gets called from /mcmmo command
public void anniversaryCheck(final CommandSender sender) {
GregorianCalendar anniversaryStart = new GregorianCalendar(CURRENT_YEAR, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryEnd = new GregorianCalendar(CURRENT_YEAR, Calendar.FEBRUARY, 6);
GregorianCalendar anniversaryStart = new GregorianCalendar(currentYear, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryEnd = new GregorianCalendar(currentYear, Calendar.FEBRUARY, 6);
GregorianCalendar day = new GregorianCalendar();
if (hasCelebrated.contains(sender.getName())) {
@ -164,7 +165,7 @@ public final class HolidayManager {
return;
}
sender.sendMessage(ChatColor.BLUE + "Happy " + (CURRENT_YEAR - START_YEAR) + " Year Anniversary! In honor of all of");
sender.sendMessage(ChatColor.BLUE + "Happy " + (currentYear - startYear) + " Year Anniversary! In honor of all of");
sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
if (sender instanceof Player) {
final int firework_amount = 10;
@ -225,7 +226,7 @@ public final class HolidayManager {
}
private void spawnFireworks(Player player) {
int power = (int) (Misc.getRandom().nextDouble() * 3) + 1;
int power = Misc.getRandom().nextInt(3) + 1;
Type fireworkType = Type.values()[Misc.getRandom().nextInt(Type.values().length)];
double varX = Misc.getRandom().nextGaussian() * 3;
double varZ = Misc.getRandom().nextGaussian() * 3;

View File

@ -172,7 +172,7 @@ public class ScoreboardManager {
public static void cleanup(ScoreboardWrapper wrapper) {
PLAYER_SCOREBOARDS.remove(wrapper.playerName);
if (wrapper != null && wrapper.revertTask != null) {
if (wrapper.revertTask != null) {
wrapper.revertTask.cancel();
}
}