diff options
author | Sychic <47618543+Sychic@users.noreply.github.com> | 2021-01-24 20:55:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 20:55:37 -0500 |
commit | 956625ccd8926cafb2d9b2b25a695d648ee63900 (patch) | |
tree | 938df6b8f67a41e2c291b5425f54d3640b9b690a /src/main | |
parent | 9838bc712ff8c4614a658b1bde4dae913f03541f (diff) | |
parent | 314abc257edc9ce40020ece4960ebfe31b2bb47e (diff) | |
download | SkyblockMod-956625ccd8926cafb2d9b2b25a695d648ee63900.tar.gz SkyblockMod-956625ccd8926cafb2d9b2b25a695d648ee63900.tar.bz2 SkyblockMod-956625ccd8926cafb2d9b2b25a695d648ee63900.zip |
Merge pull request #1 from Sychic/Reparty
Reparty changes to work better with lag
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/me/Danker/DankersSkyblockMod.java | 172 | ||||
-rw-r--r-- | src/main/java/me/Danker/commands/RepartyCommand.java | 117 | ||||
-rw-r--r-- | src/main/java/me/Danker/handlers/ConfigHandler.java | 3 |
3 files changed, 213 insertions, 79 deletions
diff --git a/src/main/java/me/Danker/DankersSkyblockMod.java b/src/main/java/me/Danker/DankersSkyblockMod.java index 0bcecba..53b42af 100644 --- a/src/main/java/me/Danker/DankersSkyblockMod.java +++ b/src/main/java/me/Danker/DankersSkyblockMod.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.KeyBinding; +import net.minecraft.command.ICommand; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.item.EntityItemFrame; @@ -308,7 +309,6 @@ public class DankersSkyblockMod { ClientCommandHandler.instance.registerCommand(new LobbySkillsCommand()); ClientCommandHandler.instance.registerCommand(new DankerGuiCommand()); ClientCommandHandler.instance.registerCommand(new SkillTrackerCommand()); - ClientCommandHandler.instance.registerCommand(new RepartyCommand()); } @EventHandler @@ -317,26 +317,31 @@ public class DankersSkyblockMod { for(Package p : packages){ if(p.getName().startsWith("com.spiderfrog.gadgets") || p.getName().startsWith("com.spiderfrog.oldanimations")){ usingOAM = true; - break; } } System.out.println("OAM detection: " + usingOAM); - usingLabymod = Loader.isModLoaded("labymod"); System.out.println("LabyMod detection: " + usingLabymod); + + if(!ClientCommandHandler.instance.getCommands().containsKey("reparty")) { + ClientCommandHandler.instance.registerCommand(new RepartyCommand()); + } else if (ConfigHandler.getBoolean("commands", "reparty")) { + for(Map.Entry<String, ICommand> entry : ClientCommandHandler.instance.getCommands().entrySet()) { + if (entry.getKey().equals("reparty") || entry.getKey().equals("rp")) { + entry.setValue(new RepartyCommand()); + } + } + } + } @SubscribeEvent public void onGuiOpenEvent(GuiOpenEvent event){ if(event.gui instanceof GuiMainMenu && usingOAM && !OAMWarning){ - System.out.println("Gui opened: Instance of GuiMainMenu."); if(!(event.gui instanceof WarningGui)){ - System.out.println("No instance of WarningGui"); event.gui = new WarningGuiRedirect(new WarningGui()); OAMWarning = true; - }else{ - System.out.println("Instance of WarningGui"); } } } @@ -426,38 +431,127 @@ public class DankersSkyblockMod { } // Reparty command - if (System.currentTimeMillis() / 1000 - RepartyCommand.callTime <= 5) { - if (!(message.contains("----") || message.contains("disbanded") || message.contains("seconds to accept") || message.contains("●") || message.contains("Party Members") || message.contains("Couldn't find a player") || message.contains("cannot invite that player") || message.length() == 0)) { - return; - } - - EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - - Pattern party_start_pattern = Pattern.compile("^Party Members \\((\\d+)\\)$"); - Pattern leader_pattern = Pattern.compile("^Party Leader: (?:\\[.+?] )?(\\w+) ●$"); - Pattern members_pattern = Pattern.compile(" (?:\\[.+?] )?(\\w+) ●"); - Matcher party_start = party_start_pattern.matcher(message); - Matcher leader = leader_pattern.matcher(message); - Matcher members = members_pattern.matcher(message); - - if (party_start.matches() && Integer.parseInt(party_start.group(1)) == 1) { - player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "You cannot reparty yourself.")); - } - else if (leader.matches() && !(leader.group(1).equals(player.getName()))) { - player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "You are not party leader.")); - } - else if (message.contains("Couldn't find a player") || message.contains("You cannot invite that player")) { - RepartyCommand.repartyFailList.add(RepartyCommand.currentMember); - } - else { - while (members.find()) { - String partyMember = members.group(1); - if (!partyMember.equals(player.getName())) { - RepartyCommand.party.add(partyMember); - } - } - } - event.setCanceled(true); + // Getting party + if (RepartyCommand.gettingParty) { + if (message.contains("-----")) { + switch(RepartyCommand.Delimiter) { + case 0: + System.out.println("Get Party Delimiter Cancelled"); + RepartyCommand.Delimiter++; + event.setCanceled(true); + return; + case 1: + System.out.println("Done querying party"); + RepartyCommand.gettingParty = false; + RepartyCommand.Delimiter = 0; + event.setCanceled(true); + return; + } + }else if (message.startsWith("Party M") || message.startsWith("Party Leader")){ + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + + Pattern party_start_pattern = Pattern.compile("^Party Members \\((\\d+)\\)$"); + Pattern leader_pattern = Pattern.compile("^Party Leader: (?:\\[.+?] )?(\\w+) ●$"); + Pattern members_pattern = Pattern.compile(" (?:\\[.+?] )?(\\w+) ●"); + Matcher party_start = party_start_pattern.matcher(message); + Matcher leader = leader_pattern.matcher(message); + Matcher members = members_pattern.matcher(message); + + if (party_start.matches() && Integer.parseInt(party_start.group(1)) == 1) { + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "You cannot reparty yourself.")); + RepartyCommand.partyThread.interrupt(); + } else if (leader.matches() && !(leader.group(1).equals(player.getName()))) { + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "You are not party leader.")); + RepartyCommand.partyThread.interrupt(); + } else { + while (members.find()) { + String partyMember = members.group(1); + if (!partyMember.equals(player.getName())) { + RepartyCommand.party.add(partyMember); + System.out.println(partyMember); + } + } + } + event.setCanceled(true); + return; + } + } + // Disbanding party + if (RepartyCommand.disbanding) { + if (message.contains("-----")) { + switch (RepartyCommand.Delimiter) { + case 0: + System.out.println("Disband Delimiter Cancelled"); + RepartyCommand.Delimiter++; + event.setCanceled(true); + return; + case 1: + System.out.println("Done disbanding"); + RepartyCommand.disbanding = false; + RepartyCommand.Delimiter = 0; + event.setCanceled(true); + return; + } + } else if (message.endsWith("has disbanded the party!")) { + event.setCanceled(true); + return; + } + } + // Inviting + if (RepartyCommand.inviting) { + if (message.contains("-----")) { + switch (RepartyCommand.Delimiter) { + case 1: + event.setCanceled(true); + RepartyCommand.Delimiter = 0; + System.out.println("Player Invited!"); + RepartyCommand.inviting = false; + return; + case 0: + RepartyCommand.Delimiter++; + event.setCanceled(true); + return; + } + } else if (message.endsWith(" to the party! They have 60 seconds to accept.")) { + Pattern invitePattern = Pattern.compile("(?:(?:\\[.+?] )?(?:\\w+) invited )(?:\\[.+?] )?(\\w+)"); + Matcher invitee = invitePattern.matcher(message); + if (invitee.find()) { + System.out.println("" + invitee.group(1) + ": " + RepartyCommand.repartyFailList.remove(invitee.group(1))); + } + event.setCanceled(true); + return; + } else if (message.contains("Couldn't find a player") || message.contains("You cannot invite that player")) { + event.setCanceled(true); + return; + } + } + // Fail Inviting + if (RepartyCommand.failInviting) { + if (message.contains("-----")) { + switch (RepartyCommand.Delimiter) { + case 1: + event.setCanceled(true); + RepartyCommand.Delimiter = 0; + System.out.println("Player Invited!"); + RepartyCommand.inviting = false; + return; + case 0: + RepartyCommand.Delimiter++; + event.setCanceled(true); + return; + } + } else if (message.endsWith(" to the party! They have 60 seconds to accept.")) { + Pattern invitePattern = Pattern.compile("(?:(?:\\[.+?] )?(?:\\w+) invited )(?:\\[.+?] )?(\\w+)"); + Matcher invitee = invitePattern.matcher(message); + if (invitee.find()) { + System.out.println("" + invitee.group(1) + ": " + RepartyCommand.repartyFailList.remove(invitee.group(1))); + } + event.setCanceled(true); + return; + } else if (message.contains("Couldn't find a player") || message.contains("You cannot invite that player")) { + event.setCanceled(true); + return; + } } if (!Utils.inSkyblock) return; diff --git a/src/main/java/me/Danker/commands/RepartyCommand.java b/src/main/java/me/Danker/commands/RepartyCommand.java index d3bf9e4..623ebf7 100644 --- a/src/main/java/me/Danker/commands/RepartyCommand.java +++ b/src/main/java/me/Danker/commands/RepartyCommand.java @@ -1,34 +1,29 @@ package me.Danker.commands; import me.Danker.DankersSkyblockMod; -import me.Danker.utils.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiNewChat; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.*; import net.minecraft.util.ChatComponentText; -import net.minecraftforge.client.event.*; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.*; -import java.text.NumberFormat; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class RepartyCommand extends CommandBase implements ICommand { - public static double callTime = 0; - public static boolean inviteFailed = false; - public static String currentMember; + public static boolean gettingParty = false; + public static int Delimiter = 0; + public static boolean disbanding = false; + public static boolean inviting = false; + public static boolean failInviting = false; public static List<String> party = new ArrayList<>(); public static List<String> repartyFailList = new ArrayList<>(); + public static Thread partyThread = null; @Override public String getCommandName() { @@ -52,47 +47,89 @@ public class RepartyCommand extends CommandBase implements ICommand { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if (args.length > 0 && (args[0].startsWith("fail") || args[0].equals("f"))) { + partyThread = new Thread(() -> { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI(); + + + try { + player.sendChatMessage("/p " + String.join(" ", repartyFailList)); + String members = String.join(EnumChatFormatting.WHITE + "\n- " + EnumChatFormatting.YELLOW, repartyFailList); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n" + + DankersSkyblockMod.MAIN_COLOUR + "Partying:" + EnumChatFormatting.WHITE + "\n- " + + EnumChatFormatting.YELLOW + members + "\n" + + DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------")); + failInviting = true; + while (failInviting) { + Thread.sleep(10); + } + if (repartyFailList.size() > 0) { + String repartyFails = String.join("\n- " + EnumChatFormatting.RED, repartyFailList); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n" + + DankersSkyblockMod.MAIN_COLOUR + "Failed to invite:" + EnumChatFormatting.WHITE + "\n- " + + EnumChatFormatting.RED + repartyFails + "\n" + + DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------")); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + partyThread.start(); + + return; + } + party.clear(); repartyFailList.clear(); // MULTI THREAD DRIFTING - new Thread(() -> { + partyThread = new Thread(() -> { EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - RepartyCommand.callTime = (double) System.currentTimeMillis() / 1000; - + + try { - Thread.sleep(210); - player.sendChatMessage("/p list"); - System.out.println("Grabbing the party members..."); - Thread.sleep(550); - if (RepartyCommand.party.size() == 0) return; - + player.sendChatMessage("/pl"); + gettingParty = true; + while (gettingParty) { + Thread.sleep(10); + } + if (party.size() == 0) return; player.sendChatMessage("/p disband"); - Thread.sleep(210); - - String members = String.join(EnumChatFormatting.WHITE + "\n- " + EnumChatFormatting.GOLD, RepartyCommand.party); + disbanding = true; + while (disbanding) { + Thread.sleep(10); + } + String members = String.join(EnumChatFormatting.WHITE + "\n- " + EnumChatFormatting.YELLOW, RepartyCommand.party); player.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n" + - DankersSkyblockMod.MAIN_COLOUR + "Repartying:" + EnumChatFormatting.WHITE + "\n- " + - EnumChatFormatting.GOLD + members + "\n" + - DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n")); - - for (int i = 0; i < RepartyCommand.party.size(); i++) { - RepartyCommand.currentMember = RepartyCommand.party.get(i); - player.sendChatMessage("/p " + RepartyCommand.currentMember); - Thread.sleep(400); + DankersSkyblockMod.MAIN_COLOUR + "Repartying:" + EnumChatFormatting.WHITE + "\n- " + + EnumChatFormatting.YELLOW + members + "\n" + + DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------")); + repartyFailList = new ArrayList<>(party); + for (String invitee : party) { + player.sendChatMessage("/p " + invitee); + inviting = true; + while (inviting) { + Thread.sleep(10); + } + Thread.sleep(100); } - - if (RepartyCommand.repartyFailList.size() > 0) { - Thread.sleep(300); - String failedMembers = String.join(EnumChatFormatting.WHITE + "\n- " + EnumChatFormatting.GOLD, RepartyCommand.repartyFailList); + while (inviting) { + Thread.sleep(10); + } + if (repartyFailList.size() > 0) { + String repartyFails = String.join("\n- " + EnumChatFormatting.RED, repartyFailList); player.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n" + - DankersSkyblockMod.ERROR_COLOUR + "Unable to Invite:" + EnumChatFormatting.WHITE + "\n- " + - EnumChatFormatting.GOLD + failedMembers + "\n" + - DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------\n")); + DankersSkyblockMod.MAIN_COLOUR + "Failed to invite:" + EnumChatFormatting.WHITE + "\n- " + + EnumChatFormatting.RED + repartyFails + "\n" + + DankersSkyblockMod.DELIMITER_COLOUR + "-----------------------------")); } } catch (InterruptedException e) { e.printStackTrace(); } - }).start(); + }); + + partyThread.start(); } }
\ No newline at end of file diff --git a/src/main/java/me/Danker/handlers/ConfigHandler.java b/src/main/java/me/Danker/handlers/ConfigHandler.java index 9f11aac..9038218 100644 --- a/src/main/java/me/Danker/handlers/ConfigHandler.java +++ b/src/main/java/me/Danker/handlers/ConfigHandler.java @@ -452,6 +452,9 @@ public class ConfigHandler { if (!hasKey("colors", "pet80To89")) writeIntConfig("colors", "pet80To89", 0x5C1F35); // idk weird magenta if (!hasKey("colors", "pet90To99")) writeIntConfig("colors", "pet90To99", 0x9E794E); // Brown if (!hasKey("colors", "pet100")) writeIntConfig("colors", "pet100", 0xF2D249); // Gold + + //Commands + if (!hasKey("commands", "reparty")) writeBooleanConfig("commands", "reparty", false); ToggleCommand.gpartyToggled = getBoolean("toggles", "GParty"); ToggleCommand.coordsToggled = getBoolean("toggles", "Coords"); |