spawn time feature v2
This commit is contained in:
parent
dcceb09186
commit
289aba550c
9 changed files with 167 additions and 104 deletions
|
@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
|
||||||
baseGroup = com.github.stachelbeere1248.zombiesutils
|
baseGroup = com.github.stachelbeere1248.zombiesutils
|
||||||
mcVersion = 1.8.9
|
mcVersion = 1.8.9
|
||||||
modid = zombiesutils
|
modid = zombiesutils
|
||||||
version = 1.1.4
|
version = 1.2.0
|
|
@ -12,6 +12,7 @@ public class ZombiesUtilsConfig {
|
||||||
private static boolean slaShortener;
|
private static boolean slaShortener;
|
||||||
private static String chatMacro;
|
private static String chatMacro;
|
||||||
private static String defaultCategory;
|
private static String defaultCategory;
|
||||||
|
private static short waveOffset;
|
||||||
public static void load() {
|
public static void load() {
|
||||||
ZombiesUtils.getInstance().getLogger().debug("Loading config...");
|
ZombiesUtils.getInstance().getLogger().debug("Loading config...");
|
||||||
config.load();
|
config.load();
|
||||||
|
@ -41,11 +42,24 @@ public class ZombiesUtilsConfig {
|
||||||
"general",
|
"general",
|
||||||
"name of the category to be selected unless specified using /runCategory"
|
"name of the category to be selected unless specified using /runCategory"
|
||||||
);
|
);
|
||||||
|
waveOffset = (short) config.getInt(
|
||||||
|
"spawn-time offset ticks",
|
||||||
|
Configuration.CATEGORY_GENERAL,
|
||||||
|
0,
|
||||||
|
-200,
|
||||||
|
200,
|
||||||
|
"max: 200 ticks"
|
||||||
|
);
|
||||||
|
|
||||||
ZombiesUtils.getInstance().getLogger().debug("Saving Config...");
|
ZombiesUtils.getInstance().getLogger().debug("Saving Config...");
|
||||||
config.save();
|
config.save();
|
||||||
ZombiesUtils.getInstance().getLogger().debug("Config saved.");
|
ZombiesUtils.getInstance().getLogger().debug("Config saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static short getWaveOffset() {
|
||||||
|
return waveOffset;
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) {
|
public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) {
|
||||||
if (event.modID.equals("zombiesutils") && event.configID == null) {
|
if (event.modID.equals("zombiesutils") && event.configID == null) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.github.stachelbeere1248.zombiesutils.game;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class GameMode {
|
public class GameMode {
|
||||||
public static GameMode currentGameMode = null;
|
|
||||||
private final Map map;
|
private final Map map;
|
||||||
private Difficulty difficulty;
|
private Difficulty difficulty;
|
||||||
|
|
||||||
|
@ -30,17 +29,6 @@ public class GameMode {
|
||||||
throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM);
|
throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static GameMode getCurrentGameMode() {
|
|
||||||
return currentGameMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call to invalidate {@link #currentGameMode} to trigger the garbage collector
|
|
||||||
*/
|
|
||||||
public static void drop() {
|
|
||||||
currentGameMode = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean is(Map map, Difficulty difficulty) {
|
public boolean is(Map map, Difficulty difficulty) {
|
||||||
return this.getDifficulty() == difficulty && this.getMap() == map;
|
return this.getDifficulty() == difficulty && this.getMap() == map;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.github.stachelbeere1248.zombiesutils.game.waves;
|
package com.github.stachelbeere1248.zombiesutils.game.waves;
|
||||||
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
|
@ -16,22 +17,18 @@ public class Waves {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
public static byte[] get(@NotNull Map map, byte round) {
|
public static byte[] get(@NotNull Map map, byte round) {
|
||||||
byte[] waves;
|
|
||||||
switch (map) {
|
switch (map) {
|
||||||
case DEAD_END:
|
case DEAD_END:
|
||||||
waves = deadEndWaveTimes[round - 1];
|
return deadEndWaveTimes[round - 1];
|
||||||
break;
|
|
||||||
case BAD_BLOOD:
|
case BAD_BLOOD:
|
||||||
waves = badBloodWaveTimes[round - 1];
|
return badBloodWaveTimes[round - 1];
|
||||||
break;
|
|
||||||
case ALIEN_ARCADIUM:
|
case ALIEN_ARCADIUM:
|
||||||
waves = alienArcadiumWaveTimes[round - 1];
|
return alienArcadiumWaveTimes[round - 1];
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + map);
|
throw new IllegalStateException("Unexpected value: " + map);
|
||||||
}
|
}
|
||||||
return waves;
|
|
||||||
}
|
}
|
||||||
public static short getSum(@NotNull Map map, byte round) {
|
public static short getSum(@NotNull Map map, byte round) {
|
||||||
short sum;
|
short sum;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.github.stachelbeere1248.zombiesutils.handlers;
|
||||||
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
|
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.Difficulty;
|
import com.github.stachelbeere1248.zombiesutils.game.Difficulty;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
||||||
|
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
||||||
import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -17,11 +18,11 @@ public class ChatHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void difficultyChange(@NotNull ClientChatReceivedEvent event) {
|
public void difficultyChange(@NotNull ClientChatReceivedEvent event) {
|
||||||
|
if (!Timer.getInstance().isPresent()) return;
|
||||||
String message = STRIP_COLOR_PATTERN.matcher(event.message.getUnformattedText()).replaceAll("").trim();
|
String message = STRIP_COLOR_PATTERN.matcher(event.message.getUnformattedText()).replaceAll("").trim();
|
||||||
GameMode gameMode = GameMode.getCurrentGameMode();
|
GameMode gameMode = Timer.getInstance().get().getGameMode();
|
||||||
|
|
||||||
if (message.contains(":")) return;
|
if (message.contains(":")) return;
|
||||||
if (gameMode == null) return;
|
|
||||||
|
|
||||||
if (message.contains("Hard Difficulty") || message.contains("困难") || message.contains("困難")) {
|
if (message.contains("Hard Difficulty") || message.contains("困难") || message.contains("困難")) {
|
||||||
gameMode.changeDifficulty(Difficulty.HARD);
|
gameMode.changeDifficulty(Difficulty.HARD);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.stachelbeere1248.zombiesutils.mixin;
|
package com.github.stachelbeere1248.zombiesutils.mixin;
|
||||||
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
||||||
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
|
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
|
||||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
|
@ -44,7 +42,7 @@ public class MixinNetHandlerPlayClient {
|
||||||
} else { Timer timer = Timer.getInstance().get();
|
} else { Timer timer = Timer.getInstance().get();
|
||||||
|
|
||||||
final Scoreboard.MapContainer map = Scoreboard.getMap().orElse(new Scoreboard.MapContainer(
|
final Scoreboard.MapContainer map = Scoreboard.getMap().orElse(new Scoreboard.MapContainer(
|
||||||
GameMode.getCurrentGameMode().getMap(),
|
timer.getGameMode().getMap(),
|
||||||
false
|
false
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -65,28 +63,23 @@ public class MixinNetHandlerPlayClient {
|
||||||
@Unique
|
@Unique
|
||||||
private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) {
|
private void zombies_utils$handleTitle(@NotNull S45PacketTitle packet) {
|
||||||
if (packet.getType() != S45PacketTitle.Type.TITLE) return;
|
if (packet.getType() != S45PacketTitle.Type.TITLE) return;
|
||||||
|
|
||||||
|
Timer.getInstance().ifPresent(timer -> {
|
||||||
if (Scoreboard.isZombies()) return;
|
if (Scoreboard.isZombies()) return;
|
||||||
final String message = packet.getMessage().getUnformattedText().trim();
|
final String message = packet.getMessage().getUnformattedText().trim();
|
||||||
|
|
||||||
if (message.equals("§aYou Win!")) {
|
if (message.equals("§aYou Win!")) {
|
||||||
switch (GameMode.getCurrentGameMode().getMap()) {
|
switch (timer.getGameMode().getMap()) {
|
||||||
case DEAD_END: case BAD_BLOOD:
|
case DEAD_END: case BAD_BLOOD:
|
||||||
Timer.getInstance().ifPresent(timer -> {
|
|
||||||
timer.split((byte) 30);
|
timer.split((byte) 30);
|
||||||
Timer.dropInstances();
|
Timer.dropInstances();
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case ALIEN_ARCADIUM:
|
case ALIEN_ARCADIUM:
|
||||||
Timer.getInstance().ifPresent(timer -> {
|
|
||||||
timer.split((byte) 105);
|
timer.split((byte) 105);
|
||||||
Timer.dropInstances();
|
Timer.dropInstances();
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (message.equals("§cGame Over!")) {
|
} else if (message.equals("§cGame Over!")) Timer.dropInstances();
|
||||||
Timer.dropInstances();
|
});
|
||||||
} else {
|
|
||||||
ZombiesUtils.getInstance().getLogger().debug(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.github.stachelbeere1248.zombiesutils.render;
|
||||||
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
|
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
||||||
|
import com.github.stachelbeere1248.zombiesutils.game.waves.Waves;
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.windows.Room;
|
import com.github.stachelbeere1248.zombiesutils.game.windows.Room;
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
||||||
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
|
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
|
||||||
|
@ -16,7 +17,6 @@ import java.util.Objects;
|
||||||
|
|
||||||
public class RenderGameOverlayHandler {
|
public class RenderGameOverlayHandler {
|
||||||
private final FontRenderer fontRenderer;
|
private final FontRenderer fontRenderer;
|
||||||
|
|
||||||
public RenderGameOverlayHandler() {
|
public RenderGameOverlayHandler() {
|
||||||
this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!");
|
this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!");
|
||||||
}
|
}
|
||||||
|
@ -24,27 +24,41 @@ public class RenderGameOverlayHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) {
|
public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) {
|
||||||
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
|
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
|
||||||
Timer.getInstance().ifPresent(timer -> renderTime(timer.roundTime()));
|
Timer.getInstance().ifPresent(timer -> {
|
||||||
|
renderTime(timer.roundTime());
|
||||||
|
renderSpawnTime(
|
||||||
|
Waves.get(
|
||||||
|
timer.getGameMode().getMap(),
|
||||||
|
timer.getRound()
|
||||||
|
),
|
||||||
|
timer.roundTime()
|
||||||
|
);
|
||||||
|
});
|
||||||
SLA.getInstance().ifPresent(sla -> {
|
SLA.getInstance().ifPresent(sla -> {
|
||||||
sla.refreshActives();
|
sla.refreshActives();
|
||||||
renderSla(sla.getRooms());
|
renderSla(sla.getRooms());
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderTime(long timerTicks) {
|
private void renderTime(long timerTicks) {
|
||||||
if (Scoreboard.isZombies()) return;
|
if (Scoreboard.isZombies()) return;
|
||||||
long minutesPart = (timerTicks*50) / 60000;
|
|
||||||
long secondsPart = ((timerTicks*50) % 60000) / 1000;
|
final String time = getTimeString(timerTicks);
|
||||||
long tenthSecondsPart = ((timerTicks*50) % 1000) / 100;
|
final int width = fontRenderer.getStringWidth(time);
|
||||||
String time = String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart);
|
|
||||||
int width = fontRenderer.getStringWidth(time);
|
final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
|
||||||
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
|
final int screenWidth = scaledResolution.getScaledWidth();
|
||||||
int screenWidth = scaledResolution.getScaledWidth();
|
final int screenHeight = scaledResolution.getScaledHeight();
|
||||||
int screenHeight = scaledResolution.getScaledHeight();
|
|
||||||
final int color = 0xFFFFFF;
|
fontRenderer.drawStringWithShadow(
|
||||||
fontRenderer.drawStringWithShadow(time, screenWidth - width, screenHeight - fontRenderer.FONT_HEIGHT, color);
|
time,
|
||||||
|
screenWidth - width,
|
||||||
|
screenHeight - fontRenderer.FONT_HEIGHT,
|
||||||
|
0xFFFFFF
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void renderSla(Room @NotNull [] rooms) {
|
private void renderSla(Room @NotNull [] rooms) {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (Room room: rooms) {
|
for (Room room: rooms) {
|
||||||
|
@ -58,4 +72,45 @@ public class RenderGameOverlayHandler {
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) {
|
||||||
|
final int length = waveTimes.length + 1;
|
||||||
|
int heightIndex = 0;
|
||||||
|
int color = 0xFFFF55;
|
||||||
|
|
||||||
|
for (byte waveTime: waveTimes) {
|
||||||
|
final short waveTicks = (short) ((waveTime * 20)-ZombiesUtilsConfig.getWaveOffset());
|
||||||
|
|
||||||
|
if (roundTicks>waveTicks) {
|
||||||
|
heightIndex++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String time = getWaveString(waveTicks, heightIndex + 1);
|
||||||
|
final int width = fontRenderer.getStringWidth(time);
|
||||||
|
final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
|
||||||
|
final int screenWidth = scaledResolution.getScaledWidth();
|
||||||
|
final int screenHeight = scaledResolution.getScaledHeight();
|
||||||
|
|
||||||
|
fontRenderer.drawStringWithShadow(
|
||||||
|
time,
|
||||||
|
screenWidth - width,
|
||||||
|
screenHeight - fontRenderer.FONT_HEIGHT * (length-heightIndex),
|
||||||
|
color
|
||||||
|
);
|
||||||
|
color = 0xAAAAAA;
|
||||||
|
heightIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static String getTimeString(long timerTicks) {
|
||||||
|
final long minutesPart = (timerTicks *50) / 60000;
|
||||||
|
final long secondsPart = ((timerTicks *50) % 60000) / 1000;
|
||||||
|
final long tenthSecondsPart = ((timerTicks *50) % 1000) / 100;
|
||||||
|
return String.format("%d:%02d.%d", minutesPart, secondsPart, tenthSecondsPart);
|
||||||
|
}
|
||||||
|
private static String getWaveString(long waveTicks, int wave) {
|
||||||
|
final long minutesPart = (waveTicks *50) / 60000;
|
||||||
|
final long secondsPart = ((waveTicks *50) % 60000) / 1000;
|
||||||
|
return String.format("W%d %d:%02d", wave, minutesPart, secondsPart);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.github.stachelbeere1248.zombiesutils.timer;
|
package com.github.stachelbeere1248.zombiesutils.timer;
|
||||||
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
|
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
|
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
|
||||||
import com.github.stachelbeere1248.zombiesutils.timer.recorder.TimesFile;
|
import com.github.stachelbeere1248.zombiesutils.timer.recorder.TimesFile;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -9,68 +8,66 @@ import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class RecordManager {
|
public class RecordManager {
|
||||||
|
private static final String bar = "§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬";
|
||||||
public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException {
|
public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException {
|
||||||
sendBar();
|
String segmentMessage = bar +
|
||||||
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
|
"\n§e Category: §d" + category.getName()
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
final TimesFile timesFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
|
||||||
short bestSegment = timesFile.getBestSegment(round);
|
short bestSegment = timesFile.getBestSegment(round);
|
||||||
if (bestSegment == (short) 0) {
|
if (bestSegment == (short) 0) {
|
||||||
timesFile.setBestSegment(round, roundTime);
|
timesFile.setBestSegment(round, roundTime);
|
||||||
|
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
|
segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***";
|
||||||
"§l§e Category: " + category.getName() + " - ***" + "§l§6 NEW BEST SEGMENT! " + "§l§e***"
|
|
||||||
));
|
|
||||||
final String timeString = formattedTime(roundTime);
|
final String timeString = formattedTime(roundTime);
|
||||||
final String message = "§cRound " + round + "§e took §a" + timeString + "§e!";
|
segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + "§e!";
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (roundTime<bestSegment) {
|
if (roundTime<bestSegment) {
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
|
segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***";
|
||||||
"§l§e Category: " + category.getName() + " - ***" + "§l§6 NEW BEST SEGMENT! " + "§l§e***"
|
|
||||||
));
|
|
||||||
timesFile.setBestSegment(round, roundTime);
|
timesFile.setBestSegment(round, roundTime);
|
||||||
}
|
}
|
||||||
final String timeString = formattedTime(roundTime);
|
final String timeString = formattedTime(roundTime);
|
||||||
final String message = "§cRound " + round + "§e took §a" + timeString + " §9" + formattedDelta(roundTime,bestSegment);
|
segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + " §9" + formattedDelta(roundTime,bestSegment);
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
|
|
||||||
}
|
}
|
||||||
sendBar();
|
segmentMessage += "\n" + bar;
|
||||||
|
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(segmentMessage));
|
||||||
}
|
}
|
||||||
public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException {
|
public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException {
|
||||||
sendBar();
|
String bestMessage = bar +
|
||||||
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
|
"\n§e Category: §d" + category.getName()
|
||||||
|
;
|
||||||
|
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
final TimesFile timesFile = category.getByGameMode(Timer.getInstance().get().getGameMode());
|
||||||
int personalBest = timesFile.getPersonalBest(round);
|
int personalBest = timesFile.getPersonalBest(round);
|
||||||
if (personalBest == 0) {
|
if (personalBest == 0) {
|
||||||
timesFile.setPersonalBest(round, gameTime);
|
timesFile.setPersonalBest(round, gameTime);
|
||||||
|
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
|
bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***";
|
||||||
"§l§e Category: " + category.getName() + " - ***" + "§l§6 NEW PERSONAL BEST! " + "§l§e***"
|
|
||||||
));
|
|
||||||
|
|
||||||
final String timeString = formattedTime(gameTime);
|
final String timeString = formattedTime(gameTime);
|
||||||
final String message = "§cRound " + round + "§e finished at §a" + timeString + "§e!";
|
bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + "§e!";
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (gameTime<personalBest) {
|
if (gameTime<personalBest) {
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
|
bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***";
|
||||||
"§l§e Category: " + category.getName() + " - ***" + "§l§6 NEW PERSONAL BEST! " + "§l§e***"
|
|
||||||
));
|
|
||||||
timesFile.setPersonalBest(round, gameTime);
|
timesFile.setPersonalBest(round, gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String timeString = formattedTime(gameTime);
|
final String timeString = formattedTime(gameTime);
|
||||||
final String message = "§cRound " + round + "§e finished at §a" + timeString + " §9" + formattedDelta(gameTime, personalBest);
|
bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + " §9" + formattedDelta(gameTime, personalBest);
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
sendBar();
|
bestMessage += "\n" + bar;
|
||||||
|
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(bestMessage));
|
||||||
}
|
}
|
||||||
private static String formattedTime(int gameTime) {
|
private static String formattedTime(int gameTime) {
|
||||||
return String.format("%d:%02d.%d",
|
gameTime *= 50;
|
||||||
(gameTime *50) / 60000,
|
return String.format("%d:%02d.%d%d",
|
||||||
((gameTime *50) % 60000) / 1000,
|
gameTime / 60000,
|
||||||
((gameTime *50) % 1000) / 100
|
(gameTime % 60000) / 1000,
|
||||||
|
(gameTime % 1000) / 100,
|
||||||
|
(gameTime % 100) / 10
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
|
@ -80,9 +77,4 @@ public class RecordManager {
|
||||||
return String.valueOf(delta);
|
return String.valueOf(delta);
|
||||||
} else return ("+" + delta);
|
} else return ("+" + delta);
|
||||||
}
|
}
|
||||||
private static void sendBar() {
|
|
||||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
|
|
||||||
"§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Optional;
|
||||||
public class Timer {
|
public class Timer {
|
||||||
|
|
||||||
private static Timer instance;
|
private static Timer instance;
|
||||||
|
private final GameMode gameMode;
|
||||||
private final long savedTotalWorldTime;
|
private final long savedTotalWorldTime;
|
||||||
private int passedRoundsTickSum = 0;
|
private int passedRoundsTickSum = 0;
|
||||||
private final String serverNumber;
|
private final String serverNumber;
|
||||||
|
@ -28,15 +29,34 @@ public class Timer {
|
||||||
* @param map The map the timer should be started for.
|
* @param map The map the timer should be started for.
|
||||||
*/
|
*/
|
||||||
public Timer (@NotNull String serverNumber, @NotNull Map map) {
|
public Timer (@NotNull String serverNumber, @NotNull Map map) {
|
||||||
instance = this;
|
|
||||||
|
|
||||||
savedTotalWorldTime = getCurrentTotalWorldTime();
|
savedTotalWorldTime = getCurrentTotalWorldTime();
|
||||||
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
|
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
|
||||||
else throw new RuntimeException("invalid servernumber");
|
else throw new RuntimeException("invalid servernumber");
|
||||||
|
|
||||||
this.category = new Category();
|
this.category = new Category();
|
||||||
GameMode.currentGameMode = new GameMode(map);
|
this.gameMode = new GameMode(map);
|
||||||
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
|
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Constructs a timer and saves it to {@link #instance}.
|
||||||
|
* @param serverNumber The game's server the timer should be bound to.
|
||||||
|
* @param map The map the timer should be started for.
|
||||||
|
* @param round If available, round to begin splitting.
|
||||||
|
*/
|
||||||
|
//TODO: brooooooooo
|
||||||
|
public Timer (@NotNull String serverNumber, @NotNull Map map, byte round) {
|
||||||
|
savedTotalWorldTime = getCurrentTotalWorldTime();
|
||||||
|
if (!serverNumber.trim().isEmpty()) this.serverNumber = serverNumber.trim();
|
||||||
|
else throw new RuntimeException("invalid servernumber");
|
||||||
|
|
||||||
|
this.category = new Category();
|
||||||
|
this.gameMode = new GameMode(map);
|
||||||
|
this.round = round;
|
||||||
|
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
|
||||||
|
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,9 +120,12 @@ public class Timer {
|
||||||
*/
|
*/
|
||||||
public static void dropInstances() {
|
public static void dropInstances() {
|
||||||
instance = null;
|
instance = null;
|
||||||
GameMode.drop();
|
|
||||||
}
|
}
|
||||||
public int getRound() {
|
public byte getRound() {
|
||||||
return round+1;
|
return (byte) (round+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameMode getGameMode() {
|
||||||
|
return gameMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue