improved map detection, quickjoin prison

This commit is contained in:
Stachelbeere1248 2024-06-22 06:21:19 +02:00
parent 7b747eb291
commit d135b38708
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
4 changed files with 77 additions and 38 deletions

View file

@ -20,13 +20,13 @@ public class QuickZombiesCommand extends CommandBase {
@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");
@ -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]);
}
}

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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<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(""));
@ -93,10 +91,11 @@ public class Scoreboard {
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);
@ -118,8 +117,8 @@ public class Scoreboard {
default:
return Optional.empty();
}
}
*/
public static int getLineCount() {
return lines.size();