diff --git a/build/classes/java/main/com/severalcircles/flames/data/user/FlamesUser.class b/build/classes/java/main/com/severalcircles/flames/data/user/FlamesUser.class index 2b912f1..ab49007 100644 Binary files a/build/classes/java/main/com/severalcircles/flames/data/user/FlamesUser.class and b/build/classes/java/main/com/severalcircles/flames/data/user/FlamesUser.class differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 0e36c21..514050f 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/severalcircles/flames/conversations/Conversation.java b/src/main/java/com/severalcircles/flames/conversations/Conversation.java index ae9db66..fc5f01e 100644 --- a/src/main/java/com/severalcircles/flames/conversations/Conversation.java +++ b/src/main/java/com/severalcircles/flames/conversations/Conversation.java @@ -8,6 +8,7 @@ import com.severalcircles.flames.data.FlamesDataManager; import com.severalcircles.flames.data.global.GlobalData; import com.severalcircles.flames.data.server.FlamesServer; +import com.severalcircles.flames.data.server.HootenannyDataManager; import com.severalcircles.flames.data.user.FlamesUser; import com.severalcircles.flames.data.user.UserEntities; import com.severalcircles.flames.exception.ConsentException; @@ -146,8 +147,17 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t user.addScore((int) score); System.out.println("Score: " + score); FlamesDataManager.saveServer(server); + GlobalData.globalScore += (int) score; GlobalData.averageScore = GlobalData.globalScore / GlobalData.participants; + if (server.todayIsHootenannyDay()) { + server.getHootenannyData().addScore(user.getDiscordId(), (int) score); + } + try { + HootenannyDataManager.saveData(server.getHootenannyData(), message.getGuildId()); + } catch (IOException e) { + throw new RuntimeException(e); + } if (user.getScore() > Today.highScore) { Today.highUser = message.getAuthor().getName() + " (" + user.getScore() + ")"; } diff --git a/src/main/java/com/severalcircles/flames/data/FlamesDataManager.java b/src/main/java/com/severalcircles/flames/data/FlamesDataManager.java index 6996d12..8accd31 100644 --- a/src/main/java/com/severalcircles/flames/data/FlamesDataManager.java +++ b/src/main/java/com/severalcircles/flames/data/FlamesDataManager.java @@ -259,6 +259,12 @@ public static void addChannelWord(String word, Channel channel) { } public static FlamesServer getServer(String id) { File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + ".fl"); + File serverHootenannyDataFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + "-hootenannyData.fl"); + try { + serverHootenannyDataFile.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } FlamesServer server; try { if (serverFile.createNewFile()) { diff --git a/src/main/java/com/severalcircles/flames/data/server/FlamesServer.java b/src/main/java/com/severalcircles/flames/data/server/FlamesServer.java index 587b449..c43bfe1 100644 --- a/src/main/java/com/severalcircles/flames/data/server/FlamesServer.java +++ b/src/main/java/com/severalcircles/flames/data/server/FlamesServer.java @@ -4,6 +4,7 @@ package com.severalcircles.flames.data.server; +import java.io.IOException; import java.util.Properties; import java.util.Random; @@ -11,12 +12,17 @@ public class FlamesServer { private int score; private String id; private int hootenannyDay; - + ServerHootenannyData hootenannyData; public FlamesServer(int score, String id, int hootenannyDay) { this.score = score; this.id = id; this.hootenannyDay = hootenannyDay; - + try { + hootenannyData = HootenannyDataManager.getData(id); + } catch (IOException e) { + e.printStackTrace(); + hootenannyData = new ServerHootenannyData(); + } } public FlamesServer(String id) { this.id = id; @@ -30,6 +36,10 @@ public Properties createData() { data.put("hootenannyDay", String.valueOf(hootenannyDay)); return data; } + public boolean todayIsHootenannyDay() { + return hootenannyDay == new java.util.Date().getDate(); + } + public int getHootenannyDay() { return hootenannyDay; } @@ -49,6 +59,10 @@ public String getId() { return id; } + public ServerHootenannyData getHootenannyData() { + return hootenannyData; + } + public void setId(String id) { this.id = id; } diff --git a/src/main/java/com/severalcircles/flames/data/server/HootenannyDataManager.java b/src/main/java/com/severalcircles/flames/data/server/HootenannyDataManager.java index dc33266..3bfbdea 100644 --- a/src/main/java/com/severalcircles/flames/data/server/HootenannyDataManager.java +++ b/src/main/java/com/severalcircles/flames/data/server/HootenannyDataManager.java @@ -4,7 +4,24 @@ package com.severalcircles.flames.data.server; -public class HootenannyDataManager { - +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Properties; +public class HootenannyDataManager { + public static ServerHootenannyData getData(String serverId) throws IOException { + Properties data = new Properties(); + data.load(Files.newInputStream(Paths.get("server/" + serverId + "-hootenannyData.fl"))); + ServerHootenannyData hootenannyData = new ServerHootenannyData(); + for (String key : data.stringPropertyNames()) { + hootenannyData.addScore(key, Integer.parseInt(data.getProperty(key))); + } + return hootenannyData; + } + public static void saveData(ServerHootenannyData hootenannyData, String serverId) throws IOException { + Properties data = hootenannyData.createData(); + data.store(Files.newOutputStream(Paths.get("server/" + serverId + "-hootenannyData.fl")), "Hootenanny Data for " + serverId); + } } diff --git a/src/main/java/com/severalcircles/flames/data/server/HootenannyTitle.java b/src/main/java/com/severalcircles/flames/data/server/HootenannyTitle.java index 5b437bc..7220338 100644 --- a/src/main/java/com/severalcircles/flames/data/server/HootenannyTitle.java +++ b/src/main/java/com/severalcircles/flames/data/server/HootenannyTitle.java @@ -5,7 +5,8 @@ package com.severalcircles.flames.data.server; public enum HootenannyTitle { - SERVER_FAN(0), SERVER_ENJOYER(100), SERVER_FIEND(500), SERVER_DEFENDER(1000), SERVER_CHAMPION(2500), SERVER_RULER(5000) + SERVER_FAN(0), SERVER_ENJOYER(100), SERVER_FIEND(500), + SERVER_DEFENDER(1000), SERVER_CHAMPION(2500), SERVER_RULER(5000) ; final int scoreThresh; HootenannyTitle(int scoreThresh) {