code cleanup

This commit is contained in:
Stachelbeere1248 2023-12-11 22:00:45 +01:00
parent e46feb6167
commit 2a48c3cdf2
29 changed files with 369 additions and 259 deletions

View file

@ -16,10 +16,12 @@ public class ZombiesUtils {
private static ZombiesUtils instance; private static ZombiesUtils instance;
private final Hotkeys hotkeys; private final Hotkeys hotkeys;
private Logger logger; private Logger logger;
public ZombiesUtils() { public ZombiesUtils() {
hotkeys = new Hotkeys(); hotkeys = new Hotkeys();
instance = this; instance = this;
} }
public static ZombiesUtils getInstance() { public static ZombiesUtils getInstance() {
return instance; return instance;
} }
@ -33,12 +35,14 @@ public class ZombiesUtils {
); );
ZombiesUtilsConfig.load(); ZombiesUtilsConfig.load();
} }
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
HandlerRegistry.registerAll(); HandlerRegistry.registerAll();
CommandRegistry.registerAll(); CommandRegistry.registerAll();
hotkeys.registerAll(); hotkeys.registerAll();
} }
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
} }

View file

@ -17,6 +17,7 @@ public class CategoryCommand extends CommandBase {
public CategoryCommand() { public CategoryCommand() {
} }
@Override @Override
public String getCommandName() { public String getCommandName() {
return "category"; return "category";
@ -32,11 +33,13 @@ public class CategoryCommand extends CommandBase {
if (args.length == 0) throw new WrongUsageException("Please enter a name for the category"); if (args.length == 0) throw new WrongUsageException("Please enter a name for the category");
else { else {
String cat = args[0]; String cat = args[0];
if (cat.contains(File.separator)) throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "subfolder"); if (cat.contains(File.separator))
throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "subfolder");
Category.setSelectedCategory(cat); Category.setSelectedCategory(cat);
Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category()));
} }
} }
@Override @Override
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos blockPos) { public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos blockPos) {
return Arrays.asList(Category.getCategories()); return Arrays.asList(Category.getCategories());

View file

@ -24,7 +24,7 @@ public class QuickZombiesCommand extends CommandBase {
} }
@Override @Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException { public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException {
if (args.length == 0) throw new WrongUsageException( if (args.length == 0) throw new WrongUsageException(
"[Missing option] options: de, bb, aa"); "[Missing option] options: de, bb, aa");
else switch (args[0]) { else switch (args[0]) {
@ -43,6 +43,7 @@ public class QuickZombiesCommand extends CommandBase {
} }
} }
@Override @Override
public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) {
if (args.length == 1) return Arrays.asList("de", "bb", "aa"); if (args.length == 1) return Arrays.asList("de", "bb", "aa");

View file

@ -135,7 +135,8 @@ public class SlaCommand extends CommandBase {
case "quick": case "quick":
//noinspection SpellCheckingInspection //noinspection SpellCheckingInspection
options.addAll(Arrays.asList("mogi_a", "ghxula", "ghxula-garden")); options.addAll(Arrays.asList("mogi_a", "ghxula", "ghxula-garden"));
default: break; default:
break;
} }
} }
return options; return options;

View file

@ -28,29 +28,35 @@ public class ZombiesUtilsCommand extends CommandBase {
else switch (args[0]) { else switch (args[0]) {
case "timer": case "timer":
switch (args[1]) { switch (args[1]) {
case "kill": Timer.dropInstances(); break; case "kill":
Timer.dropInstances();
break;
case "split": case "split":
try { try {
Timer.getInstance().ifPresent(timer -> timer.split(Byte.parseByte(args[2]))); Timer.getInstance().ifPresent(timer -> timer.split(Byte.parseByte(args[2])));
} catch (NumberFormatException | NullPointerException ignored) { } catch (NumberFormatException | NullPointerException ignored) {
throw new NumberInvalidException("t", args[2]); throw new NumberInvalidException("t", args[2]);
} break; }
break;
default: default:
throw new WrongUsageException( throw new WrongUsageException(
"[Invalid option] options: kill, split", args[0]); "[Invalid option] options: kill, split", args[0]);
} break; }
break;
default: default:
throw new WrongUsageException( throw new WrongUsageException(
"[Invalid option] options: timer", args[0]); "[Invalid option] options: timer", args[0]);
} }
} }
@Override @Override
public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) {
if (args.length == 1) return new ArrayList<>(Collections.singleton("timer")); if (args.length == 1) return new ArrayList<>(Collections.singleton("timer"));
switch (args[0]) { switch (args[0]) {
case "timer": case "timer":
return new ArrayList<>(Arrays.asList("kill", "split")); return new ArrayList<>(Arrays.asList("kill", "split"));
default: return Collections.emptyList(); default:
return Collections.emptyList();
} }
} }

View file

@ -21,10 +21,12 @@ public class Hotkeys {
); );
} }
public void registerAll() { public void registerAll() {
ClientRegistry.registerKeyBinding(this.chatMacro); ClientRegistry.registerKeyBinding(this.chatMacro);
ClientRegistry.registerKeyBinding(this.rlSpawn); ClientRegistry.registerKeyBinding(this.rlSpawn);
} }
public KeyBinding getChatMacro() { public KeyBinding getChatMacro() {
return chatMacro; return chatMacro;
} }

View file

