Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Seosean committed Mar 9, 2024
1 parent 7a23304 commit fecf0d0
Show file tree
Hide file tree
Showing 35 changed files with 502 additions and 184 deletions.
62 changes: 37 additions & 25 deletions src/main/java/com/seosean/showspawntime/ShowSpawnTime.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.seosean.showspawntime;

import com.google.gson.JsonObject;
import com.seosean.showspawntime.commands.CommandCommon;
import com.seosean.showspawntime.commands.CommandSSTConfig;
import com.seosean.showspawntime.commands.CommandSSTHUD;
Expand All @@ -9,14 +8,14 @@
import com.seosean.showspawntime.handler.GameTickHandler;
import com.seosean.showspawntime.handler.LanguageDetector;
import com.seosean.showspawntime.handler.ScoreboardManager;
import com.seosean.showspawntime.modules.features.Renderer;
import com.seosean.showspawntime.modules.features.dpscounter.DPSCounter;
import com.seosean.showspawntime.modules.features.dpscounter.DPSCounterRenderer;
import com.seosean.showspawntime.modules.features.lrqueue.LRQueue;
import com.seosean.showspawntime.modules.features.powerups.PowerupDetect;
import com.seosean.showspawntime.modules.features.powerups.PowerupRenderer;
import com.seosean.showspawntime.modules.features.spawntimes.SpawnNotice;
import com.seosean.showspawntime.modules.features.spawntimes.SpawnTimeRenderer;
import com.seosean.showspawntime.modules.features.spawntimes.SpawnTimes;
import com.seosean.showspawntime.modules.features.powerups.PowerupDetect;
import com.seosean.showspawntime.modules.features.powerups.PowerupRenderer;
import com.seosean.showspawntime.utils.DebugUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.ClientCommandHandler;
Expand All @@ -28,21 +27,15 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;
import org.lwjgl.Sys;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;

