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 = formatter.format(messageArguments);
} }
string.replaceAll("\'", "''");
string = addColors(string); string = addColors(string);
return string; return string;

View File

@ -328,11 +328,15 @@ public class mcMMO extends JavaPlugin {
File oldModPath = new File(mainDirectory + "ModConfigs" + File.separator); File oldModPath = new File(mainDirectory + "ModConfigs" + File.separator);
if (oldFlatfilePath.exists()) { 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()) { 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); new BleedTimerTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
// Old & Powerless User remover // 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) { if (purgeIntervalTicks == 0) {
new UserPurgeTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup. 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 // 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) { if (kickIntervalTicks == 0) {
new PartyAutoKickTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup. 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() { public static void saveParties() {
if (partyFile.exists()) { 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(); 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."); mcMMO.p.getLogger().info("Cleaned backup files. Deleted " + amountDeleted + " of " + amountTotal + " files.");
for (File file : toDelete) { for (File file : toDelete) {
mcMMO.p.debug("Deleted: " + file.getName()); if (file.delete()) {
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; import com.gmail.nossr50.util.player.UserManager;
public class AlchemyBrewTask extends BukkitRunnable { public class AlchemyBrewTask extends BukkitRunnable {
private final double DEFAULT_BREW_SPEED = 1.0; private static double DEFAULT_BREW_SPEED = 1.0;
private final int DEFAULT_BREW_TICKS = 400; private static int DEFAULT_BREW_TICKS = 400;
private Block brewingStand; private Block brewingStand;
private double brewSpeed; private double brewSpeed;

View File

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

View File

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