@ -15,6 +15,7 @@ public class ZombiesUtilsConfig {
private static String chatMacro; private static String chatMacro;
private static String defaultCategory; private static String defaultCategory;
private static short waveOffset; private static short waveOffset;
public static void load() { public static void load() {
ZombiesUtils.getInstance().getLogger().debug("Loading config..."); ZombiesUtils.getInstance().getLogger().debug("Loading config...");
config.load(); config.load();
@ -64,6 +65,26 @@ public class ZombiesUtilsConfig {
return waveOffset; return waveOffset;
} }
public static boolean isSlaToggled() {
return slaToggle;
}
public static boolean isSlaShortened() {
return slaShortener;
}
public static boolean isSpawntimeNotShortened() {
return shortSpawntime;
}
public static String getChatMacro() {
return chatMacro;
}
public static String getDefaultCategory() {
return defaultCategory;
}
@SubscribeEvent @SubscribeEvent
public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) { public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) {
if (event.modID.equals("zombiesutils") && event.configID == null) { if (event.modID.equals("zombiesutils") && event.configID == null) {
@ -71,19 +92,4 @@ public class ZombiesUtilsConfig {
ZombiesUtilsConfig.load(); ZombiesUtilsConfig.load();
} }
} }
public static boolean isSlaToggled() {
return slaToggle;
}
public static boolean isSlaShortened() {
return slaShortener;
}
public static boolean isSpawntimeNotShortened() {
return shortSpawntime;
}
public static String getChatMacro() {
return chatMacro;
}
public static String getDefaultCategory() {
return defaultCategory;
}
} }

View file

@ -10,25 +10,31 @@ public class GameMode {
this.map = map; this.map = map;
this.difficulty = Difficulty.NORMAL; this.difficulty = Difficulty.NORMAL;
} }
public GameMode(@NotNull Map map, @NotNull Difficulty difficulty) { public GameMode(@NotNull Map map, @NotNull Difficulty difficulty) {
this.map = map; this.map = map;
this.difficulty = difficulty; this.difficulty = difficulty;
} }
public Map getMap() { public Map getMap() {
return map; return map;
} }
public Difficulty getDifficulty() { public Difficulty getDifficulty() {
return difficulty; return difficulty;
} }
public void changeDifficulty(@NotNull Difficulty difficulty) { public void changeDifficulty(@NotNull Difficulty difficulty) {
switch (map) { switch (map) {
case DEAD_END: case BAD_BLOOD: case DEAD_END:
case BAD_BLOOD:
this.difficulty = difficulty; this.difficulty = difficulty;
break; break;
case ALIEN_ARCADIUM: case ALIEN_ARCADIUM:
throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM); throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM);
} }
} }
public boolean is(Map map, Difficulty difficulty) { public boolean is(Map map, Difficulty difficulty) {
return this.getDifficulty() == difficulty && this.getMap() == map; return this.getDifficulty() == difficulty && this.getMap() == map;
} }

View file

@ -1,4 +1,5 @@
package com.github.stachelbeere1248.zombiesutils.game; package com.github.stachelbeere1248.zombiesutils.game;
public enum Map { public enum Map {
DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM
} }

View file

