Skip to content

Commit

Permalink
improved map detection, quickjoin prison
Browse files Browse the repository at this point in the history
  • Loading branch information
Stachelbeere1248 committed Jun 22, 2024
1 parent 7b747eb commit d135b38
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public String getCommandName() {

@Override
public String getCommandUsage(ICommandSender sender) {
return "/qz <de|bb|aa>";
return "/qz <de|bb|aa|p>";
}

@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");
Expand All @@ -37,9 +37,12 @@ else switch (args[0]) {
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]);

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Map> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,30 +42,41 @@ private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
)) 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);
}
}
Expand All @@ -81,7 +93,7 @@ private void handleTitle(S45PacketTitle packetIn, CallbackInfo ci) {
switch (timer.getGameMode().getMap()) {
case DEAD_END:
case BAD_BLOOD:
case PRISON:
case PRISON: //TODO: Escape
timer.split((byte) 30);
Timer.dropInstances();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,17 +41,16 @@ public static void refresh() {
// get
title = STRIP_COLOR_PATTERN.matcher(sidebar.getDisplayName().trim()).replaceAll("");
Collection<Score> scoreCollection = scoreboard.getSortedScores(sidebar);
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;
if (filteredScores.size() > 15)
scores = Lists.newArrayList(Iterables.skip(filteredScores, scoreCollection.size() - 15));
else scores = filteredScores;
List<Score> 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(""));
Expand Down Expand Up @@ -93,10 +91,11 @@ public static Optional<String> getServerNumber() {
return Optional.ofNullable(string);
}

/* Outdated
public static Optional<Map> 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);
Expand All @@ -118,8 +117,8 @@ public static Optional<Map> getMap() {
default:
return Optional.empty();
}

}
*/

public static int getLineCount() {
return lines.size();
Expand Down

0 comments on commit d135b38

Please sign in to comment.