diff --git a/gradle.properties b/gradle.properties index a4cb2a7..ea5dff2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g baseGroup = com.github.stachelbeere1248.zombiesutils mcVersion = 1.8.9 modid = zombiesutils -version = 1.2.5 +version = 1.3 diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java index 99fa0fc..e298aa0 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/ZombiesUtils.java @@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull; public class ZombiesUtils { private static ZombiesUtils instance; private final Hotkeys hotkeys; + private ZombiesUtilsConfig config; private Handlers handlers; private Logger logger; @@ -28,14 +29,18 @@ public class ZombiesUtils { return instance; } + public static boolean isHypixel() { + String ip = Minecraft.getMinecraft().getCurrentServerData().serverIP; + return (ip.equals("localhost") || ip.matches("(.+\\.)?(hypixel\\.net)(:25565)?")); + } + @Mod.EventHandler public void preInit(@NotNull FMLPreInitializationEvent event) { logger = event.getModLog(); - ZombiesUtilsConfig.config = new Configuration( + this.config = new ZombiesUtilsConfig(new Configuration( event.getSuggestedConfigurationFile(), - "1.2.4" + "1.2.4") ); - ZombiesUtilsConfig.load(); } @Mod.EventHandler @@ -58,7 +63,7 @@ public class ZombiesUtils { return handlers; } - public static boolean isHypixel() { - return Minecraft.getMinecraft().getCurrentServerData().serverIP.matches("(.+\\.)?(hypixel\\.net)(:25565)?"); + public ZombiesUtilsConfig getConfig() { + return config; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java index d88d5d9..aa8a09f 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/CategoryCommand.java @@ -2,8 +2,8 @@ package com.github.stachelbeere1248.zombiesutils.commands; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; -import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; +import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; import net.minecraft.util.BlockPos; @@ -13,7 +13,7 @@ import java.io.File; import java.util.Arrays; import java.util.List; -public class CategoryCommand extends CommandBase { +public class CategoryCommand implements ICommand { public CategoryCommand() { } @@ -28,13 +28,18 @@ public class CategoryCommand extends CommandBase { return "/category "; } + @Override + public List getCommandAliases() { + return Arrays.asList("runCategory", "cat"); + } + @Override public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { if (args.length == 0) throw new WrongUsageException("Please enter a name for the category"); else { String cat = args[0]; if (cat.contains(File.separator)) - throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "subfolder"); + throw new WrongUsageException("Your name must not contain '" + File.separator + "' as this is the systems separator character for folder" + File.separator + "sub-folder"); Category.setSelectedCategory(cat); Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category())); } @@ -45,8 +50,18 @@ public class CategoryCommand extends CommandBase { return Arrays.asList(Category.getCategories()); } + @Override + public boolean isUsernameIndex(String[] args, int index) { + return false; + } + @Override public boolean canCommandSenderUseCommand(ICommandSender sender) { return true; } + + @Override + public int compareTo(@NotNull ICommand command) { + return this.getCommandName().compareTo(command.getCommandName()); + } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java index 7391aaf..6645ed6 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/commands/SlaCommand.java @@ -1,8 +1,8 @@ package com.github.stachelbeere1248.zombiesutils.commands; +import com.github.stachelbeere1248.zombiesutils.game.SLA; import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.github.stachelbeere1248.zombiesutils.game.sla.QuickSLA; -import com.github.stachelbeere1248.zombiesutils.game.SLA; import net.minecraft.command.*; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/CustomConfigElement.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/CustomConfigElement.java new file mode 100644 index 0000000..a337e4d --- /dev/null +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/CustomConfigElement.java @@ -0,0 +1,244 @@ +package com.github.stachelbeere1248.zombiesutils.config; + +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.config.ConfigGuiType; +import net.minecraftforge.fml.client.config.GuiConfigEntries; +import net.minecraftforge.fml.client.config.GuiEditArrayEntries; +import net.minecraftforge.fml.client.config.IConfigElement; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class CustomConfigElement implements IConfigElement { + + private final String name; + private final boolean isProperty; + private Property prop; + private ConfigCategory category; + + public CustomConfigElement(String name, Property prop) { + this.prop = prop; + this.isProperty = true; + this.name = name; + } + + public CustomConfigElement(String name, ConfigCategory category) { + this.category = category; + this.isProperty = false; + this.name = name; + } + + public static ConfigGuiType getType(Property prop) { + return prop.getType() == Property.Type.BOOLEAN ? ConfigGuiType.BOOLEAN : prop.getType() == Property.Type.DOUBLE ? ConfigGuiType.DOUBLE : + prop.getType() == Property.Type.INTEGER ? ConfigGuiType.INTEGER : prop.getType() == Property.Type.COLOR ? ConfigGuiType.COLOR : + prop.getType() == Property.Type.MOD_ID ? ConfigGuiType.MOD_ID : ConfigGuiType.STRING; + } + + @Override + public List getChildElements() { + if (!isProperty) { + List elements = new ArrayList<>(); + + for (Property property : category.getOrderedValues()) { + ConfigElement temp = new ConfigElement(property); + if (temp.showInGui()) + elements.add(temp); + } + return elements; + } + return null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isProperty() { + return isProperty; + } + + @Override + public Class getConfigEntryClass() { + return isProperty ? prop.getConfigEntryClass() : category.getConfigEntryClass(); + } + + @Override + public Class getArrayEntryClass() { + return isProperty ? prop.getArrayEntryClass() : null; + } + + @Override + public String getQualifiedName() { + return isProperty ? prop.getName() : category.getQualifiedName(); + } + + @Override + public ConfigGuiType getType() { + return isProperty ? getType(this.prop) : ConfigGuiType.CONFIG_CATEGORY; + } + + @Override + public boolean isList() { + return isProperty && prop.isList(); + } + + @Override + public boolean isListLengthFixed() { + return isProperty && prop.isListLengthFixed(); + } + + @Override + public int getMaxListLength() { + return isProperty ? prop.getMaxListLength() : -1; + } + + @Override + public String getComment() { + return isProperty ? prop.comment : category.getComment(); + } + + @Override + public boolean isDefault() { + return !isProperty || prop.isDefault(); + } + + @Override + public void setToDefault() { + if (isProperty) + prop.setToDefault(); + } + + @Override + public boolean requiresWorldRestart() { + return isProperty ? prop.requiresWorldRestart() : category.requiresWorldRestart(); + } + + @Override + public boolean showInGui() { + return isProperty ? prop.showInGui() : category.showInGui(); + } + + @Override + public boolean requiresMcRestart() { + return isProperty ? prop.requiresMcRestart() : category.requiresMcRestart(); + } + + @Override + public String[] getValidValues() { + return isProperty ? prop.getValidValues() : null; + } + + @Override + public String getLanguageKey() { + return isProperty ? prop.getLanguageKey() : category.getLanguagekey(); + } + + @Override + public Object getDefault() { + return isProperty ? prop.getDefault() : null; + } + + @Override + public Object[] getDefaults() { + if (isProperty) { + String[] aVal = prop.getDefaults(); + return getObjects(aVal); + } + return null; + } + + private Object[] getObjects(String[] aVal) { + if (prop.getType() == Property.Type.BOOLEAN) { + Boolean[] ba = new Boolean[aVal.length]; + for (int i = 0; i < aVal.length; i++) + ba[i] = Boolean.valueOf(aVal[i]); + return ba; + } else if (prop.getType() == Property.Type.DOUBLE) { + Double[] da = new Double[aVal.length]; + for (int i = 0; i < aVal.length; i++) + da[i] = Double.valueOf(aVal[i]); + return da; + } else if (prop.getType() == Property.Type.INTEGER) { + Integer[] ia = new Integer[aVal.length]; + for (int i = 0; i < aVal.length; i++) + ia[i] = Integer.valueOf(aVal[i]); + return ia; + } else + return aVal; + } + + @Override + public Pattern getValidationPattern() { + return isProperty ? prop.getValidationPattern() : null; + } + + @Override + public Object get() { + return isProperty ? prop.getString() : null; + } + + @Override + public Object[] getList() { + if (isProperty) { + String[] aVal = prop.getStringList(); + return getObjects(aVal); + } + return null; + } + + @Override + public void set(Object value) { + if (isProperty) { + if (prop.getType() == Property.Type.BOOLEAN) + prop.set(Boolean.parseBoolean(value.toString())); + else if (prop.getType() == Property.Type.DOUBLE) + prop.set(Double.parseDouble(value.toString())); + else if (prop.getType() == Property.Type.INTEGER) + prop.set(Integer.parseInt(value.toString())); + else + prop.set(value.toString()); + } + } + + @Override + public void set(Object[] aVal) { + if (isProperty) { + if (prop.getType() == Property.Type.BOOLEAN) { + boolean[] ba = new boolean[aVal.length]; + for (int i = 0; i < aVal.length; i++) + ba[i] = Boolean.parseBoolean(aVal[i].toString()); + prop.set(ba); + } else if (prop.getType() == Property.Type.DOUBLE) { + double[] da = new double[aVal.length]; + for (int i = 0; i < aVal.length; i++) + da[i] = Double.parseDouble(aVal[i].toString()); + prop.set(da); + } else if (prop.getType() == Property.Type.INTEGER) { + int[] ia = new int[aVal.length]; + for (int i = 0; i < aVal.length; i++) + ia[i] = Integer.parseInt(aVal[i].toString()); + prop.set(ia); + } else { + String[] is = new String[aVal.length]; + for (int i = 0; i < aVal.length; i++) + is[i] = aVal[i].toString(); + prop.set(is); + } + } + } + + @Override + public Object getMinValue() { + return isProperty ? prop.getMinValue() : null; + } + + @Override + public Object getMaxValue() { + return isProperty ? prop.getMaxValue() : null; + } +} diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java index 337bee3..2f17ca5 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/GuiConfig.java @@ -1,14 +1,13 @@ package com.github.stachelbeere1248.zombiesutils.config; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig { public GuiConfig(GuiScreen parentScreen) { super( parentScreen, - new ConfigElement(ZombiesUtilsConfig.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), + ZombiesUtils.getInstance().getConfig().getRootElements(), "zombiesutils", false, false, diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java index 698c04c..f2a83e4 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/config/ZombiesUtilsConfig.java @@ -4,29 +4,109 @@ import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.utils.LanguageSupport; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.config.DummyConfigElement; +import net.minecraftforge.fml.client.config.IConfigElement; import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.jetbrains.annotations.NotNull; -public class ZombiesUtilsConfig { - public static Configuration config; - private static Property slaToggle; - private static Property slaShortener; - private static Property shortSpawntime; - private static Property sst; - private static Property chatMacro; - private static Property defaultCategory; - private static Property waveOffset; - private static Property language; - private static Property auditory; - private static Property copyDelta; - private static Property cpsCounter; +import java.util.Arrays; +import java.util.List; - public static void load() { +public class ZombiesUtilsConfig { + public final Configuration config; + private Property sstHud; + private Property offset; + private Property slaToggle; + private Property slaShortener; + private Property shortSpawntime; + private Property chatMacro; + private Property defaultCategory; + private Property language; + private Property auditory; + private Property copyDelta; + private Property cpsCounter; + private Property announcePB; + + public ZombiesUtilsConfig(Configuration config) { + this.config = config; + this.read(); + } + + private void read() { ZombiesUtils.getInstance().getLogger().debug("Loading config..."); config.load(); ZombiesUtils.getInstance().getLogger().debug("Config loaded."); + //SST + sstHud = config.get( + "SST", + "enabled", + true, + "Show the spawn-time HUD?" + ); + auditory = config.get( + "SST", + "auditory", + new int[]{-40, -20, 0}, + "For every entry a sound will be played x ticks before the wave spawn.", + -200, + 200, + false, + 5 + ); + //noinspection SpellCheckingInspection + shortSpawntime = config.get( + "SST", + "autohide", + false, + "Hide passed rounds?" + ); + offset = config.get( + "SST", + "offset", + -28, + "Offset is added while in RL-mode", + -200, + 200 + ); + + //SLA + slaToggle = config.get( + "SLA", + "autostart", + false, + "Should SLA be started when a game starts?" + ); + slaShortener = config.get( + "SLA", + "shortened SLA", + true, + "If on, inactive windows / rooms will not show" + ); + + //Timer + defaultCategory = config.get( + "timer", + "Default Category", + "general", + "name of the category to be selected unless specified using /runCategory" + ); + copyDelta = config.get( + "timer", + "copy delta", + false, + "Also copy the delta-time when clicking the round-end message?" + ); + announcePB = config.get( + "timer", + "announce", + true, + "Whether to announce PBs." + ); + + + //ROOT language = config.get( Configuration.CATEGORY_GENERAL, "Language", @@ -34,66 +114,12 @@ public class ZombiesUtilsConfig { "Your Hypixel language", LanguageSupport.getLanguages() ); - slaToggle = config.get( - Configuration.CATEGORY_GENERAL, - "SLA Launcher", - false, - "Should SLA be started when a game starts?" - ); - slaShortener = config.get( - Configuration.CATEGORY_GENERAL, - "shortened SLA", - true, - "If on, inactive windows / rooms will not show" - ); chatMacro = config.get( Configuration.CATEGORY_GENERAL, "Chat Macro", "T", "The Text to be sent when pressing the chat-macro hotkey" ); - defaultCategory = config.get( - Configuration.CATEGORY_GENERAL, - "Default Category", - "general", - "name of the category to be selected unless specified using /runCategory" - ); - waveOffset = config.get( - Configuration.CATEGORY_GENERAL, - "RL-mode offset", - -28, - "ticks to be added to the wave spawn time", - -200, - 200 - ); - shortSpawntime = config.get( - Configuration.CATEGORY_GENERAL, - "passed wave spawns", - true, - "Display spawn-time for passed waves" - ); - auditory = config.get(Configuration.CATEGORY_GENERAL, - "auditory sst", - new int[]{-40, -20, 0}, - "Tick-offset to play sound", - -200, - 200, - false, - 5 - ); - sst = config.get( - Configuration.CATEGORY_GENERAL, - "SST HUD", - false, - "Enable if not using SST by Sosean" - - ); - copyDelta = config.get( - Configuration.CATEGORY_GENERAL, - "copy delta", - false, - "Also copy the delta-time when clicking the round-end message?" - ); cpsCounter = config.get( Configuration.CATEGORY_GENERAL, "cps", @@ -102,52 +128,95 @@ public class ZombiesUtilsConfig { ); } - public static short getWaveOffset() { - return (short) waveOffset.getInt(); + private List getSpawntimeElements() { + return Arrays.asList( + new CustomConfigElement("Enabled", sstHud), + new CustomConfigElement("Auditory", auditory), + new CustomConfigElement("RL pre-timing", offset), + new CustomConfigElement("Truncate", shortSpawntime) + ); } - public static boolean isSlaToggled() { + private List getSlaElements() { + return Arrays.asList( + new CustomConfigElement("Enabled", slaToggle), + new CustomConfigElement("Truncate", slaShortener), + new CustomConfigElement("PB announcements", announcePB) + ); + } + + private List getTimerElements() { + return Arrays.asList( + new CustomConfigElement("Default category", defaultCategory), + new CustomConfigElement("Paste delta", copyDelta) + ); + } + + List getRootElements() { + return Arrays.asList( + new DummyConfigElement.DummyCategoryElement("Timer", "", getSpawntimeElements()), + new DummyConfigElement.DummyCategoryElement("SST", "", getSpawntimeElements()), + new DummyConfigElement.DummyCategoryElement("SLA", "", getSpawntimeElements()), + new CustomConfigElement("Language", language), + new CustomConfigElement("Macro message", chatMacro), + new CustomConfigElement("CPS counter", cpsCounter) + + ); + } + + + public short getOffset() { + return (short) offset.getInt(); + } + + public boolean isSlaToggled() { return slaToggle.getBoolean(); } - public static boolean isSlaShortened() { + public boolean isSlaShortened() { return slaShortener.getBoolean(); } - public static boolean isSpawntimeNotShortened() { + public boolean isSpawntimeShortened() { return shortSpawntime.getBoolean(); } - public static String getChatMacro() { + public String getChatMacro() { return chatMacro.getString(); } - public static String getDefaultCategory() { + public String getDefaultCategory() { return defaultCategory.getString(); } - public static String getLanguage() { + public String getLanguage() { return language.getString(); } - public static int[] getAuditory() { + public int[] getAuditory() { return auditory.getIntList(); } - public static boolean getSST() { - return sst.getBoolean(); + + public boolean getSST() { + return sstHud.getBoolean(); } - public static boolean getCopyDelta() { + + public boolean getCopyDelta() { return copyDelta.getBoolean(); } - public static boolean getCpsToggle() { + + public boolean getCpsToggle() { return cpsCounter.getBoolean(); } + public boolean getAnnouncePB() { + return announcePB.getBoolean(); + } @SubscribeEvent public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) { if (event.modID.equals("zombiesutils") && event.configID == null) { config.save(); - ZombiesUtilsConfig.load(); } } + } 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 6fd1f72..5a88482 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,4 +1,5 @@ package com.github.stachelbeere1248.zombiesutils.game.enums; + public enum Map { - DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM, PRISON; + DEAD_END, BAD_BLOOD, ALIEN_ARCADIUM, PRISON } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/WaveTiming.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/WaveTiming.java index 5aba73e..bcc2f85 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/WaveTiming.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/WaveTiming.java @@ -1,7 +1,8 @@ package com.github.stachelbeere1248.zombiesutils.game.waves; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.timer.Timer; +import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; import net.minecraft.client.Minecraft; import org.jetbrains.annotations.NotNull; @@ -12,31 +13,36 @@ public class WaveTiming { public static byte[] getWaves(@NotNull Timer timer) { return Waves.get( - timer.getGameMode().getMap(), - timer.getRound() + timer.getGameMode().getMap(), + timer.getRound() ); } + public static byte getLastWave(@NotNull Timer timer) { return Waves.getLastWave( - timer.getGameMode().getMap(), - timer.getRound() + timer.getGameMode().getMap(), + timer.getRound() ); } public static void onTick() { + if (Scoreboard.isNotZombies()) return; Timer.getInstance().ifPresent(timer -> { - int wave = (getLastWave(timer)*20)+rl; + byte[] waves = getWaves(timer); final int roundTime = timer.roundTime(); - final int[] auditory = ZombiesUtilsConfig.getAuditory(); - final Integer pre = roundTime-wave; - if (Arrays.stream(auditory).anyMatch(pre::equals)) { - Minecraft.getMinecraft().thePlayer.playSound("note.pling",1,2); + final int[] auditory = ZombiesUtils.getInstance().getConfig().getAuditory(); + for (int wave : waves) { + wave = wave * 20 + rl; + final Integer pre = roundTime - wave; + if (Arrays.stream(auditory).anyMatch(pre::equals)) { + Minecraft.getMinecraft().thePlayer.playSound("note.pling", 1, 2); + } } }); } public static void toggleRL() { - if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset(); + if (rl == 0) rl = ZombiesUtils.getInstance().getConfig().getOffset(); else rl = 0; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java index ebbb678..2595ecf 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/waves/Waves.java @@ -18,7 +18,7 @@ public class Waves { @Contract(pure = true) public static byte[] get(@NotNull Map map, byte round) { - byte[] ret = new byte[]{ 0 }; + byte[] ret = new byte[]{0}; try { switch (map) { case DEAD_END: diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java index ac1b558..47b88a1 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/game/windows/Room.java @@ -1,6 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.game.windows; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import net.minecraft.util.Vec3; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -179,7 +179,8 @@ public class Room { StringBuilder slaString = new StringBuilder(String.format("§6%s§r§d %x§e:", this.getName(), activeWindowCount)); for (Window window : this.windows) { if (window.isActive()) slaString.append("§2 ").append(alias).append(window.getID()); - else if (!ZombiesUtilsConfig.isSlaShortened()) slaString.append("§c ").append(alias).append(window.getID()); + else if (!ZombiesUtils.getInstance().getConfig().isSlaShortened()) + slaString.append("§c ").append(alias).append(window.getID()); } return slaString.toString(); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java index ed1e3af..aa514ae 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/ChatHandler.java @@ -1,7 +1,7 @@ package com.github.stachelbeere1248.zombiesutils.handlers; -import com.github.stachelbeere1248.zombiesutils.game.enums.Difficulty; import com.github.stachelbeere1248.zombiesutils.game.GameMode; +import com.github.stachelbeere1248.zombiesutils.game.enums.Difficulty; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.utils.LanguageSupport; import net.minecraftforge.client.event.ClientChatReceivedEvent; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/Handlers.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/Handlers.java index d6c029d..2e61f87 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/Handlers.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/Handlers.java @@ -1,6 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.handlers; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import net.minecraftforge.common.MinecraftForge; public class Handlers { @@ -11,7 +11,7 @@ public class Handlers { } public void registerAll() { - MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig()); + MinecraftForge.EVENT_BUS.register(ZombiesUtils.getInstance().getConfig()); MinecraftForge.EVENT_BUS.register(renderer); MinecraftForge.EVENT_BUS.register(new TickHandler()); MinecraftForge.EVENT_BUS.register(new ChatHandler()); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java index a61c513..2986423 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/KeyInputHandler.java @@ -2,7 +2,6 @@ package com.github.stachelbeere1248.zombiesutils.handlers; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.config.Hotkeys; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.game.waves.WaveTiming; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -20,7 +19,7 @@ public class KeyInputHandler { Hotkeys hotkeys = ZombiesUtils.getInstance().getHotkeys(); if (Keyboard.getEventKey() == hotkeys.getChatMacro().getKeyCode()) { Minecraft.getMinecraft().thePlayer.sendChatMessage( - ZombiesUtilsConfig.getChatMacro() + ZombiesUtils.getInstance().getConfig().getChatMacro() ); } else if (Keyboard.getEventKey() == hotkeys.getRlSpawn().getKeyCode()) { ZombiesUtils.getInstance().getHandlers().getRenderer().toggleRL(); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java index 0c36e95..6eec298 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/handlers/RenderGameOverlayHandler.java @@ -1,6 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.handlers; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.game.SLA; import com.github.stachelbeere1248.zombiesutils.game.waves.Waves; import com.github.stachelbeere1248.zombiesutils.game.windows.Room; @@ -16,10 +16,10 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; public class RenderGameOverlayHandler { - private int rl = 0; - private final boolean[] clicks = new boolean[20]; - private int clickPointer = 0; + private final byte[] clicks = new byte[20]; private final FontRenderer fontRenderer; + private int rl = 0; + private int clickPointer = 0; public RenderGameOverlayHandler() { this.fontRenderer = Objects.requireNonNull(Minecraft.getMinecraft().fontRendererObj, "FontRenderer must not be null!"); @@ -40,7 +40,7 @@ public class RenderGameOverlayHandler { } void toggleRL() { - if (rl == 0) rl = ZombiesUtilsConfig.getWaveOffset(); + if (rl == 0) rl = ZombiesUtils.getInstance().getConfig().getOffset(); else rl = 0; } @@ -64,7 +64,7 @@ public class RenderGameOverlayHandler { renderSla(sla.getRooms()); }); - if (ZombiesUtilsConfig.getCpsToggle()) renderCPS(); + if (ZombiesUtils.getInstance().getConfig().getCpsToggle()) renderCPS(); } private void renderTime(long timerTicks) { @@ -88,7 +88,7 @@ public class RenderGameOverlayHandler { private void renderSla(Room @NotNull [] rooms) { int y = 0; for (Room room : rooms) { - if (ZombiesUtilsConfig.isSlaShortened() && room.getActiveWindowCount() == 0) continue; + if (ZombiesUtils.getInstance().getConfig().isSlaShortened() && room.getActiveWindowCount() == 0) continue; fontRenderer.drawStringWithShadow( room.getSlaString(), 1, @@ -100,7 +100,7 @@ public class RenderGameOverlayHandler { } private void renderSpawnTime(byte @NotNull [] waveTimes, short roundTicks) { - if (Scoreboard.isNotZombies() || !ZombiesUtilsConfig.getSST()) return; + if (Scoreboard.isNotZombies() || !ZombiesUtils.getInstance().getConfig().getSST()) return; final int length = waveTimes.length + 1; int heightIndex = 0; @@ -111,7 +111,7 @@ public class RenderGameOverlayHandler { final short waveTicks = (short) ((waveTime * 20) + rl); if (roundTicks > waveTicks) { - if (ZombiesUtilsConfig.isSpawntimeNotShortened()) clonedColor = 0x555555; + if (!ZombiesUtils.getInstance().getConfig().isSpawntimeShortened()) clonedColor = 0x555555; else { heightIndex++; continue; @@ -134,6 +134,7 @@ public class RenderGameOverlayHandler { heightIndex++; } } + public void renderCPS() { final String cps = String.format("%2d", getClicks()); final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -150,18 +151,18 @@ public class RenderGameOverlayHandler { public int getClicks() { int i = 0; - for (boolean tick : clicks) { - if (tick) i++; + for (byte tick : clicks) { + i += tick; } return i; } public void addClick() { - clicks[clickPointer] = true; + clicks[clickPointer]++; } public void tick() { clickPointer = (clickPointer + 1) % 20; - clicks[clickPointer] = false; + clicks[clickPointer] = 0; } } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java index e4cf817..32ce805 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java @@ -1,6 +1,6 @@ package com.github.stachelbeere1248.zombiesutils.timer; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; +import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.CategoryFile; import net.minecraft.client.Minecraft; @@ -14,8 +14,7 @@ public class RecordManager { private static final String bar = "§l§a▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"; public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException { - @SuppressWarnings("OptionalGetWithoutIsPresent") - final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); + @SuppressWarnings("OptionalGetWithoutIsPresent") final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); final short bestSegment = categoryFile.getBestSegment(round); final String timeString = formattedTime(roundTime); @@ -26,16 +25,18 @@ public class RecordManager { if (bestSegment == (short) 0) { categoryFile.setBestSegment(round, roundTime); - segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***"; + if (ZombiesUtils.getInstance().getConfig().getAnnouncePB()) + segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***"; segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + "§e!"; } else { if (roundTime < bestSegment) { - segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***"; + if (ZombiesUtils.getInstance().getConfig().getAnnouncePB()) + segmentMessage += "\n§e§l***§6§l NEW BEST SEGMENT! §e§l***"; categoryFile.setBestSegment(round, roundTime); } deltaString = formattedDelta(roundTime, bestSegment); segmentMessage += "\n§cRound " + round + "§e took §a" + timeString + " §9" + deltaString; - if (ZombiesUtilsConfig.getCopyDelta()) deltaString = " (" + deltaString + ")"; + if (ZombiesUtils.getInstance().getConfig().getCopyDelta()) deltaString = " (" + deltaString + ")"; } @@ -49,8 +50,7 @@ public class RecordManager { } public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException { - @SuppressWarnings("OptionalGetWithoutIsPresent") - final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); + @SuppressWarnings("OptionalGetWithoutIsPresent") final CategoryFile categoryFile = category.getByGameMode(Timer.getInstance().get().getGameMode()); final int personalBest = categoryFile.getPersonalBest(round); String deltaString = ""; @@ -60,16 +60,18 @@ public class RecordManager { if (personalBest == 0) { categoryFile.setPersonalBest(round, gameTime); - bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***"; + if (ZombiesUtils.getInstance().getConfig().getAnnouncePB()) + bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***"; bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + "§e!"; } else { if (gameTime < personalBest) { - bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***"; + if (ZombiesUtils.getInstance().getConfig().getAnnouncePB()) + bestMessage += "\n§e§l***§6§l NEW PERSONAL BEST! §e§l***"; categoryFile.setPersonalBest(round, gameTime); } deltaString = formattedDelta(gameTime, personalBest); bestMessage += "\n§cRound " + round + "§e finished at §a" + timeString + " §9" + deltaString; - if (ZombiesUtilsConfig.getCopyDelta()) deltaString = " (" + deltaString + ")"; + if (ZombiesUtils.getInstance().getConfig().getCopyDelta()) deltaString = " (" + deltaString + ")"; } bestMessage += "\n" + bar; final ChatComponentText message = new ChatComponentText(bestMessage); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java index 0a40560..8815d8c 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java @@ -1,10 +1,9 @@ package com.github.stachelbeere1248.zombiesutils.timer; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.game.GameMode; -import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.github.stachelbeere1248.zombiesutils.game.SLA; +import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.github.stachelbeere1248.zombiesutils.handlers.Round1Correction; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.GameFile; @@ -44,7 +43,7 @@ public class Timer { this.gameMode = new GameMode(map); this.round = round; - if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map); + if (ZombiesUtils.getInstance().getConfig().isSlaToggled()) SLA.instance = new SLA(map); MinecraftForge.EVENT_BUS.register(new Round1Correction()); } diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java index ff0d175..6867f57 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/Category.java @@ -1,9 +1,8 @@ package com.github.stachelbeere1248.zombiesutils.timer.recorder; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; -import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig; -import com.github.stachelbeere1248.zombiesutils.game.enums.Difficulty; import com.github.stachelbeere1248.zombiesutils.game.GameMode; +import com.github.stachelbeere1248.zombiesutils.game.enums.Difficulty; import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.recorder.files.CategoryFile; @@ -12,7 +11,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; public class Category { - private static String selectedCategory = ZombiesUtilsConfig.getDefaultCategory(); + private static String selectedCategory = ZombiesUtils.getInstance().getConfig().getDefaultCategory(); public final CategoryFile[] categoryFiles = new CategoryFile[7]; private final String name; diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java index d0e02c0..c7c5c5f 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/CategoryData.java @@ -29,7 +29,8 @@ public class CategoryData implements ISplitsData { Arrays.fill(personalBests, 0); } - @Override @NotNull + @Override + @NotNull public String toJSON() { Gson gson = new Gson(); return gson.toJson(this, CategoryData.class); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java index 78144dd..561ca4e 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/data/GameData.java @@ -25,7 +25,8 @@ public class GameData implements ISplitsData { Arrays.fill(segments, (short) 0); } - @Override @NotNull + @Override + @NotNull public String toJSON() { Gson gson = new Gson(); return gson.toJson(this.segments); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java index 79d855e..997e6a4 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/recorder/files/GameFile.java @@ -24,6 +24,7 @@ public class GameFile extends SplitsFile { this.data = new GameData(map); FileManager.createDataFile(this, this.data); } + @NotNull private static String formattedTime() { final LocalDateTime dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES); 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 3bb2d31..0f0e885 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.config.ZombiesUtilsConfig; import com.github.stachelbeere1248.zombiesutils.game.enums.Map; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -67,7 +66,7 @@ public class Scoreboard { } catch (IndexOutOfBoundsException | NullPointerException ignored) { return 0; } - final Pattern ROUND_LINE_PATTERN = LanguageSupport.roundPattern(ZombiesUtilsConfig.getLanguage()); + final Pattern ROUND_LINE_PATTERN = LanguageSupport.roundPattern(ZombiesUtils.getInstance().getConfig().getLanguage()); String string = ROUND_LINE_PATTERN.matcher(line).replaceAll("$1"); @@ -105,7 +104,7 @@ public class Scoreboard { return Optional.empty(); } } - final Pattern MAP_PATTERN = LanguageSupport.mapPattern(ZombiesUtilsConfig.getLanguage()); + final Pattern MAP_PATTERN = LanguageSupport.mapPattern(ZombiesUtils.getInstance().getConfig().getLanguage()); String mapString = MAP_PATTERN.matcher(line).replaceAll("$1"); switch (mapString) { case "Dead End":