aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/config/MooConfig.java9
-rw-r--r--src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java44
-rw-r--r--src/main/java/de/cowtipper/cowlection/listener/ChatListener.java37
-rw-r--r--src/main/java/de/cowtipper/cowlection/util/MooChatComponent.java9
4 files changed, 97 insertions, 2 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java
index 010a3a8..0a498dd 100644
--- a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java
+++ b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java
@@ -50,6 +50,7 @@ public class MooConfig {
// SkyBlock dungeon
public static int[] dungClassRange;
public static boolean dungFilterPartiesWithDupes;
+ public static String dungPartyFinderArmorLookup;
public static String dungItemQualityPos;
public static boolean dungOverlayEnabled;
public static int dungOverlayGuiScale;
@@ -160,6 +161,8 @@ public class MooConfig {
.setMinValue(-1).setIsListLengthFixed(true);
Property propDungFilterPartiesWithDupes = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
"dungFilterPartiesWithDupes", false, "Mark parties with duplicated classes?"), true);
+ Property propDungPartyFinderArmorLookup = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
+ "dungPartyFinderArmorLookup", "as a tooltip", "Show armor of player joining via party finder as a tooltip or in chat?", new String[]{"as a tooltip", "in chat", "disabled"}), true);
Property propDungItemQualityPos = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
"dungItemQualityPos", "top", "Position of item quality in tooltip", new String[]{"top", "bottom"}), true);
Property propDungOverlayEnabled = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
@@ -202,6 +205,7 @@ public class MooConfig {
// SkyBlock dungeon
dungClassRange = propDungClassRange.getIntList();
dungFilterPartiesWithDupes = propDungFilterPartiesWithDupes.getBoolean();
+ dungPartyFinderArmorLookup = propDungPartyFinderArmorLookup.getString();
dungItemQualityPos = propDungItemQualityPos.getString();
dungOverlayEnabled = propDungOverlayEnabled.getBoolean();
dungOverlayPositionX = propDungOverlayPositionX.getInt();
@@ -231,6 +235,7 @@ public class MooConfig {
// SkyBlock dungeon
propDungClassRange.set(dungClassRange);
propDungFilterPartiesWithDupes.set(dungFilterPartiesWithDupes);
+ propDungPartyFinderArmorLookup.set(dungPartyFinderArmorLookup);
propDungItemQualityPos.set(dungItemQualityPos);
propDungOverlayEnabled.set(dungOverlayEnabled);
propDungOverlayPositionX.set(dungOverlayPositionX);
@@ -341,6 +346,10 @@ public class MooConfig {
return dungItemQualityPos.equals("top");
}
+ public static boolean showArmorLookupInChat() {
+ return "in chat".equals(dungPartyFinderArmorLookup);
+ }
+
public class ConfigEventHandler {
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onEvent(ConfigChangedEvent.OnConfigChangedEvent e) {
diff --git a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
index 86fb0a6..05c1dd6 100644
--- a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
+++ b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
@@ -4,7 +4,15 @@ import com.google.common.collect.ComparisonChain;
import com.mojang.realmsclient.util.Pair;
import com.mojang.util.UUIDTypeAdapter;
import de.cowtipper.cowlection.util.Utils;
-
+import net.minecraft.nbt.CompressedStreamTools;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.common.util.Constants;
+import org.apache.commons.codec.binary.Base64;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.util.*;
public class HySkyBlockStats {
@@ -101,6 +109,7 @@ public class HySkyBlockStats {
private long last_save;
private long first_join;
private double coin_purse;
+ private NbtData inv_armor;
private List<String> crafted_generators;
private int fairy_souls_collected = -1;
private double experience_skill_farming = -1;
@@ -183,6 +192,39 @@ public class HySkyBlockStats {
pets.sort((p1, p2) -> ComparisonChain.start().compare(p2.active, p1.active).compare(p2.getRarity(), p1.getRarity()).compare(p2.exp, p1.exp).result());
return pets;
}
+
+ public List<String> getArmor() {
+ NBTTagCompound nbt = inv_armor.getDecodedData();
+ List<String> armorList = new ArrayList<>();
+ if (nbt.hasKey("i", Constants.NBT.TAG_LIST)) {
+ NBTTagList armor = nbt.getTagList("i", Constants.NBT.TAG_COMPOUND);
+ for (int i = 0; i < armor.tagCount(); i++) {
+ NBTTagCompound armorPiece = armor.getCompoundTagAt(i);
+ NBTTagCompound nbtDisplay = armorPiece.getCompoundTag("tag").getCompoundTag("display");
+ if (nbtDisplay != null && nbtDisplay.hasKey("Name", Constants.NBT.TAG_STRING)) {
+ String itemName = nbtDisplay.getString("Name");
+ armorList.add(0, itemName);
+ } else {
+ armorList.add(0, "" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "(empty)");
+ }
+ }
+ }
+ return armorList;
+ }
+
+ private static class NbtData {
+ private int type;
+ private String data;
+
+ private NBTTagCompound getDecodedData() {
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(this.data))) {
+ return CompressedStreamTools.readCompressed(bis);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return new NBTTagCompound();
+ }
+ }
+ }
}
private static class SlayerBossDetails {
diff --git a/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java b/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java
index 0b53166..8b563b6 100644
--- a/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java
+++ b/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java
@@ -2,6 +2,10 @@ package de.cowtipper.cowlection.listener;
import de.cowtipper.cowlection.Cowlection;
import de.cowtipper.cowlection.config.MooConfig;
+import de.cowtipper.cowlection.data.Friend;
+import de.cowtipper.cowlection.data.HySkyBlockStats;
+import de.cowtipper.cowlection.util.ApiUtils;
+import de.cowtipper.cowlection.util.MooChatComponent;
import de.cowtipper.cowlection.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
@@ -163,6 +167,10 @@ public class ChatListener {
messageSender = partyOrGameInviteMatcher.group(1);
} else if (dungeonPartyFinderJoinedMatcher.find()) {
messageSender = dungeonPartyFinderJoinedMatcher.group(1);
+ if (!"disabled".equals(MooConfig.dungPartyFinderArmorLookup)) {
+ String dungeonClass = dungeonPartyFinderJoinedMatcher.group(2) + " Lvl " + dungeonPartyFinderJoinedMatcher.group(3);
+ getDungeonPartyMemberDetails(messageSender, dungeonClass);
+ }
}
if (messageSender != null) {
@@ -171,6 +179,35 @@ public class ChatListener {
}
}
+ private void getDungeonPartyMemberDetails(String playerName, String dungeonClass) {
+ ApiUtils.fetchFriendData(playerName, stalkedPlayer -> {
+ if (stalkedPlayer != null && !stalkedPlayer.equals(Friend.FRIEND_NOT_FOUND)) {
+ ApiUtils.fetchSkyBlockStats(stalkedPlayer, hySBStalking -> {
+ if (hySBStalking != null && hySBStalking.isSuccess()) {
+ HySkyBlockStats.Profile activeProfile = hySBStalking.getActiveProfile(stalkedPlayer.getUuid());
+ if (activeProfile == null) {
+ // player hasn't played SkyBlock but joined via dungeon party finder? Maybe an API error
+ return;
+ }
+ HySkyBlockStats.Profile.Member member = activeProfile.getMember(stalkedPlayer.getUuid());
+ MooChatComponent armorLookupComponent;
+ String armorLookupPrefix = " ❈ " + EnumChatFormatting.DARK_GREEN + playerName;
+ String delimiter = "\n" + (MooConfig.showArmorLookupInChat() ? " " : "");
+ String armorLookupResult = EnumChatFormatting.LIGHT_PURPLE + " ➜ " + EnumChatFormatting.GRAY + dungeonClass + delimiter + String.join(delimiter, member.getArmor());
+ if (MooConfig.showArmorLookupInChat()) {
+ armorLookupComponent = new MooChatComponent(armorLookupPrefix + armorLookupResult).green();
+ } else {
+ // as a tooltip
+ armorLookupComponent = new MooChatComponent(armorLookupPrefix + EnumChatFormatting.GREEN + (playerName.endsWith("s") ? "" : "'s") + " armor (hover me)").green()
+ .setHover(new MooChatComponent(EnumChatFormatting.BOLD + playerName + armorLookupResult));
+ }
+ main.getChatHelper().sendMessage(armorLookupComponent.setSuggestCommand("/p kick " + playerName, MooConfig.showArmorLookupInChat()));
+ }
+ });
+ }
+ });
+ }
+
@SubscribeEvent
public void onRenderChatGui(RenderGameOverlayEvent.Chat e) {
if (e.type == RenderGameOverlayEvent.ElementType.CHAT) {
diff --git a/src/main/java/de/cowtipper/cowlection/util/MooChatComponent.java b/src/main/java/de/cowtipper/cowlection/util/MooChatComponent.java
index 062d488..4694fee 100644
--- a/src/main/java/de/cowtipper/cowlection/util/MooChatComponent.java
+++ b/src/main/java/de/cowtipper/cowlection/util/MooChatComponent.java
@@ -143,8 +143,15 @@ public class MooChatComponent extends ChatComponentText {
}
public MooChatComponent setSuggestCommand(String command) {
+ setSuggestCommand(command, true);
+ return this;
+ }
+
+ public MooChatComponent setSuggestCommand(String command, boolean addTooltip) {
setChatStyle(getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
- setHover(new KeyValueChatComponent("Run", command, " "));
+ if (addTooltip) {
+ setHover(new KeyValueChatComponent("Run", command, " "));
+ }
return this;
}