@Mod(modid = ShowSpawnTime.MODID, version = ShowSpawnTime.VERSION,
guiFactory = "com.seosean.showspawntime.config.gui.ShowSpawnTimeGuiFactory"
Expand All @@ -52,7 +45,7 @@ public class ShowSpawnTime
{
public static final String MODID = "showspawntime";
public static final String VERSION = "2.0";
private Logger logger;
private static Logger logger;
private static Configuration config;
public static final String EMOJI_REGEX = "(?:[\uD83C\uDF00-\uD83D\uDDFF]|[\uD83E\uDD00-\uD83E\uDDFF]|[\uD83D\uDE00-\uD83D\uDE4F]|[\uD83D\uDE80-\uD83D\uDEFF]|[\u2600-\u26FF]\uFE0F?|[\u2700-\u27BF]\uFE0F?|\u24C2\uFE0F?|[\uD83C\uDDE6-\uD83C\uDDFF]{1,2}|[\uD83C\uDD70\uD83C\uDD71\uD83C\uDD7E\uD83C\uDD7F\uD83C\uDD8E\uD83C\uDD91-\uD83C\uDD9A]\uFE0F?|[\u0023\u002A\u0030-\u0039]\uFE0F?\u20E3|[\u2194-\u2199\u21A9-\u21AA]\uFE0F?|[\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55]\uFE0F?|[\u2934\u2935]\uFE0F?|[\u3030\u303D]\uFE0F?|[\u3297\u3299]\uFE0F?|[\uD83C\uDE01\uD83C\uDE02\uD83C\uDE1A\uD83C\uDE2F\uD83C\uDE32-\uD83C\uDE3A\uD83C\uDE50\uD83C\uDE51]\uFE0F?|[\u203C\u2049]\uFE0F?|[\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE]\uFE0F?|[\u00A9\u00AE]\uFE0F?|[\u2122\u2139]\uFE0F?|\uD83C\uDC04\uFE0F?|\uD83C\uDCCF\uFE0F?|[\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA]\uFE0F?)";

Expand All @@ -64,17 +57,26 @@ public class ShowSpawnTime
private static PowerupDetect powerupDetect;
private static PowerupRenderer powerupRenderer;
private static SpawnTimeRenderer spawnTimeRenderer;
private static DPSCounterRenderer dpsCounterRenderer;
private static LRQueue lrQueue;
private static SpawnTimes spawnTimes;
private static SpawnNotice spawnNotice;
private static DPSCounter dpsCounter;

private static MainConfiguration mainConfiguration;
private static LanguageConfiguration languageConfiguration;
@EventHandler
public void preinit(FMLPreInitializationEvent event){
languageConfiguration = createMainConfig(event);

logger = event.getModLog();
config = new Configuration(event.getSuggestedConfigurationFile());

File modConfigFolder = new File(event.getModConfigurationDirectory(), MODID);
if (!modConfigFolder.exists()) {
modConfigFolder.getParentFile().mkdirs();
}
config = new Configuration(modConfigFolder);
languageConfiguration = createLangConfig();

mainConfiguration = new MainConfiguration(config, logger);
}

Expand All @@ -88,6 +90,8 @@ public void init(FMLInitializationEvent event)
MinecraftForge.EVENT_BUS.register(spawnNotice = new SpawnNotice());
MinecraftForge.EVENT_BUS.register(powerupRenderer = new PowerupRenderer());
MinecraftForge.EVENT_BUS.register(spawnTimeRenderer = new SpawnTimeRenderer());
MinecraftForge.EVENT_BUS.register(dpsCounterRenderer = new DPSCounterRenderer());
MinecraftForge.EVENT_BUS.register(dpsCounter = new DPSCounter());
MinecraftForge.EVENT_BUS.register(lrQueue = new LRQueue());
MinecraftForge.EVENT_BUS.register(SCOREBOARD_MANAGER);
MinecraftForge.EVENT_BUS.register(mainConfiguration);
Expand All @@ -106,24 +110,20 @@ public static ScoreboardManager getScoreboardManager() {
return SCOREBOARD_MANAGER;
}

private static LanguageConfiguration createMainConfig(FMLPreInitializationEvent event) {
File modConfigFolder = new File(event.getModConfigurationDirectory(), MODID);
if (!modConfigFolder.exists()) {
modConfigFolder.getParentFile().mkdirs();
}
File mainConfig = new File(modConfigFolder, MODID + ".lang");
if (!mainConfig.exists()) {
private static LanguageConfiguration createLangConfig() {

File langConfig = new File(config.getConfigFile().getParentFile(), MODID + ".lang");
if (!langConfig.exists()) {
try {
mainConfig.getParentFile().mkdirs();
langConfig.getParentFile().mkdirs();
ResourceLocation lang = new ResourceLocation("showspawntime", "lang/showspawntime.lang");
BufferedReader reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(lang).getInputStream(), StandardCharsets.UTF_8));
String line;

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(mainConfig.toPath()), StandardCharsets.UTF_8))) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(langConfig.toPath()), StandardCharsets.UTF_8))) {
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
// writer.println("\n");
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -132,7 +132,7 @@ private static LanguageConfiguration createMainConfig(FMLPreInitializationEvent
e.printStackTrace();
}
}
LanguageConfiguration config = new LanguageConfiguration(mainConfig);
LanguageConfiguration config = new LanguageConfiguration(langConfig);
config.load();
return config;
}
Expand Down Expand Up @@ -173,6 +173,18 @@ public static SpawnNotice getSpawnNotice() {
return spawnNotice;
}

public static DPSCounter getDpsCounter() {
return dpsCounter;
}

public static DPSCounterRenderer getDPSCounterRenderer() {
return dpsCounterRenderer;
}

public static Logger getLog() {
return logger;
}

public static Configuration getConfig() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import com.seosean.showspawntime.ShowSpawnTime;
import com.seosean.showspawntime.config.LanguageConfiguration;
import com.seosean.showspawntime.config.MainConfiguration;
import com.seosean.showspawntime.modules.features.leftnotice.LeftNotice;
import com.seosean.showspawntime.utils.DebugUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.*;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.common.FMLLog;

