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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/*
* Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
* Copyright (C) 2021 cyoung06
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package kr.syeyoung.dungeonsguide.party;
import kr.syeyoung.dungeonsguide.SkyblockStatus;
import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig;
import kr.syeyoung.dungeonsguide.e;
import kr.syeyoung.dungeonsguide.features.AbstractFeature;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
import kr.syeyoung.dungeonsguide.features.GuiFeature;
import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import kr.syeyoung.dungeonsguide.utils.TextUtils;
import net.arikia.dev.drpc.DiscordRPC;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Mouse;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
public class PartyInviteViewer {
public static final PartyInviteViewer INSTANCE = new PartyInviteViewer();
@SubscribeEvent
public void onRender(RenderGameOverlayEvent.Post postRender) {
try {
if (postRender.type == RenderGameOverlayEvent.ElementType.TEXT) {
renderRequests(false);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
@SubscribeEvent
public void onRender(GuiScreenEvent.DrawScreenEvent.Post postRender) {
renderRequests(true);
}
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent clientTickEvent) {
try {
if (clientTickEvent.phase != TickEvent.Phase.START) return;
List<PartyJoinRequest> partyJoinRequestList = new ArrayList<>();
boolean isOnHypixel = e.getDungeonsGuide().getSkyblockStatus().isOnHypixel();
for (PartyJoinRequest joinRequest:joinRequests) {
if (joinRequest.getTtl() != -1) {
joinRequest.setTtl(joinRequest.getTtl() - 1);
if (joinRequest.getTtl() == 0 || !isOnHypixel) {
partyJoinRequestList.add(joinRequest);
}
} else if (!isOnHypixel){
DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.NO);
partyJoinRequestList.add(joinRequest);
} else if (joinRequest.getExpire() < System.currentTimeMillis()) {
partyJoinRequestList.add(joinRequest);
}
}
joinRequests.removeAll(partyJoinRequestList);
} catch (Throwable e) {e.printStackTrace();}
}
@SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGH)
public void onRender(GuiScreenEvent.MouseInputEvent.Pre mouseInput) {
int mouseX = Mouse.getX();
int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3;
for (PartyJoinRequest joinRequest:joinRequests) {
if (joinRequest.getWholeRect() != null && joinRequest.getWholeRect().contains(mouseX, mouseY)) {
mouseInput.setCanceled(true);
if (Mouse.getEventButton() == -1) return;
if (joinRequest.getReply() != null) {
joinRequests.remove(joinRequest);
return;
}
if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) {
joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT);
joinRequest.setTtl(60);
DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.YES);
return;
}
if (joinRequest.getDenyRect().contains(mouseX, mouseY)) {
joinRequest.setReply(PartyJoinRequest.Reply.DENY);
joinRequest.setTtl(60);
DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.NO);
return;
}
if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) {
joinRequest.setReply(PartyJoinRequest.Reply.IGNORE);
joinRequest.setTtl(60);
DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.IGNORE);
return;
}
return;
}
}
}
public CopyOnWriteArrayList<PartyJoinRequest> joinRequests = new CopyOnWriteArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(3);
public Map<String, Future<LoadedImage>> futureMap = new HashMap<>();
public Map<String, LoadedImage> imageMap = new HashMap<>();
public Future<LoadedImage> loadImage(String url) {
if (imageMap.containsKey(url)) return CompletableFuture.completedFuture(imageMap.get(url));
if (futureMap.containsKey(url)) return futureMap.get(url);
Future<LoadedImage> future = executorService.submit(() -> {
try {
URL urlObj = new URL(url);
HttpURLConnection huc = (HttpURLConnection) urlObj.openConnection();
huc.addRequestProperty("User-Agent", "DungeonsGuideMod (dungeonsguide.kro.kr, 1.0)");
BufferedImage bufferedImage = ImageIO.read(huc.getInputStream());
LoadedImage loadedImage = new LoadedImage();
loadedImage.setImage(bufferedImage);
imageMap.put(url, loadedImage);
return loadedImage;
} catch (Exception e) {
throw e;
}
});
futureMap.put(url,future);
return future;
}
public void renderRequests(boolean hover) {
try {
GlStateManager.pushMatrix();
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
GlStateManager.scale(1.0 / sr.getScaleFactor(), 1.0 / sr.getScaleFactor(), 1.0);
int height = 90;
int gap = 5;
int x = 5;
int y = 5;
for (PartyJoinRequest partyJoinRequest : joinRequests) {
renderRequest(partyJoinRequest, x, y, 350,height, hover);
y += height + gap;
}
GlStateManager.popMatrix();
GlStateManager.enableBlend();
} catch (Throwable t) {
t.printStackTrace();
}
}
public void renderRequest(PartyJoinRequest partyJoinRequest, int x, int y, int width, int height, boolean hover) {
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
int mouseX = Mouse.getX();
int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3;
partyJoinRequest.getWholeRect().setBounds(x,y,width,height);
GlStateManager.pushMatrix();
GlStateManager.translate(x,y,0);
Gui.drawRect(0, 0,width,height, 0xFF23272a);
Gui.drawRect(2, 2, width-2, height-2, 0XFF2c2f33);
{
String avatar = "https://cdn.discordapp.com/avatars/"+partyJoinRequest.getDiscordUser().userId+"/"+partyJoinRequest.getDiscordUser().avatar+".png";
Future<LoadedImage> loadedImageFuture = loadImage(avatar);
LoadedImage loadedImage = null;
if (loadedImageFuture.isDone()) {
try {
loadedImage = loadedImageFuture.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
if (loadedImage != null) {
if (loadedImage.getResourceLocation() == null) loadedImage.buildGLThings();
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
textureManager.bindTexture(loadedImage.getResourceLocation());
GlStateManager.pushAttrib();
GlStateManager.disableLighting();
GlStateManager.color(1, 1, 1, 1.0F);
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
Gui.drawModalRectWithCustomSizedTexture(7, 7, 0, 0, height-14, height-14,loadedImage.getImage().getWidth(),loadedImage.getImage().getHeight());
GlStateManager.enableLighting();
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
GlStateManager.popAttrib();
} else {
Gui.drawRect(7, 7, height - 7, height-7, 0xFF4E4E4E);
}
}
FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
GlStateManager.pushMatrix();
GlStateManager.translate(height +3,7, 0);
GlStateManager.pushMatrix();
GlStateManager.scale(3.0,3.0,1.0);
fr.drawString(partyJoinRequest.getDiscordUser().username, 0,0, 0xFFFFFFFF, true);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.translate(fr.getStringWidth(partyJoinRequest.getDiscordUser().username) * 3 + 1, (int)(fr.FONT_HEIGHT*1.5), 0);
fr.drawString("#"+partyJoinRequest.getDiscordUser().discriminator, 0,0,0xFFaaaaaa, true);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.translate(0, fr.FONT_HEIGHT * 3 + 5, 0);
GlStateManager.scale(1.0,1.0,1.0);
fr.drawString("wants to join your party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false);
GlStateManager.popMatrix();
GlStateManager.popMatrix();
if (partyJoinRequest.getReply() == null) {
GlStateManager.pushMatrix();
GlStateManager.translate(height + 3, height - 32, 0);
int widthForTheThing = (width - height) / 3;
GlStateManager.pushMatrix();
String text = "Accept";
partyJoinRequest.getAcceptRect().setBounds(x + height + 3, y + height - 25, widthForTheThing - 10, 25);
Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getAcceptRect().contains(mouseX, mouseY) ? 0xFF859DF0 : 0xFF7289da);
GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0);
GlStateManager.scale(2.0f, 2.0f, 1.0f);
fr.drawString(text, 0, 0, 0xFFFFFFFF);
GlStateManager.popMatrix();
GlStateManager.translate(widthForTheThing, 0, 0);
partyJoinRequest.getDenyRect().setBounds(x + height + 3 + widthForTheThing, y + height - 25, widthForTheThing - 10, 25);
Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getDenyRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5);
GlStateManager.pushMatrix();
text = "Deny";
GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0);
GlStateManager.scale(2.0f, 2.0f, 1.0f);
fr.drawString(text, 0, 0, 0xFFFFFFFF);
GlStateManager.popMatrix();
GlStateManager.translate(widthForTheThing, 0, 0);
partyJoinRequest.getIgnoreRect().setBounds(x + height + 3 + widthForTheThing + widthForTheThing, y + height - 25, widthForTheThing - 10, 25);
Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getIgnoreRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5); // AEC0CB
GlStateManager.pushMatrix();
text = "Ignore";
GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0);
GlStateManager.scale(2.0f, 2.0f, 1.0f);
fr.drawString(text, 0, 0, 0xFFFFFFFF);
GlStateManager.popMatrix();
GlStateManager.popMatrix();
} else {
GlStateManager.pushMatrix();
GlStateManager.translate(height + 3, height - 28, 0);
GlStateManager.scale(2.0f,2.0f,1.0f);
fr.drawString(partyJoinRequest.getReply().getPast()+" the invite.",0,0,0xFFFFFFFF);
GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
}
}
|