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) { catch (IOException e) {
getLogger().severe(e.toString()); getLogger().severe(e.toString());
} }
Anniversary anniversary = new Anniversary();
anniversary.saveAnniversaryFiles();
getLogger().info("Was disabled."); //How informative! getLogger().info("Was disabled."); //How informative!
} }

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -21,6 +23,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
public class Anniversary { public class Anniversary {
@ -40,12 +43,11 @@ public class Anniversary {
System.out.println(ex); System.out.println(ex);
} }
} }
hasCelebrated = new ArrayList<String>(); hasCelebrated = new ArrayList<String>();
try { try {
hasCelebrated.clear(); 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(); String line = reader.readLine();
while (line != null) { 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 //This gets called from /mcmmo command
public void anniversaryCheck(final CommandSender sender) { public void anniversaryCheck(final CommandSender sender) {
if (sender instanceof Player) {
GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3); GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3);
GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6); GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6);
GregorianCalendar day = new GregorianCalendar(); GregorianCalendar day = new GregorianCalendar();
int celebrationCheck = 0;
for (String celebrated : hasCelebrated) { if (hasCelebrated.contains(sender.getName())) {
if (sender.getName().equalsIgnoreCase(celebrated)) { return;
celebrationCheck = 1; } else {
}
}
if (celebrationCheck == 0) {
if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) { 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 + "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!"); 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()); hasCelebrated.add(sender.getName());
} }
} }
}
private boolean getDateRange(Date date, Date start, Date end) { private boolean getDateRange(Date date, Date start, Date end) {
return !(date.before(start) || date.after(end)); return !(date.before(start) || date.after(end));