quickjoin command

This commit is contained in:
Stachelbeere1248 2023-12-11 19:31:51 +01:00
parent 420373160b
commit e46feb6167
8 changed files with 110 additions and 53 deletions

View file

@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = com.github.stachelbeere1248.zombiesutils baseGroup = com.github.stachelbeere1248.zombiesutils
mcVersion = 1.8.9 mcVersion = 1.8.9
modid = zombiesutils modid = zombiesutils
version = 1.2.2 version = 1.2.3

View file

@ -1,16 +1,9 @@
package com.github.stachelbeere1248.zombiesutils; package com.github.stachelbeere1248.zombiesutils;
import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand; import com.github.stachelbeere1248.zombiesutils.commands.CommandRegistry;
import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand;
import com.github.stachelbeere1248.zombiesutils.commands.ZombiesUtilsCommand;
import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; import com.github.stachelbeere1248.zombiesutils.config.Hotkeys;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler; import com.github.stachelbeere1248.zombiesutils.handlers.HandlerRegistry;
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 net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@ -42,16 +35,8 @@ public class ZombiesUtils {
} }
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig()); HandlerRegistry.registerAll();
MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); CommandRegistry.registerAll();
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());
hotkeys.registerAll(); hotkeys.registerAll();
} }
public Logger getLogger() { public Logger getLogger() {

View file

@ -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());
}
}

View file

@ -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 <de|bb|aa>";
}
@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<String> 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;
}
}

View file

@ -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());
}
}

View file

@ -37,32 +37,27 @@ public class MixinNetHandlerPlayClient {
)) return; )) return;
zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse");
try { try {
if (Timer.getInstance().isPresent()) { if (Timer.getInstance().isPresent()) {
final Timer running = Timer.getInstance().get(); final Timer running = Timer.getInstance().get();
final byte round = Scoreboard.getRound(); final byte round = Scoreboard.getRound();
if (round == 0) { 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.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new),
Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new),
round round
)); );
} else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { } else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) {
Timer.setInstance(new Timer( Timer.instance = new Timer( Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new),
Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new),
Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new),
round round
)); );
} else running.split(round); } else running.split(round);
} else Timer.instance = new Timer(
} else Timer.setInstance(new Timer(
Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new),
Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new),
Scoreboard.getRound() Scoreboard.getRound()
)); );
} catch (Timer.TimerException e) { } catch (Timer.TimerException e) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer.\nData parsing error. Blame scoreboard.")); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer.\nData parsing error. Blame scoreboard."));
ZombiesUtils.getInstance().getLogger().warn(e); ZombiesUtils.getInstance().getLogger().warn(e);

View file

@ -17,7 +17,7 @@ import java.util.Optional;
public class Timer { public class Timer {
private static Timer instance; public static Timer instance;
private final GameMode gameMode; private final GameMode gameMode;
private long savedTotalWorldTime; private long savedTotalWorldTime;
private int passedRoundsTickSum = 0; private int passedRoundsTickSum = 0;
@ -26,7 +26,7 @@ public class Timer {
private final GameFile gameFile; private final GameFile gameFile;
private boolean pbTracking = false; private boolean pbTracking = false;
private int round; private int round;
private final Round1Correction correction; private boolean r1Corrected = false;
/** /**
* @param serverNumber The game's server the timer should be bound to. * @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. * @param round If available, round to begin splitting.
*/ */
public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) { public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) {
dropInstances();
this.savedTotalWorldTime = getCurrentTotalWorldTime(); this.savedTotalWorldTime = getCurrentTotalWorldTime();
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
else throw new RuntimeException("invalid servernumber"); else throw new RuntimeException("invalid servernumber");
this.category = new Category(); this.category = new Category();
this.gameFile = new GameFile(serverNumber.trim(),map); this.gameFile = new GameFile(serverNumber.trim(), map);
this.gameMode = new GameMode(map); this.gameMode = new GameMode(map);
this.round = round; this.round = round;
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
correction = new Round1Correction();
MinecraftForge.EVENT_BUS.register(correction);
MinecraftForge.EVENT_BUS.register(new Round1Correction());
} }
@ -62,7 +59,7 @@ public class Timer {
final int gameTime = gameTime(); final int gameTime = gameTime();
final short roundTime = (short) (gameTime - passedRoundsTickSum); 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"); ZombiesUtils.getInstance().getLogger().debug("SPLIT CANCELLED");
return; return;
} }
@ -73,7 +70,9 @@ public class Timer {
round = passedRound; round = passedRound;
} }
public void correctRn() { public void correctRn() {
if (r1Corrected) return;
savedTotalWorldTime = getCurrentTotalWorldTime()-200L; savedTotalWorldTime = getCurrentTotalWorldTime()-200L;
r1Corrected = true;
} }
private void record(byte passedRound, short roundTime, int gameTime) { 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 * Call to invalidate {@link #instance} to trigger the garbage collector
*/ */
public static void dropInstances() { public static void dropInstances() {
if (instance == null) return;
if (instance.correction != null) MinecraftForge.EVENT_BUS.unregister(instance.correction);
instance = null; instance = null;
} }
public byte getRound() { public byte getRound() {
@ -132,10 +129,6 @@ public class Timer {
public GameMode getGameMode() { public GameMode getGameMode() {
return gameMode; return gameMode;
} }
public static void setInstance(@NotNull Timer instance) {
Timer.instance = instance;
}
public static abstract class TimerException extends Exception { public static abstract class TimerException extends Exception {

View file

@ -15,7 +15,7 @@ public class Category {
public final CategoryFile[] categoryFiles = new CategoryFile[7]; public final CategoryFile[] categoryFiles = new CategoryFile[7];
private final String name; private final String name;
public Category() { 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[0] = new CategoryFile(category, new GameMode(Map.DEAD_END));
categoryFiles[1] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.HARD)); categoryFiles[1] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.HARD));
categoryFiles[2] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.RIP)); categoryFiles[2] = new CategoryFile(category, new GameMode(Map.DEAD_END, Difficulty.RIP));