1.1.3
This commit is contained in:
parent
a7a206d273
commit
acb51e6a3a
15 changed files with 267 additions and 112 deletions
|
@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
|
|||
baseGroup = com.github.stachelbeere1248.zombiesutils
|
||||
mcVersion = 1.8.9
|
||||
modid = zombiesutils
|
||||
version = 1.1.2
|
||||
version = 1.1.3
|
|
@ -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());
|
||||
|
|
|
@ -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 <category-name>";
|
||||
return "/category <category-name>";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,8 +28,7 @@ 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]) {
|
||||
else switch (args[0]) {
|
||||
case "off":
|
||||
SLA.drop();
|
||||
sender.addChatMessage(new ChatComponentText("SLA data deleted"));
|
||||
|
@ -106,14 +105,14 @@ public class SlaCommand extends CommandBase {
|
|||
default:
|
||||
//noinspection SpellCheckingInspection
|
||||
throw new WrongUsageException(
|
||||
"[Invalid option] options: mogi_a, ghxula, ghxula-garden", args[1]); }
|
||||
"[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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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<String> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -91,26 +91,40 @@ public class Scoreboard {
|
|||
ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string);
|
||||
return Optional.ofNullable(string);
|
||||
}
|
||||
public static Optional<Map> getMap() {
|
||||
public static Optional<MapContainer> 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue