diff options
author | bowser0000 <bowser0000@gmail.com> | 2020-08-20 15:55:04 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2020-08-20 15:55:04 -0400 |
commit | d23181a65d0e49ea612d7d1ea2ae53701cfe7f0b (patch) | |
tree | 38788189653f502a3449892f64bf931cae9fe138 | |
parent | 4bce023a8c60e165ea1627733f6ada2a2d966350 (diff) | |
download | SkyblockMod-d23181a65d0e49ea612d7d1ea2ae53701cfe7f0b.tar.gz SkyblockMod-d23181a65d0e49ea612d7d1ea2ae53701cfe7f0b.tar.bz2 SkyblockMod-d23181a65d0e49ea612d7d1ea2ae53701cfe7f0b.zip |
Add (unfinished) skyblock players command
Still missing JSON key for Jerry Workshop
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | src/main/java/me/Danker/TheMod.java | 2 | ||||
-rw-r--r-- | src/main/java/me/Danker/commands/BankCommand.java | 3 | ||||
-rw-r--r-- | src/main/java/me/Danker/commands/DHelpCommand.java | 5 | ||||
-rw-r--r-- | src/main/java/me/Danker/commands/SkyblockPlayersCommand.java | 152 | ||||
-rw-r--r-- | src/main/java/me/Danker/utils/Utils.java | 7 |
6 files changed, 172 insertions, 7 deletions
@@ -8,6 +8,8 @@ Discord Server: https://discord.gg/QsEkNQS - Coordinate and angle display (toggleable, graphic display) (scalable) - Golden T10/T6/T4 enchant display (toggleable) - Slayer item tracker (with graphic display) (scalable) +- RNGesus drop alerts (toggleable) +- Click in chat to open Maddox (toggleable) - Fishing tracker (with graphic display) (scalable) - Dungeons tracker (with graphic display) (scalable) - API commands @@ -15,14 +17,14 @@ Discord Server: https://discord.gg/QsEkNQS ## Commands - /dhelp - Returns this message in-game. -- /toggle <gparty/coords/golden/slayercount/rngesusalerts/splitfishing/chatmaddox/list> - Toggles features. /toggle list returns values of every toggle. +- /toggle <gparty/coords/golden/slayercount/rngesusalerts/splitfishing/chatmaddox/spiritbearalerts/list> - Toggles features. /toggle list returns values of every toggle. - /setkey <key> - Sets API key. -- /getkey - Returns key set with /setkey. +- /getkey - Returns key set with /setkey and copies it to your clipboard. - /loot <zombie/spider/wolf/fishing/catacombs> [winter/f(1-4)/session] - Returns loot received from slayer quests or fishing stats. /loot fishing winter returns winter sea creatures instead. - /display <zombie/spider/wolf/fishing/catacombs> [winter/f(1-4)/session] - Text display for trackers. /display fishing winter displays winter sea creatures instead. +- /resetloot <zombie/spider/wolf/fishing/catacombs/confirm/cancel> - - Resets loot for trackers. /resetloot confirm confirms the reset. - /move <coords/display> <x> <y> - Moves text display to specified X and Y coordinates. - /scale <coords/display> <scale (0.1 - 10)> - Scales text display to a specified multipler between 0.1x and 10x. -- /resetloot <zombie/spider/wolf/fishing/catacombs/confirm/cancel> - - Resets loot for trackers. /resetloot confirm confirms the reset. - /slayer [player] - Uses API to get slayer xp of a person. If no name is provided, it checks yours. - /skills [player] - Uses API to get skill levels of a person. If no name is provided, it checks yours. - /guildof [player] - Uses API to get guild name and guild master of a person. If no name is provided, it checks yours. @@ -30,6 +32,7 @@ Discord Server: https://discord.gg/QsEkNQS - /bank [player] - Uses API to get bank and purse coins of a person. If no name is provided, it checks yours. - /armor [player] - Uses API to get armour of a person. If no name is provided, it checks yours. - /importfishing - Imports your fishing stats from your latest profile to your fishing tracker using the API. +- /sbplayers - Uses API to find how many players are on each Skyblock island. ### Notes - Slayer tracker for token drops and 20% chance drops uses a 12x12x12 bounding box centered on the player to detect the drops. If you are out of the range of the item drop, it will not count on the tracker. @@ -37,3 +40,4 @@ Discord Server: https://discord.gg/QsEkNQS - If you use too many API commands too fast, you can and will get rate-limited. - An incorrect API key will result in an HTTP error code of 403. - Importing fishing uses your sea creature kills, which may not always be exactly correct (e.x. someone else kills your sea creature). +- If you want the Maddox menu binded to a key, get a chat binding mod and use the command "/dmodopenmaddoxmenu" (Must have chat maddox enabled) diff --git a/src/main/java/me/Danker/TheMod.java b/src/main/java/me/Danker/TheMod.java index a1fc23a..8c04511 100644 --- a/src/main/java/me/Danker/TheMod.java +++ b/src/main/java/me/Danker/TheMod.java @@ -29,6 +29,7 @@ import me.Danker.commands.ResetLootCommand; import me.Danker.commands.ScaleCommand; import me.Danker.commands.SetkeyCommand; import me.Danker.commands.SkillsCommand; +import me.Danker.commands.SkyblockPlayersCommand; import me.Danker.commands.SlayerCommand; import me.Danker.commands.ToggleCommand; import me.Danker.handlers.APIHandler; @@ -141,6 +142,7 @@ public class TheMod ClientCommandHandler.instance.registerCommand(new ResetLootCommand()); ClientCommandHandler.instance.registerCommand(new ScaleCommand()); ClientCommandHandler.instance.registerCommand(new ChatMaddoxCommand()); + ClientCommandHandler.instance.registerCommand(new SkyblockPlayersCommand()); } // Update checker diff --git a/src/main/java/me/Danker/commands/BankCommand.java b/src/main/java/me/Danker/commands/BankCommand.java index 683dae7..952929f 100644 --- a/src/main/java/me/Danker/commands/BankCommand.java +++ b/src/main/java/me/Danker/commands/BankCommand.java @@ -26,8 +26,7 @@ public class BankCommand extends CommandBase { } @Override - public List<String> getCommandAliases() - { + public List<String> getCommandAliases() { return Collections.singletonList("purse"); } diff --git a/src/main/java/me/Danker/commands/DHelpCommand.java b/src/main/java/me/Danker/commands/DHelpCommand.java index 3bfafa0..0693b76 100644 --- a/src/main/java/me/Danker/commands/DHelpCommand.java +++ b/src/main/java/me/Danker/commands/DHelpCommand.java @@ -39,14 +39,15 @@ public class DHelpCommand extends CommandBase { EnumChatFormatting.GOLD + " /display <zombie/spider/wolf/fishing/catacombs/off> [winter/f(1-4)/session]" + EnumChatFormatting.AQUA + " - Text display for trackers. /display fishing winter displays winter sea creatures instead.\n" + EnumChatFormatting.GOLD + " /resetloot <zombie/spider/wolf/fishing/catacombs/confirm/cancel>" + EnumChatFormatting.AQUA + " - Resets loot for trackers. /resetloot confirm confirms the reset.\n" + EnumChatFormatting.GOLD + " /move <coords/display> <x> <y>" + EnumChatFormatting.AQUA + " - Moves text display to specified X and Y coordinates.\n" + - EnumChatFormatting.GOLD + " /scale <coords/display> <scale (0.1 - 10)" + EnumChatFormatting.AQUA + " - Scales text display to a specified multipler between 0.1x and 10x.\n" + + EnumChatFormatting.GOLD + " /scale <coords/display> <scale (0.1 - 10)>" + EnumChatFormatting.AQUA + " - Scales text display to a specified multipler between 0.1x and 10x.\n" + EnumChatFormatting.GOLD + " /slayer [player]" + EnumChatFormatting.AQUA + " - Uses API to get slayer xp of a person. If no name is provided, it checks yours.\n" + EnumChatFormatting.GOLD + " /skills [player]" + EnumChatFormatting.AQUA + " - Uses API to get skill levels of a person. If no name is provided, it checks yours.\n" + EnumChatFormatting.GOLD + " /guildof [player]" + EnumChatFormatting.AQUA + " - Uses API to get guild name and guild master of a person. If no name is provided, it checks yours.\n" + EnumChatFormatting.GOLD + " /petsof [player]" + EnumChatFormatting.AQUA + " - Uses API to get pets of a person. If no name is provided, it checks yours.\n" + EnumChatFormatting.GOLD + " /bank [player]" + EnumChatFormatting.AQUA + " - Uses API to get bank and purse coins of a person. If no name is provided, it checks yours.\n" + EnumChatFormatting.GOLD + " /armor [player]" + EnumChatFormatting.AQUA + " - Uses API to get armour of a person. If no name is provided, it checks yours.\n" + - EnumChatFormatting.GOLD + " /importfishing" + EnumChatFormatting.AQUA + " - Imports your fishing stats from your latest profile to your fishing tracker using the API.\n")); + EnumChatFormatting.GOLD + " /importfishing" + EnumChatFormatting.AQUA + " - Imports your fishing stats from your latest profile to your fishing tracker using the API.\n" + + EnumChatFormatting.GOLD + " /sbplayers" + EnumChatFormatting.AQUA + " - Uses API to find how many players are on each Skyblock island.\n")); } } diff --git a/src/main/java/me/Danker/commands/SkyblockPlayersCommand.java b/src/main/java/me/Danker/commands/SkyblockPlayersCommand.java new file mode 100644 index 0000000..98afa28 --- /dev/null +++ b/src/main/java/me/Danker/commands/SkyblockPlayersCommand.java @@ -0,0 +1,152 @@ +package me.Danker.commands; + +import java.text.NumberFormat; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +import com.google.gson.JsonObject; + +import me.Danker.handlers.APIHandler; +import me.Danker.handlers.ConfigHandler; +import me.Danker.utils.Utils; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class SkyblockPlayersCommand extends CommandBase { + + @Override + public String getCommandName() { + return "sbplayers"; + } + + @Override + public List<String> getCommandAliases() { + return Collections.singletonList("skyblockplayers"); + } + + @Override + public String getCommandUsage(ICommandSender arg0) { + return null; + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } + + @Override + public void processCommand(ICommandSender arg0, String[] arg1) throws CommandException { + // MULTI THREAD DRIFTING + new Thread(() -> { + APIHandler ah = new APIHandler(); + ConfigHandler cf = new ConfigHandler(); + EntityPlayer player = (EntityPlayer) arg0; + + // Check key + String key = cf.getString("api", "APIKey"); + if (key.equals("")) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "API key not set. Use /setkey.")); + } + + String playersURL = "https://api.hypixel.net/gameCounts?key=" + key; + System.out.println("Fetching player count..."); + JsonObject playersResponse = ah.getResponse(playersURL); + if (!playersResponse.get("success").getAsBoolean()) { + String reason = playersResponse.get("cause").getAsString(); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed with reason: " + reason)); + return; + } + + int totalPlayers = playersResponse.get("playerCount").getAsInt(); + // Skyblock players, comments show JSON key + int skyblockTotalPlayers = 0; // players + int privateIsland = 0; // dynamic + int hub = 0; // hub + int barn = 0; // farming_1 + int mushroomDesert = 0; // farming_2 + int park = 0; // foraging_1 + int goldMine = 0; // mining_1 + int deepCaverns = 0; // mining_2 + int spidersDen = 0; // combat_1 + int blazingFortress = 0; // combat_2 + int end = 0; // combat_3 + int dungeonsHub = 0; // dungeon_hub + int dungeons = 0; // dungeon + int darkAuction = 0; // dark_auction + int jerry = 0; + if (playersResponse.get("games").getAsJsonObject().get("SKYBLOCK").getAsJsonObject().has("modes")) { + JsonObject skyblockPlayers = playersResponse.get("games").getAsJsonObject().get("SKYBLOCK").getAsJsonObject().get("modes").getAsJsonObject(); + skyblockTotalPlayers = playersResponse.get("games").getAsJsonObject().get("SKYBLOCK").getAsJsonObject().get("players").getAsInt(); + if (skyblockPlayers.has("dynamic")) { + privateIsland = skyblockPlayers.get("dynamic").getAsInt(); + } + if (skyblockPlayers.has("hub")) { + hub = skyblockPlayers.get("hub").getAsInt(); + } + if (skyblockPlayers.has("farming_1")) { + barn = skyblockPlayers.get("farming_1").getAsInt(); + } + if (skyblockPlayers.has("farming_2")) { + mushroomDesert = skyblockPlayers.get("farming_2").getAsInt(); + } + if (skyblockPlayers.has("foraging_1")) { + park = skyblockPlayers.get("foraging_1").getAsInt(); + } + if (skyblockPlayers.has("mining_1")) { + goldMine = skyblockPlayers.get("mining_1").getAsInt(); + } + if (skyblockPlayers.has("mining_2")) { + deepCaverns = skyblockPlayers.get("mining_2").getAsInt(); + } + if (skyblockPlayers.has("combat_1")) { + spidersDen = skyblockPlayers.get("combat_1").getAsInt(); + } + if (skyblockPlayers.has("combat_2")) { + blazingFortress = skyblockPlayers.get("combat_2").getAsInt(); + } + if (skyblockPlayers.has("combat_3")) { + end = skyblockPlayers.get("combat_3").getAsInt(); + } + if (skyblockPlayers.has("dungeon_hub")) { + dungeonsHub = skyblockPlayers.get("dungeon_hub").getAsInt(); + } + if (skyblockPlayers.has("dungeon")) { + dungeons = skyblockPlayers.get("dungeon").getAsInt(); + } + if (skyblockPlayers.has("dark_auction")) { + darkAuction = skyblockPlayers.get("dark_auction").getAsInt(); + } + // Placeholder value until Jerry Workshop opens + if (skyblockPlayers.has("jerry")) { + jerry = skyblockPlayers.get("jerry").getAsInt(); + } + } + + NumberFormat nf = NumberFormat.getIntegerInstance(Locale.US); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD + "-------------------\n" + + EnumChatFormatting.GREEN + " Hypixel: " + EnumChatFormatting.DARK_GREEN + nf.format(totalPlayers) + "\n" + + EnumChatFormatting.GREEN + " Skyblock: " + EnumChatFormatting.DARK_GREEN + nf.format(skyblockTotalPlayers) + " / " + Utils.getPercentage(skyblockTotalPlayers, totalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Private Island: " + EnumChatFormatting.DARK_GREEN + nf.format(privateIsland) + " / " + Utils.getPercentage(privateIsland, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Hub: " + EnumChatFormatting.DARK_GREEN + nf.format(hub) + " / " + Utils.getPercentage(hub, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Barn: " + EnumChatFormatting.DARK_GREEN + nf.format(barn) + " / " + Utils.getPercentage(barn, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Mushroom Desert: " + EnumChatFormatting.DARK_GREEN + nf.format(mushroomDesert) + " / " + Utils.getPercentage(mushroomDesert, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Park: " + EnumChatFormatting.DARK_GREEN + nf.format(park) + " / " + Utils.getPercentage(park, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Gold Mine: " + EnumChatFormatting.DARK_GREEN + nf.format(goldMine) + " / " + Utils.getPercentage(goldMine, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Deep Caverns: " + EnumChatFormatting.DARK_GREEN + nf.format(deepCaverns) + " / " + Utils.getPercentage(deepCaverns, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Spider's Den: " + EnumChatFormatting.DARK_GREEN + nf.format(spidersDen) + " / " + Utils.getPercentage(spidersDen, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Blazing Fortress: " + EnumChatFormatting.DARK_GREEN + nf.format(blazingFortress) + " / " + Utils.getPercentage(blazingFortress, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " The End: " + EnumChatFormatting.DARK_GREEN + nf.format(end) + " / " + Utils.getPercentage(end, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Dungeons Hub: " + EnumChatFormatting.DARK_GREEN + nf.format(dungeonsHub) + " / " + Utils.getPercentage(dungeonsHub, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Dungeons: " + EnumChatFormatting.DARK_GREEN + nf.format(dungeons) + " / " + Utils.getPercentage(dungeons, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Dark Auction: " + EnumChatFormatting.DARK_GREEN + nf.format(darkAuction) + " / " + Utils.getPercentage(darkAuction, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.GREEN + " Jerry's Workshop: " + EnumChatFormatting.DARK_GREEN + nf.format(jerry) + " / " + Utils.getPercentage(jerry, skyblockTotalPlayers) + "%\n" + + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + " -------------------")); + }).start(); + } + +} diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java index 835e613..7153014 100644 --- a/src/main/java/me/Danker/utils/Utils.java +++ b/src/main/java/me/Danker/utils/Utils.java @@ -113,4 +113,11 @@ public class Utils { return String.join(" ", words); } + public static double getPercentage(int num1, int num2) { + if (num2 == 0) return 0D; + double result = ((double) num1 * 100D) / (double) num2; + result = Math.round(result * 100D) / 100D; + return result; + } + } |