Fixed file delete and prevented constant config saving

This commit is contained in:
Norbi Peti 2016-10-29 23:20:16 +02:00
parent 9614fa0994
commit 01ee8d7e94

View file

@ -41,6 +41,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
BufferedReader reader = Files.newReader(file, StandardCharsets.UTF_8); BufferedReader reader = Files.newReader(file, StandardCharsets.UTF_8);
String line = reader.readLine(); String line = reader.readLine();
lastannouncementtime = Long.parseLong(line); lastannouncementtime = Long.parseLong(line);
reader.close();
file.delete(); file.delete();
} else { } else {
lastannouncementtime = getConfig().getLong("lastannouncementtime"); lastannouncementtime = getConfig().getLong("lastannouncementtime");
@ -147,9 +148,12 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
genchannel.pin(sendMessageToChannel(genchannel, msgsb.toString())); genchannel.pin(sendMessageToChannel(genchannel, msgsb.toString()));
if (modmsgsb.length() > 0) if (modmsgsb.length() > 0)
sendMessageToChannel(annchannel, modmsgsb.toString()); sendMessageToChannel(annchannel, modmsgsb.toString());
if (lastannouncementtime != lastanntime) {
lastannouncementtime = lastanntime; // If sending succeeded lastannouncementtime = lastanntime; // If sending succeeded
getConfig().set("lastannouncementtime", lastannouncementtime); getConfig().set("lastannouncementtime", lastannouncementtime);
getConfig().set("lastseentime", lastseentime); getConfig().set("lastseentime", lastseentime);
saveConfig();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }