1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/*
* 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.autosubscribe.NEUAutoSubscribe;
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;
@NEUAutoSubscribe
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 = "";
}
}
|