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

Commit

Permalink
1.3.0: GUI command (#23)
Browse files Browse the repository at this point in the history
* starting gui

* README.md: Finally making release schedule

* 1.2.1: Various patches (#18)

* mcmod.info update

* Version changes for 1.2.1 prep

* ISSUE-9: Update link in message (#13)

* Removed DS_STORE

* ISSUE-9: Update link in message

* ISSUE-16: Check to make sure mob name is long enough (#17)

* 1.2.2: Fixes & /zc toggle (#21)

* refractoring (starting)

* working on it

* end of gui
  • Loading branch information
symt authored Dec 27, 2019
1 parent 27e2226 commit a83da55
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 212 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ local.properties

# PDT-specific
.buildpath

out/

.DS_STORE
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# zealot-counter
Zealot counter for Hypixel Skyblock

### Update Schedule

For future updates, check the chart below:

| Version | Release |
|:-------:|:--------|
|1.3.0|2019 Dec 22|
|1.4.0|2020 Jan 12|

<sup><sub>The dates on this list are estimates and can be much earlier depending on how fast things move along</sub></sup>
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.2.0"
version = "1.3.0"
group= "io.github.symt"
archivesBaseName = "ZealotCounter"

Expand Down
223 changes: 135 additions & 88 deletions src/main/java/io/github/symt/EventHandler.java

Large diffs are not rendered by default.

170 changes: 119 additions & 51 deletions src/main/java/io/github/symt/ZealotCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,34 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;

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

static final String MODID = "ZealotCounter";
static final String VERSION = "1.2.0";
private static final String ZEALOT_PATH = "zealotcounter.dat";
static boolean loggedIn = false;
static boolean usingLabyMod = false;
static boolean dragonsNest = false;
static int color = 0x55FFFF;
static String align = "left";
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;

static void scheduleFileSave(boolean toggle, int delay) {
if (autoSaveExecutor != null && !autoSaveExecutor.isShutdown()) {
autoSaveExecutor.shutdownNow();
}
if (toggle) {
autoSaveExecutor = Executors.newSingleThreadScheduledExecutor();
autoSaveExecutor.scheduleAtFixedRate(() -> {
if (loggedIn && isInSkyblock) {
saveZealotInfo(zealotCount, summoningEyes, sinceLastEye);
}
}, 0, delay, TimeUnit.SECONDS);
}
}

static void saveZealotInfo(int zealots, int eyes, int last) {
new Thread(() -> {
File zealot_file = new File(ZEALOT_PATH);
try {
FileWriter fw = new FileWriter(zealot_file, false);
fw.write(
zealots + "," + eyes + "," + last + "," + guiLocation[0] + "," + guiLocation[1] + ","
+ Integer
.toHexString(color) + "," + align);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
public static final String MODID = "ZealotCounter";
public static final String VERSION = "1.3.0";
private static final String ZEALOT_PATH = "zealotcounter.json";
public static ZealotCounter instance;
public String openGui = "";
public String currentSetup = "";
public int zealotCount = 0;
public int summoningEyes = 0;
public int sinceLastEye = 0;
public boolean toggled = true;
public EventHandler eventHandler;
public String align = "left";
public int[] guiLocation = new int[]{2, 2};
public int zealotSession = 0;
boolean loggedIn = false;
boolean usingLabyMod = false;
boolean dragonsNest = false;
int color = 0x55FFFF;
String lastSetup = "";
JSONObject zealotData;
boolean isInSkyblock = false;
private ScheduledExecutorService autoSaveExecutor;

static boolean isInteger(String s) {
return isInteger(s, 10);
Expand All @@ -98,7 +77,74 @@ static boolean isInteger(String s, int radix) {
return true;
}

static List<String> getSidebarLines() {
void scheduleFileSave(boolean toggle, int delay) {
if (autoSaveExecutor != null && !autoSaveExecutor.isShutdown()) {
autoSaveExecutor.shutdownNow();
}
if (toggle) {
autoSaveExecutor = Executors.newSingleThreadScheduledExecutor();
autoSaveExecutor.scheduleAtFixedRate(() -> {
if (loggedIn && !currentSetup.equals("")) {
saveSetup(currentSetup.split(" ")[0],
currentSetup.split(" ")[1], zealotCount,
summoningEyes, sinceLastEye);
}
}, 0, delay, TimeUnit.SECONDS);
}
}

public void updateInfoWithCurrentSetup(String uuid, String profile) {
if (!lastSetup.equals("")) {
saveSetup(lastSetup.split(" ")[0], lastSetup.split(" ")[1], zealotCount, summoningEyes,
sinceLastEye);
}
lastSetup = currentSetup;
if (!zealotData.getJSONObject("player").isNull(uuid)
&& !zealotData.getJSONObject("player").getJSONObject(uuid).isNull(profile)) {
JSONObject currentProfile = zealotData.getJSONObject("player").getJSONObject(uuid)
.getJSONObject(profile);
zealotCount = currentProfile.getInt("zealotCount");
summoningEyes = currentProfile.getInt("summoningEyes");
sinceLastEye = currentProfile.getInt("sinceLastEye");
} else {
saveSetup(currentSetup.split(" ")[0], currentSetup.split(" ")[1], zealotCount, summoningEyes,
sinceLastEye);
}
}

public void saveSetup(String uuid, String profile, int zealotCount, int summoningEyes,
int sinceLastEye) {
if (zealotData.getJSONObject("player").isNull(uuid)) {
zealotData.getJSONObject("player").put(uuid, new JSONObject("{}"));
}
if (zealotData.getJSONObject("player").getJSONObject(uuid).isNull(profile)) {
zealotData.getJSONObject("player").getJSONObject(uuid).put(profile, new JSONObject("{}"));
}
zealotData.getJSONObject("player").getJSONObject(uuid).getJSONObject(profile)
.put("zealotCount", zealotCount);
zealotData.getJSONObject("player").getJSONObject(uuid).getJSONObject(profile)
.put("summoningEyes", summoningEyes);
zealotData.getJSONObject("player").getJSONObject(uuid).getJSONObject(profile)
.put("sinceLastEye", sinceLastEye);
saveZealotInfo();
}

private void saveZealotInfo() {
new Thread(() -> {
File zealot_file = new File(ZEALOT_PATH);
try {
FileWriter fw = new FileWriter(zealot_file, false);
zealotData.getJSONObject("player").put("color", Integer.toHexString(color));
zealotData.getJSONObject("player").put("location", guiLocation);
fw.write(zealotData.toString());
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}

List<String> getSidebarLines() {
List<String> lines = new ArrayList<>();
Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard();
if (scoreboard == null) {
Expand Down Expand Up @@ -133,11 +179,31 @@ static List<String> getSidebarLines() {

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new ZealotCounterCommand());
MinecraftForge.EVENT_BUS.register(new io.github.symt.EventHandler());
instance = this;
eventHandler = new EventHandler(this);
ClientCommandHandler.instance.registerCommand(new ZealotCounterCommand(this));
MinecraftForge.EVENT_BUS.register(eventHandler);
if (new File(ZEALOT_PATH).isFile()) {
try {
String[] input = new BufferedReader(new FileReader(ZEALOT_PATH)).readLine().split(",");
zealotData = new JSONObject(
IOUtils.toString(new BufferedReader(new FileReader(ZEALOT_PATH))));
guiLocation = new int[]{
Integer.parseInt(
zealotData.getJSONObject("player").getJSONArray("location").toList().toArray()[0]
.toString()),
Integer.parseInt(
zealotData.getJSONObject("player").getJSONArray("location").toList().toArray()[1]
.toString())
};
color = Integer.parseInt(zealotData.getJSONObject("player").getString("color"), 16);
} catch (IOException e) {
e.printStackTrace();
}
} else if (new File("zealotcounter.dat").isFile()) {
try {
String[] input = new BufferedReader(new FileReader("zealotcounter.dat")).readLine()
.split(",");
zealotData = new JSONObject("{\"player\":{\"color\": \"ff00ff\", \"location\": [2, 2]}}");
if (input.length == 7 && isInteger(input[0]) && isInteger(input[1]) && isInteger(input[2])
&& isInteger(input[3]) && isInteger(input[4]) && isInteger(input[5], 16)) {
zealotCount = Integer.parseInt(input[0]);
Expand All @@ -147,13 +213,15 @@ && isInteger(input[3]) && isInteger(input[4]) && isInteger(input[5], 16)) {
color = Integer.parseInt(input[5], 16);
align = input[6];
} else {
saveZealotInfo(0, 0, 0);
saveZealotInfo();
}
new File("zealotcounter.dat").deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
}
} else {
saveZealotInfo(0, 0, 0);
zealotData = new JSONObject("{\"player\":{\"color\": \"ff00ff\", \"location\": [2, 2]}}");
saveZealotInfo();
}
scheduleFileSave(true, 120);
}
Expand Down
89 changes: 23 additions & 66 deletions src/main/java/io/github/symt/ZealotCounterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@

public class ZealotCounterCommand extends CommandBase {

private ZealotCounter zealotCounter;

ZealotCounterCommand(ZealotCounter zealotCounter) {
this.zealotCounter = zealotCounter;
}

@Override
public List getCommandAliases() {
public List<String> getCommandAliases() {
return new ArrayList<String>() {
{
add("zc");
Expand All @@ -33,25 +39,15 @@ public String getCommandUsage(ICommandSender sender) {

@Override
public void processCommand(ICommandSender ics, String[] args) {
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])) {
ZealotCounter.guiLocation = new int[]{Integer.parseInt(args[1]), Integer.parseInt(args[2])};
ZealotCounter.saveZealotInfo(ZealotCounter.zealotCount, ZealotCounter.summoningEyes,
ZealotCounter.sinceLastEye);
} else if (args.length == 2 && args[0].equalsIgnoreCase("align")) {
ZealotCounter.align = (args[1].equalsIgnoreCase("right")) ? "right" : "left";
} 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
if (ics instanceof EntityPlayer && zealotCounter.isInSkyblock) {
EntityPlayer player = (EntityPlayer)ics;
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();
zealotCounter.zealotSession = 0;
zealotCounter.eventHandler.perHourTimer = new StopWatch();
player
.addChatMessage(
new ChatComponentText(
Expand All @@ -60,9 +56,9 @@ public void processCommand(ICommandSender ics, String[] args) {
+ EnumChatFormatting.GREEN + " to restart the timer"));
break;
case "stop":
if (!EventHandler.perHourTimer.isSuspended() && !EventHandler.perHourTimer
if (!zealotCounter.eventHandler.perHourTimer.isSuspended() && !zealotCounter.eventHandler.perHourTimer
.isStopped()) {
EventHandler.perHourTimer.suspend();
zealotCounter.eventHandler.perHourTimer.suspend();
player
.addChatMessage(new ChatComponentText(
EnumChatFormatting.GREEN + "Session paused. Use "
Expand All @@ -78,12 +74,12 @@ public void processCommand(ICommandSender ics, String[] args) {
break;
case "start":
case "resume":
if (EventHandler.perHourTimer.isSuspended()) {
EventHandler.perHourTimer.resume();
if (zealotCounter.eventHandler.perHourTimer.isSuspended()) {
zealotCounter.eventHandler.perHourTimer.resume();
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "Session resumed."));
} else if (EventHandler.perHourTimer.isStopped()) {
EventHandler.perHourTimer.start();
} else if (zealotCounter.eventHandler.perHourTimer.isStopped()) {
zealotCounter.eventHandler.perHourTimer.start();
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "Session started."));
} else {
Expand All @@ -98,52 +94,13 @@ public void processCommand(ICommandSender ics, String[] args) {
+ EnumChatFormatting.DARK_RED + "/zc"));
break;
}

} else if (args.length == 1 && args[0].equalsIgnoreCase("reset")) {
ZealotCounter.summoningEyes = 0;
ZealotCounter.zealotCount = 0;
ZealotCounter.sinceLastEye = 0;
ZealotCounter.saveZealotInfo(0, 0, 0);
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "ZealotCounter has been reset"));
} else if (args.length == 3 && args[0].equalsIgnoreCase("autosave") && (
args[1].equalsIgnoreCase("disable") || args[1].equalsIgnoreCase("enable"))
&& ZealotCounter.isInteger(args[2])) {
ZealotCounter
.scheduleFileSave(args[1].equalsIgnoreCase("enable"), Integer.parseInt(args[2]));
} else if (args.length == 1 && args[0].equalsIgnoreCase("save")) {
ZealotCounter.saveZealotInfo(ZealotCounter.zealotCount, ZealotCounter.summoningEyes,
ZealotCounter.sinceLastEye);
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.GREEN + "ZealotCounter has been saved"));
} 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 {
player.addChatMessage(
new ChatComponentText(EnumChatFormatting.DARK_GRAY + "---------------------------"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.BLUE + "/zealotcounter [subcommand] [arguments]"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "1. " + EnumChatFormatting.LIGHT_PURPLE + "save"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "2. " + EnumChatFormatting.LIGHT_PURPLE + "reset"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "3. " + EnumChatFormatting.LIGHT_PURPLE
+ "location (x) (y)"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "4. " + EnumChatFormatting.LIGHT_PURPLE
+ "color (hex color)"));
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.DARK_PURPLE + "5. " + EnumChatFormatting.LIGHT_PURPLE
+ "align (left|right)"));
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 + "---------------------------"));
zealotCounter.openGui = "normal";
}
} else if (!ZealotCounter.isInSkyblock) {
} else if (!zealotCounter.isInSkyblock) {
ics.addChatMessage(
new ChatComponentText(
EnumChatFormatting.RED + "Please join SkyBlock to use this command."));
Expand Down
Loading

0 comments on commit a83da55

Please sign in to comment.