aboutsummaryrefslogtreecommitdiff
path: root/me/Danker/commands/BankCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'me/Danker/commands/BankCommand.java')
-rw-r--r--me/Danker/commands/BankCommand.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/me/Danker/commands/BankCommand.java b/me/Danker/commands/BankCommand.java
new file mode 100644
index 0000000..f569e7f
--- /dev/null
+++ b/me/Danker/commands/BankCommand.java
@@ -0,0 +1,105 @@
+package me.Danker.commands;
+
+import java.text.NumberFormat;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.gson.JsonObject;
+
+import me.Danker.handlers.APIHandler;
+import me.Danker.handlers.ConfigHandler;
+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 BankCommand extends CommandBase {
+
+ @Override
+ public String getCommandName() {
+ return "bank";
+ }
+
+ @Override
+ public List<String> getCommandAliases()
+ {
+ return Collections.singletonList("purse");
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender arg0) {
+ return getCommandName() + " [name]";
+ }
+
+ @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."));
+ }
+
+ // Get UUID for Hypixel API requests
+ String username;
+ String uuid;
+ if (arg1.length == 0) {
+ username = player.getName();
+ uuid = player.getUniqueID().toString().replaceAll("[\\-]", "");
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Checking coins of " + EnumChatFormatting.DARK_GREEN + username));
+ } else {
+ username = arg1[0];
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Checking coins of " + EnumChatFormatting.DARK_GREEN + username));
+ uuid = ah.getUUID(username);
+ }
+
+ // Find stats of latest profile
+ String latestProfile = ah.getLatestProfileID(uuid, key);
+ if (latestProfile == null) return;
+
+ String profileURL = "https://api.hypixel.net/skyblock/profile?profile=" + latestProfile + "&key=" + key;
+ System.out.println("Fetching profile...");
+ JsonObject profileResponse = ah.getResponse(profileURL);
+ if (!profileResponse.get("success").getAsBoolean()) {
+ String reason = profileResponse.get("cause").getAsString();
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed with reason: " + reason));
+ return;
+ }
+
+ System.out.println("Fetching bank + purse coins...");
+ double purseCoins = profileResponse.get("profile").getAsJsonObject().get("members").getAsJsonObject().get(uuid).getAsJsonObject().get("coin_purse").getAsDouble();
+ purseCoins = (double) Math.floor(purseCoins * 100.0) / 100.0;
+
+ // Check for bank api
+ if (profileResponse.get("profile").getAsJsonObject().has("banking")) {
+ double bankCoins = profileResponse.get("profile").getAsJsonObject().get("banking").getAsJsonObject().get("balance").getAsDouble();
+ bankCoins = (double) Math.floor(bankCoins * 100.0) / 100.0;
+
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD + "-------------------\n" +
+ EnumChatFormatting.AQUA + " " + username + "'s Coins:\n" +
+ EnumChatFormatting.GREEN + " Bank: " + EnumChatFormatting.GOLD + NumberFormat.getInstance().format(bankCoins) + "\n" +
+ EnumChatFormatting.GREEN + " Purse: " + EnumChatFormatting.GOLD + NumberFormat.getInstance().format(purseCoins) + "\n" +
+ EnumChatFormatting.AQUA + " " + EnumChatFormatting.BOLD + "-------------------"));
+ } else {
+ player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "" + EnumChatFormatting.BOLD + "-------------------\n" +
+ EnumChatFormatting.AQUA + " " + username + "'s Coins:\n" +
+ EnumChatFormatting.GREEN + " Bank: " + EnumChatFormatting.RED + "Bank API disabled.\n" +
+ EnumChatFormatting.GREEN + " Purse: " + EnumChatFormatting.GOLD + NumberFormat.getInstance().format(purseCoins) + "\n" +
+ EnumChatFormatting.AQUA + " " + EnumChatFormatting.BOLD + "-------------------"));
+ }
+ }).start();
+ }
+
+}