import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ public void ConfigLoad(){

XSpawnTime = config.get(Configuration.CATEGORY_CLIENT, "XSpawnTime", -1, "X").getDouble();
YSpawnTime = config.get(Configuration.CATEGORY_CLIENT, "YSpawnTime", -1, "Y").getDouble();

XPowerup = config.get(Configuration.CATEGORY_CLIENT, "XPowerup", -1, "X").getDouble();
YPowerup = config.get(Configuration.CATEGORY_CLIENT, "YPowerup", -1, "Y").getDouble();

XDPSCounter = config.get(Configuration.CATEGORY_CLIENT, "XDPSCounter", -1, "X").getDouble();
YDPSCounter = config.get(Configuration.CATEGORY_CLIENT, "YDPSCounter", -1, "Y").getDouble();

String comment;
String commentPlaySound;
String commentDEBBPlaySound;
Expand Down Expand Up @@ -182,8 +186,8 @@ public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
public static double YSpawnTime;
public static double XPowerup;
public static double YPowerup;
public static double XSplitter;
public static double YSplitter;
public static double XDPSCounter;
public static double YDPSCounter;

public static double getXSpawnTime(){
int screenWidth = new ScaledResolution(minecraft).getScaledWidth();
Expand Down Expand Up @@ -219,20 +223,20 @@ public static double getYPowerup(){
return YPowerup;
}

public double getXSplitter(){
public static double getXDPSCounter(){
int screenWidth = new ScaledResolution(minecraft).getScaledWidth();
if(XSplitter < 0){
return 1 - (double)minecraft.fontRendererObj.getStringWidth("0:00:0") / (double)screenWidth;
if(XDPSCounter < 0){
return 0.75 - (double)minecraft.fontRendererObj.getStringWidth("DPS: INSTA KILL") / (double)screenWidth;
}
return XSplitter;
return XDPSCounter;
}

public double getYSplitter(){
public static double getYDPSCounter(){
int screenHeight = new ScaledResolution(minecraft).getScaledHeight();
if(YSplitter < 0){
return 1 - minecraft.fontRendererObj.FONT_HEIGHT / (double)screenHeight;
if(YDPSCounter < 0){
return 1 - minecraft.fontRendererObj.FONT_HEIGHT * 2 / (double)screenHeight;
}
return YSplitter;
return YDPSCounter;
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,62 @@ public ShowSpawnTimeGuiConfig(GuiScreen parent) {
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
try

if (button.id == 2000) {
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 2001)
{
this.entryList.setAllToDefault(this.chkApplyGlobally.isChecked());
}
else if (button.id == 2002)
{
if ((configID != null || this.parentScreen == null || !(this.parentScreen instanceof GuiConfig))
&& (this.entryList.hasChangedEntry(true)))
{
this.entryList.undoAllChanges(this.chkApplyGlobally.isChecked());
}

try {
if ((this.entryList.hasChangedEntry(true))) {
boolean requiresMcRestart = this.entryList.saveConfigElements();

if (Loader.isModLoaded(modID))
{
if (Loader.isModLoaded(modID)) {
ConfigChangedEvent event = new ConfigChangedEvent.OnConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart);
MinecraftForge.EVENT_BUS.post(event);

if (!event.getResult().equals(Event.Result.DENY)) {
MinecraftForge.EVENT_BUS.post(new ConfigChangedEvent.PostConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart));
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}

if (this.parentScreen instanceof GuiConfig) {
((GuiConfig) this.parentScreen).needsRefresh = true;
}

@Override
public void onGuiClosed()
{
super.onGuiClosed();

try {
if ((this.entryList.hasChangedEntry(true))) {
boolean requiresMcRestart = this.entryList.saveConfigElements();

if (Loader.isModLoaded(modID)) {
ConfigChangedEvent event = new ConfigChangedEvent.OnConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart);
MinecraftForge.EVENT_BUS.post(event);

if (!event.getResult().equals(Event.Result.DENY)) {
MinecraftForge.EVENT_BUS.post(new ConfigChangedEvent.PostConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart));
}
}
}
}
catch (Throwable e)
{
} catch (Throwable e) {
e.printStackTrace();
}
}


private static List<IConfigElement> getElements() {
List<IConfigElement> list = new ArrayList<>();

Expand Down
38 changes: 24 additions & 14 deletions src/main/java/com/seosean/showspawntime/config/hud/ConfigGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.ArrayList;
import java.util.List;

import static com.seosean.showspawntime.ShowSpawnTime.*;

public class ConfigGui extends GuiScreen {
private int selected = -1;
private int scroll = 0;
Expand Down Expand Up @@ -58,6 +56,7 @@ public void initGui() {
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.InitGuiEvent.Post(this, buttonList));
int widthTime = this.fontRendererObj.getStringWidth("➤ W2 00:00");
int widthPowerup = this.fontRendererObj.getStringWidth("-BONUS GOLD - 00:00 ");
int widthDPSCounter = this.fontRendererObj.getStringWidth("DPS: INSTA KILL");
ScaledResolution sr = new ScaledResolution(this.mc);
this.buttonList.add(new GuiButton(1, sr.getScaledWidth() / 2 - 82, sr.getScaledHeight() - 25, 80, 20, "Done"));
this.buttonList.add(new GuiButton(2, sr.getScaledWidth() / 2 - 82 + 85, sr.getScaledHeight() - 25, 80, 20, "Reset"));
Expand All @@ -66,22 +65,12 @@ public void initGui() {
boxes.add(boxSpawnTime);
HudCoordinate boxPowerup = new HudCoordinate(1, MainConfiguration.getXPowerup(), MainConfiguration.getYPowerup(), widthPowerup, this.fontRendererObj.FONT_HEIGHT * 6, this.width, this.height);
boxes.add(boxPowerup);
// if(AutoSplitsApi.isAutoSplitsInstalled() && AutoSplitsApi.ApiManager()) {
// int widthSplits = this.fontRendererObj.getStringWidth("0:00:0");
// HudCoordinate boxSplits = new HudCoordinate(2, AutoSplitsApi.XSplitter, AutoSplitsApi.YSplitter, widthSplits, this.fontRendererObj.FONT_HEIGHT, this.width, this.height);
// boxes.add(boxSplits);
// }
HudCoordinate boxDPSCounter = new HudCoordinate(2, MainConfiguration.getXDPSCounter(), MainConfiguration.getYDPSCounter(), widthDPSCounter, this.fontRendererObj.FONT_HEIGHT, this.width, this.height);
boxes.add(boxDPSCounter);
}

protected void mouseClicked(int mouseX, int mouseY, int p_mouseClicked_3_) throws IOException {
super.mouseClicked(mouseX, mouseY, p_mouseClicked_3_);
// ScaledResolution sr = new ScaledResolution(this.mc);
// int minY = 10 + this.fontRendererObj.FONT_HEIGHT + 10;
// int maxY = sr.getScaledHeight() - 25 - 10;
// if (mouseY >= minY && mouseY <= maxY) {
// int selectedRender = (mouseY - minY) / (5 + this.fontRendererObj.FONT_HEIGHT + 5);
// this.selected = selectedRender + this.scroll;
// }
}

protected void mouseReleased(int p_mouseReleased_1_, int p_mouseReleased_2_, int p_mouseReleased_3_) {
Expand Down Expand Up @@ -118,6 +107,11 @@ protected void actionPerformed(GuiButton button) throws IOException {
MainConfiguration.YPowerup = box.y;
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "XPowerup", -1).set(box.x);
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "YPowerup", -1).set(box.y);
} else if (box.getContents() == 2) {
MainConfiguration.XDPSCounter = box.x;
MainConfiguration.YDPSCounter = box.y;
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "XDPSCounter", -1).set(box.x);
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "YDPSCounter", -1).set(box.y);
}
}
ShowSpawnTime.getConfig().save();
Expand Down Expand Up @@ -158,6 +152,22 @@ public void run() {
}.runTaskLater(2);


} else if (box.getContents() == 2) {
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "XDPSCounter", -1).set(-1);
ShowSpawnTime.getConfig().get(Configuration.CATEGORY_CLIENT, "YDPSCounter", -1).set(-1);
MainConfiguration.XDPSCounter = -1;
MainConfiguration.YDPSCounter = -1;
new DelayedTask() {
@Override
public void run() {
box.x = MainConfiguration.getXDPSCounter();
box.absoluteX = (int)(MainConfiguration.getXDPSCounter() * ConfigGui.this.width);
box.y = MainConfiguration.getYDPSCounter();
box.absoluteY = (int)(MainConfiguration.getYDPSCounter() * ConfigGui.this.height);
}
}.runTaskLater(2);


}
}
ShowSpawnTime.getConfig().save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void draw(GuiScreen gui) {
this.fontRendererObj.drawStringWithShadow(" BONUS GOLD - 00:00", absoluteX, absoluteY + this.fontRendererObj.FONT_HEIGHT * 5, 0xFFFF55);
}else if(contents == 2){
Gui.drawRect(absoluteX, absoluteY, absoluteX + width, absoluteY + height, color);
this.fontRendererObj.drawStringWithShadow("0:00:0", absoluteX, absoluteY, 0xFFFFFF);
this.fontRendererObj.drawStringWithShadow("DPS: INSTA KILL", absoluteX, absoluteY, 0xFFFFFF);
}
}

Expand Down
Loading

0 comments on commit fecf0d0

Please sign in to comment.