From acb51e6a3ae8832bf618d446548e4e893672242b Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sat, 18 Nov 2023 01:42:55 +0100 Subject: [PATCH] 1.1.3 --- gradle.properties | 2 +- .../zombiesutils/ZombiesUtils.java | 3 +- .../commands/CategoryCommand.java | 4 +- .../zombiesutils/commands/SlaCommand.java | 163 +++++++++--------- .../commands/ZombiesUtilsCommand.java | 68 ++++++++ .../zombiesutils/config/Hotkeys.java | 17 +- .../handlers/KeyInputHandler.java | 49 ++++++ .../zombiesutils/handlers/TickHandler.java | 1 + .../mixin/MixinNetHandlerPlayClient.java | 17 +- .../zombiesutils/timer/Timer.java | 20 ++- .../zombiesutils/timer/recorder/Category.java | 2 +- .../zombiesutils/timer/recorder/FileData.java | 2 +- .../timer/recorder/TimesFile.java | 5 +- .../recorder => utils}/FileManager.java | 4 +- .../zombiesutils/utils/Scoreboard.java | 22 ++- 15 files changed, 267 insertions(+), 112 deletions(-) create mode 100644 src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java create mode 100644 src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java rename src/main/java/com/github/stachelbeere1248/zombiesutils/{timer/recorder => utils}/FileManager.java (89%) diff --git a/gradle.properties b/gradle.properties index 398e13f..38a7006 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g baseGroup = com.github.stachelbeere1248.zombiesutils mcVersion = 1.8.9 modid = zombiesutils -version = 1.1.2 \ No newline at end of file +version = 1.1.3 \ No newline at end of file diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java index 3dc985c..94a823a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -5,6 +5,7 @@ import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand; import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler; +import com.github.stachelbeere1248.zombiesutils.handlers.KeyInputHandler; import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler; import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; import net.minecraftforge.client.ClientCommandHandler; @@ -44,7 +45,7 @@ public class ZombiesUtils { MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); MinecraftForge.EVENT_BUS.register(new TickHandler()); MinecraftForge.EVENT_BUS.register(new ChatHandler()); - MinecraftForge.EVENT_BUS.register(hotkeys); + MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); ClientCommandHandler.instance.registerCommand(new CategoryCommand()); ClientCommandHandler.instance.registerCommand(new SlaCommand()); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java index 06322ec..514cdf6 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java @@ -19,12 +19,12 @@ public class CategoryCommand extends CommandBase { } @Override public String getCommandName() { - return "runCategory"; + return "category"; } @Override public String getCommandUsage(ICommandSender sender) { - return "runCategory "; + return "/category "; } @Override diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java index 65c5a68..3b8040a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java @@ -28,90 +28,89 @@ public class SlaCommand extends CommandBase { public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { if (args.length == 0) throw new WrongUsageException( "[Missing option] options: off, offset, rotate, mirror, map, quick"); - else { - switch (args[0]) { - case "off": - SLA.drop(); - sender.addChatMessage(new ChatComponentText("SLA data deleted")); - break; - case "offset": - if (args.length == 1) SLA.getInstance().ifPresent(SLA::resetOffset); - else if (args.length != 4) throw new WrongUsageException( - "An offset should have three coordinates!"); - else { - try { - int x = Integer.parseInt(args[1]); - int y = Integer.parseInt(args[2]); - int z = Integer.parseInt(args[3]); - SLA.getInstance().ifPresent(sla -> sla.setOffset(new int[]{x, y, z})); - } catch (NumberFormatException ignored) { - throw new NumberInvalidException("Invalid Integer:", args[1]); - } + else switch (args[0]) { + case "off": + SLA.drop(); + sender.addChatMessage(new ChatComponentText("SLA data deleted")); + break; + case "offset": + if (args.length == 1) SLA.getInstance().ifPresent(SLA::resetOffset); + else if (args.length != 4) throw new WrongUsageException( + "An offset should have three coordinates!"); + else { + try { + int x = Integer.parseInt(args[1]); + int y = Integer.parseInt(args[2]); + int z = Integer.parseInt(args[3]); + SLA.getInstance().ifPresent(sla -> sla.setOffset(new int[]{x, y, z})); + } catch (NumberFormatException ignored) { + throw new NumberInvalidException("Invalid Integer:", args[1]); } - break; - case "rotate": - if (args.length == 1) SLA.getInstance().ifPresent(sla -> sla.rotate(1)); - else { - int rotations; - try { - rotations = Integer.parseInt(args[1]); - } catch (NumberFormatException ignored) { - throw new NumberInvalidException("Invalid Integer:", args[1]); - } - SLA.getInstance().ifPresent(sla -> sla.rotate(rotations)); + } + break; + case "rotate": + if (args.length == 1) SLA.getInstance().ifPresent(sla -> sla.rotate(1)); + else { + int rotations; + try { + rotations = Integer.parseInt(args[1]); + } catch (NumberFormatException ignored) { + throw new NumberInvalidException("Invalid Integer:", args[1]); } - break; - case "mirror": - switch (args[1]) { - case "x": - SLA.getInstance().ifPresent(SLA::mirrorX); - break; - case "z": - SLA.getInstance().ifPresent(SLA::mirrorZ); - break; - default: - throw new WrongUsageException("Invalid option: available: x, z"); - } - break; - case "map": - switch (args[1]) { - case "de": - SLA.instance = new SLA(Map.DEAD_END); - break; - case "bb": - SLA.instance = new SLA(Map.BAD_BLOOD); - break; - case "aa": - SLA.instance = new SLA(Map.ALIEN_ARCADIUM); - break; - default: - throw new WrongUsageException( - "[Invalid option] options: de, bb, aa", args[1]); - } - break; - case "quick": - switch (args[1]) { + SLA.getInstance().ifPresent(sla -> sla.rotate(rotations)); + } + break; + case "mirror": + switch (args[1]) { + case "x": + SLA.getInstance().ifPresent(SLA::mirrorX); + break; + case "z": + SLA.getInstance().ifPresent(SLA::mirrorZ); + break; + default: + throw new WrongUsageException("Invalid option: available: x, z"); + } + break; + case "map": + switch (args[1]) { + case "de": + SLA.instance = new SLA(Map.DEAD_END); + break; + case "bb": + SLA.instance = new SLA(Map.BAD_BLOOD); + break; + case "aa": + SLA.instance = new SLA(Map.ALIEN_ARCADIUM); + break; + default: + throw new WrongUsageException( + "[Invalid option] options: de, bb, aa", args[1]); + } + break; + case "quick": + switch (args[1]) { + //noinspection SpellCheckingInspection + case "mogi_a": + QuickSLA.mogi_a(); + break; + //noinspection SpellCheckingInspection + case "ghxula": + QuickSLA.ghxula(); + break; + //noinspection SpellCheckingInspection + case "ghxula-garden": + QuickSLA.ghxulaGarden(); + break; + default: //noinspection SpellCheckingInspection - case "mogi_a": - QuickSLA.mogi_a(); - break; - //noinspection SpellCheckingInspection - case "ghxula": - QuickSLA.ghxula(); - break; - //noinspection SpellCheckingInspection - case "ghxula-garden": - QuickSLA.ghxulaGarden(); - break; - default: - //noinspection SpellCheckingInspection - throw new WrongUsageException( - "[Invalid option] options: mogi_a, ghxula, ghxula-garden", args[1]); } - break; - default: - throw new WrongUsageException( - "[Invalid option] options: off, offset, rotate, mirror, map", args[0]); - } + throw new WrongUsageException( + "[Invalid option] options: mogi_a, ghxula, ghxula-garden", args[1]); + } + break; + default: + throw new WrongUsageException( + "[Invalid option] options: off, offset, rotate, mirror, map", args[0]); } } @@ -136,7 +135,7 @@ public class SlaCommand extends CommandBase { case "quick": //noinspection SpellCheckingInspection options.addAll(Arrays.asList("mogi_a", "ghxula", "ghxula-garden")); - default: + default: break; } } return options; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java new file mode 100644 index 0000000..e118c60 --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/ZombiesUtilsCommand.java @@ -0,0 +1,68 @@ +package com.github.stachelbeere1248.zombiesutils.commands; + +import com.github.stachelbeere1248.zombiesutils.timer.Timer; +import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; +import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; +import net.minecraft.command.*; +import net.minecraft.util.BlockPos; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class ZombiesUtilsCommand extends CommandBase { + @Override + public String getCommandName() { + return "zombiesutils"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/zombiesutils"; + } + + @Override + public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { + if (args.length == 0) throw new WrongUsageException( + "[Missing option] options: timer"); + else switch (args[0]) { + case "timer": + switch (args[1]) { + case "kill": Timer.dropInstances(); break; + case "split": + try { + Timer.getInstance().ifPresent(timer -> timer.split(Byte.parseByte(args[2]))); + } catch (NumberFormatException | NullPointerException ignored) { + throw new NumberInvalidException("t",args[2]); + } break; + case "start": new Timer( + Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), + Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map + ); break; + default: + throw new WrongUsageException( + "[Invalid option] options: kill, split, start", args[0]); + } break; + default: + throw new WrongUsageException( + "[Invalid option] options: timer", args[0]); + } + } + @Override + public List addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { + if (args.length == 1) return new ArrayList<>(Collections.singleton("timer")); + switch (args[0]) { + case "timer": + return new ArrayList<>(Arrays.asList("kill","split","start")); + default: return Collections.emptyList(); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java index 205fdbc..aca8b51 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Hotkeys.java @@ -9,6 +9,7 @@ import org.lwjgl.input.Keyboard; public class Hotkeys { private final KeyBinding chatMacro; + private final KeyBinding debug; public Hotkeys() { chatMacro = new KeyBinding( @@ -16,14 +17,20 @@ public class Hotkeys { Keyboard.KEY_Q, "Zombies Utils" ); + debug = new KeyBinding( + "Debug", + Keyboard.KEY_K, + "Zombies Utils" + ); } public void registerAll() { ClientRegistry.registerKeyBinding(this.chatMacro); + ClientRegistry.registerKeyBinding(this.debug); } - @SubscribeEvent - public void onKeyInput(InputEvent.KeyInputEvent event) { - if (Keyboard.getEventKey() == chatMacro.getKeyCode() && Keyboard.getEventKeyState() && Minecraft.getMinecraft().currentScreen == null) { - Minecraft.getMinecraft().thePlayer.sendChatMessage(ZombiesUtilsConfig.getChatMacro()); - } + public KeyBinding getChatMacro() { + return chatMacro; + } + public KeyBinding getDebugger() { + return debug; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java new file mode 100644 index 0000000..f95538f --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java @@ -0,0 +1,49 @@ +package com.github.stachelbeere1248.zombiesutils.handlers; + +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; +import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; +import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import org.lwjgl.input.Keyboard; + + +public class KeyInputHandler { + /* + @SuppressWarnings("SpellCheckingInspection") + private final String[] secret = new String[]{ + "Rule #1: Use Zombies Utils.", + "Rule #2: Use the god damn maarkro.", + "Rule #3: Be as toxic as possible (not).", + "Rule #4: /friend remove 9c3584fe963d4d579081e7e9e225763d", + "Rule #5: Play legit.", + "Rule #6: Don't type wave 3.", + "Rule #7: Don't trust shotgun.", + "Rule #8: Hit your wallshots.", + "Rule #9: Start the recording right now.", + "Rule #10: Don't s1 on wr pace.", + "Rule #11: There can be only one GOAT.", + "Rule #12: Fast T please.", + "Rule #13: Step back if insta.", + "Rule #14: No killing Teammates.", + "rule #15: No arguing because prplx is always left." + }; + private int secretIndex = 0;*/ + @SubscribeEvent + public void onKeyInput(InputEvent.KeyInputEvent event) { + if (Keyboard.getEventKeyState() && Minecraft.getMinecraft().currentScreen == null) { + Hotkeys hotkeys = ZombiesUtils.getInstance().getHotkeys(); + if (Keyboard.getEventKey() == hotkeys.getChatMacro().getKeyCode()) { + Minecraft.getMinecraft().thePlayer.sendChatMessage( + ZombiesUtilsConfig.getChatMacro() + ); + } else if (Keyboard.getEventKey() == hotkeys.getDebugger().getKeyCode()) { + for (Entity entity:Minecraft.getMinecraft().theWorld.loadedEntityList) { + System.out.println(entity.getNBTTagCompound()); + } + } + } + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java index b335814..246b7ae 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java @@ -1,6 +1,7 @@ package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; +import net.minecraftforge.client.event.sound.PlaySoundEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java index 7a63e3e..e5ef7bf 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -4,6 +4,7 @@ import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.game.GameMode; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; +import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.S29PacketSoundEffect; import net.minecraft.network.play.server.S45PacketTitle; @@ -40,18 +41,24 @@ public class MixinNetHandlerPlayClient { ZombiesUtils.getInstance().getLogger().info("Attempting creation of new timer"); new Timer( Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), - Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")) + Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")).map ); - } else { - Timer timer = Timer.getInstance().get(); - if (timer.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) timer.split(Scoreboard.getRound()); + } else { Timer timer = Timer.getInstance().get(); + Scoreboard.MapContainer map = Scoreboard.getMap().orElseThrow(() -> new RuntimeException("Scoreboard Error")); + if (map.pregame) { + ZombiesUtils.getInstance().getLogger().info("Attempting creation of new timer"); + new Timer( + Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), + map.map + ); + } else if (timer.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) timer.split(Scoreboard.getRound()); else { ZombiesUtils.getInstance().getLogger().info("Attempting creation of new timer"); //also kills the previous timer using the garbage collector new Timer( Scoreboard.getServerNumber().orElseThrow(() -> new RuntimeException("cannot figure out servernumber")), - Scoreboard.getMap().orElseThrow(() -> new RuntimeException("cannot figure out map")) + map.map ); } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java index 85b0dc4..dbe122b 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java @@ -20,7 +20,7 @@ public class Timer { private final String serverNumber; public Category category; private boolean pbTracking = false; - private byte dontDupeSplitPlease = 0; + private int round = 0; /** * Constructs a timer and saves it to {@link #instance}. @@ -49,12 +49,19 @@ public class Timer { final int gameTime = gameTime(); final short roundTime = (short) (gameTime - passedRoundsTickSum); - if (dontDupeSplitPlease == passedRound || passedRound == 0 || roundTime == 0) { + if ((round == passedRound) || (passedRound == 0) || (roundTime == 0)) { ZombiesUtils.getInstance().getLogger().debug("SPLIT CANCELLED"); return; } - if (passedRound == (byte) 1) pbTracking = true; + record(passedRound, roundTime, gameTime); + + passedRoundsTickSum = gameTime; + round = passedRound; + } + + private void record(byte passedRound, short roundTime, int gameTime) { + if (passedRound == (byte) 1) pbTracking = true; try { RecordManager.compareSegment(passedRound, roundTime, category); @@ -64,12 +71,9 @@ public class Timer { String.format("Split not recorded. (invalid round parsed from scoreboard: %s)", passedRound) )); } - passedRoundsTickSum = gameTime; - dontDupeSplitPlease = passedRound; } - private long getCurrentTotalWorldTime() { if (Minecraft.getMinecraft() == null) return 0; if (Minecraft.getMinecraft().theWorld == null) return 0; @@ -97,6 +101,8 @@ public class Timer { public static void dropInstances() { instance = null; GameMode.drop(); - SLA.drop(); + } + public int getRound() { + return round+1; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java index 264847f..f4d6c6e 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java @@ -46,7 +46,7 @@ public class Category { Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); } public static String[] getCategories() { - File dir = new File("zombies"); + File dir = new File("zombies"+File.separator+"splits"); if (dir.isDirectory()) return dir.list(); else return new String[0]; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileData.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileData.java index a293790..5b98763 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileData.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileData.java @@ -19,7 +19,7 @@ public class FileData{ Arrays.fill(bestSegments, (short) 0); Arrays.fill(personalBests, 0); } - String getAsJsonString() { + public String getAsJsonString() { Gson gson = new Gson(); return gson.toJson(this, FileData.class); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/TimesFile.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/TimesFile.java index c6e6531..497b13e 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/TimesFile.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/TimesFile.java @@ -1,6 +1,7 @@ package com.github.stachelbeere1248.zombiesutils.timer.recorder; import com.github.stachelbeere1248.zombiesutils.game.GameMode; +import com.github.stachelbeere1248.zombiesutils.utils.FileManager; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -11,7 +12,7 @@ public class TimesFile extends File { public TimesFile(String category, @NotNull GameMode gameMode) { // Game-directory -> custom category -> file named "MAP_DIFFICULTY.times" // Content encoded in StandardCharsets.UTF_16 - super("zombies" + File.separator + category,gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); + super("zombies" + File.separator + "splits" + File.separator + category,gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); this.gameMode = gameMode; fileData = FileManager.readOrCreate(this); } @@ -31,7 +32,7 @@ public class TimesFile extends File { FileManager.writeDataToFile(fileData,this); } - GameMode getGameMode() { + public GameMode getGameMode() { return gameMode; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/FileManager.java similarity index 89% rename from src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java rename to src/main/java/com/github/stachelbeere1248/zombiesutils/utils/FileManager.java index dda0259..866c56b 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/FileManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/FileManager.java @@ -1,5 +1,7 @@ -package com.github.stachelbeere1248.zombiesutils.timer.recorder; +package com.github.stachelbeere1248.zombiesutils.utils; +import com.github.stachelbeere1248.zombiesutils.timer.recorder.FileData; +import com.github.stachelbeere1248.zombiesutils.timer.recorder.TimesFile; import com.google.gson.Gson; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java index 267f910..62cf7a1 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java @@ -91,26 +91,40 @@ public class Scoreboard { ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string); return Optional.ofNullable(string); } - public static Optional getMap() { + public static Optional getMap() { String line; + boolean pregame; try { line = lines.get(12); + pregame = false; } catch (Exception couldBePregame) { try { line = lines.get(2); + pregame = true; } catch (IndexOutOfBoundsException | NullPointerException ignored) { return Optional.empty(); } } String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); switch (mapString) { - case "Dead End": return Optional.of(Map.DEAD_END); - case "Bad Blood": return Optional.of(Map.BAD_BLOOD); - case "Alien Arcadium": return Optional.of(Map.ALIEN_ARCADIUM); + case "Dead End": return Optional.of(new MapContainer(Map.DEAD_END,pregame)); + case "Bad Blood": return Optional.of(new MapContainer(Map.BAD_BLOOD,pregame)); + case "Alien Arcadium": return Optional.of(new MapContainer(Map.ALIEN_ARCADIUM,pregame)); default: return Optional.empty(); } + } public static boolean isZombies() { return (!"ZOMBIES".equals(title)); } + + public static class MapContainer { + public final Map map; + public final boolean pregame; + + public MapContainer(Map map, boolean pregame) { + this.map = map; + this.pregame = pregame; + } + } } \ No newline at end of file