Skip to content

Commit

Permalink
remove illegal characters from reset save file names
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Mar 21, 2024
1 parent 525e957 commit a856f13
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/us/ajg0702/leaderboards/utils/ResetSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class ResetSaver {

Expand All @@ -32,6 +34,8 @@ public ResetSaver(LeaderboardPlugin plugin) {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private final SimpleDateFormat timeDateFormat = new SimpleDateFormat("yyyy-MM-dd_'h'HH'm'mm");

private final List<String> illegalFileNameChars = Arrays.asList(":", ",", File.separator);

public void save(String board, TimedType type) {

int count = plugin.getAConfig().getInt("reset-save-positions");
Expand Down Expand Up @@ -72,7 +76,10 @@ public void save(String board, TimedType type) {
File.separator + type.lowerName() + File.separator
);
File file = new File(folder,
board.replaceAll(Matcher.quoteReplacement(File.separator), "_") +
board.replaceAll(
"(" + illegalFileNameChars.stream().map(Matcher::quoteReplacement).collect(Collectors.joining("|")) + ")",
"_"
) +
"_" + type.lowerName() + "_" + date + ".json"
);
if(folder.mkdirs()) {
Expand Down

0 comments on commit a856f13

Please sign in to comment.