From 94d9b97575abcde4f5f8549c12b063d6cb8491a1 Mon Sep 17 00:00:00 2001 From: dev-hydrogen Date: Sat, 12 Feb 2022 21:16:20 +0200 Subject: [PATCH] add option to ignore chroma events --- .../com/ilm9001/nightclub/beatmap/BeatmapParser.java | 10 +++++----- .../com/ilm9001/nightclub/beatmap/BeatmapPlayer.java | 9 ++++++--- .../com/ilm9001/nightclub/commands/BeatmapCommand.java | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapParser.java b/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapParser.java index 513405c..6abf08c 100644 --- a/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapParser.java +++ b/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapParser.java @@ -21,7 +21,7 @@ public class BeatmapParser { * @return InfoData which includes bpm, artist, song folder and the beatmaps author. * Returns null if no info.dat file can be found. */ - public static @Nullable InfoData getInfoData(String folder) { + public static @Nullable InfoData getInfoData(String folder, boolean dontUseChroma) { File dataFolder = Nightclub.DATA_FOLDER; File infoFolder = new File(dataFolder + "/" + folder); @SuppressWarnings("ConstantConditions") // compiler warns about "infoFolder.listFiles() might be null". please tell me how. @@ -77,7 +77,7 @@ public class BeatmapParser { secondaryColor = new Color(envColorLeft.get("r").getAsFloat(), envColorRight.get("g").getAsFloat(), envColorRight.get("b").getAsFloat()); isChroma = true; } - if (requirements != null && !isChroma) { + if (requirements != null) { isChroma = requirements.contains(new JsonPrimitive("Chroma")) || requirements.contains(new JsonPrimitive("Chroma Lighting Events")) || requirements.contains(new JsonPrimitive("Chroma Special Events")); @@ -102,7 +102,7 @@ public class BeatmapParser { .mapper(info.get("_levelAuthorName").getAsString()) .songSubName(info.get("_songSubName").getAsString()) .beatmapFileName(filename) - .isChroma(isChroma) + .isChroma(!dontUseChroma && isChroma) .primaryColor(primaryColor) .secondaryColor(secondaryColor) .build(); @@ -113,11 +113,11 @@ public class BeatmapParser { * @param name Folder where beatmap is (/name/ExpertPlus.dat/) * @return List of LightEvent's in the beatmap file. Returns an empty list if info file can't be found */ - public static @NotNull List getEvents(String name) { + public static @NotNull List getEvents(String name, boolean dontUseChroma) { File dataFolder = Nightclub.DATA_FOLDER; List events = new ArrayList<>(); JsonArray eventArray; - InfoData info = BeatmapParser.getInfoData(name); + InfoData info = BeatmapParser.getInfoData(name, dontUseChroma); if (info == null) { return new ArrayList<>(); } diff --git a/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapPlayer.java b/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapPlayer.java index 0f0b010..8d8e1fe 100644 --- a/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapPlayer.java +++ b/src/main/java/com/ilm9001/nightclub/beatmap/BeatmapPlayer.java @@ -23,14 +23,17 @@ public class BeatmapPlayer { private ScheduledExecutorService executorService; @Getter private boolean isPlaying; + public BeatmapPlayer(String name) { + this(name, false); + } /** * Constructor that defines a new Beatmap you can play from. * * @param name name of the folder the beatmap itself resides in (/name/ExpertPlus.dat) */ - public BeatmapPlayer(String name) { - info = BeatmapParser.getInfoData(name); - events = BeatmapParser.getEvents(name); + public BeatmapPlayer(String name, boolean dontUseChroma) { + info = BeatmapParser.getInfoData(name, dontUseChroma); + events = BeatmapParser.getEvents(name, dontUseChroma); this.name = name; playTo = new ArrayList<>(); } diff --git a/src/main/java/com/ilm9001/nightclub/commands/BeatmapCommand.java b/src/main/java/com/ilm9001/nightclub/commands/BeatmapCommand.java index ce169c7..e7f5845 100644 --- a/src/main/java/com/ilm9001/nightclub/commands/BeatmapCommand.java +++ b/src/main/java/com/ilm9001/nightclub/commands/BeatmapCommand.java @@ -33,11 +33,12 @@ public static void onPlay(CommandSender sender, String[] args) { List errors = LightUniverseCommand.isUnloaded(args, 1); errors.add(Util.getStringValuesFromArray(new File(Nightclub.getInstance().getDataFolder().getAbsolutePath()).listFiles(File::isDirectory)) .stream().noneMatch(beatmap -> args[0].equals(beatmap)) ? CommandError.INVALID_ARGUMENT : CommandError.VALID); + errors.add(args.length >= 2 && !(args[1].toLowerCase().contains("true") || args[1].toLowerCase().contains("false")) ? CommandError.INVALID_ARGUMENT : CommandError.VALID); if (errors.stream().anyMatch(error -> error != CommandError.VALID)) { sender.sendMessage(formatErrors(errors)); return; } - player = new BeatmapPlayer(args[0]); + player = new BeatmapPlayer(args[0], args.length >= 2 && Boolean.parseBoolean(args[1])); ArrayList playTo = new ArrayList<>(Bukkit.getOnlinePlayers()); InfoData info = player.play(playTo); String playBackMessage = ChatColor.GOLD + "Now Playing: " + ChatColor.AQUA + info.getSongAuthorName() + " - " + info.getSongName() + " " + info.getSongSubName() + System.lineSeparator()