Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
1.1.0: Zealots/Hour & mod disabled while not in skyblock
Browse files Browse the repository at this point in the history
  • Loading branch information
symt committed Dec 4, 2019
1 parent 1b38940 commit 88d7a79
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
version = "1.0.3"
version = "1.1.0"
group= "io.github.symt"
archivesBaseName = "ZealotCounter"

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
95 changes: 85 additions & 10 deletions src/main/java/io/github/symt/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
Expand All @@ -16,21 +17,27 @@
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import org.apache.commons.lang3.time.StopWatch;
import org.json.JSONObject;

public class EventHandler {

static StopWatch perHourTimer = new StopWatch();
private boolean firstJoin = true;
private FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
private int attackedEntity = -1;
private int prevEntity = -1;
private int tick = 1;
private boolean tempSuspend = false;

@SubscribeEvent(priority = EventPriority.HIGH)
public void onMobDeath(LivingDeathEvent event) {
Expand All @@ -43,6 +50,9 @@ public void onMobDeath(LivingDeathEvent event) {
&& prevEntity != event.entity.getEntityId()
&& ZealotCounter.dragonsNest) {
prevEntity = event.entity.getEntityId();
if (perHourTimer.isStarted() && !perHourTimer.isSuspended()) {
ZealotCounter.zealotSession++;
}
ZealotCounter.zealotCount++;
ZealotCounter.sinceLastEye++;
}
Expand All @@ -65,6 +75,61 @@ public void onChatMessageReceived(ClientChatReceivedEvent e) {
}
}

private String stripString(String s) {
char[] nonValidatedString = StringUtils.stripControlCodes(s).toCharArray();
StringBuilder validated = new StringBuilder();
for (char a : nonValidatedString) {
if ((int) a < 127 && (int) a > 20) {
validated.append(a);
}
}
return validated.toString();
}

@SubscribeEvent(priority = EventPriority.HIGH)
public void onTick(TickEvent.ClientTickEvent e) {
if (e.phase == TickEvent.Phase.START) {
tick++;
if (tick > 99 && Minecraft.getMinecraft() != null
&& Minecraft.getMinecraft().thePlayer != null) {
if (Minecraft.getMinecraft().theWorld.getScoreboard().getObjectiveInDisplaySlot(1)
!= null) {
ZealotCounter.isInSkyblock = (stripString(StringUtils.stripControlCodes(
Minecraft.getMinecraft().theWorld.getScoreboard().getObjectiveInDisplaySlot(1)
.getDisplayName())).startsWith("SKYBLOCK") && Minecraft.getMinecraft()
.getCurrentServerData().serverIP.toLowerCase().contains("hypixel.net"));
}
if (ZealotCounter.loggedIn && ZealotCounter.isInSkyblock) {
List<String> scoreboard = ZealotCounter.getSidebarLines();
boolean found = false;
for (String s : scoreboard) {
String validated = stripString(s);
if (validated.contains("Dragon's Nest")) {
if (tempSuspend) {
tempSuspend = false;
EventHandler.perHourTimer.resume();
}
found = true;
break;
}
}
if (!found && !tempSuspend && EventHandler.perHourTimer.isStarted()
&& !EventHandler.perHourTimer.isSuspended()) {
EventHandler.perHourTimer.suspend();
tempSuspend = true;
}
ZealotCounter.dragonsNest = found;
} else if (!ZealotCounter.isInSkyblock) {
if (perHourTimer.isStarted() && !perHourTimer.isSuspended()) {
perHourTimer.suspend();
}
ZealotCounter.dragonsNest = false;
}
tick = 0;
}
}
}

@SubscribeEvent
public void onPlayerJoinEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) {
if (firstJoin) {
Expand Down Expand Up @@ -134,44 +199,54 @@ public void onPlayerLeaveEvent(FMLNetworkEvent.ClientDisconnectionFromServerEven

@SubscribeEvent
public void renderGameOverlayEvent(RenderGameOverlayEvent event) {
if (event.type == RenderGameOverlayEvent.ElementType.TEXT) {
if (event.type == RenderGameOverlayEvent.ElementType.TEXT && ZealotCounter.isInSkyblock) {
String zealotEye =
"Zealots/Eye: " + ((ZealotCounter.summoningEyes == 0) ? ZealotCounter.zealotCount
: new DecimalFormat("#.##")
.format(ZealotCounter.zealotCount / (ZealotCounter.summoningEyes * 1.0d)));
String zealot = "Zealots: " + ZealotCounter.zealotCount;
String eye = "Eyes: " + ZealotCounter.summoningEyes;
String lastEye = "Zealots since last eye: " + ZealotCounter.sinceLastEye;
String zealotsPerHour = "Zealots/Hour: " + new DecimalFormat("#.###")
.format(ZealotCounter.zealotSession / (
((perHourTimer.getTime() == 0) ? 1 : perHourTimer.getTime()) / 3600000d));
String chanceOfEye =
"Current drop rate: " + (1 + Math.floor(ZealotCounter.zealotCount / 420d)) + "/420";
String longest =
(lastEye.length() > zealot.length() && lastEye.length() > zealotEye.length()) ? lastEye
: (zealot.length() > zealotEye.length()) ? zealot : zealotEye;
if (ZealotCounter.align.equals("right")) {
renderer.drawString(zealot, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealot),
ZealotCounter.guiLocation[1], ZealotCounter.color, true);
renderer.drawString(eye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(eye),
ZealotCounter.guiLocation[1], ZealotCounter.color, true);
renderer.drawString(zealot, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealot),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT, ZealotCounter.color, true);
renderer.drawString(zealotEye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealotEye),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 2, ZealotCounter.color, true);
renderer.drawString(zealotsPerHour, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(zealotsPerHour),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 3, ZealotCounter.color, true);
renderer.drawString(lastEye, ZealotCounter.guiLocation[0] +
renderer.getStringWidth(longest) -
renderer.getStringWidth(lastEye),
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 3, ZealotCounter.color, true);
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 4, ZealotCounter.color, true);
} else {
renderer.drawString(zealot, ZealotCounter.guiLocation[0],
renderer.drawString(eye, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1], ZealotCounter.color, true);
renderer.drawString(eye,
ZealotCounter.guiLocation[0],
renderer.drawString(zealot, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT, ZealotCounter.color, true);
renderer.drawString(zealotEye, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 2, ZealotCounter.color, true);
renderer.drawString(lastEye, ZealotCounter.guiLocation[0],
renderer.drawString(zealotsPerHour, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 3, ZealotCounter.color, true);
renderer.drawString(lastEye, ZealotCounter.guiLocation[0],
ZealotCounter.guiLocation[1] + renderer.FONT_HEIGHT * 4, ZealotCounter.color, true);
}
}
}
Expand Down
30 changes: 6 additions & 24 deletions src/main/java/io/github/symt/ZealotCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

@Mod(modid = ZealotCounter.MODID, version = ZealotCounter.VERSION)
public class ZealotCounter {

static final String MODID = "ZealotCounter";
static final String VERSION = "1.0.3";
static final String VERSION = "1.1.0";
private static final String ZEALOT_PATH = "zealotcounter.dat";
static boolean loggedIn = false;
static boolean dragonsNest = false;
Expand All @@ -39,34 +37,19 @@ public class ZealotCounter {
static int zealotCount = 0;
static int summoningEyes = 0;
static int sinceLastEye = 0;
static int zealotSession = 0;
static boolean isInSkyblock = false;
static int[] guiLocation = new int[]{2, 2};
private static ScheduledExecutorService autoSaveExecutor;

private static void scheduleNestCheck() {
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {
if (loggedIn) {
List<String> scoreboard = getSidebarLines();
boolean found = false;
for (String s : scoreboard) {
if (StringUtils.stripControlCodes(s).contains("Dragon's") && StringUtils
.stripControlCodes(s).contains("Nest")) {
found = true;
break;
}
}
dragonsNest = found;
}
}, 0, 5, TimeUnit.SECONDS);
}

static void scheduleFileSave(boolean toggle, int delay) {
if (autoSaveExecutor != null && !autoSaveExecutor.isShutdown()) {
autoSaveExecutor.shutdownNow();
}
if (toggle) {
autoSaveExecutor = Executors.newSingleThreadScheduledExecutor();
autoSaveExecutor.scheduleAtFixedRate(() -> {
if (loggedIn) {
if (loggedIn && isInSkyblock) {
saveZealotInfo(zealotCount, summoningEyes, sinceLastEye);
}
}, 0, delay, TimeUnit.SECONDS);
Expand Down Expand Up @@ -112,7 +95,7 @@ static boolean isInteger(String s, int radix) {
return true;
}

private static List<String> getSidebarLines() {
static List<String> getSidebarLines() {
List<String> lines = new ArrayList<>();
Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard();
if (scoreboard == null) {
Expand Down Expand Up @@ -145,7 +128,7 @@ private static List<String> getSidebarLines() {
return lines;
}

@EventHandler
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new ZealotCounterCommand());
MinecraftForge.EVENT_BUS.register(new io.github.symt.EventHandler());
Expand All @@ -170,6 +153,5 @@ && isInteger(input[3]) && isInteger(input[4]) && isInteger(input[5], 16)) {
saveZealotInfo(0, 0, 0);
}
scheduleFileSave(true, 120);
scheduleNestCheck();
}
}
59 changes: 58 additions & 1 deletion src/main/java/io/github/symt/ZealotCounterCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.symt;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import org.apache.commons.lang3.time.StopWatch;

public class ZealotCounterCommand extends CommandBase {

Expand All @@ -31,7 +33,7 @@ public String getCommandUsage(ICommandSender sender) {

@Override
public void processCommand(ICommandSender ics, String[] args) {
if (ics instanceof EntityPlayer) {
if (ics instanceof EntityPlayer && ZealotCounter.isInSkyblock) {
final EntityPlayer player = (EntityPlayer) ics;
if (args.length == 3 && args[0].equalsIgnoreCase("location") && ZealotCounter
.isInteger(args[1]) && ZealotCounter.isInteger(args[2])) {
Expand All @@ -43,6 +45,54 @@ public void processCommand(ICommandSender ics, String[] args) {
} else if (args.length == 2 && args[0].equalsIgnoreCase("color") && ZealotCounter
.isInteger(args[1], 16) && args[1].length() == 6) {
ZealotCounter.color = Integer.parseInt(args[1], 16);
} else if (args.length == 2 && args[0].equalsIgnoreCase("timer") && (Arrays
.asList(new String[]{"start", "stop", "reset", "resume"})
.contains(args[1].toLowerCase()))) {
switch (args[1].toLowerCase()) {
case "reset":
ZealotCounter.zealotSession = 0;
EventHandler.perHourTimer = new StopWatch();
EventHandler.perHourTimer.start();
player
.addChatMessage(
new ChatComponentText(
EnumChatFormatting.GREEN + "Session reset successfully."));
break;
case "stop":
if (!EventHandler.perHourTimer.isSuspended()) {
EventHandler.perHourTimer.suspend();
player
.addChatMessage(new ChatComponentText(
EnumChatFormatting.GREEN + "Session paused. Use "
+ EnumChatFormatting.DARK_GREEN + "/zc timer resume"
+ EnumChatFormatting.GREEN
+ " to resume"));
} else {
player
.addChatMessage(new ChatComponentText(EnumChatFormatting.RED
+ "The timer is either started or is already paused. Use "
+ EnumChatFormatting.DARK_RED + "/zc timer start"));
}
break;
case "start":
case "resume":
if (EventHandler.perHourTimer.isSuspended()) {
EventHandler.perHourTimer.resume();
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "Session resumed."));
} else {
EventHandler.perHourTimer.start();
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "Session started."));
}
break;
default:
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.RED + "Please use a valid option. To see the options, use "
+ EnumChatFormatting.DARK_RED + "/zc"));
break;
}

} else if (args.length == 1 && args[0].equalsIgnoreCase("reset")) {
ZealotCounter.summoningEyes = 0;
ZealotCounter.zealotCount = 0;
Expand Down Expand Up @@ -81,9 +131,16 @@ public void processCommand(ICommandSender ics, String[] args) {
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "6. " + EnumChatFormatting.LIGHT_PURPLE
+ "autosave (enable|disable) (delay in seconds)"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "7. " + EnumChatFormatting.LIGHT_PURPLE
+ "timer (start|stop|resume|reset)"));
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.DARK_GRAY + "---------------------------"));
}
} else if (!ZealotCounter.isInSkyblock) {
ics.addChatMessage(
new ChatComponentText(
EnumChatFormatting.RED + "Please join SkyBlock to use this command."));
}
}

Expand Down

0 comments on commit 88d7a79

Please sign in to comment.