This repository has been archived by the owner on Jun 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scoreboard saving should be complete
- Loading branch information
1 parent
49140fc
commit 923be64
Showing
6 changed files
with
151 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/usa/cactuspuppy/uhc_automation/ScoreboardUtils/ScoreboardIO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package usa.cactuspuppy.uhc_automation.ScoreboardUtils; | ||
|
||
import org.bukkit.scoreboard.Scoreboard; | ||
import usa.cactuspuppy.uhc_automation.Main; | ||
|
||
import java.io.*; | ||
import java.util.Optional; | ||
|
||
public class ScoreboardIO { | ||
public boolean saveScoreboardToFile() { | ||
Scoreboard scoreboard = Main.getInstance().getGameInstance().getScoreboard(); | ||
String outLoc = Main.getInstance().getDataFolder() + "/scoreboard.dat"; | ||
File outFile = new File(outLoc); | ||
if (outFile.isFile() && !outFile.delete()) { | ||
Main.getInstance().getLogger().severe("Could not override existing scoreboard data at " + outFile.getPath()); | ||
return false; | ||
} | ||
try { | ||
FileOutputStream fileOut = new FileOutputStream(outLoc); | ||
ObjectOutputStream out = new ObjectOutputStream(fileOut); | ||
out.writeObject(new ScoreboardWrapper(scoreboard)); | ||
out.close(); | ||
fileOut.close(); | ||
Main.getInstance().getLogger().info("Scoreboard data saved to " + outLoc); | ||
} catch (IOException e) { | ||
Main.getInstance().getLogger().severe("Failed to save scoreboard data!"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public Optional<Scoreboard> readScoreboardFromFile() { | ||
String inLoc = Main.getInstance().getDataFolder() + "/scoreboard.dat"; | ||
Scoreboard scoreboard = null; | ||
try { | ||
FileInputStream fileIn = new FileInputStream(inLoc); | ||
ObjectInputStream in = new ObjectInputStream(fileIn); | ||
scoreboard = (Scoreboard) in.readObject(); | ||
in.close(); | ||
fileIn.close(); | ||
} catch (IOException e) { | ||
Main.getInstance().getLogger().severe("Could not load scoreboard data from " + inLoc); | ||
return Optional.empty(); | ||
} catch (ClassNotFoundException e) { | ||
Main.getInstance().getLogger().severe("Did not find expected scoreboard class at " + inLoc); | ||
} | ||
return Optional.ofNullable(scoreboard); | ||
} | ||
|
||
public boolean scoreboardDataExists() { | ||
String sbLoc = Main.getInstance().getDataFolder() + "/scoreboard.dat"; | ||
return (new File(sbLoc)).isFile(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/usa/cactuspuppy/uhc_automation/ScoreboardUtils/ScoreboardWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package usa.cactuspuppy.uhc_automation.ScoreboardUtils; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.scoreboard.Scoreboard; | ||
|
||
import java.io.Serializable; | ||
import java.util.Set; | ||
|
||
@Getter @AllArgsConstructor | ||
public class ScoreboardWrapper implements Serializable { | ||
private Scoreboard scoreboard; | ||
} |
9 changes: 0 additions & 9 deletions
9
src/main/java/usa/cactuspuppy/uhc_automation/Tasks/ScoreboardSaver.java
This file was deleted.
Oops, something went wrong.