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

@ -14,9 +14,10 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class CategoryCommand extends CommandBase { 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

@ -121,7 +121,7 @@ public class SlaCommand extends CommandBase {
else { else {
if (args.length > 1) switch (args[0]) { if (args.length > 1) switch (args[0]) {
case "offset": case "offset":
if (args.length<5) options.add("0"); if (args.length < 5) options.add("0");
break; break;
case "map": case "map":
options.addAll(Arrays.asList("de", "bb", "aa")); options.addAll(Arrays.asList("de", "bb", "aa"));
@ -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

@ -10,7 +10,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class ZombiesUtilsCommand extends CommandBase { public class ZombiesUtilsCommand extends CommandBase {
@Override @Override
public String getCommandName() { public String getCommandName() {
return "zombiesutils"; return "zombiesutils";
@ -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

@ -7,13 +7,15 @@ public class QuickSLA {
public static void mogi_a() { public static void mogi_a() {
SLA.instance = new SLA(Map.BAD_BLOOD); SLA.instance = new SLA(Map.BAD_BLOOD);
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,37 +19,55 @@ 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()) {
window.rotate(rotations); window.rotate(rotations);
} }
} }
} }
public void mirrorX() { public void mirrorX() {
for (Room room : rooms) { for (Room room : rooms) {
for (Window window: room.getWindows()) { for (Window window : room.getWindows()) {
window.mirrorX(); window.mirrorX();
} }
} }
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()) {
window.mirrorZ(); window.mirrorZ();
} }
} }
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 = {
@ -57,14 +75,14 @@ public class SLA {
player.posY - offset[1], player.posY - offset[1],
player.posZ - offset[2] player.posZ - offset[2]
}; };
for (Room room: rooms for (Room room : rooms
) { ) {
room.resetActiveWindowCount(); room.resetActiveWindowCount();
for (Window window: room.getWindows() for (Window window : room.getWindows()
) { ) {
double distanceDoubledThenSquared = 0; double distanceDoubledThenSquared = 0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
distanceDoubledThenSquared += ((playerCoords[i]*2 - window.getXYZ()[i]) * (playerCoords[i]*2 - window.getXYZ()[i])); distanceDoubledThenSquared += ((playerCoords[i] * 2 - window.getXYZ()[i]) * (playerCoords[i] * 2 - window.getXYZ()[i]));
} }
// (2x)²+(2y)²+(2z)² = 4(x²+y²+z²) = 4d² // (2x)²+(2y)²+(2z)² = 4(x²+y²+z²) = 4d²
@ -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

@ -6,15 +6,12 @@ import org.jetbrains.annotations.NotNull;
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
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,9 +45,10 @@ 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,69 +10,63 @@ 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);
t.rotatePitch(3); t.rotatePitch(3);
return new Room[]{ return new Room[]{
new Room("Alley", "al", new Window[]{ new Room("Alley", "al", new Window[]{
new Window(1,9,138,87), new Window(1, 9, 138, 87),
new Window(2,13,138,63), new Window(2, 13, 138, 63),
new Window(3,85,140,59), new Window(3, 85, 140, 59),
new Window(4,79,140,17) new Window(4, 79, 140, 17)
}), }),
new Room("Office", "o", new Window[]{ new Room("Office", "o", new Window[]{
new Window(1,85,152,53), new Window(1, 85, 152, 53),
new Window(2,105,152,63), new Window(2, 105, 152, 63),
new Window(3,115,152,129) new Window(3, 115, 152, 129)
}), }),
new Room("Hotel", "h", new Window[]{ new Room("Hotel", "h", new Window[]{
new Window(1,1,136,93), new Window(1, 1, 136, 93),
new Window(2,-19,136,29), new Window(2, -19, 136, 29),
new Window(3,53,138,7), new Window(3, 53, 138, 7),
new Window(4,51,138,-7), new Window(4, 51, 138, -7),
new Window(5,-7,152,-43), new Window(5, -7, 152, -43),
new Window(6,51,152,-11) new Window(6, 51, 152, -11)
}), }),
new Room("Apartments", "a", new Window[]{ new Room("Apartments", "a", new Window[]{
new Window(1,39,152,19), new Window(1, 39, 152, 19),
new Window(2,-31,152,31), new Window(2, -31, 152, 31),
new Window(3,-27,152,103), new Window(3, -27, 152, 103),
new Window(4,-9,152,125) new Window(4, -9, 152, 125)
}), }),
new Room("Power Station", "ps", new Window[]{ new Room("Power Station", "ps", new Window[]{
new Window(1,-5,166,65), new Window(1, -5, 166, 65),
new Window(2,7,166,125), new Window(2, 7, 166, 125),
new Window(3,-11,136,133) new Window(3, -11, 136, 133)
}), }),
new Room("Rooftop", "rt", new Window[]{ new Room("Rooftop", "rt", new Window[]{
new Window(1,-31,166,129), new Window(1, -31, 166, 129),
new Window(2,-27,166,61), new Window(2, -27, 166, 61),
new Window(3,-75,166,51), new Window(3, -75, 166, 51),
new Window(4,-99,166,77) new Window(4, -99, 166, 77)
}), }),
new Room("Garden", "g", new Window[]{ new Room("Garden", "g", new Window[]{
new Window(1,1,136,-33), new Window(1, 1, 136, -33),
new Window(2,49,136,-67), new Window(2, 49, 136, -67),
new Window(3,69,136,-33) new Window(3, 69, 136, -33)
}), }),
new Room("Gallery", "gal", new Window[]{ new Room("Gallery", "gal", new Window[]{
new Window(1,45,152,155), new Window(1, 45, 152, 155),
new Window(2,61,152,109), new Window(2, 61, 152, 109),
new Window(3,31,152,131) new Window(3, 31, 152, 131)
}) })
}; };
} }
@ -81,92 +75,104 @@ public class Room {
public static Room @NotNull [] getBB() { public static Room @NotNull [] getBB() {
return new Room[]{ return new Room[]{
new Room("Courtyard", "co", new Window[]{ new Room("Courtyard", "co", new Window[]{
new Window(1,39,138,41), new Window(1, 39, 138, 41),
new Window(2,61,138,21), new Window(2, 61, 138, 21),
new Window(3,49,138,-37), new Window(3, 49, 138, -37),
new Window(4,25,138,-35) new Window(4, 25, 138, -35)
}), }),
new Room("Mansion", "m", new Window[]{ new Room("Mansion", "m", new Window[]{
new Window(1,1,148,-35), new Window(1, 1, 148, -35),
new Window(2,1,148,37), new Window(2, 1, 148, 37),
new Window(3,-25,146,57) new Window(3, -25, 146, 57)
}), }),
new Room("Library", "l", new Window[]{ new Room("Library", "l", new Window[]{
new Window(1,3,148,-89), new Window(1, 3, 148, -89),
new Window(2,-41,148,-59), new Window(2, -41, 148, -59),
new Window(3,-81,148,-61), new Window(3, -81, 148, -61),
new Window(4,-79,148,-115), new Window(4, -79, 148, -115),
new Window(5,-109,148,-93), new Window(5, -109, 148, -93),
new Window(6,-107,148,-67) new Window(6, -107, 148, -67)
}), }),
new Room("Dungeon", "d", new Window[]{ new Room("Dungeon", "d", new Window[]{
new Window(1,-21,136,-99), new Window(1, -21, 136, -99),
new Window(2,-57,136,-69), new Window(2, -57, 136, -69),
new Window(3,-19,136,-45), new Window(3, -19, 136, -45),
new Window(4,-19,136,-37), new Window(4, -19, 136, -37),
new Window(5,-73,136,-23) new Window(5, -73, 136, -23)
}), }),
new Room("Crypts", "cr", new Window[]{ new Room("Crypts", "cr", new Window[]{
new Window(1,-7,136,-5), new Window(1, -7, 136, -5),
new Window(2,-31,136,1), new Window(2, -31, 136, 1),
new Window(3,-57,136,41) new Window(3, -57, 136, 41)
}), }),
new Room("Graveyard", "gy", new Window[]{ new Room("Graveyard", "gy", new Window[]{
new Window(1,-71,136,63), new Window(1, -71, 136, 63),
new Window(2,-33,136,101), new Window(2, -33, 136, 101),
new Window(3,-13,136,67) new Window(3, -13, 136, 67)
}), }),
new Room("Balcony", "b", new Window[]{ new Room("Balcony", "b", new Window[]{
new Window(1,-65,148,-37), new Window(1, -65, 148, -37),
new Window(2,-113,148,5), new Window(2, -113, 148, 5),
new Window(3,-107,144,25), new Window(3, -107, 144, 25),
new Window(4,-83,136,55) new Window(4, -83, 136, 55)
}), }),
new Room("Great Hall", "gh", new Window[]{ new Room("Great Hall", "gh", new Window[]{
new Window(1,-39,148,-27), new Window(1, -39, 148, -27),
new Window(2,-55,148,31), new Window(2, -55, 148, 31),
new Window(3,-63,152,31) new Window(3, -63, 152, 31)
}) })
}; };
} }
@Contract(" -> new") @Contract(" -> new")
public static Room @NotNull [] getAA() { public static Room @NotNull [] getAA() {
return new Room[]{ return new Room[]{
new Room("Park Entrance", "ent", new Window[]{ new Room("Park Entrance", "ent", new Window[]{
new Window(1,13,144,63), new Window(1, 13, 144, 63),
new Window(2,-45,144,31), new Window(2, -45, 144, 31),
new Window(3,-43,144,21), new Window(3, -43, 144, 21),
new Window(4,-21,144,-11), new Window(4, -21, 144, -11),
new Window(5,45,144,27) new Window(5, 45, 144, 27)
}), }),
new Room("Roller Coaster", "rc", new Window[]{ new Room("Roller Coaster", "rc", new Window[]{
new Window(1,-25,144,79), new Window(1, -25, 144, 79),
new Window(2,-57,144,55) new Window(2, -57, 144, 55)
}), }),
new Room("Ferris Wheel", "fw", new Window[]{ new Room("Ferris Wheel", "fw", new Window[]{
new Window(1,55,144,63), new Window(1, 55, 144, 63),
new Window(2,35,144,89) new Window(2, 35, 144, 89)
}), }),
new Room("Bumper Cars", "bp", new Window[]{ new Room("Bumper Cars", "bp", new Window[]{
new Window(1,45,146,-27), new Window(1, 45, 146, -27),
new Window(2,67,146,-3) new Window(2, 67, 146, -3)
}) })
}; };
} }
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) {
if (window.isActive()) slaString.append("§2 ").append(alias).append(window.getID()); if (window.isActive()) slaString.append("§2 ").append(alias).append(window.getID());
else if (!ZombiesUtilsConfig.isSlaShortened()) slaString.append("§c ").append(alias).append(window.getID()); else if (!ZombiesUtilsConfig.isSlaShortened()) slaString.append("§c ").append(alias).append(window.getID());
} }

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 {
public ChatHandler () {
}
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE); private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE);
public ChatHandler() {
}
@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,10 +79,9 @@ 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) {
if (ZombiesUtilsConfig.isSlaShortened() && room.getActiveWindowCount() == 0) continue; if (ZombiesUtilsConfig.isSlaShortened() && room.getActiveWindowCount() == 0) continue;
fontRenderer.drawStringWithShadow( fontRenderer.drawStringWithShadow(
room.getSlaString(), room.getSlaString(),
@ -74,18 +92,19 @@ 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;
final int length = waveTimes.length + 1; final int length = waveTimes.length + 1;
int heightIndex = 0; int heightIndex = 0;
int color = 0xFFFF55; int color = 0xFFFF55;
for (byte waveTime: waveTimes) { for (byte waveTime : waveTimes) {
int clonedColor = color; int clonedColor = color;
final short waveTicks = (short) ((waveTime * 20)+rl); final short waveTicks = (short) ((waveTime * 20) + rl);
if (roundTicks>waveTicks) { if (roundTicks > waveTicks) {
if (ZombiesUtilsConfig.isSpawntimeNotShortened()) clonedColor = 0x555555; if (ZombiesUtilsConfig.isSpawntimeNotShortened()) clonedColor = 0x555555;
else { else {
heightIndex++; heightIndex++;
@ -102,28 +121,11 @@ public class RenderGameOverlayHandler {
fontRenderer.drawStringWithShadow( fontRenderer.drawStringWithShadow(
time, time,
screenWidth - width, screenWidth - width,
screenHeight - fontRenderer.FONT_HEIGHT * (length-heightIndex), screenHeight - fontRenderer.FONT_HEIGHT * (length - heightIndex),
clonedColor clonedColor
); );
if (clonedColor!=0x555555) color = 0xAAAAAA; if (clonedColor != 0x555555) color = 0xAAAAAA;
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,21 +19,24 @@ 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;
final String soundEffect = packet.getSoundName(); final String soundEffect = packet.getSoundName();
if (!( if (!(
soundEffect.equals("mob.wither.spawn") soundEffect.equals("mob.wither.spawn")
|| (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened) || (soundEffect.equals("mob.guardian.curse") && !zombies_utils$alienUfoOpened)
)) return; )) return;
zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse");
try { try {
@ -42,13 +45,14 @@ public class MixinNetHandlerPlayClient {
final byte round = Scoreboard.getRound(); final byte round = Scoreboard.getRound();
if (round == 0) { if (round == 0) {
if (Scoreboard.getLineCount()<13) Timer.instance = 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.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);
@ -25,23 +24,22 @@ public class RecordManager {
final String timeString = formattedTime(roundTime); final String timeString = formattedTime(roundTime);
segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + "§e!"; segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + "§e!";
} else { } else {
if (roundTime<bestSegment) { if (roundTime < bestSegment) {
segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***"; segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***";
categoryFile.setBestSegment(round, roundTime); categoryFile.setBestSegment(round, roundTime);
} }
final String timeString = formattedTime(roundTime); final String timeString = formattedTime(roundTime);
segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + " §9" + formattedDelta(roundTime,bestSegment); segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + " §9" + formattedDelta(roundTime, bestSegment);
} }
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);
@ -50,7 +48,7 @@ public class RecordManager {
final String timeString = formattedTime(gameTime); final String timeString = formattedTime(gameTime);
bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + "§e!"; bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + "§e!";
} else { } else {
if (gameTime<personalBest) { if (gameTime < personalBest) {
bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***"; bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***";
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,10 +69,11 @@ 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;
if (delta<0) { if (delta < 0) {
return String.valueOf(delta); return String.valueOf(delta);
} else return ("+" + delta); } else return ("+" + delta);
} }

View file

@ -19,40 +19,50 @@ 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;
/** /**
* @param serverNumber The game's server the timer should be bound to. * @param serverNumber The game's server the timer should be bound to.
* @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();
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
else throw new Timer.TimerException.ServerNumberException();
this.savedTotalWorldTime = getCurrentTotalWorldTime(); this.category = new Category();
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim(); this.gameFile = new GameFile(serverNumber.trim(), map);
else throw new RuntimeException("invalid servernumber");
this.category = new Category(); this.gameMode = new GameMode(map);
this.gameFile = new GameFile(serverNumber.trim(), map); this.round = round;
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
this.gameMode = new GameMode(map);
this.round = round;
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
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,9 +79,10 @@ 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;
r1Corrected = true; r1Corrected = true;
} }
@ -79,7 +90,7 @@ public class Timer {
if (passedRound == (byte) 1) pbTracking = true; if (passedRound == (byte) 1) pbTracking = true;
try { try {
gameFile.setSegment(passedRound,roundTime); gameFile.setSegment(passedRound, roundTime);
RecordManager.compareSegment(passedRound, roundTime, category); RecordManager.compareSegment(passedRound, roundTime, category);
if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category); if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category);
} catch (IndexOutOfBoundsException exception) { } catch (IndexOutOfBoundsException exception) {
@ -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,21 +121,13 @@ 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);
} }
public GameMode getGameMode() { public GameMode getGameMode() {
@ -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,31 +13,41 @@ 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
super(category,gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); super(category, gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times");
this.gameMode = gameMode; this.gameMode = gameMode;
data = FileManager.categoryReadOrCreate(this); data = FileManager.categoryReadOrCreate(this);
} }
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) {
data.setPersonalBest(round-1, ticks);
try { FileManager.writeDataToFile(this); } public void setPersonalBest(int round, int ticks) {
catch (IOException e) { throw new RuntimeException(e); } data.setPersonalBest(round - 1, ticks);
try {
FileManager.writeDataToFile(this);
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
public GameMode getGameMode() { public GameMode getGameMode() {

View file

@ -25,14 +25,17 @@ public class GameFile extends SplitsFile {
private static @NotNull String formattedTime() { private static @NotNull String formattedTime() {
final LocalDateTime dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES); final LocalDateTime dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
return dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace(':','-').replaceFirst("T","_"); return dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace(':', '-').replaceFirst("T", "_");
} }
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,13 +47,14 @@ 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);
lines = new ArrayList<>(); lines = new ArrayList<>();
for (Score score: scores for (Score score : scores
) { ) {
ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName());
String scoreboardLine = ScorePlayerTeam.formatPlayerName(team, score.getPlayerName()).trim(); String scoreboardLine = ScorePlayerTeam.formatPlayerName(team, score.getPlayerName()).trim();
lines.add(STRIP_COLOR_PATTERN.matcher(SIDEBAR_EMOJI_PATTERN.matcher(scoreboardLine).replaceAll("")).replaceAll("")); lines.add(STRIP_COLOR_PATTERN.matcher(SIDEBAR_EMOJI_PATTERN.matcher(scoreboardLine).replaceAll("")).replaceAll(""));
@ -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));
} }