diff --git a/gradle.properties b/gradle.properties index 5563fb3..eab8011 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.2.2 \ No newline at end of file +version = 1.2.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 7c00347..8129b8f 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -1,16 +1,9 @@ package com.github.stachelbeere1248.zombiesutils; -import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand; -import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand; -import com.github.stachelbeere1248.zombiesutils.commands.ZombiesUtilsCommand; +import com.github.stachelbeere1248.zombiesutils.commands.CommandRegistry; 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; -import net.minecraftforge.common.MinecraftForge; +import com.github.stachelbeere1248.zombiesutils.handlers.HandlerRegistry; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; @@ -42,16 +35,8 @@ public class ZombiesUtils { } @Mod.EventHandler public void init(FMLInitializationEvent event) { - MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig()); - MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); - MinecraftForge.EVENT_BUS.register(new TickHandler()); - MinecraftForge.EVENT_BUS.register(new ChatHandler()); - MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); - - ClientCommandHandler.instance.registerCommand(new CategoryCommand()); - ClientCommandHandler.instance.registerCommand(new SlaCommand()); - ClientCommandHandler.instance.registerCommand(new ZombiesUtilsCommand()); - + HandlerRegistry.registerAll(); + CommandRegistry.registerAll(); hotkeys.registerAll(); } public Logger getLogger() { diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CommandRegistry.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CommandRegistry.java new file mode 100644 index 0000000..00d8270 --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CommandRegistry.java @@ -0,0 +1,12 @@ +package com.github.stachelbeere1248.zombiesutils.commands; + +import net.minecraftforge.client.ClientCommandHandler; + +public class CommandRegistry { + public static void registerAll() { + ClientCommandHandler.instance.registerCommand(new CategoryCommand()); + ClientCommandHandler.instance.registerCommand(new SlaCommand()); + ClientCommandHandler.instance.registerCommand(new ZombiesUtilsCommand()); + ClientCommandHandler.instance.registerCommand(new QuickZombiesCommand()); + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java new file mode 100644 index 0000000..728a0ea --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java @@ -0,0 +1,57 @@ +package com.github.stachelbeere1248.zombiesutils.commands; + +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.util.BlockPos; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class QuickZombiesCommand extends CommandBase { + @Override + public String getCommandName() { + return "qz"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/qz "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if (args.length == 0) throw new WrongUsageException( + "[Missing option] options: de, bb, aa"); + else switch (args[0]) { + case "de": + Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_dead_end"); + break; + case "bb": + Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_bad_blood"); + break; + case "aa": + Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_alien_arcadium"); + break; + default: + throw new WrongUsageException( + "[Invalid option] options: de, bb, aa", args[0]); + + } + } + @Override + public List addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { + if (args.length == 1) return Arrays.asList("de", "bb", "aa"); + else return Collections.emptyList(); + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } + +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java new file mode 100644 index 0000000..53a437b --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/HandlerRegistry.java @@ -0,0 +1,15 @@ +package com.github.stachelbeere1248.zombiesutils.handlers; + +import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; +import net.minecraftforge.common.MinecraftForge; + +public class HandlerRegistry { + public static void registerAll() { + MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig()); + MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); + MinecraftForge.EVENT_BUS.register(new TickHandler()); + MinecraftForge.EVENT_BUS.register(new ChatHandler()); + MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); + } +} 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 3c7df58..a9291c4 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -37,32 +37,27 @@ public class MixinNetHandlerPlayClient { )) return; zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); try { - if (Timer.getInstance().isPresent()) { final Timer running = Timer.getInstance().get(); final byte round = Scoreboard.getRound(); if (round == 0) { - if (Scoreboard.getLineCount()<13) Timer.setInstance(new Timer( + if (Scoreboard.getLineCount()<13) Timer.instance = new Timer( Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), round - )); + ); } else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { - Timer.setInstance(new Timer( - Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Timer.instance = new Timer( Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), round - )); + ); } else running.split(round); - - - - } else Timer.setInstance(new Timer( + } else Timer.instance = new Timer( Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), Scoreboard.getRound() - )); + ); } catch (Timer.TimerException e) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer.\nData parsing error. Blame scoreboard.")); ZombiesUtils.getInstance().getLogger().warn(e); 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 b82439a..ab663fa 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java @@ -17,7 +17,7 @@ import java.util.Optional; public class Timer { - private static Timer instance; + public static Timer instance; private final GameMode gameMode; private long savedTotalWorldTime; private int passedRoundsTickSum = 0; @@ -26,7 +26,7 @@ public class Timer { private final GameFile gameFile; private boolean pbTracking = false; private int round; - private final Round1Correction correction; + private boolean r1Corrected = false; /** * @param serverNumber The game's server the timer should be bound to. @@ -34,22 +34,19 @@ public class Timer { * @param round If available, round to begin splitting. */ public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) { - dropInstances(); - this.savedTotalWorldTime = getCurrentTotalWorldTime(); - if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); - else throw new RuntimeException("invalid servernumber"); + this.savedTotalWorldTime = getCurrentTotalWorldTime(); + if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); + else throw new RuntimeException("invalid servernumber"); - this.category = new Category(); - this.gameFile = new GameFile(serverNumber.trim(),map); + this.category = new Category(); + this.gameFile = new GameFile(serverNumber.trim(), map); - this.gameMode = new GameMode(map); - this.round = round; - if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); - - correction = new Round1Correction(); - MinecraftForge.EVENT_BUS.register(correction); + this.gameMode = new GameMode(map); + this.round = round; + if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); + MinecraftForge.EVENT_BUS.register(new Round1Correction()); } @@ -62,7 +59,7 @@ public class Timer { final int gameTime = gameTime(); final short roundTime = (short) (gameTime - passedRoundsTickSum); - if ((round == passedRound) || (passedRound == 0) || (roundTime == 0)) { + if ((round == passedRound) || (passedRound == 0) || (roundTime < 100)) { ZombiesUtils.getInstance().getLogger().debug("SPLIT CANCELLED"); return; } @@ -73,7 +70,9 @@ public class Timer { round = passedRound; } public void correctRn() { + if (r1Corrected) return; savedTotalWorldTime = getCurrentTotalWorldTime()-200L; + r1Corrected = true; } private void record(byte passedRound, short roundTime, int gameTime) { @@ -121,8 +120,6 @@ public class Timer { * Call to invalidate {@link #instance} to trigger the garbage collector */ public static void dropInstances() { - if (instance == null) return; - if (instance.correction != null) MinecraftForge.EVENT_BUS.unregister(instance.correction); instance = null; } public byte getRound() { @@ -132,10 +129,6 @@ public class Timer { public GameMode getGameMode() { return gameMode; } - public static void setInstance(@NotNull Timer instance) { - Timer.instance = instance; - } - public static abstract class TimerException extends Exception { 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 996b10a..783b3fd 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 @@ -15,7 +15,7 @@ public class Category { public final CategoryFile[] categoryFiles = new CategoryFile[7]; private final String name; public Category() { - final File category = new File("zombies" + File.separator + "splits" + File.separator + selectedCategory); + final File category = new File(new File("zombies", "splits"), selectedCategory); categoryFiles[0] = new CategoryFile(category, new GameMode(Map.DEAD_END)); categoryFiles[1] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.HARD)); categoryFiles[2] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.RIP));