@ -9,11 +9,13 @@ public class QuickSLA {
SLA.instance.rotate(3); SLA.instance.rotate(3);
SLA.instance.setOffset(new int[]{-3, 35, -9}); SLA.instance.setOffset(new int[]{-3, 35, -9});
} }
public static void ghxula() { public static void ghxula() {
SLA.instance = new SLA(Map.DEAD_END); SLA.instance = new SLA(Map.DEAD_END);
SLA.instance.rotate(1); SLA.instance.rotate(1);
SLA.instance.setOffset(new int[]{27, 35, 5}); SLA.instance.setOffset(new int[]{27, 35, 5});
} }
public static void ghxulaGarden() { public static void ghxulaGarden() {
SLA.instance = new SLA(Map.DEAD_END); SLA.instance = new SLA(Map.DEAD_END);
SLA.instance.rotate(1); SLA.instance.rotate(1);

View file

@ -19,13 +19,28 @@ public class SLA {
public SLA(@NotNull Map map) { public SLA(@NotNull Map map) {
switch (map) { switch (map) {
case DEAD_END: this.rooms = Room.getDE(); break; case DEAD_END:
case BAD_BLOOD: this.rooms = Room.getBB(); break; this.rooms = Room.getDE();
case ALIEN_ARCADIUM: this.rooms = Room.getAA(); break; break;
default: throw new IllegalStateException("Unexpected value: " + map); case BAD_BLOOD:
this.rooms = Room.getBB();
break;
case ALIEN_ARCADIUM:
this.rooms = Room.getAA();
break;
default:
throw new IllegalStateException("Unexpected value: " + map);
} }
} }
public static Optional<SLA> getInstance() {
return Optional.ofNullable(instance);
}
public static void drop() {
instance = null;
}
public void rotate(int rotations) { public void rotate(int rotations) {
for (Room room : rooms) { for (Room room : rooms) {
for (Window window : room.getWindows()) { for (Window window : room.getWindows()) {
@ -33,6 +48,7 @@ public class SLA {
} }
} }
} }
public void mirrorX() { public void mirrorX() {
for (Room room : rooms) { for (Room room : rooms) {
for (Window window : room.getWindows()) { for (Window window : room.getWindows()) {
@ -41,6 +57,7 @@ public class SLA {
} }
System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ())); System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ()));
} }
public void mirrorZ() { public void mirrorZ() {
for (Room room : rooms) { for (Room room : rooms) {
for (Window window : room.getWindows()) { for (Window window : room.getWindows()) {
@ -50,6 +67,7 @@ public class SLA {
short[] win0 = rooms[0].getWindows()[0].getXYZ(); short[] win0 = rooms[0].getWindows()[0].getXYZ();
ZombiesUtils.getInstance().getLogger().info("Window \"0\" is now at %s %s %s" + (double) win0[0] / 2 + (double) win0[1] / 2 + (double) win0[2] / 2); ZombiesUtils.getInstance().getLogger().info("Window \"0\" is now at %s %s %s" + (double) win0[0] / 2 + (double) win0[1] / 2 + (double) win0[2] / 2);
} }
public void refreshActives() { public void refreshActives() {
final EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; final EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
final double[] playerCoords = { final double[] playerCoords = {
@ -76,19 +94,14 @@ public class SLA {
} }
} }
public static Optional<SLA> getInstance() {
return Optional.ofNullable(instance);
}
public static void drop() {
instance = null;
}
public Room[] getRooms() { public Room[] getRooms() {
return rooms; return rooms;
} }
public void resetOffset() { public void resetOffset() {
Arrays.fill(this.offset, 0); Arrays.fill(this.offset, 0);
} }
public void setOffset(int[] offset) { public void setOffset(int[] offset) {
System.arraycopy(offset, 0, this.offset, 0, 3); System.arraycopy(offset, 0, this.offset, 0, 3);
} }

View file

@ -8,13 +8,10 @@ import org.jetbrains.annotations.NotNull;
public class Waves { public class Waves {
private static final byte[][] deadEndWaveTimes = {{10, 20}, {10, 20}, {10, 20, 35}, {10, 20, 35}, {10, 22, 37}, {10, 22, 44}, {10, 25, 47}, {10, 25, 50}, {10, 22, 38}, {10, 24, 45}, {10, 25, 48}, {10, 25, 50}, {10, 25, 50}, {10, 25, 45}, {10, 25, 46}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 49}, {10, 23, 44}, {10, 23, 45}, {10, 23, 42}, {10, 23, 43}, {10, 23, 43}, {10, 23, 36}, {10, 24, 44}, {10, 24, 42}, {10, 24, 42}, {10, 24, 45}}, private static final byte[][] deadEndWaveTimes = {{10, 20}, {10, 20}, {10, 20, 35}, {10, 20, 35}, {10, 22, 37}, {10, 22, 44}, {10, 25, 47}, {10, 25, 50}, {10, 22, 38}, {10, 24, 45}, {10, 25, 48}, {10, 25, 50}, {10, 25, 50}, {10, 25, 45}, {10, 25, 46}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 47}, {10, 24, 49}, {10, 23, 44}, {10, 23, 45}, {10, 23, 42}, {10, 23, 43}, {10, 23, 43}, {10, 23, 36}, {10, 24, 44}, {10, 24, 42}, {10, 24, 42}, {10, 24, 45}},
badBloodWaveTimes = {{10, 22}, {10, 22}, {10, 22}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 24, 38}, {10, 24, 38}, {10, 22, 34}, {10, 24, 38}, {10, 22, 34}}, badBloodWaveTimes = {{10, 22}, {10, 22}, {10, 22}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34}, {10, 24, 38}, {10, 24, 38}, {10, 22, 34}, {10, 24, 38}, {10, 22, 34}},
alienArcadiumWaveTimes = {{10,13,16,19},{10,14,18,22},{10,13,16,19},{10,14,17,21,25,28},{10,14,18,22,26,30},{10,14,19,23,28,32},{10,15,19,23,27,31},{10,15,20,25,30,35},{10,14,19,23,28,32},{10,16,22,27,33,38},{10,16,21,27,32,38},{10,16,22,28,34,40},{10,16,22,28,34,40},{10,16,21,26,31,36},{10,17,24,31,38,46},{10,16,22,27,33,38},{10,14,19,23,28,32},{10,14,19,23,28,32},{10,14,18,22,26,30},{10,15,21,26,31,36},{10,14,19,23,28,32},{10,14,19,23,28,34},{10,14,18,22,26,30},{10,14,19,23,28,32},{10},{10,23,36},{10,22,34},{10,20,30},{10,24,38},{10,22,34},{10,22,34},{10,21,32},{10,22,34},{10,22,34},{10},{10,22,34},{10,20,31},{10,22,34},{10,22,34},{10,22,34,37,45},{10,21,32},{10,22,34},{10,13,22,25,34,37},{10,22,34},{10,22,34,35},{10,21,32,35},{10,20,30},{10,20,30,33},{10,21,32},{10,22,34,37},{10,20,30,33},{10,22,34,37},{10,22,34,37},{10,20,32,35,39},{10,16,22,28,34,40},{10,14,18},{10,14,18},{10,22,34,37,38},{10,14,18,22,26,30},{10,20,30,33},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,27,32},{10,14,18,22,27,32},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{10,14,18,22,26,30},{5},{5},{5},{5},{5}} alienArcadiumWaveTimes = {{10, 13, 16, 19}, {10, 14, 18, 22}, {10, 13, 16, 19}, {10, 14, 17, 21, 25, 28}, {10, 14, 18, 22, 26, 30}, {10, 14, 19, 23, 28, 32}, {10, 15, 19, 23, 27, 31}, {10, 15, 20, 25, 30, 35}, {10, 14, 19, 23, 28, 32}, {10, 16, 22, 27, 33, 38}, {10, 16, 21, 27, 32, 38}, {10, 16, 22, 28, 34, 40}, {10, 16, 22, 28, 34, 40}, {10, 16, 21, 26, 31, 36}, {10, 17, 24, 31, 38, 46}, {10, 16, 22, 27, 33, 38}, {10, 14, 19, 23, 28, 32}, {10, 14, 19, 23, 28, 32}, {10, 14, 18, 22, 26, 30}, {10, 15, 21, 26, 31, 36}, {10, 14, 19, 23, 28, 32}, {10, 14, 19, 23, 28, 34}, {10, 14, 18, 22, 26, 30}, {10, 14, 19, 23, 28, 32}, {10}, {10, 23, 36}, {10, 22, 34}, {10, 20, 30}, {10, 24, 38}, {10, 22, 34}, {10, 22, 34}, {10, 21, 32}, {10, 22, 34}, {10, 22, 34}, {10}, {10, 22, 34}, {10, 20, 31}, {10, 22, 34}, {10, 22, 34}, {10, 22, 34, 37, 45}, {10, 21, 32}, {10, 22, 34}, {10, 13, 22, 25, 34, 37}, {10, 22, 34}, {10, 22, 34, 35}, {10, 21, 32, 35}, {10, 20, 30}, {10, 20, 30, 33}, {10, 21, 32}, {10, 22, 34, 37}, {10, 20, 30, 33}, {10, 22, 34, 37}, {10, 22, 34, 37}, {10, 20, 32, 35, 39}, {10, 16, 22, 28, 34, 40}, {10, 14, 18}, {10, 14, 18}, {10, 22, 34, 37, 38}, {10, 14, 18, 22, 26, 30}, {10, 20, 30, 33}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 27, 32}, {10, 14, 18, 22, 27, 32}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {10, 14, 18, 22, 26, 30}, {5}, {5}, {5}, {5}, {5}};
;
private static final short[] deadEndRoundTimesSum = {0, 20, 40, 75, 110, 147, 191, 238, 288, 326, 371, 419, 469, 519, 564, 610, 657, 704, 751, 798, 847, 891, 936, 978, 1021, 1064, 1100, 1144, 1186, 1228, 1273}, private static final short[] deadEndRoundTimesSum = {0, 20, 40, 75, 110, 147, 191, 238, 288, 326, 371, 419, 469, 519, 564, 610, 657, 704, 751, 798, 847, 891, 936, 978, 1021, 1064, 1100, 1144, 1186, 1228, 1273},
badBloodRoundTimesSum = {0, 22, 44, 66, 100, 134, 168, 202, 236, 270, 304, 338, 372, 406, 440, 474, 508, 542, 576, 610, 644, 678, 712, 746, 780, 814, 852, 890, 924, 962, 996}, badBloodRoundTimesSum = {0, 22, 44, 66, 100, 134, 168, 202, 236, 270, 304, 338, 372, 406, 440, 474, 508, 542, 576, 610, 644, 678, 712, 746, 780, 814, 852, 890, 924, 962, 996},
alienArcadiumRoundTimesSum = {0,19,41,60,88,118,150,181,216,248,286,324,364,404,440,486,524,556,588,618,654,686,720,750,782,792,828,862,892,930,964,998,1030,1064,1098,1108,1142,1173,1207,1241,1286,1318,1352,1389,1423,1458,1493,1523,1556,1588,1625,1658,1695,1732,1771,1811,1829,1847,1885,1915,1948,1978,2008,2038,2068,2098,2128,2158,2188,2218,2248,2278,2308,2338,2368,2400,2432,2462,2492,2522,2552,2582,2612,2642,2672,2702,2732,2762,2792,2822,2852,2882,2912,2942,2972,3002,3032,3062,3092,3122,3152,3157,3162,3167,3172,3177} alienArcadiumRoundTimesSum = {0, 19, 41, 60, 88, 118, 150, 181, 216, 248, 286, 324, 364, 404, 440, 486, 524, 556, 588, 618, 654, 686, 720, 750, 782, 792, 828, 862, 892, 930, 964, 998, 1030, 1064, 1098, 1108, 1142, 1173, 1207, 1241, 1286, 1318, 1352, 1389, 1423, 1458, 1493, 1523, 1556, 1588, 1625, 1658, 1695, 1732, 1771, 1811, 1829, 1847, 1885, 1915, 1948, 1978, 2008, 2038, 2068, 2098, 2128, 2158, 2188, 2218, 2248, 2278, 2308, 2338, 2368, 2400, 2432, 2462, 2492, 2522, 2552, 2582, 2612, 2642, 2672, 2702, 2732, 2762, 2792, 2822, 2852, 2882, 2912, 2942, 2972, 3002, 3032, 3062, 3092, 3122, 3152, 3157, 3162, 3167, 3172, 3177};
;
@Contract(pure = true) @Contract(pure = true)
@ -30,6 +27,7 @@ public class Waves {
throw new IllegalStateException("Unexpected value: " + map); throw new IllegalStateException("Unexpected value: " + map);
} }
} }
public static short getSum(@NotNull Map map, byte round) { public static short getSum(@NotNull Map map, byte round) {
short sum; short sum;
switch (map) { switch (map) {
@ -47,6 +45,7 @@ public class Waves {
} }
return sum; return sum;
} }
public static byte getLastWave(@NotNull Map map, byte round) { public static byte getLastWave(@NotNull Map map, byte round) {
byte[] aByte = get(map, round); byte[] aByte = get(map, round);
return aByte[aByte.length - 1]; return aByte[aByte.length - 1];

View file

@ -10,19 +10,13 @@ public class Room {
private final String name; private final String name;
private final String alias; private final String alias;
private int activeWindowCount; private int activeWindowCount;
public Room(String name, String alias, Window[] windows) { public Room(String name, String alias, Window[] windows) {
this.windows = windows; this.windows = windows;
this.name = name; this.name = name;
this.alias = alias; this.alias = alias;
} }
public String getName() {
return name;
}
public Window[] getWindows() {
return windows;
}
@Contract(" -> new") @Contract(" -> new")
public static Room @NotNull [] getDE() { public static Room @NotNull [] getDE() {
Vec3 t = new Vec3(3, 3, 3); Vec3 t = new Vec3(3, 3, 3);
@ -130,6 +124,7 @@ public class Room {
}; };
} }
@Contract(" -> new") @Contract(" -> new")
public static Room @NotNull [] getAA() { public static Room @NotNull [] getAA() {
return new Room[]{ return new Room[]{
@ -155,15 +150,26 @@ public class Room {
}; };
} }
public String getName() {
return name;
}
public Window[] getWindows() {
return windows;
}
public void increaseActiveWindowCount() { public void increaseActiveWindowCount() {
this.activeWindowCount++; this.activeWindowCount++;
} }
public void resetActiveWindowCount() { public void resetActiveWindowCount() {
this.activeWindowCount = 0; this.activeWindowCount = 0;
} }
public int getActiveWindowCount() { public int getActiveWindowCount() {
return activeWindowCount; return activeWindowCount;
} }
public String getSlaString() { public String getSlaString() {
StringBuilder slaString = new StringBuilder(String.format("§6%s§r§d %x§e:", this.getName(), activeWindowCount)); StringBuilder slaString = new StringBuilder(String.format("§6%s§r§d %x§e:", this.getName(), activeWindowCount));
for (Window window : this.windows) { for (Window window : this.windows) {

View file

@ -7,54 +7,68 @@ public class Window {
public Window(int id, int x, int y, int z) { public Window(int id, int x, int y, int z) {
this.id = id; this.id = id;
xyz[0] = (short) x; xyz[1] = (short) y; xyz[2] = (short) z; xyz[0] = (short) x;
xyz[1] = (short) y;
xyz[2] = (short) z;
} }
public int getID() { public int getID() {
return id; return id;
} }
public short[] getXYZ() { public short[] getXYZ() {
return xyz; return xyz;
} }
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) { public void setActive(boolean active) {
isActive = active; isActive = active;
} }
public boolean isActive() {
return isActive;
}
private void rotateCounterClockwise() { private void rotateCounterClockwise() {
final short x = xyz[0], z = xyz[2]; final short x = xyz[0], z = xyz[2];
xyz[0] = (short) -z; xyz[0] = (short) -z;
xyz[2] = x; xyz[2] = x;
} }
private void mirrorBoth() { private void mirrorBoth() {
xyz[0] = (short) -xyz[0]; xyz[0] = (short) -xyz[0];
xyz[2] = (short) -xyz[2]; xyz[2] = (short) -xyz[2];
} }
private void rotateClockwise() { private void rotateClockwise() {
final short x = xyz[0], z = xyz[2]; final short x = xyz[0], z = xyz[2];
xyz[0] = z; xyz[0] = z;
xyz[2] = (short) -x; xyz[2] = (short) -x;
} }
public void rotate(int rotations) { public void rotate(int rotations) {
rotations %= 4; rotations %= 4;
switch (rotations) { switch (rotations) {
case -3: case 1: case -3:
case 1:
rotateCounterClockwise(); rotateCounterClockwise();
break; break;
case -2: case 2: case -2:
case 2:
mirrorBoth(); mirrorBoth();
break; break;
case -1: case 3: case -1:
case 3:
rotateClockwise(); rotateClockwise();
break; break;
case 0: break; case 0:
break;
} }
} }
public void mirrorX() { public void mirrorX() {
xyz[0] = (short) -xyz[0]; xyz[0] = (short) -xyz[0];
} }
public void mirrorZ() { public void mirrorZ() {
xyz[2] = (short) -xyz[2]; xyz[2] = (short) -xyz[2];
} }

View file

@ -10,11 +10,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class ChatHandler { public class ChatHandler {
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE);
public ChatHandler() { public ChatHandler() {
} }
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE);
@SubscribeEvent @SubscribeEvent
public void difficultyChange(@NotNull ClientChatReceivedEvent event) { public void difficultyChange(@NotNull ClientChatReceivedEvent event) {
if (!Timer.getInstance().isPresent()) return; if (!Timer.getInstance().isPresent()) return;

View file

@ -1,7 +1,6 @@
package com.github.stachelbeere1248.zombiesutils.handlers; package com.github.stachelbeere1248.zombiesutils.handlers;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
public class HandlerRegistry { public class HandlerRegistry {

View file

@ -3,7 +3,6 @@ package com.github.stachelbeere1248.zombiesutils.handlers;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
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.render.RenderGameOverlayHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.common.gameevent.InputEvent;

View file

@ -1,4 +1,4 @@
package com.github.stachelbeere1248.zombiesutils.render; package com.github.stachelbeere1248.zombiesutils.handlers;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
@ -16,13 +16,32 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
public class RenderGameOverlayHandler { public class RenderGameOverlayHandler {
private final FontRenderer fontRenderer;
private static int rl = 0; private static int rl = 0;
private final FontRenderer fontRenderer;
public RenderGameOverlayHandler() { public RenderGameOverlayHandler() {
this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!"); this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!");
} }
private static String getTimeString(long timerTicks) {
final long minutesPart = (timerTicks * 50) / 60000;
final long secondsPart = ((timerTicks * 50) % 60000) / 1000;
final long tenthSecondsPart = ((timerTicks * 50) % 1000) / 100;
return String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart);
}
private static String getWaveString(long waveTicks, int wave) {
final long minutesPart = (waveTicks * 50) / 60000;
final long secondsPart = ((waveTicks * 50) % 60000) / 1000;
final long tenthSecondsPart = ((waveTicks * 50) % 1000) / 100;
return String.format("W%d %d:%02d.%d", wave, minutesPart, secondsPart, tenthSecondsPart);
}
static void toggleRL() {
if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset();
else rl = 0;
}
@SubscribeEvent @SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) { public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) {
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return; if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
@ -60,7 +79,6 @@ public class RenderGameOverlayHandler {
); );
} }
private void renderSla(Room @NotNull [] rooms) { private void renderSla(Room @NotNull [] rooms) {
int y = 0; int y = 0;
for (Room room : rooms) { for (Room room : rooms) {
@ -74,6 +92,7 @@ public class RenderGameOverlayHandler {
y++; y++;
} }
} }
private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) { private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) {
if (Scoreboard.isNotZombies()) return; if (Scoreboard.isNotZombies()) return;
@ -109,21 +128,4 @@ public class RenderGameOverlayHandler {
heightIndex++; heightIndex++;
} }
} }
private static String getTimeString(long timerTicks) {
final long minutesPart = (timerTicks *50) / 60000;
final long secondsPart = ((timerTicks *50) % 60000) / 1000;
final long tenthSecondsPart = ((timerTicks *50) % 1000) / 100;
return String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart);
}
private static String getWaveString(long waveTicks, int wave) {
final long minutesPart = (waveTicks *50) / 60000;
final long secondsPart = ((waveTicks *50) % 60000) / 1000;
final long tenthSecondsPart = ((waveTicks *50) % 1000) / 100;
return String.format("W%d %d:%02d.%d", wave, minutesPart, secondsPart, tenthSecondsPart);
}
public static void toggleRL() {
if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset();
else rl = 0;
}
} }

View file

@ -19,14 +19,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class MixinNetHandlerPlayClient { public class MixinNetHandlerPlayClient {
@Unique @Unique
private boolean zombies_utils$alienUfoOpened; private boolean zombies_utils$alienUfoOpened;
@Inject(method = "handleSoundEffect", at = @At(value = "HEAD")) @Inject(method = "handleSoundEffect", at = @At(value = "HEAD"))
private void handleSound(S29PacketSoundEffect packetIn, CallbackInfo ci) { private void handleSound(S29PacketSoundEffect packetIn, CallbackInfo ci) {
zombies_utils$handleSound(packetIn); zombies_utils$handleSound(packetIn);
} }
@Inject(method = "handleTitle", at = @At(value = "HEAD")) @Inject(method = "handleTitle", at = @At(value = "HEAD"))
private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) { private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
zombies_utils$handleTitle(packetIn); zombies_utils$handleTitle(packetIn);
} }
@Unique @Unique
private void zombies_utils$handleSound(@NotNull S29PacketSoundEffect packet) { private void zombies_utils$handleSound(@NotNull S29PacketSoundEffect packet) {
if (Scoreboard.isNotZombies()) return; if (Scoreboard.isNotZombies()) return;
@ -48,7 +51,8 @@ public class MixinNetHandlerPlayClient {
round round
); );
} else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { } else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) {
Timer.instance = 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), Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new),
round round
); );
@ -63,6 +67,7 @@ public class MixinNetHandlerPlayClient {
ZombiesUtils.getInstance().getLogger().warn(e); ZombiesUtils.getInstance().getLogger().warn(e);
} }
} }
@Unique @Unique
private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) { private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) {
if (packet.getType() != S45PacketTitle.Type.TITLE) return; if (packet.getType() != S45PacketTitle.Type.TITLE) return;
@ -73,7 +78,8 @@ public class MixinNetHandlerPlayClient {
if (message.equals("§aYou Win!")) { if (message.equals("§aYou Win!")) {
switch (timer.getGameMode().getMap()) { switch (timer.getGameMode().getMap()) {
case DEAD_END: case BAD_BLOOD: case DEAD_END:
case BAD_BLOOD:
timer.split((byte) 30); timer.split((byte) 30);
Timer.dropInstances(); Timer.dropInstances();
break; break;

View file

@ -9,14 +9,13 @@ import org.jetbrains.annotations.NotNull;
public class RecordManager { public class RecordManager {
private static final String bar = "§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"; private static final String bar = "§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬";
public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException { public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException {
String segmentMessage = bar + String segmentMessage = bar +
"\n§e Category: §d" + category.getName() "\n§e Category: §d" + category.getName();
;
@SuppressWarnings("OptionalGetWithoutIsPresent") @SuppressWarnings("OptionalGetWithoutIsPresent") final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
short bestSegment = categoryFile.getBestSegment(round); short bestSegment = categoryFile.getBestSegment(round);
if (bestSegment == (short) 0) { if (bestSegment == (short) 0) {
categoryFile.setBestSegment(round, roundTime); categoryFile.setBestSegment(round, roundTime);
@ -35,13 +34,12 @@ public class RecordManager {
segmentMessage += "\n" + bar; segmentMessage += "\n" + bar;
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(segmentMessage)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(segmentMessage));
} }
public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException { public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException {
String bestMessage = bar + String bestMessage = bar +
"\n§e Category: §d" + category.getName() "\n§e Category: §d" + category.getName();
;
@SuppressWarnings("OptionalGetWithoutIsPresent") @SuppressWarnings("OptionalGetWithoutIsPresent") final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
int personalBest = categoryFile.getPersonalBest(round); int personalBest = categoryFile.getPersonalBest(round);
if (personalBest == 0) { if (personalBest == 0) {
categoryFile.setPersonalBest(round, gameTime); categoryFile.setPersonalBest(round, gameTime);
@ -61,6 +59,7 @@ public class RecordManager {
bestMessage += "\n" + bar; bestMessage += "\n" + bar;
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(bestMessage)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(bestMessage));
} }
private static String formattedTime(int gameTime) { private static String formattedTime(int gameTime) {
gameTime *= 50; gameTime *= 50;
return String.format("%d:%02d.%d%d", return String.format("%d:%02d.%d%d",
@ -70,6 +69,7 @@ public class RecordManager {
(gameTime % 100) / 10 (gameTime % 100) / 10
); );
} }
@Contract(pure = true) @Contract(pure = true)
private static @NotNull String formattedDelta(int newTime, int prevTime) { private static @NotNull String formattedDelta(int newTime, int prevTime) {
double delta = (double) (newTime - prevTime) / 20; double delta = (double) (newTime - prevTime) / 20;

View file

@ -19,11 +19,11 @@ public class Timer {
public static Timer instance; public static Timer instance;
private final GameMode gameMode; private final GameMode gameMode;
private final String serverNumber;
private final GameFile gameFile;
public Category category;
private long savedTotalWorldTime; private long savedTotalWorldTime;
private int passedRoundsTickSum = 0; private int passedRoundsTickSum = 0;
private final String serverNumber;
public Category category;
private final GameFile gameFile;
private boolean pbTracking = false; private boolean pbTracking = false;
private int round; private int round;
private boolean r1Corrected = false; private boolean r1Corrected = false;
@ -33,11 +33,10 @@ public class Timer {
* @param map The map the timer should be started for. * @param map The map the timer should be started for.
* @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) throws TimerException.ServerNumberException {
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 Timer.TimerException.ServerNumberException();
this.category = new Category(); this.category = new Category();
this.gameFile = new GameFile(serverNumber.trim(), map); this.gameFile = new GameFile(serverNumber.trim(), map);
@ -49,10 +48,21 @@ public class Timer {
MinecraftForge.EVENT_BUS.register(new Round1Correction()); MinecraftForge.EVENT_BUS.register(new Round1Correction());
} }
public static Optional<Timer> getInstance() {
return Optional.ofNullable(instance);
}
/**
* Call to invalidate {@link #instance} to trigger the garbage collector
*/
public static void dropInstances() {
instance = null;
}
/** /**
* The main splitting function. * The main splitting function.
* Cancels on the second occurring sound-effect, important for {@link RecordManager} to not override values incorrectly. * Cancels on the second occurring sound-effect, important for {@link RecordManager} to not override values incorrectly.
*
* @param passedRound The round that has been passed. * @param passedRound The round that has been passed.
*/ */
public void split(byte passedRound) { public void split(byte passedRound) {
@ -69,6 +79,7 @@ public class Timer {
passedRoundsTickSum = gameTime; passedRoundsTickSum = gameTime;
round = passedRound; round = passedRound;
} }
public void correctRn() { public void correctRn() {
if (r1Corrected) return; if (r1Corrected) return;
savedTotalWorldTime = getCurrentTotalWorldTime() - 200L; savedTotalWorldTime = getCurrentTotalWorldTime() - 200L;
@ -89,15 +100,16 @@ public class Timer {
} }
} }
private long getCurrentTotalWorldTime() { private long getCurrentTotalWorldTime() {
if (Minecraft.getMinecraft() == null) return 0; if (Minecraft.getMinecraft() == null) return 0;
if (Minecraft.getMinecraft().theWorld == null) return 0; if (Minecraft.getMinecraft().theWorld == null) return 0;
return Minecraft.getMinecraft().theWorld.getTotalWorldTime(); return Minecraft.getMinecraft().theWorld.getTotalWorldTime();
} }
public int gameTime() { public int gameTime() {
return (int) (getCurrentTotalWorldTime() - savedTotalWorldTime); return (int) (getCurrentTotalWorldTime() - savedTotalWorldTime);
} }
public short roundTime() { public short roundTime() {
return (short) (gameTime() - passedRoundsTickSum); return (short) (gameTime() - passedRoundsTickSum);
} }
@ -109,19 +121,11 @@ public class Timer {
public boolean equalsServerOrNull(String serverNumber) { public boolean equalsServerOrNull(String serverNumber) {
return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty()); return (serverNumber == null || serverNumber.equals(this.serverNumber) || serverNumber.isEmpty());
} }
public void setCategory(Category category) { public void setCategory(Category category) {
this.category = category; this.category = category;
} }
public static Optional<Timer> getInstance() {
return Optional.ofNullable(instance);
}
/**
* Call to invalidate {@link #instance} to trigger the garbage collector
*/
public static void dropInstances() {
instance = null;
}
public byte getRound() { public byte getRound() {
return (byte) (round + 1); return (byte) (round + 1);
} }
@ -134,6 +138,7 @@ public class Timer {
public static class MapException extends TimerException { public static class MapException extends TimerException {
} }
public static class ServerNumberException extends TimerException { public static class ServerNumberException extends TimerException {
} }
} }

View file

@ -14,6 +14,7 @@ public class Category {
private static String selectedCategory = ZombiesUtilsConfig.getDefaultCategory(); private static String selectedCategory = ZombiesUtilsConfig.getDefaultCategory();
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(new File("zombies", "splits"), 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));
@ -28,7 +29,16 @@ public class Category {
this.name = Category.selectedCategory; this.name = Category.selectedCategory;
} }
public static void setSelectedCategory(String selectedCategory) {
Category.selectedCategory = selectedCategory;
Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category()));
}
public static String[] getCategories() {
File dir = new File("zombies" + File.separator + "splits");
if (dir.isDirectory()) return dir.list();
else return new String[0];
}
public CategoryFile getByGameMode(@NotNull GameMode gameMode) { public CategoryFile getByGameMode(@NotNull GameMode gameMode) {
if (gameMode.is(Map.DEAD_END, Difficulty.NORMAL)) return categoryFiles[0]; if (gameMode.is(Map.DEAD_END, Difficulty.NORMAL)) return categoryFiles[0];
@ -43,16 +53,6 @@ public class Category {
else throw new IllegalStateException("Unexpected value: " + gameMode); else throw new IllegalStateException("Unexpected value: " + gameMode);
} }
public static void setSelectedCategory(String selectedCategory) {
Category.selectedCategory = selectedCategory;
Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category()));
}
public static String[] getCategories() {
File dir = new File("zombies"+File.separator+"splits");
if (dir.isDirectory()) return dir.list();
else return new String[0];
}
public String getName() { public String getName() {
return name; return name;
} }

View file

@ -26,6 +26,7 @@ public class FileManager {
return gson.fromJson(dataJson, CategoryData.class); return gson.fromJson(dataJson, CategoryData.class);
} }
public static void createDataFile(@NotNull SplitsFile splitsFile) { public static void createDataFile(@NotNull SplitsFile splitsFile) {
try { try {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
@ -37,9 +38,11 @@ public class FileManager {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public static void writeDataToFile(SplitsFile splitsFile) throws IOException { public static void writeDataToFile(SplitsFile splitsFile) throws IOException {
FileUtils.writeStringToFile(splitsFile, splitsFile.getData().toJSON(), StandardCharsets.UTF_16); FileUtils.writeStringToFile(splitsFile, splitsFile.getData().toJSON(), StandardCharsets.UTF_16);
} }
public static CategoryData categoryReadOrCreate(CategoryFile file) { public static CategoryData categoryReadOrCreate(CategoryFile file) {
CategoryData data; CategoryData data;
try { try {

View file

@ -8,8 +8,10 @@ public abstract class SplitsFile extends File {
public SplitsFile(String parent, @NotNull String child) { public SplitsFile(String parent, @NotNull String child) {
super(parent, child); super(parent, child);
} }
public SplitsFile(File category, String child) { public SplitsFile(File category, String child) {
super(category, child); super(category, child);
} }
abstract public ISplitsData getData(); abstract public ISplitsData getData();
} }

View file

@ -10,13 +10,15 @@ import java.util.Arrays;
public class CategoryData implements ISplitsData { public class CategoryData implements ISplitsData {
private final short[] bestSegments; //in ticks, max ~27 min private final short[] bestSegments; //in ticks, max ~27 min
private final int[] personalBests; //in ticks, private final int[] personalBests; //in ticks,
public CategoryData(@NotNull Map map) { public CategoryData(@NotNull Map map) {
switch (map) { switch (map) {
case ALIEN_ARCADIUM: case ALIEN_ARCADIUM:
bestSegments = new short[105]; bestSegments = new short[105];
personalBests = new int[105]; personalBests = new int[105];
break; break;
case DEAD_END: case BAD_BLOOD: case DEAD_END:
case BAD_BLOOD:
bestSegments = new short[30]; bestSegments = new short[30];
personalBests = new int[30]; personalBests = new int[30];
break; break;
@ -26,6 +28,7 @@ public class CategoryData implements ISplitsData {
Arrays.fill(bestSegments, (short) 0); Arrays.fill(bestSegments, (short) 0);
Arrays.fill(personalBests, 0); Arrays.fill(personalBests, 0);
} }
@Override @Override
public String toJSON() { public String toJSON() {
Gson gson = new Gson(); Gson gson = new Gson();
@ -35,12 +38,15 @@ public class CategoryData implements ISplitsData {
public short getBestSegment(int index) { public short getBestSegment(int index) {
return bestSegments[index]; return bestSegments[index];
} }
public int getPersonalBest(int index) { public int getPersonalBest(int index) {
return personalBests[index]; return personalBests[index];
} }
public void setBestSegment(int index, short ticks) { public void setBestSegment(int index, short ticks) {
bestSegments[index] = ticks; bestSegments[index] = ticks;
} }
public void setPersonalBest(int index, int ticks) { public void setPersonalBest(int index, int ticks) {
personalBests[index] = ticks; personalBests[index] = ticks;
} }

View file

@ -15,7 +15,8 @@ public class GameData implements ISplitsData {
case ALIEN_ARCADIUM: case ALIEN_ARCADIUM:
segments = new short[105]; segments = new short[105];
break; break;
case DEAD_END: case BAD_BLOOD: case DEAD_END:
case BAD_BLOOD:
segments = new short[30]; segments = new short[30];
break; break;
default: default:
@ -29,6 +30,7 @@ public class GameData implements ISplitsData {
Gson gson = new Gson(); Gson gson = new Gson();
return gson.toJson(this.segments); return gson.toJson(this.segments);
} }
public void setSegment(int index, short ticks) { public void setSegment(int index, short ticks) {
segments[index] = ticks; segments[index] = ticks;
} }

View file

@ -13,6 +13,7 @@ import java.io.IOException;
public class CategoryFile extends SplitsFile { public class CategoryFile extends SplitsFile {
private final CategoryData data; private final CategoryData data;
private final GameMode gameMode; private final GameMode gameMode;
public CategoryFile(File category, @NotNull GameMode gameMode) { public CategoryFile(File category, @NotNull GameMode gameMode) {
// Game-directory -> custom category -> file named "MAP_DIFFICULTY.times" // Game-directory -> custom category -> file named "MAP_DIFFICULTY.times"
// Content encoded in StandardCharsets.UTF_16 // Content encoded in StandardCharsets.UTF_16
@ -24,20 +25,29 @@ public class CategoryFile extends SplitsFile {
public short getBestSegment(int round) { public short getBestSegment(int round) {
return data.getBestSegment(round - 1); return data.getBestSegment(round - 1);
} }
public void setBestSegment(int round, short ticks) { public void setBestSegment(int round, short ticks) {
data.setBestSegment(round - 1, ticks); data.setBestSegment(round - 1, ticks);
try { FileManager.writeDataToFile(this); } try {
catch (IOException e) { throw new RuntimeException(e); } FileManager.writeDataToFile(this);
} catch (IOException e) {
throw new RuntimeException(e);
} }
}
public int getPersonalBest(int round) { public int getPersonalBest(int round) {
return data.getPersonalBest(round - 1); return data.getPersonalBest(round - 1);
} }
public void setPersonalBest(int round, int ticks) { public void setPersonalBest(int round, int ticks) {
data.setPersonalBest(round - 1, ticks); data.setPersonalBest(round - 1, ticks);
try { FileManager.writeDataToFile(this); } try {
catch (IOException e) { throw new RuntimeException(e); } FileManager.writeDataToFile(this);
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
public GameMode getGameMode() { public GameMode getGameMode() {

View file

@ -31,8 +31,11 @@ public class GameFile extends SplitsFile {
public void setSegment(int round, short ticks) { public void setSegment(int round, short ticks) {
data.setSegment(round - 1, ticks); data.setSegment(round - 1, ticks);
try { FileManager.writeDataToFile(this); } try {
catch (IOException e) { throw new RuntimeException(e); } FileManager.writeDataToFile(this);
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
@Override @Override

View file

@ -47,7 +47,8 @@ public class Scoreboard {
List<Score> filteredScores = scoreCollection.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList()); List<Score> filteredScores = scoreCollection.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList());
List<Score> scores; List<Score> scores;
if (filteredScores.size() > 15) scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15)); if (filteredScores.size() > 15)
scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15));
else scores = filteredScores; else scores = filteredScores;
scores = Lists.reverse(scores); scores = Lists.reverse(scores);
@ -79,6 +80,7 @@ public class Scoreboard {
return 0; return 0;
} }
} }
public static Optional<String> getServerNumber() { public static Optional<String> getServerNumber() {
String line; String line;
try { try {
@ -91,6 +93,7 @@ public class Scoreboard {
ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string); ZombiesUtils.getInstance().getLogger().debug("Servernumber: " + string);
return Optional.ofNullable(string); return Optional.ofNullable(string);
} }
public static Optional<Map> getMap() { public static Optional<Map> getMap() {
String line; String line;
try { try {
@ -104,16 +107,22 @@ public class Scoreboard {
} }
String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); String mapString = MAP_PATTERN.matcher(line).replaceAll("$1");
switch (mapString) { switch (mapString) {
case "Dead End": return Optional.of(Map.DEAD_END); case "Dead End":
case "Bad Blood": return Optional.of(Map.BAD_BLOOD); return Optional.of(Map.DEAD_END);
case "Alien Arcadium": return Optional.of(Map.ALIEN_ARCADIUM); case "Bad Blood":
default: return Optional.empty(); return Optional.of(Map.BAD_BLOOD);
case "Alien Arcadium":
return Optional.of(Map.ALIEN_ARCADIUM);
default:
return Optional.empty();
} }
} }
public static int getLineCount() { public static int getLineCount() {
return lines.size(); return lines.size();
} }
public static boolean isNotZombies() { public static boolean isNotZombies() {
return (!"ZOMBIES".equals(title)); return (!"ZOMBIES".equals(title));
} }