diff options
Diffstat (limited to 'src/main/java/kr')
4 files changed, 168 insertions, 37 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java index 0d11a8f2..fd72e758 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/RichPresenceManager.java @@ -36,7 +36,7 @@ public class RichPresenceManager implements Runnable { }).setJoinRequestEventHandler(request -> { PartyJoinRequest partyJoinRequest = new PartyJoinRequest(); partyJoinRequest.setDiscordUser(request); - partyJoinRequest.setTime(Instant.now()); + partyJoinRequest.setExpire(System.currentTimeMillis() + 30000); PartyInviteViewer.INSTANCE.joinRequests.add(partyJoinRequest); }).setJoinGameEventHandler(joinSecret -> { @@ -61,7 +61,7 @@ public class RichPresenceManager implements Runnable { } else { DiscordRichPresence.Builder richPresenceBuilder = new DiscordRichPresence.Builder(skyblockStatus.getDungeonName()); richPresenceBuilder.setBigImage("mort", "mort") - .setParty(PartyManager.INSTANCE.getPartyID(), 1, 5); + .setParty(PartyManager.INSTANCE.getPartyID(), PartyManager.INSTANCE.getMemberCount(), 5); if (skyblockStatus.getContext() != null) { long init = skyblockStatus.getContext().getInit(); @@ -99,7 +99,7 @@ public class RichPresenceManager implements Runnable { lastLoc = skyblockStatus.getDungeonName()+""; } updatePresence(); - Thread.sleep(1000L); + Thread.sleep(300L); } catch (Exception e) {e.printStackTrace();} } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java index efaa471f..845b7308 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java @@ -7,16 +7,20 @@ 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.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; @@ -24,8 +28,10 @@ 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 { @@ -51,35 +57,39 @@ public class PartyInviteViewer { public void onTick(TickEvent.ClientTickEvent clientTickEvent) { try { if (clientTickEvent.phase != TickEvent.Phase.START) return; - Iterator<PartyJoinRequest> partyJoinRequestIterator = joinRequests.iterator(); - while (partyJoinRequestIterator.hasNext()) { - PartyJoinRequest joinRequest = partyJoinRequestIterator.next(); + 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) { - partyJoinRequestIterator.remove(); + 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 + @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; - Iterator<PartyJoinRequest> requestIter = joinRequests.iterator(); - while (requestIter.hasNext()) { - PartyJoinRequest joinRequest = requestIter.next(); + 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) { - requestIter.remove(); + joinRequests.remove(joinRequest); return; } @@ -120,11 +130,18 @@ public class PartyInviteViewer { if (imageMap.containsKey(url)) return CompletableFuture.completedFuture(imageMap.get(url)); if (futureMap.containsKey(url)) return futureMap.get(url); Future<LoadedImage> future = executorService.submit(() -> { - BufferedImage bufferedImage = ImageIO.read(new URL(url)); - LoadedImage loadedImage = new LoadedImage(); - loadedImage.setImage(bufferedImage); - imageMap.put(url, loadedImage); - return loadedImage; + 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; @@ -180,7 +197,20 @@ public class PartyInviteViewer { 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); } @@ -202,10 +232,10 @@ public class PartyInviteViewer { 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!", 0,0,0xFFFFFFFF,false); + fr.drawString("wants to join your party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false); GlStateManager.popMatrix(); GlStateManager.popMatrix(); - if (partyJoinRequest == null || partyJoinRequest.getReply() == null) { + if (partyJoinRequest.getReply() == null) { GlStateManager.pushMatrix(); GlStateManager.translate(height + 3, height - 32, 0); int widthForTheThing = (width - height) / 3; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java index 4b11cc94..799f79c3 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java @@ -12,7 +12,7 @@ import java.time.Instant; @Data public class PartyJoinRequest { private DiscordUser discordUser; - private Instant time; + private long expire; private Rectangle wholeRect = new Rectangle(); private Rectangle acceptRect = new Rectangle(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java index a170568c..36ce815f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java @@ -14,6 +14,7 @@ import kr.syeyoung.dungeonsguide.utils.TextUtils; import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.json.JSONArray; @@ -41,6 +42,7 @@ public class PartyManager implements StompMessageHandler { private boolean allowAskToJoin = false; @Getter private boolean canInvite = false; + private int invitedDash =0; public void toggleAllowAskToJoin() { if (canInvite) allowAskToJoin = !allowAskToJoin; @@ -49,6 +51,10 @@ public class PartyManager implements StompMessageHandler { } } + public int getMemberCount() { + return Math.max(1, members.size()); + } + public void setPartyID(String partyID) { if (this.partyID != null && partyID == null) { JSONObject object = new JSONObject(); @@ -59,6 +65,7 @@ public class PartyManager implements StompMessageHandler { if (partyID != null && !partyID.equals(this.partyID)) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); + invitedDash = 1; } else { canInvite = true; allowAskToJoin = false; @@ -92,26 +99,28 @@ public class PartyManager implements StompMessageHandler { RichPresenceManager.INSTANCE.updatePresence(); } - private boolean partyJoin = false; + private int partyJoin =0; private Set<String> members = new HashSet<>(); private Map<String, Long> recentlyJoined = new HashMap<>(); - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGHEST) public void onMessage(ClientChatReceivedEvent chatReceivedEvent) { if (chatReceivedEvent.type == 2) return; String str = chatReceivedEvent.message.getFormattedText(); + System.out.println(str); + if (str.startsWith("§eYou have joined ")) { - setPartyID(null); members.clear(); String strs[] = TextUtils.stripColor(str).split(" "); for (String s : strs) { if (s.endsWith("'s")) { members.add(s.substring(0, s.indexOf("'s"))); - partyJoin = true; break; } } + members.add(Minecraft.getMinecraft().getSession().getUsername()); + partyJoin = 100; } else if (str.startsWith("§eYou'll be partying with: ")) { String[] players = TextUtils.stripColor(str.substring(27)).split(" "); for (String player : players) { @@ -119,9 +128,11 @@ public class PartyManager implements StompMessageHandler { members.add(player); } } else if (str.equals("§9§m-----------------------------§r")) { - if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} - if (partyJoin) { - partyJoin = false; + if ((checkPlayer > 0 || partyJoin > 0) && partyJoin != 100) { + chatReceivedEvent.setCanceled(true); + } + if (partyJoin == 2 || partyJoin == 100) { + partyJoin = 0; // REQ PARTY JOIN JSONArray jsonArray = new JSONArray(); @@ -133,41 +144,73 @@ public class PartyManager implements StompMessageHandler { StompInterface stompInterface = e.getDungeonsGuide().getStompConnection(); stompInterface.send(new StompPayload().payload(object.toString()).header("destination", "/app/party.join")); } - if (checkPlayer == 2) { + if (checkPlayer == 3) { checkPlayer = 0; String playerName = theObject.getString("player"); String token = theObject.getString("token"); - Long loong = recentlyJoined.get(playerName); if (!members.contains(playerName)) { e.getDungeonsGuide().getStompConnection().send(new StompPayload().payload(new JSONObject().put("status", "failure").put("token", token).toString()).header("destination", "/app/party.check.resp")); - } else if (loong > System.currentTimeMillis() - 2000){ + } else { e.getDungeonsGuide().getStompConnection().send(new StompPayload().payload(new JSONObject().put("status", "success").put("token", token).toString()).header("destination", "/app/party.check.resp")); } } + if (invitedDash > 0) { + invitedDash++; + chatReceivedEvent.setCanceled(true); + } + if (invitedDash == 3) invitedDash = 0; } else if (str.endsWith("§ejoined the party.§r")) { String asd = null; for (String s : TextUtils.stripColor(str).split(" ")) { if (s.startsWith("[")) continue; asd = s; + break; } if (asd != null) - recentlyJoined.put(asd, System.currentTimeMillis()); + members.add(asd); + } else if (str.contains("§r§ejoined the dungeon group! (§r§b")) { + String username = TextUtils.stripColor(str).split(" ")[3]; + if (username.equalsIgnoreCase(Minecraft.getMinecraft().getSession().getUsername())) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); + partyJoin = 1; + } else { + members.add(username); + } + } else if (str.endsWith("§ehas been removed from the party.§r") + || str.endsWith("§ehas left the party.§r")) { + String asd = null; + for (String s : TextUtils.stripColor(str).split(" ")) { + if (s.startsWith("[")) continue; + asd = s; + break; + } + if (asd != null) + members.remove(asd); } else if ((str.equals("§eYou left the party.§r") - || str.equals("§cThe party was disbanded because all invites expired and the party was empty§r")) - ){ + || str.startsWith("§cThe party was disbanded") + || str.endsWith("§ehas disbanded the party!§r")) + ) { + members.clear(); setPartyID(null); } else if (str.startsWith("§6Party Members ")) { - if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} - partyJoin = true; + if (checkPlayer > 0|| partyJoin > 0) { + chatReceivedEvent.setCanceled(true); + } + if (partyJoin == 1) partyJoin = 2; + if (checkPlayer == 2) checkPlayer = 3; members.clear(); } else if (str.startsWith("§cYou are not currently in a party.§r")) { members.clear(); + partyJoin = 0; setPartyID(null); + } else if (TextUtils.stripColor(str).trim().isEmpty()) { + if ((checkPlayer > 0|| partyJoin > 0) && partyJoin != 100) {chatReceivedEvent.setCanceled(true);} } else if (str.startsWith("§cYou are not in a party")) { members.clear(); + partyJoin = 0; setPartyID(null); } else if (str.startsWith("§eParty ") && str.contains(":")) { - if (checkPlayer == 2) {chatReceivedEvent.setCanceled(true);} + if (checkPlayer > 0|| partyJoin > 0) {chatReceivedEvent.setCanceled(true);} String playerNames = TextUtils.stripColor(str.split(":")[1]); for (String s : playerNames.split(" ")) { if (s.isEmpty()) continue; @@ -176,12 +219,14 @@ public class PartyManager implements StompMessageHandler { members.add(s); } } else if (str.equals("§cYou are not allowed to invite players.§r")) { + if (invitedDash > 0) chatReceivedEvent.setCanceled(true); canInvite = false; allowAskToJoin = false; askToJoinSecret = ""; RichPresenceManager.INSTANCE.updatePresence(); } else if (str.equals("§cCouldn't find a player with that name!§r")) { canInvite = true; + if (invitedDash > 0) chatReceivedEvent.setCanceled(true); } else if (str.equals("§cYou cannot invite that player since they're not online.")) { canInvite = true; } else if (str.endsWith("§aenabled All Invite§r")) { @@ -192,6 +237,61 @@ public class PartyManager implements StompMessageHandler { askToJoinSecret = ""; RichPresenceManager.INSTANCE.updatePresence(); Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); + invitedDash = 1; + } else if (str.endsWith("§r§eto Party Moderator§r")) { + // §b[MVP§r§f+§r§b] apotato321§r§e has promoted §r§a[VIP§r§6+§r§a] syeyoung §r§eto Party Moderator§r + String[] thetext = TextUtils.stripColor(str).split(" "); + int seenThings = 0; + for (String s : thetext) { + if (s.equals("has") && seenThings == 0) seenThings = 1; + else if (s.equals("promoted") && seenThings == 1) seenThings = 2; + else if (s.equals("[")) continue; + else if (seenThings == 2) { + if (s.equals(Minecraft.getMinecraft().getSession().getUsername())) { + canInvite = true; + } else { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); + invitedDash = 1; + } + } else { + seenThings = 0; + } + } + } else if (str.startsWith("§eThe party was transferred to ")) { + //§eThe party was transferred to §r§b[MVP§r§f+§r§b] apotato321 §r§eby §r§a[VIP§r§6+§r§a] syeyoung§r + String[] thetext = TextUtils.stripColor(str.substring(31)).split(" "); + String asd = null; + for (String s : thetext) { + if (s.startsWith("[")) continue; + asd = s; + break; + } + if (asd != null && Minecraft.getMinecraft().getSession().getUsername().equalsIgnoreCase(asd)) { + canInvite = true; + } else { + + Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); + invitedDash = 1; + } + } else if (str.endsWith("§eto Party Leader§r")) { + // §a[VIP§r§6+§r§a] syeyoung§r§e has promoted §r§b[MVP§r§f+§r§b] apotato321 §r§eto Party Leader§r + String[] thetext = TextUtils.stripColor(str).split(" "); + int seenThings = 0; + for (String s : thetext) { + if (s.equals("has") && seenThings == 0) seenThings = 1; + else if (s.equals("promoted") && seenThings == 1) seenThings = 2; + else if (s.equals("[")) continue; + else if (seenThings == 2) { + if (s.equals(Minecraft.getMinecraft().getSession().getUsername())) { + canInvite = true; + } else { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/p invite -"); + invitedDash = 1; + } + } else { + seenThings = 0; + } + } } } @SubscribeEvent @@ -207,6 +307,7 @@ public class PartyManager implements StompMessageHandler { @SubscribeEvent public void onHypixelJoin(HypixelJoinedEvent skyblockJoinedEvent) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/pl"); + partyJoin = 1; } private int checkPlayer = 0; |