From ba64f4bd1b66efa51aa817ff0a8b8837f7663a3a Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Tue, 7 Nov 2023 16:45:32 +0100 Subject: [PATCH] sla improved, minor bug fixes --- README.md | 1 + .../zombiesutils/ZombiesUtils.java | 15 ++--- .../commands/CategoryCommand.java | 13 ++-- .../zombiesutils/commands/SlaCommand.java | 66 ++++++++++++------- .../zombiesutils/config/Config.java | 39 +++++++++++ .../zombiesutils/config/GuiConfig.java | 18 +++++ .../zombiesutils/config/GuiFactory.java | 34 ++++++++++ .../zombiesutils/game/GameMode.java | 1 + .../zombiesutils/game/Waves.java | 1 + .../zombiesutils/game/windows/Room.java | 3 + .../zombiesutils/game/windows/Sla.java | 43 ++++++++---- .../zombiesutils/game/windows/Window.java | 17 ++++- .../zombiesutils/handlers/ChatHandler.java | 3 +- .../zombiesutils/handlers/TickHandler.java | 3 +- .../mixin/MixinNetHandlerPlayClient.java | 11 ++-- .../render/RenderGameOverlayHandler.java | 6 +- .../zombiesutils/timer/RecordManager.java | 22 ++++--- .../zombiesutils/timer/Timer.java | 5 +- .../timer/recorder/FileManager.java | 7 +- .../timer/recorder/TimesFile.java | 3 +- .../zombiesutils/utils/Scoreboard.java | 5 +- 21 files changed, 236 insertions(+), 80 deletions(-) create mode 100644 src/main/java/com/github/stachelbeere1248/zombiesutils/config/Config.java create mode 100644 src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java create mode 100644 src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiFactory.java diff --git a/README.md b/README.md index dc1c9cf..effb6e6 100644 --- a/README.md +++ b/README.md @@ -15,5 +15,6 @@ The Timer automatically splits every round. The Personal-Best-recorder automatic - default state: disabled - /sla set \ - forcefully set the map - /sla offset \ \ \ - set an offset, allowing you to use sla on map-recreations, such as housings + - Mogi_a: 41 -35 22 ### Extra - Migration of split-category names: In your minecraft folder is a folder called "zombies". You can simply rename the sub-folders. diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java index 9f4739c..6febd0a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -2,6 +2,7 @@ package com.github.stachelbeere1248.zombiesutils; import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand; import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand; +import com.github.stachelbeere1248.zombiesutils.config.Config; import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler; import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler; import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; @@ -12,11 +13,11 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; -@Mod(modid = "zombiesutils", useMetadata = true, clientSideOnly = true) +@Mod(modid = "zombiesutils", useMetadata = true, clientSideOnly = true, guiFactory = "com.github.stachelbeere1248.zombiesutils.config.GuiFactory") public class ZombiesUtils { private static ZombiesUtils instance; - private Configuration config; private Logger logger; public ZombiesUtils() { instance = this; @@ -26,22 +27,20 @@ public class ZombiesUtils { } @Mod.EventHandler - public void preInit(FMLPreInitializationEvent event) { + public void preInit(@NotNull FMLPreInitializationEvent event) { logger = event.getModLog(); - config = new Configuration(event.getSuggestedConfigurationFile()); - config.load(); + Config.config = new Configuration(event.getSuggestedConfigurationFile()); + Config.load(); } @Mod.EventHandler public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); MinecraftForge.EVENT_BUS.register(new TickHandler()); MinecraftForge.EVENT_BUS.register(new ChatHandler()); + MinecraftForge.EVENT_BUS.register(new Config()); ClientCommandHandler.instance.registerCommand(new CategoryCommand()); ClientCommandHandler.instance.registerCommand(new SlaCommand()); } - public Configuration getConfig() { - return config; - } public Logger getLogger() { return logger; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java index 073c751..06322ec 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java @@ -3,10 +3,13 @@ package com.github.stachelbeere1248.zombiesutils.commands; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; +import org.jetbrains.annotations.NotNull; +import java.io.File; import java.util.Arrays; import java.util.List; @@ -25,10 +28,12 @@ public class CategoryCommand extends CommandBase { } @Override - public void processCommand(ICommandSender sender, String[] args) { - if (args.length == 0) sender.addChatMessage(new ChatComponentText(getCommandUsage(sender))); + public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { + if (args.length == 0) throw new WrongUsageException("Please enter a name for the category"); else { - Category.setSelectedCategory(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"); + Category.setSelectedCategory(cat); Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java index 30136e8..0acb753 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java @@ -2,9 +2,8 @@ package com.github.stachelbeere1248.zombiesutils.commands; import com.github.stachelbeere1248.zombiesutils.game.Map; import com.github.stachelbeere1248.zombiesutils.game.windows.Sla; -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; +import net.minecraft.client.Minecraft; +import net.minecraft.command.*; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import org.jetbrains.annotations.NotNull; @@ -22,7 +21,7 @@ public class SlaCommand extends CommandBase { @Override public String getCommandUsage(ICommandSender sender) { - return "/sla toggle\n/sla offset [x] [x] [x]\n/sla set "; + return "/sla off\n/sla offset [x] [x] [x]\n/sla rotate\n/sla mirror\n/sla map "; } @Override @@ -30,13 +29,13 @@ public class SlaCommand extends CommandBase { if (args.length == 0) sender.addChatMessage(new ChatComponentText(getCommandUsage(sender))); else { switch (args[0]) { - case "toggle": - Sla.toggle(); - sender.addChatMessage(new ChatComponentText("SLA active: " + Sla.isEnabled())); + case "off": + Sla.drop(); + sender.addChatMessage(new ChatComponentText("SLA data deleted")); break; case "offset": if (args.length == 1) Sla.getInstance().ifPresent(Sla::resetOffset); - else if (args.length != 4) sender.addChatMessage(new ChatComponentText("/sla offset [x] [x] [x]")); + else if (args.length != 4) throw new WrongUsageException("An offset should have three coordinates!"); else { try { double x = Double.parseDouble(args[1]); @@ -45,38 +44,57 @@ public class SlaCommand extends CommandBase { Sla.getInstance().ifPresent(sla -> sla.setOffset(new double[]{x, y, z})); sender.addChatMessage(new ChatComponentText(String.format("Offset set to %s %s %s", x, y, z))); } catch (NumberFormatException ignored) { - sender.addChatMessage(new ChatComponentText("Please input valid numbers")); + throw new NumberInvalidException(); } } break; - case "set": + case "rotate": + sender.addChatMessage(new ChatComponentText("Rotating map...")); + Sla.getInstance().ifPresent(Sla::rotate); + break; + case "mirror": switch (args[1]) { - case "de": - new Sla(Map.DEAD_END); + case "x": + Sla.getInstance().ifPresent(Sla::mirrorX); break; - case "bb": - new Sla(Map.BAD_BLOOD); + case "z": + Sla.getInstance().ifPresent(Sla::mirrorZ); break; - case "aa": - new Sla(Map.ALIEN_ARCADIUM); - break; - default: - sender.addChatMessage(new ChatComponentText("/sla set ")); + default: throw new WrongUsageException("Invalid option: available: x, z"); } break; - default: - sender.addChatMessage(new ChatComponentText(getCommandUsage(sender))); + case "map": + switch (args[1]) { + case "de": + Sla.instance = new Sla(Map.DEAD_END); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map DE")); + break; + case "bb": + Sla.instance = new Sla(Map.BAD_BLOOD); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map BB")); + break; + case "aa": + Sla.instance = new Sla(Map.ALIEN_ARCADIUM); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map AA")); + break; + default: throw new WrongUsageException("Invalid option: available: de, bb, aa"); + + } break; + default: throw new WrongUsageException("Invalid option: available: off, offset, rotate, mirror, map"); } } } @Override public List addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { - List options = new ArrayList(); - if (args.length == 1) options.addAll(Arrays.asList("toggle","offset","set")); + List options = new ArrayList<>(); + if (args.length == 1) options.addAll(Arrays.asList("off","offset","rotate","mirror","map")); else if ("offset".equals(args[0]) && (args.length == 2 || args.length == 3 || args.length == 4)) options.add("0"); - else if ("set".equals(args[0])) options.addAll(Arrays.asList("de", "bb", "aa")); + else if ("map".equals(args[0])) options.addAll(Arrays.asList("de", "bb", "aa")); + else if ("mirror".equals(args[0])) { + options.addAll(Arrays.asList("x","z")); + } return options; } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Config.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Config.java new file mode 100644 index 0000000..dd64c8e --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/Config.java @@ -0,0 +1,39 @@ +package com.github.stachelbeere1248.zombiesutils.config; + +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.jetbrains.annotations.NotNull; + +public class Config { + public static Configuration config; + + private static boolean slaToggle; + public static void load() { + ZombiesUtils.getInstance().getLogger().debug("Loading config..."); + config.load(); + ZombiesUtils.getInstance().getLogger().debug("Config loaded."); + + slaToggle = config.getBoolean( + "SLA Launcher", + Configuration.CATEGORY_GENERAL, + slaToggle, + "Should SLA be started when a game starts?" + ); + + ZombiesUtils.getInstance().getLogger().debug("Saving Config..."); + config.save(); + ZombiesUtils.getInstance().getLogger().debug("Config saved."); + } + @SubscribeEvent + public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) { + if (event.modID.equals("zombiesutils") && event.configID == null) { + config.save(); + Config.load(); + } + } + public static boolean isSlaToggled() { + return slaToggle; + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java new file mode 100644 index 0000000..ccd417b --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java @@ -0,0 +1,18 @@ +package com.github.stachelbeere1248.zombiesutils.config; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Configuration; + +public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig { + public GuiConfig(GuiScreen parentScreen) { + super( + parentScreen, + new ConfigElement(Config.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), + "zombiesutils", + false, + false, + "Zombies Utils" + ); + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiFactory.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiFactory.java new file mode 100644 index 0000000..c852b12 --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiFactory.java @@ -0,0 +1,34 @@ +package com.github.stachelbeere1248.zombiesutils.config; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.fml.client.IModGuiFactory; + +import java.util.Set; + +public class GuiFactory implements IModGuiFactory { + + public boolean hasConfigGui() { + return true; + } + + @Override + public void initialize(Minecraft minecraft) { + + } + + @Override + public Class mainConfigGuiClass() { + return GuiConfig.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java index 4d04d8b..b8669da 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/GameMode.java @@ -2,6 +2,7 @@ package com.github.stachelbeere1248.zombiesutils.game; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("DuplicatedCode") public class GameMode { private static GameMode currentGameMode = null; public static final GameMode DEAD_END_NORMAL = new GameMode(Map.DEAD_END), DEAD_END_HARD = new GameMode(Map.DEAD_END, Difficulty.HARD), DEAD_END_RIP = new GameMode(Map.DEAD_END, Difficulty.RIP); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Waves.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Waves.java index 9e42765..5edb473 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Waves.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/Waves.java @@ -2,6 +2,7 @@ package com.github.stachelbeere1248.zombiesutils.game; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("DuplicatedCode") 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}}, 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}}, diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java index cde7382..801a8e0 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java @@ -1,5 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.game.windows; +import net.minecraft.util.Vec3; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -21,6 +22,8 @@ public class Room { @Contract(" -> new") public static Room @NotNull [] getDE() { + Vec3 t = new Vec3(3,3,3); + t.rotatePitch(3); return new Room[]{ new Room("Alley", new Window[]{ new Window(1,13,138,63), diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Sla.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Sla.java index ab4d6af..17cbe4a 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Sla.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Sla.java @@ -1,16 +1,17 @@ package com.github.stachelbeere1248.zombiesutils.game.windows; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.game.Map; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Optional; public class Sla { - private static Sla instance = null; - private static boolean enabled = false; + public static Sla instance = null; private final double[] offset = new double[3]; private final Room[] rooms; @@ -22,15 +23,39 @@ public class Sla { case ALIEN_ARCADIUM: this.rooms = Room.getAA(); break; default: throw new IllegalStateException("Unexpected value: " + map); } - instance = this; } + public void rotate() { + for (Room room : rooms) { + for (Window window: room.getWindows()) { + window.rotate(); + } + } + System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ())); + } + public void mirrorX() { + for (Room room : rooms) { + for (Window window: room.getWindows()) { + window.mirrorX(); + } + } + System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ())); + } + public void mirrorZ() { + for (Room room : rooms) { + for (Window window: room.getWindows()) { + window.mirrorZ(); + } + } + 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); + } public void refreshActives() { final EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; final double[] playerCoords = { - player.posX + offset[0], - player.posY + offset[1], - player.posZ + offset[2] + (player.posX - offset[0]), + player.posY - offset[1], + player.posZ - offset[2] }; for (Room room: rooms ) { @@ -61,12 +86,6 @@ public class Sla { public Room[] getRooms() { return rooms; } - public static boolean isEnabled() { - return enabled; - } - public static void toggle() { - Sla.enabled = !Sla.enabled; - } public void resetOffset() { Arrays.fill(this.offset, 0); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java index 9154412..8753b85 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Window.java @@ -17,10 +17,21 @@ public class Window { return xyz; } - public boolean isActive() { - return isActive; - } public void setActive(boolean active) { isActive = active; } + public boolean isActive() { + return isActive; + } + public void rotate() { + final short x = xyz[0], z = xyz[2]; + xyz[0] = (short) -z; + xyz[2] = x; + } + public void mirrorX() { + xyz[0] = (short) -xyz[0]; + } + public void mirrorZ() { + xyz[2] = (short) -xyz[2]; + } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java index 3a44092..56ee1e7 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java @@ -5,6 +5,7 @@ import com.github.stachelbeere1248.zombiesutils.game.Difficulty; import com.github.stachelbeere1248.zombiesutils.game.GameMode; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.jetbrains.annotations.NotNull; import java.util.regex.Pattern; @@ -15,7 +16,7 @@ public class ChatHandler { private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE); @SubscribeEvent - public void difficultyChange(ClientChatReceivedEvent event) { + public void difficultyChange(@NotNull ClientChatReceivedEvent event) { String message = STRIP_COLOR_PATTERN.matcher(event.message.getUnformattedText()).replaceAll("").trim(); GameMode gameMode = GameMode.getCurrentGameMode(); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java index 5cd8ffc..b335814 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/TickHandler.java @@ -3,10 +3,11 @@ package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.jetbrains.annotations.NotNull; public class TickHandler { @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { + public void onTick(TickEvent.@NotNull ClientTickEvent event) { if (event.phase == TickEvent.Phase.START) return; Scoreboard.refresh(); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java index 69a022b..7a63e3e 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -16,7 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(NetHandlerPlayClient.class) public class MixinNetHandlerPlayClient { - public MixinNetHandlerPlayClient() {} @Unique private boolean zombies_utils$alienUfoOpened; @Inject(method = "handleSoundEffect", at = @At(value = "HEAD")) @@ -29,7 +28,7 @@ public class MixinNetHandlerPlayClient { } @Unique private void zombies_utils$handleSound(@NotNull S29PacketSoundEffect packet) { - if (!Scoreboard.isZombies()) return; + if (Scoreboard.isZombies()) return; String soundEffect = packet.getSoundName(); if (!( soundEffect.equals("mob.wither.spawn") @@ -58,11 +57,11 @@ public class MixinNetHandlerPlayClient { } } @Unique - private void zombies_utils$handleTitle(S45PacketTitle packet) { + private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) { if (packet.getType() != S45PacketTitle.Type.TITLE) return; - if (!Scoreboard.isZombies()) return; + if (Scoreboard.isZombies()) return; final String message = packet.getMessage().getUnformattedText().trim(); - if (message.equals("\u00a7aYou Win!")) { + if (message.equals("§aYou Win!")) { switch (GameMode.getCurrentGameMode().getMap()) { case DEAD_END: case BAD_BLOOD: Timer.getInstance().ifPresent(timer -> { @@ -77,7 +76,7 @@ public class MixinNetHandlerPlayClient { }); break; } - } else if (message.equals("\u00a7cGame Over!")) { + } else if (message.equals("§cGame Over!")) { Timer.dropInstances(); } else { ZombiesUtils.getInstance().getLogger().debug(message); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java index 1f11e8c..038180e 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/render/RenderGameOverlayHandler.java @@ -21,10 +21,10 @@ public class RenderGameOverlayHandler { } @SubscribeEvent - public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) { + public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) { if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return; Timer.getInstance().ifPresent(timer -> renderTime(timer.roundTime())); - if (Sla.isEnabled()) Sla.getInstance().ifPresent(sla -> { + Sla.getInstance().ifPresent(sla -> { sla.refreshActives(); renderSla(sla.getRooms()); }); @@ -32,7 +32,7 @@ public class RenderGameOverlayHandler { } private void renderTime(long timerTicks) { - if (!Scoreboard.isZombies()) return; + if (Scoreboard.isZombies()) return; long minutesPart = (timerTicks*50) / 60000; long secondsPart = ((timerTicks*50) % 60000) / 1000; long tenthSecondsPart = ((timerTicks*50) % 1000) / 100; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java index 30930a5..678aa11 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java @@ -5,6 +5,7 @@ import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import com.github.stachelbeere1248.zombiesutils.timer.recorder.TimesFile; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public class RecordManager { @@ -16,21 +17,21 @@ public class RecordManager { timesFile.setBestSegment(round, roundTime); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - "\u00a7l\u00a7e Category: " + category.getName() + " - ***" + "\u00a7l\u00a76 NEW BEST SEGMENT! " + "\u00a7l\u00a7e***" + "§l§e Category: " + category.getName() + " - ***" + "§l§6 NEW BEST SEGMENT! " + "§l§e***" )); final String timeString = formattedTime(roundTime); - final String message = "\u00a7cRound " + round + "\u00a7e took \u00a7a" + timeString + "\u00a7e!"; + final String message = "§cRound " + round + "§e took §a" + timeString + "§e!"; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message)); } else { if (roundTime custom category -> file named "MAP_DIFFICULTY.times" // Content encoded in StandardCharsets.UTF_16 super("zombies" + File.separator + category,gameMode.getMap() + "_" + gameMode.getDifficulty() + ".times"); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java index 31369c3..267f910 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java @@ -17,6 +17,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; public class Scoreboard { + @SuppressWarnings("UnnecessaryUnicodeEscape") private static final Pattern SIDEBAR_EMOJI_PATTERN = Pattern.compile("[\uD83D\uDD2B\uD83C\uDF6B\uD83D\uDCA3\uD83D\uDC7D\uD83D\uDD2E\uD83D\uDC0D\uD83D\uDC7E\uD83C\uDF20\uD83C\uDF6D\u26BD\uD83C\uDFC0\uD83D\uDC79\uD83C\uDF81\uD83C\uDF89\uD83C\uDF82]+"); private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("§[0-9A-FK-ORZ]", Pattern.CASE_INSENSITIVE); private static final Pattern ROUND_LINE_PATTERN = Pattern.compile("(Round )([0-9]{1,3})"); @@ -50,7 +51,7 @@ public class Scoreboard { else scores = filteredScores; scores = Lists.reverse(scores); - lines = new ArrayList(); + lines = new ArrayList<>(); for (Score score: scores ) { ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); @@ -110,6 +111,6 @@ public class Scoreboard { } } public static boolean isZombies() { - return ("ZOMBIES".equals(title)); + return (!"ZOMBIES".equals(title)); } } \ No newline at end of file