Fixing a java.io.FileNotFoundException when using SQL

This commit is contained in:
TfT_02 2013-01-14 00:20:41 +01:00
parent 06df8e7f7b
commit 664239c567
2 changed files with 42 additions and 26 deletions

View File

@ -319,6 +319,8 @@ public class mcMMO extends JavaPlugin {
catch (IOException e) {
getLogger().severe(e.toString());
}
Anniversary anniversary = new Anniversary();
anniversary.saveAnniversaryFiles();
getLogger().info("Was disabled."); //How informative!
}

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
@ -21,6 +23,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import com.gmail.nossr50.mcMMO;
public class Anniversary {
@ -40,12 +43,11 @@ public class Anniversary {
System.out.println(ex);
}
}
hasCelebrated = new ArrayList<String>();
try {
hasCelebrated.clear();
BufferedReader reader = new BufferedReader(new FileReader(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "players"));
BufferedReader reader = new BufferedReader(new FileReader(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "anniversary"));
String line = reader.readLine();
while (line != null) {
@ -59,20 +61,31 @@ public class Anniversary {
}
}
//This gets called onDisable
public void saveAnniversaryFiles() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + "anniversary"));
for (String player : hasCelebrated) {
writer.write(player);
writer.newLine();
}
writer.close();
}
catch (Exception ex) {
System.out.println(ex);
}
}
//This gets called from /mcmmo command
public void anniversaryCheck(final CommandSender sender) {
if (sender instanceof Player) {
GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6);
GregorianCalendar day = new GregorianCalendar();
int celebrationCheck = 0;
for (String celebrated : hasCelebrated) {
if (sender.getName().equalsIgnoreCase(celebrated)) {
celebrationCheck = 1;
}
}
if (celebrationCheck == 0) {
if (hasCelebrated.contains(sender.getName())) {
return;
} else {
if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) {
sender.sendMessage(ChatColor.BLUE + "Happy 2 Year Anniversary! In honor of all of");
sender.sendMessage(ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
@ -90,6 +103,7 @@ public class Anniversary {
hasCelebrated.add(sender.getName());
}
}
}
private boolean getDateRange(Date date, Date start, Date end) {
return !(date.before(start) || date.after(end));