aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2022-11-20 13:42:58 +0100
committerGitHub <noreply@github.com>2022-11-20 13:42:58 +0100
commit3d37cee20ddcf92b47144cb1e3ae25785a5e8bc2 (patch)
tree43ffa014196baf4e2c027a37ed54304f8db4827f /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java
parentf6fc2742b86333947fe506de1e80093b1f8ad7ad (diff)
downloadnotenoughupdates-3d37cee20ddcf92b47144cb1e3ae25785a5e8bc2.tar.gz
notenoughupdates-3d37cee20ddcf92b47144cb1e3ae25785a5e8bc2.tar.bz2
notenoughupdates-3d37cee20ddcf92b47144cb1e3ae25785a5e8bc2.zip
Added Abiphone contact requirements and location. (#411)
* Added Abiphone contact requirements and location. * Using more repo data and less item lore data * F3+H support * merge problems Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java
new file mode 100644
index 00000000..d2a5fc84
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.miscfeatures;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
+import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.event.entity.player.ItemTooltipEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import org.lwjgl.input.Keyboard;
+
+import java.util.List;
+import java.util.Map;
+
+public class AbiphoneContactHelper {
+
+ private static final AbiphoneContactHelper INSTANCE = new AbiphoneContactHelper();
+
+ public static AbiphoneContactHelper getInstance() {
+ return INSTANCE;
+ }
+
+ private String selectedWaypointName = "";
+ private long lastClick = 0L;
+
+ @SubscribeEvent
+ public void onItemTooltip(ItemTooltipEvent event) {
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return;
+ if (!Utils.getOpenChestName().equals("Contacts Directory")) return;
+
+ List<String> list = event.toolTip;
+ if (list == null) return;
+ if (list.isEmpty()) return;
+ String rawNpcName = event.itemStack.getDisplayName();
+ String npcName = StringUtils.cleanColour(rawNpcName);
+
+ JsonObject data = getJsonData(npcName);
+ if (data == null) return;
+
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactRequirements) {
+ if (data.has("requirement")) {
+ JsonArray requirements = data.get("requirement").getAsJsonArray();
+ if (requirements.size() > 0) {
+ list.add(" ");
+ list.add("§e§lRequirements:");
+
+ for (JsonElement requirementObject : requirements) {
+ String requirement = requirementObject.getAsString();
+ list.add(requirement);
+ }
+ }
+ }
+ }
+
+ if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactMarker) {
+ if (data.has("x")) {
+ if (selectedWaypointName.equals(npcName)) {
+ list.set(0, npcName + " §f- §aMarker set!");
+ }
+
+ list.add(" ");
+ if (selectedWaypointName.equals(npcName)) {
+ list.add("§eClick to remove the marker!");
+ } else {
+ list.add("§eClick to set a marker!");
+ }
+ list.add("§eShift-Click to teleport to the nearest waypoint!");
+ }
+ }
+ }
+
+ @SubscribeEvent
+ public void onStackClick(SlotClickEvent event) {
+ if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return;
+ if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactMarker) return;
+ if (!Utils.getOpenChestName().equals("Contacts Directory")) return;
+
+ ItemStack stack = event.slot.getStack();
+ if (stack == null || stack.getDisplayName() == null) return;
+
+ String rawNpcName = stack.getDisplayName();
+ String npcName = StringUtils.cleanColour(rawNpcName);
+
+ JsonObject data = getJsonData(npcName);
+ if (data == null) return;
+ if (!data.has("x")) return;
+
+ int x = data.get("x").getAsInt();
+ int y = data.get("y").getAsInt();
+ int z = data.get("z").getAsInt();
+
+ String rawIslandName = data.get("island").getAsString();
+ if (rawIslandName == null) return;
+
+ if (lastClick + 500 > System.currentTimeMillis()) return;
+ lastClick = System.currentTimeMillis();
+
+ boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
+ if (selectedWaypointName.equals(npcName) && !shiftPressed) {
+ NotEnoughUpdates.INSTANCE.navigation.untrackWaypoint();
+ selectedWaypointName = "";
+ } else {
+ trackWaypoint(rawNpcName, x, y, z, rawIslandName);
+ if (shiftPressed) {
+ NotEnoughUpdates.INSTANCE.navigation.useWarpCommand();
+ }
+ selectedWaypointName = npcName;
+ }
+ Utils.playPressSound();
+ }
+
+ private static void trackWaypoint(String rawNpcName, int x, int y, int z, String rawIslandName) {
+ JsonObject waypoint = new JsonObject();
+ waypoint.add("x", new JsonPrimitive(x));
+ waypoint.add("y", new JsonPrimitive(y));
+ waypoint.add("z", new JsonPrimitive(z));
+ waypoint.add("displayname", new JsonPrimitive(rawNpcName));
+ waypoint.add("island", new JsonPrimitive(rawIslandName));
+ waypoint.add("internalname", new JsonPrimitive("abiphone-contact-" + rawNpcName));
+
+ NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(waypoint);
+ }
+
+ private JsonObject getJsonData(String npcName) {
+ JsonObject abiphone = Constants.ABIPHONE;
+ if (abiphone == null) return null;
+
+ JsonObject contacts = abiphone.getAsJsonObject();
+ for (Map.Entry<String, JsonElement> entry : contacts.entrySet()) {
+ String repoName = entry.getKey();
+ if (repoName.equals(npcName)) {
+ return entry.getValue().getAsJsonObject();
+ }
+ }
+ return null;
+ }
+
+ public void resetMarker() {
+ selectedWaypointName = "";
+ }
+}