From d135b38708de956283b08fe1791556de3dd7aaeb Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sat, 22 Jun 2024 06:21:19 +0200 Subject: [PATCH] improved map detection, quickjoin prison --- .../commands/QuickZombiesCommand.java | 9 ++- .../zombiesutils/game/enums/Map.java | 27 ++++++++- .../mixin/MixinNetHandlerPlayClient.java | 58 +++++++++++-------- .../zombiesutils/utils/Scoreboard.java | 21 ++++--- 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java index 2cf1ec3..711da30 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/QuickZombiesCommand.java @@ -20,13 +20,13 @@ public class QuickZombiesCommand extends CommandBase { @Override public String getCommandUsage(ICommandSender sender) { - return "/qz "; + return "/qz "; } @Override public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { if (args.length == 0) throw new WrongUsageException( - "[Missing option] options: de, bb, aa"); + "[Missing option] options: de, bb, aa, p"); else switch (args[0]) { case "de": Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_dead_end"); @@ -37,9 +37,12 @@ public class QuickZombiesCommand extends CommandBase { case "aa": Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_alien_arcadium"); break; + case "p": + Minecraft.getMinecraft().thePlayer.sendChatMessage("/play arcade_zombies_prison"); + break; default: throw new WrongUsageException( - "[Invalid option] options: de, bb, aa", args[0]); + "[Invalid option] options: de, bb, aa, p", args[0]); } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/enums/Map.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/enums/Map.java index 5a88482..df07904 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/enums/Map.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/enums/Map.java @@ -1,5 +1,30 @@ package com.github.stachelbeere1248.zombiesutils.game.enums; +import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import java.util.Optional; + public enum Map { - DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM, PRISON + DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM, PRISON; + + public static Optional getMap() { + World world = Minecraft.getMinecraft().theWorld; + BlockPos pos = new BlockPos(44,71,0); + if (!world.isBlockLoaded(pos) || Scoreboard.isNotZombies()) return Optional.empty(); + Block block = world.getBlockState(pos).getBlock(); + if (block.equals(Blocks.air)) { + return Optional.of(Map.DEAD_END); + } else if (block.equals(Blocks.wool)) { + return Optional.of(Map.BAD_BLOOD); + } else if (block.equals(Blocks.stone_slab)) { + return Optional.of(Map.ALIEN_ARCADIUM); + } else if (block.equals(Blocks.wooden_slab)) { + return Optional.of(Map.PRISON); + } else return Optional.empty(); + } } 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 59b9bc5..cc3c078 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/mixin/MixinNetHandlerPlayClient.java @@ -1,6 +1,7 @@ package com.github.stachelbeere1248.zombiesutils.mixin; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; +import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.utils.LanguageSupport; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; @@ -41,30 +42,41 @@ public class MixinNetHandlerPlayClient { )) return; zombies_utils$alienUfoOpened = soundEffect.equals("mob.guardian.curse"); try { - if (Timer.getInstance().isPresent()) { - final Timer running = Timer.getInstance().get(); - final byte round = Scoreboard.getRound(); - if (round == 0) { - if (Scoreboard.getLineCount() < 13) Timer.instance = new Timer( - Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), - Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), - round - ); - } else if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { - Timer.instance = new Timer( - Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), - Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), - round - ); - } else running.split(round); - } else Timer.instance = new Timer( - Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), - Scoreboard.getMap().orElseThrow(Timer.TimerException.MapException::new), - Scoreboard.getRound() - ); + if (!Timer.getInstance().isPresent()) { + Timer.instance = new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Map.getMap().orElseThrow(Timer.TimerException.MapException::new), + Scoreboard.getRound() + ); + return; + } + + final Timer running = Timer.getInstance().get(); + final byte round = Scoreboard.getRound(); + + if (round == 0) { + if (Scoreboard.getLineCount() < 13) Timer.instance = new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Map.getMap().orElseThrow(Timer.TimerException.MapException::new), + round + ); + return; + } + + if (!running.equalsServerOrNull(Scoreboard.getServerNumber().orElse(null))) { + Timer.instance = new Timer( + Scoreboard.getServerNumber().orElseThrow(Timer.TimerException.ServerNumberException::new), + Map.getMap().orElseThrow(Timer.TimerException.MapException::new), + round + ); + return; + } + + running.split(round); + } catch (Timer.TimerException e) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer.\nData parsing error. Blame scoreboard.")); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§cFailed to start or split timer. Please send a log to Stachelbeere1248.")); ZombiesUtils.getInstance().getLogger().warn(e); } } @@ -81,7 +93,7 @@ public class MixinNetHandlerPlayClient { switch (timer.getGameMode().getMap()) { case DEAD_END: case BAD_BLOOD: - case PRISON: + case PRISON: //TODO: Escape timer.split((byte) 30); Timer.dropInstances(); break; 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 1c17f26..c8f5180 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/utils/Scoreboard.java @@ -1,7 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.utils; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; -import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; @@ -42,17 +41,16 @@ public class Scoreboard { // get title = STRIP_COLOR_PATTERN.matcher(sidebar.getDisplayName().trim()).replaceAll(""); Collection scoreCollection = scoreboard.getSortedScores(sidebar); - List filteredScores = scoreCollection.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")).collect(Collectors.toList()); + List filteredScores = scoreCollection + .stream() + .filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#")) + .collect(Collectors.toList()); - List scores; - if (filteredScores.size() > 15) - scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15)); - else scores = filteredScores; + List scores = (filteredScores.size() > 15) ? Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15)) : filteredScores; scores = Lists.reverse(scores); - lines = new ArrayList<>(); - for (Score score : scores - ) { + lines = new ArrayList<>(scores.size()); + for (Score score : scores) { ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); String scoreboardLine = ScorePlayerTeam.formatPlayerName(team, score.getPlayerName()).trim(); lines.add(STRIP_COLOR_PATTERN.matcher(SIDEBAR_EMOJI_PATTERN.matcher(scoreboardLine).replaceAll("")).replaceAll("")); @@ -93,10 +91,11 @@ public class Scoreboard { return Optional.ofNullable(string); } + /* Outdated public static Optional getMap() { String line; try { - line = lines.get(12); //TODO: This was changed! + line = lines.get(12); //This was changed! } catch (Exception couldBePregame) { try { line = lines.get(2); @@ -118,8 +117,8 @@ public class Scoreboard { default: return Optional.empty(); } - } + */ public static int getLineCount() { return lines.size();