Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqlvin committed Sep 3, 2023
1 parent 8dddcc0 commit 7dc644c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 53 deletions.
7 changes: 3 additions & 4 deletions src/main/java/me/mqlvin/wwp/WoolWarsPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,20 @@ public static WWPConfig getConfig() {


@SubscribeEvent // checks if screen size has changed
public void onTickCheckScreenSize(TickEvent.ClientTickEvent e){
if(showGui) {
public void onTickCheckScreenSize(TickEvent.ClientTickEvent e) {
if (showGui) {
showGui = false;
Minecraft.getMinecraft().displayGuiScreen(new GuiConfig());
}

if(lastScreenHeight != Minecraft.getMinecraft().displayHeight || lastScreenWidth != Minecraft.getMinecraft().displayWidth) {
if (lastScreenHeight != Minecraft.getMinecraft().displayHeight || lastScreenWidth != Minecraft.getMinecraft().displayWidth) {
featureSD.updateRenderPosition();
}
lastScreenWidth = Minecraft.getMinecraft().displayWidth;
lastScreenHeight = Minecraft.getMinecraft().displayHeight;
}



public static SideCount getSideCount() {
return featureSD;
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/me/mqlvin/wwp/command/ConfigCommand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package me.mqlvin.wwp.command;

import me.mqlvin.wwp.WoolWarsPlus;
import me.mqlvin.wwp.util.ScoreboardUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.ChatComponentText;

import java.util.ArrayList;
import java.util.List;
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/me/mqlvin/wwp/config/GuiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {

@Override
public void actionPerformed(GuiButton button) {
if(button.id == 0x01) {
if (button.id == 0x01) {
WoolWarsPlus.getConfig().toggleShowItemNametags();
button.displayString = EnumChatFormatting.WHITE + "Show item holograms: " + (WoolWarsPlus.getConfig().showItemNametags() ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled");
} else
if(button.id == 0x02) {
} else if (button.id == 0x02) {
WoolWarsPlus.getConfig().toggleShowNametagDistance();
button.displayString = EnumChatFormatting.WHITE + "Show item distance: " + (WoolWarsPlus.getConfig().showNametagDistance() ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled");
} else
if(button.id == 0x03) {
} else if (button.id == 0x03) {
WoolWarsPlus.getConfig().toggleShowPlayerCount();
button.displayString = EnumChatFormatting.WHITE + "Show team counts: " + (WoolWarsPlus.getConfig().showPlayerCount() ? EnumChatFormatting.GREEN + "Enabled" : EnumChatFormatting.RED + "Disabled");
} else
if(button.id == 0x04) {
} else if (button.id == 0x04) {
WoolWarsPlus.getConfig().scrollPlayerCountPos();
button.displayString = EnumChatFormatting.WHITE + "Team count position: " + EnumChatFormatting.YELLOW + EnumChatFormatting.BOLD + WoolWarsPlus.getConfig().getPlayerCountPos().getFormattedName();
WoolWarsPlus.getSideCount().updateRenderPosition();
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/me/mqlvin/wwp/config/WWPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WWPConfig {
private boolean showPlayerCount;

public WWPConfig() {
if(!configFile.exists()) {
if (!configFile.exists()) {
showItemNametags = true;
showNametagDistance = false;
playerCountPos = Position.TOP_MIDDLE;
Expand All @@ -43,13 +43,13 @@ public void saveConfig() {

try {
FileUtils.writeStringToFile(configFile, obj.toString());
} catch(IOException e) {
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void loadConfig() {
if(configFile.exists()) {
if (configFile.exists()) {
try {
JsonObject obj = new JsonParser().parse(FileUtils.readFileToString(configFile)).getAsJsonObject();
showItemNametags = obj.get("showHol").getAsBoolean();
Expand All @@ -69,40 +69,36 @@ private void loadConfig() {
public boolean showItemNametags() {
return showItemNametags;
}

public boolean showNametagDistance() {
return showNametagDistance;
}

public boolean showPlayerCount() {
return this.showPlayerCount;
}

public Position getPlayerCountPos() {
return this.playerCountPos;
}

public void toggleShowItemNametags() {
this.showItemNametags = !this.showItemNametags;
}

public void toggleShowNametagDistance() {
this.showNametagDistance = !this.showNametagDistance;
}

public void toggleShowPlayerCount() {
this.showPlayerCount = !this.showPlayerCount;
}

public void scrollPlayerCountPos() {
this.playerCountPos = this.playerCountPos.next();
}










public enum Position {
TOP_LEFT("Top Left"),
TOP_RIGHT("Top Right"),
Expand All @@ -113,6 +109,7 @@ public enum Position {

private static final Position[] positions = values();
private final String formattedName;

Position(String formattedName) {
this.formattedName = formattedName;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/mqlvin/wwp/feature/PowerupDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class PowerupDisplay {

@SubscribeEvent
public void nametagRender(RenderLivingEvent.Specials.Pre event) {
if(!WoolWarsPlus.getConfig().showItemNametags()) return;
if(!POWERUP_FORMAT.containsKey(event.entity.getName())) return; // if it isn't a coloured hologram, ignore
if (!WoolWarsPlus.getConfig().showItemNametags()) return;
if (!POWERUP_FORMAT.containsKey(event.entity.getName())) return; // if it isn't a coloured hologram, ignore

powerups.add(event.entity);
event.setCanceled(true);
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/me/mqlvin/wwp/feature/SideCount.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package me.mqlvin.wwp.feature;

import com.google.common.eventbus.Subscribe;
import me.mqlvin.wwp.WoolWarsPlus;
import me.mqlvin.wwp.util.ScoreboardUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
Expand All @@ -23,11 +21,12 @@ public class SideCount {
private static int renderY = 0;



@SubscribeEvent
public void render(RenderGameOverlayEvent.Text event) {
roundActive = isInGame();
if(!roundActive || !WoolWarsPlus.getConfig().showPlayerCount()) { return; }
if (!roundActive || !WoolWarsPlus.getConfig().showPlayerCount()) {
return;
}

updateCount();

Expand All @@ -36,41 +35,49 @@ public void render(RenderGameOverlayEvent.Text event) {
}

public void updateCount() {
if(!roundActive) return;
if (!roundActive) return;
List<String> sbLines = ScoreboardUtils.getSidebarSuffixes(Minecraft.getMinecraft().theWorld.getScoreboard());

if(sbLines.size() != 8) { return; }; // not the right scoreboard or time
if (sbLines.size() != 8) {
return;
}
; // not the right scoreboard or time

String possibleRedCount = sbLines.stream().filter(s -> s.contains("§c§r")).findFirst().orElse(null);
String possibleBlueCount = sbLines.stream().filter(s -> s.contains("§9§r")).findFirst().orElse(null);

if(possibleRedCount == null || possibleBlueCount == null) { redCount = 4; blueCount = 4; return; } // if lines aren't there return
if (possibleRedCount == null || possibleBlueCount == null) {
redCount = 4;
blueCount = 4;
return;
} // if lines aren't there return

try {
possibleRedCount = possibleRedCount.substring(4); // removes emoji/colour code
possibleBlueCount = possibleBlueCount.substring(4);
redCount = Integer.parseInt(String.valueOf(possibleRedCount.charAt(0))); // there is a trailing space at the end
blueCount = Integer.parseInt(String.valueOf(possibleBlueCount.charAt(0)));
} catch (Exception ignore) {}
} catch (Exception ignore) {
}
}

@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
if(event.message.getUnformattedText().startsWith(" ") && event.message.getUnformattedText().contains("Round")) {
blueCount = 4; redCount = 4;
if (event.message.getUnformattedText().startsWith(" ") && event.message.getUnformattedText().contains("Round")) {
blueCount = 4;
redCount = 4;
}
}



public void updateRenderPosition() {
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
int width = sr.getScaledWidth();
int height = sr.getScaledHeight();

int stringWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth("4 : 4") + 2;

switch(WoolWarsPlus.getConfig().getPlayerCountPos()) {
switch (WoolWarsPlus.getConfig().getPlayerCountPos()) {
case TOP_LEFT: {
renderX = 10;
renderY = 10;
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/me/mqlvin/wwp/util/ScoreboardUtils.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package me.mqlvin.wwp.util;

import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Written by Aaron1998ish on 11/12/2017.
*
* <p>
* Useful methods for retrieving data on scoreboards on Hypixel
*
*/
public class ScoreboardUtils {
public static List<String> getSidebarSuffixes(Scoreboard scoreboard) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/me/mqlvin/wwp/util/WaypointUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static void renderWaypointText(String str, boolean showDist, double posX,
* @change `distSq` value and calculation to make nametag slightly larger.
*/

double distSq = x*x + y*y + z*z;
double distSq = x * x + y * y + z * z;
double dist = Math.sqrt(distSq);
if(distSq > 100) {
x *= 10/dist;
y *= 10/dist;
z *= 10/dist;
if (distSq > 100) {
x *= 10 / dist;
y *= 10 / dist;
z *= 10 / dist;
}
GlStateManager.translate(x, y, z);
GlStateManager.translate(0, viewer.getEyeHeight(), 0);
Expand All @@ -58,7 +58,7 @@ public static void renderWaypointText(String str, boolean showDist, double posX,
* @author change by @Mqlvin
* @change only draw one nametag, with distance appended at the end.
*/
drawNametag(str + (showDist ? " " + EnumChatFormatting.GRAY + Math.round(dist)+"m" : ""));
drawNametag(str + (showDist ? " " + EnumChatFormatting.GRAY + Math.round(dist) + "m" : ""));

GlStateManager.popMatrix();
GlStateManager.disableLighting();
Expand All @@ -67,6 +67,7 @@ public static void renderWaypointText(String str, boolean showDist, double posX,
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
*
* @author Moulberry
*/
public static void drawNametag(String str) {
Expand Down

0 comments on commit 7dc644c

Please sign in to comment.