Added some methods from the 1.8.9 update.
This commit is contained in:
parent
b2b8542604
commit
207a43135b
5 changed files with 99 additions and 19 deletions
|
@ -1,9 +1,9 @@
|
|||
package xyz.stachel.zombiesutils.handlers;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Location {
|
||||
|
||||
private static String serverNumber;
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package xyz.stachel.zombiesutils.mixin.client;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import xyz.stachel.zombiesutils.game.GameManager;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Mixin(ClientPlayNetworkHandler.class)
|
||||
public class ClientPlayNetworkHandlerMixin {
|
||||
private static final Pattern pattern = Pattern.compile("Round (\\d{1,3})");
|
||||
|
@ -23,7 +22,7 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
if (matcher.find()) {
|
||||
int number = Integer.parseInt(matcher.group(1));
|
||||
if (number >= 1 && number <= 105) {
|
||||
GameManager.onRound(number);
|
||||
new GameManager().onRound(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package xyz.stachel.zombiesutils.game;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.stachel.zombiesutils.ZombiesUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
class Game extends Timer {
|
||||
private final boolean joinedRoundOne;
|
||||
|
@ -27,8 +31,25 @@ class Game extends Timer {
|
|||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void pass(int round) {
|
||||
if ((round == 0) || (this.round == round + 1) || (this.roundTime() < 100)) {
|
||||
ZombiesUtils.LOGGER.debug("SPLIT CANCELLED");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// record();
|
||||
} catch (Exception e) {
|
||||
ZombiesUtils.LOGGER.error(ExceptionUtils.getStackTrace(e));
|
||||
MinecraftClient.getInstance().player.sendMessage(Text.of("Error recording splits"), false);
|
||||
}
|
||||
this.split();
|
||||
this.round = round + 1;
|
||||
}
|
||||
|
||||
public long split(final int round) {
|
||||
if (round )
|
||||
if (round == 1) {
|
||||
|
||||
}
|
||||
return super.split();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
package xyz.stachel.zombiesutils.game;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.stachel.zombiesutils.game.GameMode.Map;
|
||||
import xyz.stachel.zombiesutils.handlers.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class GameManager {
|
||||
private final HashMap<String, Game> games = new HashMap<>();
|
||||
private Optional<GameMode.Difficulty> queuedDifficulty = Optional.empty();
|
||||
private String queuedDifficultyServer = "INVALID";
|
||||
|
||||
private void addGame(final String serverNumber, final GameMode mode, final int round) {
|
||||
if (serverNumber.equals(queuedDifficultyServer)) {
|
||||
this.queuedDifficulty.ifPresent(mode::changeDifficulty);
|
||||
}
|
||||
this.queuedDifficulty = Optional.empty();
|
||||
this.games.put(serverNumber, new Game(new GameFile(serverNumber), mode));
|
||||
}
|
||||
|
||||
|
@ -17,11 +26,58 @@ public class GameManager {
|
|||
final String mode = Location.getMode();
|
||||
if (sn == null || mode == null || !mode.startsWith("ZOMBIES")) return;
|
||||
|
||||
if (!games.containsKey(sn)) addGame(sn, new GameMode(Map.DEAD_END), round);
|
||||
else games.get(sn).split(round);
|
||||
if (!this.games.containsKey(sn)) {
|
||||
addGame(sn, new GameMode(Map.DEAD_END), round);
|
||||
} else {
|
||||
this.games.get(sn).split(round);
|
||||
}
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
final String sn = Location.getServerNumber();
|
||||
return this.games.get(sn);
|
||||
}
|
||||
|
||||
public void endGame(final String serverNumber, final boolean isWin) {
|
||||
if (!games.containsKey(serverNumber)) return;
|
||||
final Game game = games.get(serverNumber);
|
||||
if (isWin) {
|
||||
switch (game.mode.getMap()) {
|
||||
case DEAD_END:
|
||||
case BAD_BLOOD:
|
||||
case PRISON:
|
||||
game.pass(30);
|
||||
break;
|
||||
case ALIEN_ARCADIUM:
|
||||
game.pass(105);
|
||||
break;
|
||||
}
|
||||
}
|
||||
games.remove(serverNumber);
|
||||
|
||||
}
|
||||
|
||||
public void splitOrNew(GameMode mode, int round) {
|
||||
final String serverNumber = Location.getServerNumber();
|
||||
if (games.containsKey(serverNumber)) {
|
||||
if (round == 0) addGame(serverNumber, mode, round);
|
||||
else games.get(serverNumber).pass(round);
|
||||
} else addGame(serverNumber, mode, round);
|
||||
}
|
||||
|
||||
public void setDifficulty(@NotNull GameMode.Difficulty difficulty) {
|
||||
this.queuedDifficultyServer = Location.getServerNumber();
|
||||
if (this.games.containsKey(this.queuedDifficultyServer)) {
|
||||
this.games.get(this.queuedDifficultyServer).mode.changeDifficulty(difficulty);
|
||||
} else this.queuedDifficulty = Optional.of(difficulty);
|
||||
}
|
||||
|
||||
public Set<String> getGames() {
|
||||
return this.games.keySet();
|
||||
}
|
||||
|
||||
public void killAll() {
|
||||
games.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ class GameMode {
|
|||
this.difficulty = map != Map.ALIEN_ARCADIUM ? difficulty : Difficulty.NORMAL;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
enum Map {
|
||||
DEAD_END, BAD_BLOOD, PRISON, ALIEN_ARCADIUM;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue