From bb2c2a07668864ca58934d3aed451c20c65fae46 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 4 May 2022 19:19:18 +0200 Subject: [PATCH 01/34] message when you already reported a player (cherry picked from commit 53b8922d30d49d6d0adb465b0644921f21179d0e) --- .../fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java index 5391dc9f..8dc654ed 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java @@ -189,6 +189,8 @@ private static boolean checkAndSendReportSuggestion(@Nullable String messageSend if (isSenderMyself) { new DelayedTask(() -> addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "\u2716" + EnumChatFormatting.GRAY + " This player has already been reported during this game")), 0); return true; + } else { + new DelayedTask(() -> addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "\u2714" + EnumChatFormatting.GRAY + " You already reported this player during this game")), 0); } } From 9f76d6d10105bfae3f2fef161e94721996e6464c Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Sun, 8 May 2022 01:34:10 +0200 Subject: [PATCH 02/34] displays amount of players in the tablist at the top (cherry picked from commit 521ff111f5ee7e4cbeb2b95bd5ea997fc62ad78f) --- .../asm/hooks/GuiPlayerTabOverlayHook.java | 13 +++++++++++++ .../GuiPlayerTabOverlayTransformer.java | 14 +++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java index 5ef434ae..834c17a3 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java @@ -6,6 +6,9 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.util.EnumChatFormatting; +import java.util.ArrayList; +import java.util.List; + @SuppressWarnings("unused") public class GuiPlayerTabOverlayHook { @@ -24,6 +27,16 @@ public static void renderFinals(int playersFinals, int x, int y) { fontRendererObj.drawStringWithShadow(s1, (float) (x - fontRendererObj.getStringWidth(s1) - FK_SCORE_WIDTH), (float) y, 16777215); } + public static List addPlayerCountinHeader(List listIn) { + if (listIn != null) { + final ArrayList list = new ArrayList<>(listIn); + int i = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().size(); + list.add(0, EnumChatFormatting.GREEN + "Player" + (i < 2 ? "" : "s") + ": " + EnumChatFormatting.GOLD + i); + return list; + } + return null; + } + public static EnumChatFormatting getColoredHP(int healthPoints) { if (ConfigHandler.useColoredScores) { diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiPlayerTabOverlayTransformer.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiPlayerTabOverlayTransformer.java index 1c32dd38..04fd26f1 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiPlayerTabOverlayTransformer.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiPlayerTabOverlayTransformer.java @@ -20,7 +20,7 @@ public String getTargetClassName() { public ClassNode transform(ClassNode classNode, InjectionStatus status) { boolean isPatcherLoaded = true; - int injectionPoints = 5; + int injectionPoints = 6; status.setInjectionPoints(injectionPoints); try { @@ -34,6 +34,9 @@ public ClassNode transform(ClassNode classNode, InjectionStatus status) { for (MethodNode methodNode : classNode.methods) { if (methodNode.name.equals(ASMLoadingPlugin.isObf ? "a" : "renderPlayerlist") && methodNode.desc.equals(ASMLoadingPlugin.isObf ? "(ILauo;Lauk;)V" : "(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")) { + + boolean foundListFormattedStringToWidth = false; + for (AbstractInsnNode insnNode : methodNode.instructions.toArray()) { if (insnNode.getOpcode() == BIPUSH && insnNode instanceof IntInsnNode && ((IntInsnNode) insnNode).operand == 20) { @@ -65,6 +68,15 @@ public ClassNode transform(ClassNode classNode, InjectionStatus status) { } } + if (!foundListFormattedStringToWidth && insnNode instanceof MethodInsnNode && insnNode.getOpcode() == INVOKEVIRTUAL && + ((MethodInsnNode) insnNode).owner.equals(ASMLoadingPlugin.isObf ? "avn" : "net/minecraft/client/gui/FontRenderer") + && ((MethodInsnNode) insnNode).name.equals(ASMLoadingPlugin.isObf ? "c" : "listFormattedStringToWidth") + && ((MethodInsnNode) insnNode).desc.equals("(Ljava/lang/String;I)Ljava/util/List;")) { + foundListFormattedStringToWidth = true; + methodNode.instructions.insertBefore(insnNode.getNext(), new MethodInsnNode(INVOKESTATIC, "fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook", "addPlayerCountinHeader", "(Ljava/util/List;)Ljava/util/List;", false)); + status.addInjection(); + } + } } From 7aa41cccde0af4f222ee2e4500fa163941538ce8 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Sun, 8 May 2022 22:02:06 +0200 Subject: [PATCH 03/34] stop preventing certain non dangerous hotkey (cherry picked from commit 3ac0da74b733e1cb3ff79ccf9c1e81f67c2bbc0c) --- .../megawallsenhancementsmod/asm/hooks/GuiContainerHook.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java index 746478d4..d3ccdccd 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java @@ -69,6 +69,11 @@ private static boolean isItemImportant(Slot theSlot, int i) { if (theSlot.inventory instanceof InventoryPlayer) { return false; } + final ItemStack itemstackInSlot = theSlot.inventory.getStackInSlot(theSlot.slotNumber); + /*If the targeted slot for the hotkey has an item, it won't hotkey the item in hotbar in the inventory in vanilla*/ + if (itemstackInSlot != null) { + return false; + } final EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; final ItemStack itemStack = thePlayer.inventory.mainInventory[i]; if (itemStack != null && itemStackHasCustomDisplayName(itemStack)) { From f787245316ce1a8269dbc77f10017355b6199f04 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Thu, 12 May 2022 17:37:51 +0200 Subject: [PATCH 04/34] don't show amount of players in tablist when < 2 (cherry picked from commit 4840d9c1976a7122ba6b550d2b96d845e7006550) --- .../asm/hooks/GuiPlayerTabOverlayHook.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java index 834c17a3..0192e044 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook.java @@ -29,9 +29,12 @@ public static void renderFinals(int playersFinals, int x, int y) { public static List addPlayerCountinHeader(List listIn) { if (listIn != null) { - final ArrayList list = new ArrayList<>(listIn); int i = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().size(); - list.add(0, EnumChatFormatting.GREEN + "Player" + (i < 2 ? "" : "s") + ": " + EnumChatFormatting.GOLD + i); + if (i < 2) { + return listIn; + } + final ArrayList list = new ArrayList<>(listIn); + list.add(0, EnumChatFormatting.GREEN + "Players: " + EnumChatFormatting.GOLD + i); return list; } return null; From 42cba0ff13b1ed98ac59caecf28e6b5281328cb1 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 17 May 2022 00:58:37 +0200 Subject: [PATCH 05/34] keybind to get a new nick (cherry picked from commit c6e3a81fba5aa4b80ea618c6962feb7c71f6a41f) --- .../MegaWallsEnhancementsMod.java | 2 + .../asm/hooks/GuiScreenBookHook.java | 45 +++++++++++++++++-- .../GuiScreenBookTransformer.java | 42 +++++++++++++++-- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java index 6dbbba95..6154d08e 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java @@ -25,6 +25,7 @@ public class MegaWallsEnhancementsMod { public static final String modName = "MegaWallsEnhancements"; public static final String version = "1.8"; public static final KeyBinding toggleDroppedItemLimit = new KeyBinding("Toggle dropped item limit", 0, "MegaWallsEnhancements"); + public static final KeyBinding newNickKey = new KeyBinding("New Random Nick", 0, "MegaWallsEnhancements"); public static File configurationFile; @EventHandler @@ -39,6 +40,7 @@ public void init(FMLInitializationEvent event) { FKCounterMod.init(); ClientRegistry.registerKeyBinding(toggleDroppedItemLimit); + ClientRegistry.registerKeyBinding(newNickKey); MinecraftForge.EVENT_BUS.register(new GuiManager()); MinecraftForge.EVENT_BUS.register(new ChatEvents()); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook.java index 9e103019..3543e983 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook.java @@ -1,11 +1,14 @@ package fr.alexdoru.megawallsenhancementsmod.asm.hooks; +import fr.alexdoru.megawallsenhancementsmod.MegaWallsEnhancementsMod; import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; +import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import org.lwjgl.input.Keyboard; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -13,9 +16,14 @@ @SuppressWarnings("unused") public class GuiScreenBookHook { - private static final Pattern nickSuccessPattern = Pattern.compile("You have finished setting up your nickname!\\s*When you go into a game, you will be nicked as\\s*(?:|\\[(?:MV|VI)P\\+?\\+?\\] )(\\w{2,16})"); + private static boolean isOnNickGenerationPage = false; + private static long lastTimeClicked; + + private static final Pattern nickSuccessPagePattern = Pattern.compile("You have finished setting up your nickname!\\s*When you go into a game, you will be nicked as\\s*(?:|\\[(?:MV|VI)P\\+?\\+?\\] )(\\w{2,16})"); + private static final Pattern nickGenerationPagePattern = Pattern.compile("We've generated a random username for you:\\s*\\w{2,16}"); public static void onBookInit(ItemStack book) { + isOnNickGenerationPage = false; if (book.hasTagCompound()) { NBTTagCompound nbttagcompound = book.getTagCompound(); NBTTagList bookPages = nbttagcompound.getTagList("pages", 8); @@ -27,18 +35,47 @@ public static void onBookInit(ItemStack book) { } for (int i = 0; i < bookTotalPages; i++) { String pagetext = EnumChatFormatting.getTextWithoutFormattingCodes(IChatComponent.Serializer.jsonToComponent(bookPages.getStringTagAt(i)).getUnformattedText().replace("\n", "")); - final Matcher matcher2 = nickSuccessPattern.matcher(pagetext); - if (matcher2.find()) { - final String newNick = matcher2.group(1); + Matcher matcher = nickSuccessPagePattern.matcher(pagetext); + if (matcher.find()) { + final String newNick = matcher.group(1); if (newNick != null && !newNick.equals("")) { ConfigHandler.hypixelNick = newNick; ConfigHandler.saveConfig(); return; } } + matcher = nickGenerationPagePattern.matcher(pagetext); + if (matcher.find()) { + isOnNickGenerationPage = true; + return; + } } } } } + public static void onKeyTyped(int keycode) { + if (isOnNickGenerationPage && System.currentTimeMillis() - lastTimeClicked > 500 && MegaWallsEnhancementsMod.newNickKey.getKeyCode() != 0 && MegaWallsEnhancementsMod.newNickKey.getKeyCode() == keycode) { + lastTimeClicked = System.currentTimeMillis(); + Minecraft.getMinecraft().thePlayer.sendChatMessage("/nick help setrandom"); + } + } + + public static void renderInstructions(int screenWidth, int y) { + if (isOnNickGenerationPage) { + final int keyCode = MegaWallsEnhancementsMod.newNickKey.getKeyCode(); + final String text; + if (keyCode == 0) { + text = EnumChatFormatting.GREEN + "Go to " + EnumChatFormatting.GOLD + "Option -> Controls -> MegaWallsEnhancements" + EnumChatFormatting.GREEN + ", to set the keybind to get a random nick"; + } else { + text = EnumChatFormatting.GREEN + "Press " + EnumChatFormatting.GOLD + Keyboard.getKeyName(keyCode) + EnumChatFormatting.GREEN + " to get a new random nick"; + } + drawCenteredStringAt(screenWidth / 2, y + 24 + 24, text); + } + } + + private static void drawCenteredStringAt(int x, int y, String text) { + Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, (float) (x - Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) / 2), (float) y, 0); + } + } diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiScreenBookTransformer.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiScreenBookTransformer.java index 918aff37..3b0470b6 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiScreenBookTransformer.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/transformers/GuiScreenBookTransformer.java @@ -5,8 +5,7 @@ import fr.alexdoru.megawallsenhancementsmod.asm.InjectionStatus; import org.objectweb.asm.tree.*; -import static org.objectweb.asm.Opcodes.ALOAD; -import static org.objectweb.asm.Opcodes.INVOKESTATIC; +import static org.objectweb.asm.Opcodes.*; public class GuiScreenBookTransformer implements IMyClassTransformer { @@ -17,8 +16,9 @@ public String getTargetClassName() { @Override public ClassNode transform(ClassNode classNode, InjectionStatus status) { - status.setInjectionPoints(1); + status.setInjectionPoints(3); for (MethodNode methodNode : classNode.methods) { + if (methodNode.name.equals("") && methodNode.desc.equals(ASMLoadingPlugin.isObf ? "(Lwn;Lzx;Z)V" : "(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;Z)V")) { InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 2)); @@ -31,6 +31,42 @@ public ClassNode transform(ClassNode classNode, InjectionStatus status) { methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), list); status.addInjection(); } + + if (methodNode.name.equals(ASMLoadingPlugin.isObf ? "a" : "keyTyped") && methodNode.desc.equals("(CI)V")) { + InsnList list = new InsnList(); + list.add(new VarInsnNode(ILOAD, 2)); + list.add(new MethodInsnNode(INVOKESTATIC, + "fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook", + "onKeyTyped", + "(I)V", + false)); + methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), list); + status.addInjection(); + } + + if (methodNode.name.equals(ASMLoadingPlugin.isObf ? "a" : "drawScreen") && methodNode.desc.equals("(IIF)V")) { + for (AbstractInsnNode insnNode : methodNode.instructions.toArray()) { + if(insnNode instanceof MethodInsnNode && insnNode.getOpcode() == INVOKEVIRTUAL + && ((MethodInsnNode) insnNode).owner.equals(ASMLoadingPlugin.isObf ? "ayo" : "net/minecraft/client/gui/GuiScreenBook") + && ((MethodInsnNode) insnNode).name.equals(ASMLoadingPlugin.isObf ? "b" : "drawTexturedModalRect") + && ((MethodInsnNode) insnNode).desc.equals("(IIIIII)V")) { + InsnList list = new InsnList(); + list.add(new VarInsnNode(ALOAD, 0)); + list.add(new FieldInsnNode(GETFIELD, ASMLoadingPlugin.isObf ? "ayo" : "net/minecraft/client/gui/GuiScreenBook", ASMLoadingPlugin.isObf ? "l" : "width", "I")); + list.add(new VarInsnNode(ALOAD, 0)); + list.add(new FieldInsnNode(GETFIELD, ASMLoadingPlugin.isObf ? "ayo" : "net/minecraft/client/gui/GuiScreenBook", ASMLoadingPlugin.isObf ? "v" : "bookImageHeight", "I")); + list.add(new MethodInsnNode(INVOKESTATIC, + "fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiScreenBookHook", + "renderInstructions", + "(II)V", + false)); + methodNode.instructions.insertBefore(insnNode.getNext(), list); + status.addInjection(); + break; + } + } + } + } return classNode; } From 39f4cc316906704ae78d4180dab7adc607a21057 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 17 May 2022 19:07:50 +0200 Subject: [PATCH 06/34] fix typo (cherry picked from commit 6df055904b827282785d162fcd182286a56e1d73) --- .../fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java index 8dc654ed..7780f008 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java @@ -174,7 +174,7 @@ private static boolean checkAndSendReportSuggestion(@Nullable String messageSend if (canReportSuggestionPlayer(reportedPlayer)) { if (isSenderMyself) { - new DelayedTask(() -> addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "\u2714" + EnumChatFormatting.GRAY + " You report will be shared with other players in the game")), 0); + new DelayedTask(() -> addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "\u2714" + EnumChatFormatting.GRAY + " Your report will be shared with other players in the game")), 0); return true; } checkReportSpam(); From 855aa70510154231b0db8aef8adaadd38fc60924 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 17 May 2022 21:43:50 +0200 Subject: [PATCH 07/34] fix hotkoey protection on droppable pirate bows (cherry picked from commit 0474b87d149c0b7cd19d6da4f3539afc53e35de4) --- .../asm/hooks/GuiContainerHook.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java index d3ccdccd..46bfe956 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiContainerHook.java @@ -61,7 +61,7 @@ public static boolean shouldCancelHotkey(Slot theSlot, int i) { * iron sword w sharpness * diamond sword except quantum sword check silk touch * potions / exept phx/ren splash & squid abs - * bow except if you have enchanted bows on you (pirate bows) + * kit bow except if you have enchanted bows on you (pirate bows) */ private static boolean isItemImportant(Slot theSlot, int i) { if (FKCounterMod.isInMwGame && ConfigHandler.safeInventory) { @@ -109,7 +109,7 @@ private static boolean isItemImportant(Slot theSlot, int i) { } if (item == Items.bow) { if (itemStack.isItemEnchanted()) { - return true; + return !isSpecialPirateBow(itemStack); } return !hasAnotherBowThatsEnchanted(thePlayer.inventory.mainInventory); } @@ -121,8 +121,8 @@ private static boolean isItemImportant(Slot theSlot, int i) { private static boolean itemStackHasCustomDisplayName(ItemStack itemStack) { final NBTTagCompound tagCompound = itemStack.getTagCompound(); if (tagCompound != null && tagCompound.hasKey("display", 10)) { - NBTTagCompound nbttagcompound = tagCompound.getCompoundTag("display"); - return nbttagcompound.hasKey("Name", 8); + NBTTagCompound displayTag = tagCompound.getCompoundTag("display"); + return displayTag.hasKey("Name", 8); } return false; } @@ -135,6 +135,13 @@ private static boolean isEnchantedWithSilkTouch(ItemStack itemStack) { return EnchantmentHelper.getEnchantments(itemStack).containsKey(Enchantment.silkTouch.effectId); } + private static boolean isSpecialPirateBow(ItemStack itemStack) { + final NBTTagCompound tagCompound = itemStack.getTagCompound(); + final NBTTagCompound displayTag = tagCompound.getCompoundTag("display"); + final String itemName = displayTag.getString("Name"); + return itemName != null && (itemName.contains("Matey Coconut Bow") || itemName.contains("Matey Voodoo Bow")); + } + private static boolean hasAnotherBowThatsEnchanted(ItemStack[] mainInventory) { for (ItemStack itemStack : mainInventory) { if (itemStack != null) { From 257502c090827d7ace66760ccfda736b2ec2ff8c Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 18 May 2022 17:45:47 +0200 Subject: [PATCH 08/34] zzzzzzz (cherry picked from commit e01377a2b2bc5adeec1a66da3037e590dc88a92e) --- .../megawallsenhancementsmod/config/ConfigHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java index 581c0945..d296f2c1 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java @@ -15,11 +15,6 @@ public class ConfigHandler { private static Configuration config; - private static final String CATEGORY_FKCounter = "Final Kill Counter"; - private static final String CATEGORY_MWENh = "MegaWallsEnhancements"; - private static final String CATEGORY_GUI = "GUI"; - private static final String CATEGORY_NOCHEATERS = "NoCheaters"; - private static final String CATEGORY_HITBOX = "Hitbox"; /** * FKCounter config @@ -119,6 +114,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro } /*Reads the fiels in the config and stores them in the property objects, and defines a default value if the fields doesn't exist*/ + final String CATEGORY_FKCounter = "Final Kill Counter"; final Property pXpos_fkcHUD = config.get(CATEGORY_FKCounter, "Xpos FKCounter HUD", 0d, "The x position of the final kill counter HUD, value ranges from 0 to 1"); final Property pYpos_fkcHUD = config.get(CATEGORY_FKCounter, "Ypos FKCounter HUD", 0.1d, "The y position of the final kill counter HUD, value ranges from 0 to 1"); final Property pshow_fkcHUD = config.get(CATEGORY_FKCounter, "Show FKCounter HUD", true, "Displays the HUD of the final kill counter"); @@ -131,6 +127,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property pPlayerAmount = config.get(CATEGORY_FKCounter, "Player amount", 3, "Amount of players displayed on screen when you use the \"Show players\" setting"); final Property pfinalsInTablist = config.get(CATEGORY_FKCounter, "Fks in tablist", true, "Draws the finals in the tablist"); + final String CATEGORY_MWENh = "MegaWallsEnhancements"; final Property pAPIKey = config.get(CATEGORY_MWENh, "APIKey", "", "Your Hypixel API Key"); final Property phypixelNick = config.get(CATEGORY_MWENh, "Hypixel Nick", "", "Your nick on Hypixel"); final Property pstrengthParticules = config.get(CATEGORY_MWENh, "Strength particules", true, "Spawns strength particules when an herobrine or dreadlord get a final"); @@ -146,6 +143,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property phideRepetitiveMWChatMsg = config.get(CATEGORY_MWENh, "Delete repetitive chat messages in mw", true, "Delete repetitive chat messages in mw"); final Property pclearVision = config.get(CATEGORY_MWENh, "Clear Vision", true, "Hides particles too close to the camera"); + final String CATEGORY_GUI = "GUI"; final Property pShow_killcooldownHUD = config.get(CATEGORY_GUI, "Show kill cooldown HUD", true, "Displays the cooldown for the /kill command when in MegaWalls"); final Property pXpos_killcooldownHUD = config.get(CATEGORY_GUI, "Xpos kill cooldown HUD", 0d, "The x position of the killcooldown HUD, value ranges from 0 to 1"); final Property pYpos_killcooldownHUD = config.get(CATEGORY_GUI, "Ypos kill cooldown HUD", 0d, "The y position of the killcooldown HUD, value ranges from 0 to 1"); @@ -160,6 +158,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property pXpos_hunterHUD = config.get(CATEGORY_GUI, "Xpos hunter Strength HUD", 0.5d, "The x position of the Hunter Strength HUD, value ranges from 0 to 1"); final Property pYpos_hunterHUD = config.get(CATEGORY_GUI, "Ypos hunter Strength HUD", 8d / 20d, "The y position of the Hunter Strength HUD, value ranges from 0 to 1"); + final String CATEGORY_NOCHEATERS = "NoCheaters"; final Property pToggleicons = config.get(CATEGORY_NOCHEATERS, "Toggle Icons", true, "Display warning symbol on nametags of reported players"); final Property pTogglewarnings = config.get(CATEGORY_NOCHEATERS, "Toggle Warnings", false, "Gives warning messages in chat for reported players"); final Property preportsuggestions = config.get(CATEGORY_NOCHEATERS, "Report suggestion", true, "Give report suggestions in the chat based on messages in shouts"); @@ -171,6 +170,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property pdeleteCheaterChatMsg = config.get(CATEGORY_NOCHEATERS, "Delete Cheater Chat", false, "Deletes chat messages sent by reported cheaters"); final Property psafeReportingMode = config.get(CATEGORY_NOCHEATERS, "Safe reporting", false, "Registers your wdr commands and sends them over time to prevent spam"); + final String CATEGORY_HITBOX = "Hitbox"; final Property pisDebugHitboxOn = config.get(CATEGORY_HITBOX, "Toggle hitbox", false, "Toggle hitbox"); final Property pdrawHitboxForPlayers = config.get(CATEGORY_HITBOX, "Hitbox for players", true, "Hitbox for players"); final Property pdrawHitboxForGroundedArrows = config.get(CATEGORY_HITBOX, "Hitbox for grounded arrows", true, "Hitbox for grounded arrows"); From 4e673e14c9fda7d0c762b462e62feee1ce3c2ba7 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 18 May 2022 17:59:11 +0200 Subject: [PATCH 09/34] added debug mode to the report queue (cherry picked from commit 63241402f7e14d32ce575fac6d180a4d96c7f713) --- .../utils/NameUtil.java | 2 +- .../commands/CommandNocheaters.java | 9 ++++ .../nocheatersmod/events/ReportQueue.java | 52 ++++++++++++++----- .../util/NoCheatersMessages.java | 2 +- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/utils/NameUtil.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/utils/NameUtil.java index fca9cf19..888b42e0 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/utils/NameUtil.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/utils/NameUtil.java @@ -131,7 +131,7 @@ public static void transformNametag(EntityPlayer player, boolean onPlayerJoin) { if (onPlayerJoin && mwPlayerData.wdr != null && mwPlayerData.wdr.transformName()) { // player was reported long datenow = (new Date()).getTime(); String playerName = player.getName(); - boolean gotautoreported = ReportQueue.INSTANCE.sendAutoReport(datenow, playerName, mwPlayerData.wdr); + boolean gotautoreported = ReportQueue.INSTANCE.addAutoReportToQueue(datenow, playerName, mwPlayerData.wdr); if (ConfigHandler.togglewarnings || mwPlayerData.wdr.shouldPrintBigText(datenow)) { String uuid = player.getUniqueID().toString().replace("-", ""); ((GuiNewChatAccessor) mc.ingameGUI.getChatGUI()).deleteWarningMessagesFor(playerName); diff --git a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandNocheaters.java b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandNocheaters.java index ff124a4d..f0d1f12a 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandNocheaters.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandNocheaters.java @@ -366,6 +366,15 @@ public void processCommand(ICommandSender sender, String[] args) { ReportQueue.INSTANCE.clearReportsFor(args[1]); } + } else if (args[0].equalsIgnoreCase("debugreportqueue")) { + + ReportQueue.isDebugMode = !ReportQueue.isDebugMode; + if(ReportQueue.isDebugMode) { + debug("enabled debug report queue"); + } else { + debug("disabled debug report queue"); + } + } else { addChatMessage(getCommandHelp()); diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 258fec37..b06c0d9d 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -5,8 +5,10 @@ import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil; import fr.alexdoru.nocheatersmod.data.WDR; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -20,8 +22,10 @@ public class ReportQueue { + public static boolean isDebugMode = false; public static final ReportQueue INSTANCE = new ReportQueue(); private static final Minecraft mc = Minecraft.getMinecraft(); + private static final FontRenderer frObj = mc.fontRendererObj; private static final int TIME_BETWEEN_REPORTS_MAX = 4 * 60 * 20; private static final int TIME_BETWEEN_REPORTS_MIN = 2 * 60 * 20; @@ -40,7 +44,7 @@ public void onTick(TickEvent.ClientTickEvent event) { if (counter <= 0 && !queueList.isEmpty() && mc.thePlayer != null) { String playername = queueList.remove(queueList.size() - 1).reportedPlayer; - mc.thePlayer.sendChatMessage("/wdr " + playername + " cheating"); + mc.thePlayer.sendChatMessage("/wdr " + playername); final int i = TIME_BETWEEN_REPORTS_MAX - 12 * 20 * (queueList.isEmpty() ? 0 : queueList.size() - 1); counter = (int) ((10d * random.nextGaussian() / 6d) + Math.max(i, TIME_BETWEEN_REPORTS_MIN)); addReportTimestamp(false); @@ -54,6 +58,26 @@ public void onTick(TickEvent.ClientTickEvent event) { } + @SubscribeEvent + public void onRender(RenderGameOverlayEvent.Post event) { + if (isDebugMode && event.type == RenderGameOverlayEvent.ElementType.TEXT) { + int x = 0; + int y = frObj.FONT_HEIGHT * 4; + frObj.drawString(EnumChatFormatting.DARK_GREEN + "REPORT QUEUE", x, y, 0, true); + y += frObj.FONT_HEIGHT; + boolean first = true; + for (int i = queueList.size() - 1; i >= 0; i--) { + final ReportInQueue reportInQueue = queueList.get(i); + frObj.drawString(EnumChatFormatting.RED + reportInQueue.reportedPlayer, x, y, 0, true); + if (first) { + frObj.drawString(EnumChatFormatting.GOLD + " " + counter / 20 + "s", x + frObj.getStringWidth(reportInQueue.reportedPlayer), y, 0, true); + } + y += frObj.FONT_HEIGHT; + first = false; + } + } + } + public void addPlayerToQueue(String playername, boolean printDelayMsg) { if (canReportPlayerThisGame(playername)) { if (isReportQueueInactive()) { @@ -66,6 +90,14 @@ public void addPlayerToQueue(String playername, boolean printDelayMsg) { } } + private void addPlayerToQueue(String suggestionSender, String playername, int tickDelay) { + if (isReportQueueInactive()) { + MinecraftForge.EVENT_BUS.register(this); + counter = tickDelay; + } + queueList.add(new ReportInQueue(suggestionSender, playername)); + } + /** * Called from the auto-report suggestions * Returns true if it adds the players to the report queue @@ -78,24 +110,12 @@ public boolean addPlayerToQueueRandom(String suggestionSender, String reportedPl return false; } - private void addPlayerToQueue(String suggestionSender, String playername, int tickDelay) { - if (isReportQueueInactive()) { - MinecraftForge.EVENT_BUS.register(this); - counter = tickDelay; - } - queueList.add(new ReportInQueue(suggestionSender, playername)); - } - - private boolean isReportQueueInactive() { - return counter <= 0 && queueList.isEmpty(); - } - /** * Handles the auto report feature * * @return true if it sends a report */ - public boolean sendAutoReport(long datenow, String playerName, WDR wdr) { + public boolean addAutoReportToQueue(long datenow, String playerName, WDR wdr) { if (wdr.canBeAutoreported(datenow) && wdr.hasValidCheats()) { wdr.timestamp = datenow; addPlayerToQueue(playerName, false); @@ -104,6 +124,10 @@ public boolean sendAutoReport(long datenow, String playerName, WDR wdr) { return false; } + private boolean isReportQueueInactive() { + return counter <= 0 && queueList.isEmpty(); + } + public void clearReportsSentBy(String playername) { StringBuilder stringBuilder = new StringBuilder(); final Iterator iterator = queueList.iterator(); diff --git a/src/main/java/fr/alexdoru/nocheatersmod/util/NoCheatersMessages.java b/src/main/java/fr/alexdoru/nocheatersmod/util/NoCheatersMessages.java index 8a228720..98a99408 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/util/NoCheatersMessages.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/util/NoCheatersMessages.java @@ -39,7 +39,7 @@ public static void printReportMessagesForWorld(boolean callFromCommand) { continue; } foundReport = true; - boolean gotautoreported = ReportQueue.INSTANCE.sendAutoReport(datenow, playerName, wdr); + boolean gotautoreported = ReportQueue.INSTANCE.addAutoReportToQueue(datenow, playerName, wdr); if (wdr.transformName()) { printWarningMessage( datenow, From edb1a458f1c4dbfe560d7f73534490a84b94ba93 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 18 May 2022 19:22:58 +0200 Subject: [PATCH 10/34] prioritize report suggestions and sends them right away --- .../nocheatersmod/events/ReportQueue.java | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index b06c0d9d..61680fbf 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -43,11 +43,16 @@ public void onTick(TickEvent.ClientTickEvent event) { } if (counter <= 0 && !queueList.isEmpty() && mc.thePlayer != null) { - String playername = queueList.remove(queueList.size() - 1).reportedPlayer; + int index = getIndexOffFirstReportSuggestion(); + String playername = queueList.remove(index == -1 ? 0 : index).reportedPlayer; mc.thePlayer.sendChatMessage("/wdr " + playername); - final int i = TIME_BETWEEN_REPORTS_MAX - 12 * 20 * (queueList.isEmpty() ? 0 : queueList.size() - 1); - counter = (int) ((10d * random.nextGaussian() / 6d) + Math.max(i, TIME_BETWEEN_REPORTS_MIN)); addReportTimestamp(false); + if (doesQueueHaveReportSuggestion()) { + counter = getTickDelay() + 10 * 20; + } else { + final int i = TIME_BETWEEN_REPORTS_MAX - 12 * 20 * (queueList.isEmpty() ? 0 : queueList.size() - 1); + counter = (int) ((10d * random.nextGaussian() / 6d) + Math.max(i, TIME_BETWEEN_REPORTS_MIN)); + } } if (isReportQueueInactive()) { @@ -58,6 +63,24 @@ public void onTick(TickEvent.ClientTickEvent event) { } + private int getIndexOffFirstReportSuggestion() { + for (int i = 0; i < queueList.size(); i++) { + if (queueList.get(i).isReportSuggestion) { + return i; + } + } + return -1; + } + + private boolean doesQueueHaveReportSuggestion() { + for (ReportInQueue reportInQueue : queueList) { + if (reportInQueue.isReportSuggestion) { + return true; + } + } + return false; + } + @SubscribeEvent public void onRender(RenderGameOverlayEvent.Post event) { if (isDebugMode && event.type == RenderGameOverlayEvent.ElementType.TEXT) { @@ -66,9 +89,8 @@ public void onRender(RenderGameOverlayEvent.Post event) { frObj.drawString(EnumChatFormatting.DARK_GREEN + "REPORT QUEUE", x, y, 0, true); y += frObj.FONT_HEIGHT; boolean first = true; - for (int i = queueList.size() - 1; i >= 0; i--) { - final ReportInQueue reportInQueue = queueList.get(i); - frObj.drawString(EnumChatFormatting.RED + reportInQueue.reportedPlayer, x, y, 0, true); + for (final ReportInQueue reportInQueue : queueList) { + frObj.drawString((reportInQueue.isReportSuggestion ? EnumChatFormatting.RED : EnumChatFormatting.GREEN) + reportInQueue.reportedPlayer, x, y, 0, true); if (first) { frObj.drawString(EnumChatFormatting.GOLD + " " + counter / 20 + "s", x + frObj.getStringWidth(reportInQueue.reportedPlayer), y, 0, true); } @@ -86,16 +108,16 @@ public void addPlayerToQueue(String playername, boolean printDelayMsg) { } else if (printDelayMsg) { ChatUtil.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + "Sending report in a moment...")); } - queueList.add(0, new ReportInQueue(null, playername)); + queueList.add(new ReportInQueue(null, playername, false)); } } private void addPlayerToQueue(String suggestionSender, String playername, int tickDelay) { if (isReportQueueInactive()) { MinecraftForge.EVENT_BUS.register(this); - counter = tickDelay; } - queueList.add(new ReportInQueue(suggestionSender, playername)); + counter = tickDelay; + queueList.add(new ReportInQueue(suggestionSender, playername, true)); } /** @@ -104,12 +126,21 @@ private void addPlayerToQueue(String suggestionSender, String playername, int ti */ public boolean addPlayerToQueueRandom(String suggestionSender, String reportedPlayer) { if (canReportPlayerThisGame(reportedPlayer)) { - addPlayerToQueue(suggestionSender, reportedPlayer, (int) (100d + Math.abs(100d * random.nextGaussian() + 240d))); + addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); return true; } return false; } + /** + * Gaussian + * Min value : 5 seconds + * Avg value : 17 seconds + */ + private int getTickDelay() { + return (int) (100d + Math.abs(100d * random.nextGaussian() + 240d)); + } + /** * Handles the auto report feature * @@ -211,10 +242,12 @@ class ReportInQueue { public String messageSender; public String reportedPlayer; + public boolean isReportSuggestion; - public ReportInQueue(String messageSender, String reportedPlayer) { + public ReportInQueue(String messageSender, String reportedPlayer, boolean isReportSuggestion) { this.messageSender = messageSender; this.reportedPlayer = reportedPlayer; + this.isReportSuggestion = isReportSuggestion; } } From 3f547f414e8d6975fc4b9c69ed27ee4f8836c8e9 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 18 May 2022 20:05:07 +0200 Subject: [PATCH 11/34] stops reporting because the name check was case-sensitive --- src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 61680fbf..35b7b3f6 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -228,7 +228,7 @@ private boolean canReportPlayerThisGame(String playername) { long timestamp = System.currentTimeMillis(); playersReportedThisGame.removeIf(o -> (o.timestamp + 40L * 60L * 1000L < timestamp)); for (StringLong stringLong : playersReportedThisGame) { - if (stringLong.message != null && stringLong.message.equals(playername)) { + if (stringLong.message != null && stringLong.message.equalsIgnoreCase(playername)) { return false; } } From 565a2471afef225b7081cd98e8acdde49178c047 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 18 May 2022 20:12:46 +0200 Subject: [PATCH 12/34] moves report on top when there is a report suggestion and the player was already in the queue --- .../fr/alexdoru/nocheatersmod/events/ReportQueue.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 35b7b3f6..85a4656b 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -46,6 +46,9 @@ public void onTick(TickEvent.ClientTickEvent event) { int index = getIndexOffFirstReportSuggestion(); String playername = queueList.remove(index == -1 ? 0 : index).reportedPlayer; mc.thePlayer.sendChatMessage("/wdr " + playername); + if (isDebugMode) { + ChatUtil.debug("sent report for " + playername); + } addReportTimestamp(false); if (doesQueueHaveReportSuggestion()) { counter = getTickDelay() + 10 * 20; @@ -122,12 +125,18 @@ private void addPlayerToQueue(String suggestionSender, String playername, int ti /** * Called from the auto-report suggestions + * if an auto-report for that player is already in the queue, it prioritizes it * Returns true if it adds the players to the report queue */ public boolean addPlayerToQueueRandom(String suggestionSender, String reportedPlayer) { if (canReportPlayerThisGame(reportedPlayer)) { addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); return true; + } else { + if (queueList.removeIf(reportInQueue -> (reportInQueue.reportedPlayer.equalsIgnoreCase(reportedPlayer) && !reportInQueue.isReportSuggestion))) { + addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); + return true; + } } return false; } From 041ff3ccab70a74f44c186c860cef4b75f57ac9f Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Thu, 19 May 2022 20:02:45 +0200 Subject: [PATCH 13/34] Revert "safe reporting mode" This reverts commit 3ba0fbf6 --- .../config/ConfigHandler.java | 5 ----- .../gui/NoCheatersConfigGuiScreen.java | 16 ++-------------- .../nocheatersmod/commands/CommandWDR.java | 10 ++-------- .../nocheatersmod/events/ReportQueue.java | 5 ++--- 4 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java index d296f2c1..fb6a61fa 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java @@ -73,7 +73,6 @@ public class ConfigHandler { public static long timeDeleteReport; public static boolean censorCheaterChatMsg; public static boolean deleteCheaterChatMsg; - public static boolean safeReportingMode; /** * Hitbox Config @@ -168,7 +167,6 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property ptimeDeleteReport = config.get(CATEGORY_NOCHEATERS, "Time delete reports", 365, "Reports older than this will be deleted on game start (days)"); final Property pcensorCheaterChatMsg = config.get(CATEGORY_NOCHEATERS, "Censor Cheater Chat", false, "Censors chat messages sent by reported cheaters"); final Property pdeleteCheaterChatMsg = config.get(CATEGORY_NOCHEATERS, "Delete Cheater Chat", false, "Deletes chat messages sent by reported cheaters"); - final Property psafeReportingMode = config.get(CATEGORY_NOCHEATERS, "Safe reporting", false, "Registers your wdr commands and sends them over time to prevent spam"); final String CATEGORY_HITBOX = "Hitbox"; final Property pisDebugHitboxOn = config.get(CATEGORY_HITBOX, "Toggle hitbox", false, "Toggle hitbox"); @@ -247,7 +245,6 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro pOrderNOCHEATERS.add(ptimeDeleteReport.getName()); pOrderNOCHEATERS.add(pcensorCheaterChatMsg.getName()); pOrderNOCHEATERS.add(pdeleteCheaterChatMsg.getName()); - pOrderNOCHEATERS.add(psafeReportingMode.getName()); config.setCategoryPropertyOrder(CATEGORY_NOCHEATERS, pOrderNOCHEATERS); List pOrderHitbox = new ArrayList<>(); @@ -318,7 +315,6 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro timeDeleteReport = 24L * 3600L * 1000L * ((long) ptimeDeleteReport.getInt()); censorCheaterChatMsg = pcensorCheaterChatMsg.getBoolean(); deleteCheaterChatMsg = pdeleteCheaterChatMsg.getBoolean(); - safeReportingMode = psafeReportingMode.getBoolean(); isDebugHitboxOn = pisDebugHitboxOn.getBoolean(); drawHitboxForPlayers = pdrawHitboxForPlayers.getBoolean(); @@ -400,7 +396,6 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro ptimeDeleteReport.set((int) (timeDeleteReport / (24L * 3600L * 1000L))); pcensorCheaterChatMsg.set(censorCheaterChatMsg); pdeleteCheaterChatMsg.set(deleteCheaterChatMsg); - psafeReportingMode.set(safeReportingMode); pisDebugHitboxOn.set(isDebugHitboxOn); pdrawHitboxForPlayers.set(drawHitboxForPlayers); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java index e05f1048..74622e52 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java @@ -42,8 +42,7 @@ public void initGui() { buttonList.add(new GuiButton(6, xPos, getYposForButton(1), buttonsWidth, ButtonsHeight, getButtonDisplayString(6))); buttonList.add(new GuiSlider(7, xPos, getYposForButton(2), buttonsWidth, 20, "Delete reports older than : ", " days", 1d, 365d, ConfigHandler.timeDeleteReport / (24f * 3600f * 1000f), false, true, this)); buttonList.add(new GuiButton(10, xPos, getYposForButton(3), buttonsWidth, ButtonsHeight, getButtonDisplayString(10))); - buttonList.add(new GuiButton(11, xPos, getYposForButton(4), buttonsWidth, ButtonsHeight, getButtonDisplayString(11))); - buttonList.add(new GuiButton(3, getxCenter() - 150 / 2, getYposForButton(6), 150, ButtonsHeight, getButtonDisplayString(3))); + buttonList.add(new GuiButton(3, getxCenter() - 150 / 2, getYposForButton(5), 150, ButtonsHeight, getButtonDisplayString(3))); super.initGui(); } @@ -61,8 +60,6 @@ private String getButtonDisplayString(int id) { return "Delete old reports : " + getSuffix(ConfigHandler.deleteReports); case 10: return "Censor cheaters in chat : " + (ConfigHandler.deleteCheaterChatMsg ? EnumChatFormatting.GREEN + "Delete" : (ConfigHandler.censorCheaterChatMsg ? EnumChatFormatting.YELLOW + "Censor" : EnumChatFormatting.RED + "Disabled")); - case 11: - return "Safe reporting mode : " + getSuffix(ConfigHandler.safeReportingMode); case 3: return parent == null ? "Close" : "Done"; default: @@ -109,13 +106,7 @@ public List getTooltipText(int id) { textLines.add(EnumChatFormatting.GRAY + "You can ignore players by using " + EnumChatFormatting.YELLOW + "/nocheaters ignore "); break; case 10: - textLines.add(EnumChatFormatting.GREEN + "Deletes or censors chat messages sent by reported players"); - break; - case 11: - textLines.add(EnumChatFormatting.GREEN + "Hypixel ignores your reports if you send too many in a short time period"); - textLines.add(EnumChatFormatting.GREEN + "With this setting ON, it will save your " + EnumChatFormatting.YELLOW + "/wdr" + EnumChatFormatting.GREEN + " commands and send them over time"); - textLines.add(EnumChatFormatting.GREEN + "It also limits to one command per player per game, in case you type the command several times for the same player"); - textLines.add(EnumChatFormatting.GRAY + "Only works in Mega Walls"); + textLines.add(EnumChatFormatting.GREEN + "Deletes or censors chat messages sent by repoted players"); break; } return textLines; @@ -159,9 +150,6 @@ protected void actionPerformed(GuiButton button) throws IOException { ConfigHandler.deleteCheaterChatMsg = false; ConfigHandler.censorCheaterChatMsg = false; break; - case 11: - ConfigHandler.safeReportingMode = !ConfigHandler.safeReportingMode; - break; case 2: ConfigHandler.toggleautoreport = !ConfigHandler.toggleautoreport; NameUtil.refreshAllNamesInWorld(); diff --git a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java index 1f7f73ed..1271fe7a 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java @@ -5,7 +5,6 @@ import fr.alexdoru.megawallsenhancementsmod.api.cache.CachedMojangUUID; import fr.alexdoru.megawallsenhancementsmod.api.exceptions.ApiException; import fr.alexdoru.megawallsenhancementsmod.api.hypixelplayerdataparser.LoginData; -import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.utils.*; import fr.alexdoru.nocheatersmod.data.TimeMark; import fr.alexdoru.nocheatersmod.data.WDR; @@ -192,16 +191,11 @@ public static void handleWDRCommand(String[] args, boolean sentFromAutoReport) { if (sentFromAutoReport) { ReportQueue.INSTANCE.addPlayerToQueueRandom(null, playername); } else { - if (ConfigHandler.safeReportingMode && FKCounterMod.isInMwGame) { - ReportQueue.INSTANCE.addPlayerToQueue(playername, true); - } else { - if (mc.thePlayer != null) { - mc.thePlayer.sendChatMessage(message.toString()); - } + if (mc.thePlayer != null) { + mc.thePlayer.sendChatMessage(message.toString()); } } - ReportQueue.INSTANCE.addReportTimestamp(true); if (FKCounterMod.preGameLobby) { diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 85a4656b..287385ee 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -222,9 +222,8 @@ public void clearReportsFor(String reportedPlayer) { public void addReportTimestamp(boolean manualReport) { long l = System.currentTimeMillis(); timestampsLastReports.removeIf(o -> (o + 2 * 60 * 1000L < l)); - if (manualReport && timestampsLastReports.size() > 3) { - ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagNoCheaters() + EnumChatFormatting.RED + "Don't report too many players at once or Hypixel will ignore your reports thinking you are a bot trying to flood their system." - + (FKCounterMod.isInMwGame ? EnumChatFormatting.GOLD + " You can turn on NoCheaters' safe reporting mode to prevent this." : ""))); + if (manualReport && timestampsLastReports.size() > 4) { + ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagNoCheaters() + EnumChatFormatting.RED + "Don't report too many players at once or Hypixel will ignore your reports thinking you are a bot trying to flood their system")); } timestampsLastReports.add(l); } From 044b27720f77336f9feadbedf74af87c27ee6703 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Thu, 19 May 2022 20:10:25 +0200 Subject: [PATCH 14/34] typo --- .../megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java index 74622e52..ec8b3a90 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/NoCheatersConfigGuiScreen.java @@ -106,7 +106,7 @@ public List getTooltipText(int id) { textLines.add(EnumChatFormatting.GRAY + "You can ignore players by using " + EnumChatFormatting.YELLOW + "/nocheaters ignore "); break; case 10: - textLines.add(EnumChatFormatting.GREEN + "Deletes or censors chat messages sent by repoted players"); + textLines.add(EnumChatFormatting.GREEN + "Deletes or censors chat messages sent by reported players"); break; } return textLines; From 3cef9cb94edbaf31a3292a36acef3c740424c6da Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Fri, 20 May 2022 01:30:49 +0200 Subject: [PATCH 15/34] send report suggestion even if you already autoreported --- .../alexdoru/nocheatersmod/events/ReportQueue.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 287385ee..06fea1c9 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -129,16 +129,9 @@ private void addPlayerToQueue(String suggestionSender, String playername, int ti * Returns true if it adds the players to the report queue */ public boolean addPlayerToQueueRandom(String suggestionSender, String reportedPlayer) { - if (canReportPlayerThisGame(reportedPlayer)) { - addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); - return true; - } else { - if (queueList.removeIf(reportInQueue -> (reportInQueue.reportedPlayer.equalsIgnoreCase(reportedPlayer) && !reportInQueue.isReportSuggestion))) { - addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); - return true; - } - } - return false; + queueList.removeIf(reportInQueue -> (reportInQueue.reportedPlayer.equalsIgnoreCase(reportedPlayer))); + addPlayerToQueue(suggestionSender, reportedPlayer, getTickDelay()); + return true; } /** From 029ac5551841748550dd6ade315f0290ad0b2b37 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Fri, 20 May 2022 01:41:42 +0200 Subject: [PATCH 16/34] clears autoreports in queue on game end and extended time between reports --- .../nocheatersmod/events/ReportQueue.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 06fea1c9..94084752 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -1,6 +1,7 @@ package fr.alexdoru.nocheatersmod.events; import fr.alexdoru.fkcountermod.FKCounterMod; +import fr.alexdoru.fkcountermod.events.MwGameEvent; import fr.alexdoru.megawallsenhancementsmod.data.StringLong; import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil; import fr.alexdoru.nocheatersmod.data.WDR; @@ -26,8 +27,8 @@ public class ReportQueue { public static final ReportQueue INSTANCE = new ReportQueue(); private static final Minecraft mc = Minecraft.getMinecraft(); private static final FontRenderer frObj = mc.fontRendererObj; - private static final int TIME_BETWEEN_REPORTS_MAX = 4 * 60 * 20; - private static final int TIME_BETWEEN_REPORTS_MIN = 2 * 60 * 20; + private static final int TIME_BETWEEN_REPORTS_MAX = 5 * 60 * 20; + private static final int TIME_BETWEEN_REPORTS_MIN = 3 * 60 * 20; private int counter; private final List queueList = new ArrayList<>(); @@ -43,13 +44,16 @@ public void onTick(TickEvent.ClientTickEvent event) { } if (counter <= 0 && !queueList.isEmpty() && mc.thePlayer != null) { - int index = getIndexOffFirstReportSuggestion(); - String playername = queueList.remove(index == -1 ? 0 : index).reportedPlayer; - mc.thePlayer.sendChatMessage("/wdr " + playername); - if (isDebugMode) { - ChatUtil.debug("sent report for " + playername); + final int index = getIndexOffFirstReportSuggestion(); + final ReportInQueue reportInQueue = queueList.remove(index == -1 ? 0 : index); + final String playername = reportInQueue.reportedPlayer; + if (reportInQueue.isReportSuggestion || FKCounterMod.isInMwGame) { + mc.thePlayer.sendChatMessage("/wdr " + playername); + addReportTimestamp(false); + if (isDebugMode) { + ChatUtil.debug("sent report for " + playername); + } } - addReportTimestamp(false); if (doesQueueHaveReportSuggestion()) { counter = getTickDelay() + 10 * 20; } else { @@ -103,6 +107,13 @@ public void onRender(RenderGameOverlayEvent.Post event) { } } + @SubscribeEvent + public void onGameEnd(MwGameEvent event) { + if (event.getType() == MwGameEvent.EventType.GAME_END) { + queueList.removeIf(reportInQueue -> !reportInQueue.isReportSuggestion); + } + } + public void addPlayerToQueue(String playername, boolean printDelayMsg) { if (canReportPlayerThisGame(playername)) { if (isReportQueueInactive()) { From df0576dad90dd84a6dfcee36f95d4369783bb9d0 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Fri, 20 May 2022 18:52:35 +0200 Subject: [PATCH 17/34] stop flaggin old players with really high fkd --- .../megawallsenhancementsmod/commands/CommandScanGame.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java index a8b7cc40..45498b56 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java @@ -149,8 +149,7 @@ public String call() { if ((megawallsstats.getGames_played() <= 25 && megawallsstats.getFkdr() > 3.5f) || (megawallsstats.getGames_played() <= 250 && megawallsstats.getFkdr() > 5f) || - (megawallsstats.getGames_played() <= 500 && megawallsstats.getFkdr() > 8f) || - (megawallsstats.getFkdr() > 10f)) { + (megawallsstats.getGames_played() <= 500 && megawallsstats.getFkdr() > 8f)) { imsg = getFormattedNameWithPlanckeClickEvent(networkPlayerInfo).appendSibling(new ChatComponentText( EnumChatFormatting.GRAY + " played : " + EnumChatFormatting.GOLD + megawallsstats.getGames_played() From 954120682da5055e14d2ee5054ac5450ab616ab1 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Sat, 21 May 2022 15:15:37 +0200 Subject: [PATCH 18/34] remove the report buttons on scangame to avoid spamming --- .../commands/CommandScanGame.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java index 45498b56..a2bc01e4 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java @@ -57,14 +57,6 @@ public static void put(String uuid, IChatComponent msg) { scanmap.put(uuid, msg); } - protected static IChatComponent getMessageStart(String playername) { - IChatComponent imsg = new ChatComponentText(ChatUtil.getTagMW()); - if (FKCounterMod.isInMwGame) { - imsg.appendSibling(ChatUtil.makeReportButtons(playername, "cheating", "", ClickEvent.Action.RUN_COMMAND, ClickEvent.Action.SUGGEST_COMMAND)); - } - return imsg; - } - @Override public String getCommandName() { return "scangame"; @@ -99,7 +91,7 @@ public void processCommand(ICommandSender sender, String[] args) { i++; Multithreading.addTaskToQueue(new ScanPlayerTask(networkPlayerInfo)); } else if (!imsg.equals(nomatch)) { - ChatUtil.addChatMessage(getMessageStart(networkPlayerInfo.getGameProfile().getName()).appendSibling(imsg)); + ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagMW()).appendSibling(imsg)); } } @@ -203,7 +195,7 @@ public String call() { } if (imsg != null) { - ChatUtil.addChatMessage(CommandScanGame.getMessageStart(playername).appendSibling(imsg)); + ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagMW()).appendSibling(imsg)); CommandScanGame.put(uuid, imsg); NameUtil.updateGameProfileAndName(networkPlayerInfo); } else { From 8d2d13488a8745d013a88138296e8bcdc0248ff9 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 13:40:07 +0200 Subject: [PATCH 19/34] 3 autoreport per game --- .../java/fr/alexdoru/nocheatersmod/events/ReportQueue.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 94084752..5f018d37 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -31,6 +31,7 @@ public class ReportQueue { private static final int TIME_BETWEEN_REPORTS_MIN = 3 * 60 * 20; private int counter; + private int autoReportSent; private final List queueList = new ArrayList<>(); private final List timestampsLastReports = new ArrayList<>(); private final List playersReportedThisGame = new ArrayList<>(); @@ -160,9 +161,10 @@ private int getTickDelay() { * @return true if it sends a report */ public boolean addAutoReportToQueue(long datenow, String playerName, WDR wdr) { - if (wdr.canBeAutoreported(datenow) && wdr.hasValidCheats()) { + if (autoReportSent < 3 && wdr.canBeAutoreported(datenow) && wdr.hasValidCheats()) { wdr.timestamp = datenow; addPlayerToQueue(playerName, false); + autoReportSent++; return true; } return false; @@ -234,6 +236,7 @@ public void addReportTimestamp(boolean manualReport) { public void clearPlayersReportedThisGame() { playersReportedThisGame.clear(); + autoReportSent = 0; } private boolean canReportPlayerThisGame(String playername) { From 6c8564b3a9a7b1e6542e5ab71fb3a8fd89937fd1 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 15:09:39 +0200 Subject: [PATCH 20/34] random time for first report --- src/main/java/fr/alexdoru/nocheatersmod/data/WDR.java | 2 +- src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/data/WDR.java b/src/main/java/fr/alexdoru/nocheatersmod/data/WDR.java index 14c1765d..5792a53e 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/data/WDR.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/data/WDR.java @@ -11,7 +11,7 @@ public class WDR { public static final String NICK = "nick"; public static final String IGNORED = "ignored"; - public static final long TIME_BETWEEN_AUTOREPORT = 40L * 60L * 1000L; //40 minutes + public static final long TIME_BETWEEN_AUTOREPORT = 60L * 60L * 1000L; //60 minutes private static final long TIME_MAX_AUTOREPORT = 7L * 24L * 60L * 60L * 1000L; //1 week public long timestamp; diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 5f018d37..a160774a 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -119,7 +119,7 @@ public void addPlayerToQueue(String playername, boolean printDelayMsg) { if (canReportPlayerThisGame(playername)) { if (isReportQueueInactive()) { MinecraftForge.EVENT_BUS.register(this); - counter = 0; + counter = random.nextInt(TIME_BETWEEN_REPORTS_MAX); } else if (printDelayMsg) { ChatUtil.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + "Sending report in a moment...")); } From 1a0baad20e25bd0160f9de05fcd65fb32edf5e60 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 19:04:38 +0200 Subject: [PATCH 21/34] fix crash with people who don't want to update forge --- .../megawallsenhancementsmod/gui/MyGuiScreen.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/MyGuiScreen.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/MyGuiScreen.java index 1be51d60..2e735b9e 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/MyGuiScreen.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/MyGuiScreen.java @@ -18,14 +18,20 @@ public abstract class MyGuiScreen extends GuiScreen { @Override public void initGui() { - mc.entityRenderer.loadShader(SHADER); + try { + mc.entityRenderer.loadShader(SHADER); + } catch (Exception ignored) { + } super.initGui(); } @Override public void onGuiClosed() { ConfigHandler.saveConfig(); - mc.entityRenderer.stopUseShader(); + try { + mc.entityRenderer.stopUseShader(); + } catch (Exception ignored) { + } super.onGuiClosed(); } From 7f5d1cfd43cb7a63599e263af8363208532acb00 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 21:09:07 +0200 Subject: [PATCH 22/34] lower level to tigger booster flag in scangame --- .../megawallsenhancementsmod/commands/CommandScanGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java index a2bc01e4..8303063d 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandScanGame.java @@ -153,7 +153,7 @@ public String call() { GeneralInfo generalInfo = new GeneralInfo(playerdata.getPlayerData()); boolean firstGame = megawallsstats.getGames_played() == 0; - boolean secondFlag = generalInfo.getCompletedQuests() < 20 && generalInfo.getNetworkLevel() > 42f; + boolean secondFlag = generalInfo.getCompletedQuests() < 20 && generalInfo.getNetworkLevel() > 30f; JsonObject classesdata = megawallsstats.getClassesdata(); if (FKCounterMod.isInMwGame) { From 70a1aba1b8dc6bbb6bf9bec4f4ec6da9a0258697 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 21:10:43 +0200 Subject: [PATCH 23/34] keep custom name in squad --- .../megawallsenhancementsmod/events/SquadEvent.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java index 732a56ad..7f6fbbe6 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java @@ -111,13 +111,18 @@ public static void formSquad() { } + final String myName = Minecraft.getMinecraft().thePlayer.getName(); + final String myCustomName = squadmap.get(myName); + squadmap.clear(); squadmap.putAll(newsquad); - if (!squadmap.isEmpty()) { - addPlayer(Minecraft.getMinecraft().thePlayer.getName()); + if (myCustomName != null) { + addPlayer(myName, myCustomName); + } else if (!squadmap.isEmpty()) { + addPlayer(myName); if (!ConfigHandler.hypixelNick.equals("")) { - addPlayer(ConfigHandler.hypixelNick, EnumChatFormatting.ITALIC + Minecraft.getMinecraft().thePlayer.getName()); + addPlayer(ConfigHandler.hypixelNick, EnumChatFormatting.ITALIC + myName); } } From 866bc264409aaef757166fac232257b67ab78e6a Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Mon, 23 May 2022 21:38:09 +0200 Subject: [PATCH 24/34] delete useless class --- .../commands/CommandSetupApiKey.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSetupApiKey.java diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSetupApiKey.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSetupApiKey.java deleted file mode 100644 index d665d971..00000000 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSetupApiKey.java +++ /dev/null @@ -1,39 +0,0 @@ -//package fr.alexdoru.megawallsenhancementsmod.commands; -// -//import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil; -//import fr.alexdoru.megawallsenhancementsmod.utils.HypixelApiKeyUtil; -//import net.minecraft.command.CommandBase; -//import net.minecraft.command.ICommandSender; -//import net.minecraft.util.ChatComponentText; -//import net.minecraft.util.EnumChatFormatting; -// -//public class CommandSetupApiKey extends CommandBase { -// -// @Override -// public String getCommandName() { -// return "setapikey"; -// } -// -// @Override -// public String getCommandUsage(ICommandSender sender) { -// return "/setapikey "; -// } -// -// @Override -// public void processCommand(ICommandSender sender, String[] args) { -// -// if (args.length != 1) { -// ChatUtil.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage : " + getCommandUsage(sender) + "\n" -// + EnumChatFormatting.RED + "Connect on Hypixel and type \"/api new\" to get an Api key")); -// } else { -// HypixelApiKeyUtil.setApiKey(args[0]); -// } -// -// } -// -// @Override -// public boolean canCommandSenderUseCommand(ICommandSender sender) { -// return true; -// } -// -//} From db530eb4615c6b63b2ab17fcb3501bb6837f510e Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 16:09:55 +0200 Subject: [PATCH 25/34] remove the hypixel server detection --- .../alexdoru/fkcountermod/FKCounterMod.java | 1 - .../fkcountermod/events/ScoreboardEvent.java | 26 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/alexdoru/fkcountermod/FKCounterMod.java b/src/main/java/fr/alexdoru/fkcountermod/FKCounterMod.java index 1f03e888..483a2be3 100644 --- a/src/main/java/fr/alexdoru/fkcountermod/FKCounterMod.java +++ b/src/main/java/fr/alexdoru/fkcountermod/FKCounterMod.java @@ -23,7 +23,6 @@ public class FKCounterMod { * True during the preparation phase of a mega walls game */ public static boolean isitPrepPhase = false; - public static boolean isHypixel = false; public static boolean isMWEnvironement = false; public static void init() { diff --git a/src/main/java/fr/alexdoru/fkcountermod/events/ScoreboardEvent.java b/src/main/java/fr/alexdoru/fkcountermod/events/ScoreboardEvent.java index 9fd9e178..d7d8be3a 100644 --- a/src/main/java/fr/alexdoru/fkcountermod/events/ScoreboardEvent.java +++ b/src/main/java/fr/alexdoru/fkcountermod/events/ScoreboardEvent.java @@ -1,14 +1,12 @@ package fr.alexdoru.fkcountermod.events; import fr.alexdoru.fkcountermod.FKCounterMod; -import fr.alexdoru.fkcountermod.utils.MinecraftUtils; import fr.alexdoru.fkcountermod.utils.ScoreboardParser; import net.minecraft.client.Minecraft; import net.minecraft.scoreboard.Scoreboard; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent; public class ScoreboardEvent { @@ -29,12 +27,20 @@ public void onTick(TickEvent.ClientTickEvent event) { return; } - if (mc.theWorld == null || !FKCounterMod.isHypixel) { + if (mc.theWorld == null) { + FKCounterMod.isInMwGame = false; + FKCounterMod.isMWEnvironement = false; + FKCounterMod.preGameLobby = false; + FKCounterMod.isitPrepPhase = false; return; } Scoreboard scoreboard = mc.theWorld.getScoreboard(); if (scoreboard == null) { + FKCounterMod.isInMwGame = false; + FKCounterMod.isMWEnvironement = false; + FKCounterMod.preGameLobby = false; + FKCounterMod.isitPrepPhase = false; return; } @@ -48,13 +54,13 @@ public void onTick(TickEvent.ClientTickEvent event) { FKCounterMod.preGameLobby = mwScoreboardParser.isPreGameLobby(); FKCounterMod.isitPrepPhase = mwScoreboardParser.isitPrepPhase(); - if (gameId == null) { // not in a MW game + if (gameId == null) { // not in MW game if (prevGameId != null) { MinecraftForge.EVENT_BUS.post(new MwGameEvent(MwGameEvent.EventType.DISCONNECT)); } - } else { // is in a MW game + } else { // is in MW game if (amountWitherAlive == 1 && prevAmountWitherAlive > 1) { MinecraftForge.EVENT_BUS.post(new MwGameEvent(MwGameEvent.EventType.THIRD_WITHER_DEATH)); @@ -78,14 +84,4 @@ public void onTick(TickEvent.ClientTickEvent event) { } - @SubscribeEvent - public void onConnection(FMLNetworkEvent.ClientConnectedToServerEvent event) { - FKCounterMod.isHypixel = MinecraftUtils.isHypixel(); - } - - @SubscribeEvent - public void onDisconnection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) { - FKCounterMod.isHypixel = false; - } - } From 179034096fd3ab8f36cfaa5c30706001212bd016 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 20:23:09 +0200 Subject: [PATCH 26/34] ignore case when checking report suggestion --- .../fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java index 7780f008..65728c6e 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java @@ -272,7 +272,7 @@ private static boolean canReportSuggestionPlayer(String playername) { long timestamp = System.currentTimeMillis(); reportSuggestionHistory.removeIf(o -> (o.timestamp + TIME_BETWEEN_REPORT_SUGGESTION_PLAYER < timestamp)); for (StringLong stringLong : reportSuggestionHistory) { - if (stringLong.message != null && stringLong.message.equals(playername)) { + if (stringLong.message != null && stringLong.message.equalsIgnoreCase(playername)) { return false; } } From c11942b974d0cb51b75643802940bfc572c59d7c Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 20:35:46 +0200 Subject: [PATCH 27/34] only send the WDR commande once if you spam to report in the chat --- .../alexdoru/nocheatersmod/commands/CommandWDR.java | 8 +++++--- .../nocheatersmod/util/ReportSuggestionHandler.java | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java index 1271fe7a..8688cecb 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/commands/CommandWDR.java @@ -71,10 +71,10 @@ public void processCommand(ICommandSender sender, String[] args) { addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage : " + getCommandUsage(sender))); return; } - handleWDRCommand(args, false); + handleWDRCommand(args, false, false); } - public static void handleWDRCommand(String[] args, boolean sentFromAutoReport) { + public static void handleWDRCommand(String[] args, boolean sentFromAutoReport, boolean canWDRPlayer) { Multithreading.addTaskToQueue(() -> { boolean isaTimestampedReport = false; boolean usesTimeMark = false; @@ -189,7 +189,9 @@ public static void handleWDRCommand(String[] args, boolean sentFromAutoReport) { } if (sentFromAutoReport) { - ReportQueue.INSTANCE.addPlayerToQueueRandom(null, playername); + if (canWDRPlayer) { + ReportQueue.INSTANCE.addPlayerToQueueRandom(null, playername); + } } else { if (mc.thePlayer != null) { mc.thePlayer.sendChatMessage(message.toString()); diff --git a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java index 65728c6e..05fbd597 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/util/ReportSuggestionHandler.java @@ -137,7 +137,7 @@ private static boolean checkAndSendReportSuggestion(@Nullable String messageSend if (isSenderMyself) { String[] args = new String[]{reportedPlayer, cheat}; - CommandWDR.handleWDRCommand(args, true); + CommandWDR.handleWDRCommand(args, true, canWDRPlayer(reportedPlayer)); } if (FKCounterMod.isitPrepPhase) { @@ -280,6 +280,17 @@ private static boolean canReportSuggestionPlayer(String playername) { return true; } + private static boolean canWDRPlayer(String playername) { + long timestamp = System.currentTimeMillis(); + reportSuggestionHistory.removeIf(o -> (o.timestamp + TIME_BETWEEN_REPORT_SUGGESTION_PLAYER < timestamp)); + for (StringLong stringLong : reportSuggestionHistory) { + if (stringLong.message != null && stringLong.message.equalsIgnoreCase(playername)) { + return false; + } + } + return true; + } + private static void addButtons(IChatComponent imsg, String reportedPlayer, String cheat, boolean isSenderMyself, boolean isTargetMyself, boolean gotautoreported) { if (isTargetMyself) { return; From e91671d42c7b2bab4d3ca9c13aea23fc7f4fd966 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 21:32:30 +0200 Subject: [PATCH 28/34] eeee --- .../java/fr/alexdoru/nocheatersmod/events/ReportQueue.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index a160774a..02d96043 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -29,6 +29,7 @@ public class ReportQueue { private static final FontRenderer frObj = mc.fontRendererObj; private static final int TIME_BETWEEN_REPORTS_MAX = 5 * 60 * 20; private static final int TIME_BETWEEN_REPORTS_MIN = 3 * 60 * 20; + private static final int AUTOREPORT_PER_GAME = 3; private int counter; private int autoReportSent; @@ -56,7 +57,7 @@ public void onTick(TickEvent.ClientTickEvent event) { } } if (doesQueueHaveReportSuggestion()) { - counter = getTickDelay() + 10 * 20; + counter = getTickDelay() + 20 * 20; } else { final int i = TIME_BETWEEN_REPORTS_MAX - 12 * 20 * (queueList.isEmpty() ? 0 : queueList.size() - 1); counter = (int) ((10d * random.nextGaussian() / 6d) + Math.max(i, TIME_BETWEEN_REPORTS_MIN)); @@ -161,7 +162,7 @@ private int getTickDelay() { * @return true if it sends a report */ public boolean addAutoReportToQueue(long datenow, String playerName, WDR wdr) { - if (autoReportSent < 3 && wdr.canBeAutoreported(datenow) && wdr.hasValidCheats()) { + if (autoReportSent < AUTOREPORT_PER_GAME && wdr.canBeAutoreported(datenow) && wdr.hasValidCheats()) { wdr.timestamp = datenow; addPlayerToQueue(playerName, false); autoReportSent++; From 8334e2044222ff18d4885a12bd654889d46339b1 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 22:49:28 +0200 Subject: [PATCH 29/34] 2autoreports per game --- src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java index 02d96043..56c7f1c3 100644 --- a/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java +++ b/src/main/java/fr/alexdoru/nocheatersmod/events/ReportQueue.java @@ -29,7 +29,7 @@ public class ReportQueue { private static final FontRenderer frObj = mc.fontRendererObj; private static final int TIME_BETWEEN_REPORTS_MAX = 5 * 60 * 20; private static final int TIME_BETWEEN_REPORTS_MIN = 3 * 60 * 20; - private static final int AUTOREPORT_PER_GAME = 3; + private static final int AUTOREPORT_PER_GAME = 2; private int counter; private int autoReportSent; From 60a7b3d39b3d00586de32804751003b11def800a Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Tue, 24 May 2022 23:59:57 +0200 Subject: [PATCH 30/34] put updater in one class --- .../MegaWallsEnhancementsMod.java | 3 +- .../events/UpdateNotifier.java | 32 ------------------- .../updater/ModUpdater.java | 32 ++++++++++++++++--- 3 files changed, 30 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/fr/alexdoru/megawallsenhancementsmod/events/UpdateNotifier.java diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java index 6154d08e..f118e2e1 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java @@ -6,6 +6,7 @@ import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.events.*; import fr.alexdoru.megawallsenhancementsmod.gui.guiapi.GuiManager; +import fr.alexdoru.megawallsenhancementsmod.updater.ModUpdater; import fr.alexdoru.nocheatersmod.NoCheatersMod; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.client.ClientCommandHandler; @@ -47,7 +48,7 @@ public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new SquadEvent()); MinecraftForge.EVENT_BUS.register(new KillCounter()); MinecraftForge.EVENT_BUS.register(new LowHPIndicator()); - MinecraftForge.EVENT_BUS.register(new UpdateNotifier()); + MinecraftForge.EVENT_BUS.register(new ModUpdater()); MinecraftForge.EVENT_BUS.register(new KeybindingsEvent()); MinecraftForge.EVENT_BUS.register(new MWGameStatsEvent()); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/UpdateNotifier.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/UpdateNotifier.java deleted file mode 100644 index e3853e1b..00000000 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/UpdateNotifier.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.alexdoru.megawallsenhancementsmod.events; - -import fr.alexdoru.megawallsenhancementsmod.api.exceptions.ApiException; -import fr.alexdoru.megawallsenhancementsmod.updater.ModUpdater; -import fr.alexdoru.megawallsenhancementsmod.utils.Multithreading; -import net.minecraft.client.Minecraft; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; - -public class UpdateNotifier { - - private final Minecraft mc = Minecraft.getMinecraft(); - private boolean hasTriggered = false; - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (mc.theWorld != null && mc.thePlayer != null && !hasTriggered) { - hasTriggered = true; - Multithreading.addTaskToQueue(() -> { - try { - ModUpdater.checkForUpdate(); - } catch (ApiException e) { - e.printStackTrace(); - } - return null; - }); - MinecraftForge.EVENT_BUS.unregister(this); - } - } - -} diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java index 85cceae2..a4eb3fee 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java @@ -8,16 +8,40 @@ import fr.alexdoru.megawallsenhancementsmod.api.exceptions.ApiException; import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil; import fr.alexdoru.megawallsenhancementsmod.utils.JsonUtil; +import fr.alexdoru.megawallsenhancementsmod.utils.Multithreading; +import net.minecraft.client.Minecraft; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; public class ModUpdater { private static final String GITHUB_API_URL = "https://api.github.com/repos/Alexdoru/MegaWallsEnhancements/releases"; private static final String GITHUB_URL = "https://github.com/Alexdoru/MegaWallsEnhancements/releases"; + public static boolean isUpTodate = false; + private final Minecraft mc = Minecraft.getMinecraft(); + private boolean hasTriggered = false; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (mc.theWorld != null && mc.thePlayer != null && !hasTriggered) { + hasTriggered = true; + Multithreading.addTaskToQueue(() -> { + try { + checkForUpdate(); + } catch (ApiException e) { + e.printStackTrace(); + } + return null; + }); + MinecraftForge.EVENT_BUS.unregister(this); + } + } public static void checkForUpdate() throws ApiException { @@ -53,12 +77,12 @@ public static void checkForUpdate() throws ApiException { if (Integer.parseInt(MegaWallsEnhancementsMod.version.replace(".", "")) < latestVersion) { ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagMW() + EnumChatFormatting.RED + EnumChatFormatting.BOLD + "Mega Walls Enhancements " - + EnumChatFormatting.GOLD + "version v" + version + EnumChatFormatting.GREEN + " is available for download, click this message to see the changelog and download page.") + + EnumChatFormatting.GOLD + "version v" + version + EnumChatFormatting.GREEN + " is available, click this message to see the changelog and download page.") .setChatStyle(new ChatStyle() .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, GITHUB_URL)) - .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.YELLOW + GITHUB_URL))) - ) - ); + .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.YELLOW + GITHUB_URL))))); + } else { + isUpTodate = true; } } From e5a0ac68d9035ffbc2cc5c2e52ab05a91305b492 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Wed, 25 May 2022 19:33:12 +0200 Subject: [PATCH 31/34] squad command help --- .../commands/CommandSquad.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java index b0bee34b..f8e2366d 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java @@ -17,8 +17,7 @@ import java.util.List; import java.util.Map.Entry; -import static fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil.addChatMessage; -import static fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil.getTagMW; +import static fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil.*; public class CommandSquad extends CommandBase { @@ -56,7 +55,7 @@ public void processCommand(ICommandSender sender, String[] args) { } if (args.length < 1) { - addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage : " + getCommandUsage(sender))); + addChatMessage(getCommandHelp()); return; } @@ -128,6 +127,8 @@ public void processCommand(ICommandSender sender, String[] args) { } } + } else { + addChatMessage(getCommandHelp()); } } @@ -138,4 +139,18 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args return args.length == 1 ? getListOfStringsMatchingLastWord(args, args1) : args.length >= 2 ? getListOfStringsMatchingLastWord(args, TabCompletionUtil.getOnlinePlayersByName()) : null; } + private IChatComponent getCommandHelp() { + + return new ChatComponentText(EnumChatFormatting.GREEN + bar() + "\n" + + centerLine(EnumChatFormatting.GOLD + "Squad Help\n\n") + + EnumChatFormatting.YELLOW + "/squad add " + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "add a player to the squad\n" + + EnumChatFormatting.YELLOW + "/squad add as Nickname" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "add a player to the squad and change their name\n" + + EnumChatFormatting.YELLOW + "/squad remove " + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "remove a player from the squad\n" + + EnumChatFormatting.YELLOW + "/squad list" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "list players in the squad\n" + + EnumChatFormatting.YELLOW + "/squad disband" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "disband the squad\n" + + EnumChatFormatting.GREEN + bar() + ); + + } + } From 037d111d6604383949e5c008f6ac12615ba8e444 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Thu, 26 May 2022 19:39:12 +0200 Subject: [PATCH 32/34] remove the isHypixel checks --- .../fkcountermod/utils/MinecraftUtils.java | 33 ------------------- .../fkcountermod/utils/ScoreboardUtils.java | 11 ++----- .../commands/CommandSquad.java | 3 +- .../events/ChatEvents.java | 4 --- .../events/SquadEvent.java | 3 +- 5 files changed, 4 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/fr/alexdoru/fkcountermod/utils/MinecraftUtils.java diff --git a/src/main/java/fr/alexdoru/fkcountermod/utils/MinecraftUtils.java b/src/main/java/fr/alexdoru/fkcountermod/utils/MinecraftUtils.java deleted file mode 100644 index 026cdd34..00000000 --- a/src/main/java/fr/alexdoru/fkcountermod/utils/MinecraftUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package fr.alexdoru.fkcountermod.utils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraftforge.fml.client.FMLClientHandler; - -import java.util.regex.Pattern; - -public class MinecraftUtils { - /* Regex made by Sk1er */ - private static final Pattern HYPIXEL_PATTERN = Pattern.compile( - "^(?:(?:(?:.+\\.)?hypixel\\.net)|(?:209\\.222\\.115\\.\\d{1,3})|(?:99\\.198\\.123\\.[123]?\\d?))\\.?(?::\\d{1,5}\\.?)?$", - Pattern.CASE_INSENSITIVE - ); - - public static boolean isHypixel() { - FMLClientHandler instance = FMLClientHandler.instance(); - - if (instance == null) { - return false; - } - - Minecraft client = instance.getClient(); - - if (client == null) { - return false; - } - - ServerData currentServerData = client.getCurrentServerData(); - return (currentServerData != null && HYPIXEL_PATTERN.matcher(currentServerData.serverIP).find()); - } -} - diff --git a/src/main/java/fr/alexdoru/fkcountermod/utils/ScoreboardUtils.java b/src/main/java/fr/alexdoru/fkcountermod/utils/ScoreboardUtils.java index 3561416f..71b168f0 100644 --- a/src/main/java/fr/alexdoru/fkcountermod/utils/ScoreboardUtils.java +++ b/src/main/java/fr/alexdoru/fkcountermod/utils/ScoreboardUtils.java @@ -24,18 +24,14 @@ public class ScoreboardUtils { * Item at index 0 is the first line etc */ public static List getFormattedSidebarText() { - List lines = new ArrayList<>(); - - if (mc.theWorld == null || !MinecraftUtils.isHypixel()) { + if (mc.theWorld == null) { return lines; } - Scoreboard scoreboard = mc.theWorld.getScoreboard(); if (scoreboard == null) { return lines; } - return getFormattedSidebarText(scoreboard); } @@ -126,10 +122,7 @@ public static String getUnformattedSidebarTitle(Scoreboard scoreboard) { } public static String getUnformattedSidebarTitle() { - if (mc.theWorld == null || !MinecraftUtils.isHypixel()) { - return null; - } - return getUnformattedSidebarTitle(mc.theWorld.getScoreboard()); + return mc.theWorld == null ? null : getUnformattedSidebarTitle(mc.theWorld.getScoreboard()); } } diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java index f8e2366d..40b9c54c 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/commands/CommandSquad.java @@ -1,6 +1,5 @@ package fr.alexdoru.megawallsenhancementsmod.commands; -import fr.alexdoru.fkcountermod.utils.MinecraftUtils; import fr.alexdoru.fkcountermod.utils.ScoreboardUtils; import fr.alexdoru.megawallsenhancementsmod.events.SquadEvent; import fr.alexdoru.megawallsenhancementsmod.utils.TabCompletionUtil; @@ -42,7 +41,7 @@ public void processCommand(ICommandSender sender, String[] args) { Minecraft mc = Minecraft.getMinecraft(); String title = null; - if (mc.theWorld != null && MinecraftUtils.isHypixel()) { + if (mc.theWorld != null) { Scoreboard scoreboard = mc.theWorld.getScoreboard(); if (scoreboard != null) { title = ScoreboardUtils.getUnformattedSidebarTitle(scoreboard); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/ChatEvents.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/ChatEvents.java index d6b8f088..7a5d41fc 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/ChatEvents.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/ChatEvents.java @@ -4,7 +4,6 @@ import fr.alexdoru.fkcountermod.events.KillCounter; import fr.alexdoru.fkcountermod.events.MwGameEvent; import fr.alexdoru.fkcountermod.utils.DelayedTask; -import fr.alexdoru.fkcountermod.utils.MinecraftUtils; import fr.alexdoru.megawallsenhancementsmod.asm.hooks.NetHandlerPlayClientHook; import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.gui.ArrowHitGui; @@ -194,9 +193,6 @@ public void onChatMessage(ClientChatReceivedEvent event) { private boolean parseAPIKey(String msg) { Matcher matcherapikey = API_KEY_PATTERN.matcher(msg); if (matcherapikey.matches()) { - if (!MinecraftUtils.isHypixel()) { - return false; - } HypixelApiKeyUtil.setApiKey(matcherapikey.group(1)); return true; } diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java index 7f6fbbe6..9382707f 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/events/SquadEvent.java @@ -1,6 +1,5 @@ package fr.alexdoru.megawallsenhancementsmod.events; -import fr.alexdoru.fkcountermod.utils.MinecraftUtils; import fr.alexdoru.fkcountermod.utils.ScoreboardUtils; import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.utils.NameUtil; @@ -64,7 +63,7 @@ public static void formSquad() { Minecraft mc = Minecraft.getMinecraft(); - if (mc.theWorld == null || !MinecraftUtils.isHypixel()) { + if (mc.theWorld == null) { return; } From 681e570f448b94e86dec37f57226239eb32e0c10 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Sat, 28 May 2022 02:29:41 +0200 Subject: [PATCH 33/34] auto updater --- build.gradle | 2 +- .../MegaWallsEnhancementsMod.java | 2 + .../config/ConfigHandler.java | 5 + .../gui/GeneralConfigGuiScreen.java | 6 + .../updater/ModUpdater.java | 108 +++++++++++++++++- 5 files changed, 117 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 87c08714..384dbeae 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle.forge' version = "1.8" group = "fr.alexdoru" -archivesBaseName = "[1.8.9] MegaWallsEnhancements" +archivesBaseName = "[1.8.9]MegaWallsEnhancements" sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java index f118e2e1..d667b064 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java @@ -28,11 +28,13 @@ public class MegaWallsEnhancementsMod { public static final KeyBinding toggleDroppedItemLimit = new KeyBinding("Toggle dropped item limit", 0, "MegaWallsEnhancements"); public static final KeyBinding newNickKey = new KeyBinding("New Random Nick", 0, "MegaWallsEnhancements"); public static File configurationFile; + public static File jarFile; @EventHandler public void preInit(FMLPreInitializationEvent event) { configurationFile = event.getSuggestedConfigurationFile(); ConfigHandler.preinit(configurationFile); + jarFile = event.getSourceFile(); } @EventHandler diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java index fb6a61fa..389c6f18 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/config/ConfigHandler.java @@ -47,6 +47,7 @@ public class ConfigHandler { public static boolean prestigeV; public static boolean hideRepetitiveMWChatMsg; public static boolean clearVision; + public static boolean automaticUpdate; /** * GUI config @@ -141,6 +142,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro final Property pprestigeV = config.get(CATEGORY_MWENh, "Prestige V colored Tag", false, "Prestige V colored Tag"); final Property phideRepetitiveMWChatMsg = config.get(CATEGORY_MWENh, "Delete repetitive chat messages in mw", true, "Delete repetitive chat messages in mw"); final Property pclearVision = config.get(CATEGORY_MWENh, "Clear Vision", true, "Hides particles too close to the camera"); + final Property pautomaticUpdate = config.get(CATEGORY_MWENh, "Automatic Update", true, "Updates the mod automatically"); final String CATEGORY_GUI = "GUI"; final Property pShow_killcooldownHUD = config.get(CATEGORY_GUI, "Show kill cooldown HUD", true, "Displays the cooldown for the /kill command when in MegaWalls"); @@ -217,6 +219,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro pOrderMWWENh.add(pprestigeV.getName()); pOrderMWWENh.add(phideRepetitiveMWChatMsg.getName()); pOrderMWWENh.add(pclearVision.getName()); + pOrderMWWENh.add(pautomaticUpdate.getName()); config.setCategoryPropertyOrder(CATEGORY_MWENh, pOrderMWWENh); List pOrderGUI = new ArrayList<>(); @@ -295,6 +298,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro prestigeV = !HypixelApiKeyUtil.apiKeyIsNotSetup() && pprestigeV.getBoolean(); hideRepetitiveMWChatMsg = phideRepetitiveMWChatMsg.getBoolean(); clearVision = pclearVision.getBoolean(); + automaticUpdate = pautomaticUpdate.getBoolean(); show_killcooldownHUD = pShow_killcooldownHUD.getBoolean(); killcooldownHUDPosition.setRelative(pXpos_killcooldownHUD.getDouble(), pYpos_killcooldownHUD.getDouble()); @@ -365,6 +369,7 @@ private static void syncConfig(boolean loadFromConfigFile, boolean readFieldsFro pprestigeV.set(prestigeV); phideRepetitiveMWChatMsg.set(hideRepetitiveMWChatMsg); pclearVision.set(clearVision); + pautomaticUpdate.set(automaticUpdate); pShow_killcooldownHUD.set(show_killcooldownHUD); double[] killcooldownHUDarray = killcooldownHUDPosition.getRelativePosition(); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/GeneralConfigGuiScreen.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/GeneralConfigGuiScreen.java index 7ac961f5..3ebb17ba 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/GeneralConfigGuiScreen.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/gui/GeneralConfigGuiScreen.java @@ -1,6 +1,7 @@ package fr.alexdoru.megawallsenhancementsmod.gui; import fr.alexdoru.fkcountermod.gui.FKConfigGuiScreen; +import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.gui.guiapi.HitboxConfigGuiScreen; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.EnumChatFormatting; @@ -18,6 +19,7 @@ public void initGui() { this.buttonList.add(new GuiButton(0, getxCenter() - buttonsWidth / 2, getYposForButton(-2), buttonsWidth, ButtonsHeight, EnumChatFormatting.AQUA + "Final Kill Counter")); this.buttonList.add(new GuiButton(1, getxCenter() - buttonsWidth / 2, getYposForButton(-1), buttonsWidth, ButtonsHeight, EnumChatFormatting.GREEN + "Mega Walls Enhancements")); this.buttonList.add(new GuiButton(2, getxCenter() - buttonsWidth / 2, getYposForButton(0), buttonsWidth, ButtonsHeight, EnumChatFormatting.RED + "No Cheaters")); + this.buttonList.add(new GuiButton(5, getxCenter() + buttonsWidth, getYposForButton(0), buttonsWidth, ButtonsHeight, EnumChatFormatting.WHITE + "Automatic Updates : " + getSuffix(ConfigHandler.automaticUpdate))); this.buttonList.add(new GuiButton(4, getxCenter() - buttonsWidth / 2, getYposForButton(1), buttonsWidth, ButtonsHeight, EnumChatFormatting.BLUE + "Hitboxes, better F3+b")); this.buttonList.add(new GuiButton(3, getxCenter() - 150 / 2, getYposForButton(4), 150, ButtonsHeight, "Close")); super.initGui(); @@ -48,6 +50,10 @@ protected void actionPerformed(GuiButton button) throws IOException { case 4: mc.displayGuiScreen(new HitboxConfigGuiScreen(this)); break; + case 5: + ConfigHandler.automaticUpdate = !ConfigHandler.automaticUpdate; + button.displayString = EnumChatFormatting.WHITE + "Automatic Updates : " + getSuffix(ConfigHandler.automaticUpdate); + break; } super.actionPerformed(button); diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java index a4eb3fee..e7d5bdfe 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/updater/ModUpdater.java @@ -1,11 +1,13 @@ package fr.alexdoru.megawallsenhancementsmod.updater; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import fr.alexdoru.megawallsenhancementsmod.MegaWallsEnhancementsMod; import fr.alexdoru.megawallsenhancementsmod.api.HttpClient; import fr.alexdoru.megawallsenhancementsmod.api.exceptions.ApiException; +import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler; import fr.alexdoru.megawallsenhancementsmod.utils.ChatUtil; import fr.alexdoru.megawallsenhancementsmod.utils.JsonUtil; import fr.alexdoru.megawallsenhancementsmod.utils.Multithreading; @@ -15,17 +17,22 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Util; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + public class ModUpdater { - private static final String GITHUB_API_URL = "https://api.github.com/repos/Alexdoru/MegaWallsEnhancements/releases"; - private static final String GITHUB_URL = "https://github.com/Alexdoru/MegaWallsEnhancements/releases"; + private static final Minecraft mc = Minecraft.getMinecraft(); + private static boolean hasTriggered = false; public static boolean isUpTodate = false; - private final Minecraft mc = Minecraft.getMinecraft(); - private boolean hasTriggered = false; @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { @@ -43,8 +50,12 @@ public void onTick(TickEvent.ClientTickEvent event) { } } - public static void checkForUpdate() throws ApiException { + /** + * https://github.com/DeDiamondPro/Auto-Updater + */ + public static void checkForUpdate() throws ApiException, IOException { + String GITHUB_API_URL = "https://api.github.com/repos/Alexdoru/MegaWallsEnhancements/releases"; HttpClient httpClient = new HttpClient(GITHUB_API_URL); String rawresponse = httpClient.getrawresponse(); if (rawresponse == null) { @@ -62,6 +73,7 @@ public static void checkForUpdate() throws ApiException { int latestVersion = 0; String version = ""; + String browser_download_url = null; for (JsonElement jsonElement : element.getAsJsonArray()) { JsonObject release = jsonElement.getAsJsonObject(); @@ -71,20 +83,106 @@ public static void checkForUpdate() throws ApiException { if (releaseVersion > latestVersion) { latestVersion = releaseVersion; version = tag_name; + final JsonElement assets = release.get("assets"); + if (assets != null && assets.isJsonArray()) { + final JsonArray assetsJsonArray = assets.getAsJsonArray(); + for (JsonElement assetsElement : assetsJsonArray) { + if (assetsElement != null && assetsElement.isJsonObject()) { + final JsonObject assetsJsonObject = assetsElement.getAsJsonObject(); + browser_download_url = JsonUtil.getString(assetsJsonObject, "browser_download_url"); + } + } + } } } } if (Integer.parseInt(MegaWallsEnhancementsMod.version.replace(".", "")) < latestVersion) { + + String GITHUB_URL = "https://github.com/Alexdoru/MegaWallsEnhancements/releases"; ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagMW() + EnumChatFormatting.RED + EnumChatFormatting.BOLD + "Mega Walls Enhancements " + EnumChatFormatting.GOLD + "version v" + version + EnumChatFormatting.GREEN + " is available, click this message to see the changelog and download page.") .setChatStyle(new ChatStyle() .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, GITHUB_URL)) .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.YELLOW + GITHUB_URL))))); + + if (ConfigHandler.automaticUpdate && browser_download_url != null && browser_download_url.endsWith(".jar")) { + + File cacheDir = new File("config/updatecache"); + if (!cacheDir.exists() && !cacheDir.mkdir()) { + throw new IllegalStateException("Could not create cache folder"); + } + + String newModFileName = getFileName(browser_download_url); + File modCacheFile = new File(cacheDir, newModFileName); + downloadFileTo(browser_download_url, modCacheFile); + System.out.println("Downloaded MWEnhancement Update"); + + String GITHUB_DELETER_URL = "https://github.com/W-OVERFLOW/Deleter/releases/download/v1.4/Deleter-1.4.jar";// TODO essayer de faire marcher le 1.5 + String deleterFileName = getFileName(GITHUB_DELETER_URL); + File deleterFile = new File(cacheDir, deleterFileName); + downloadFileTo(GITHUB_DELETER_URL, deleterFile); + System.out.println("Downloaded Mod Deleter"); + + if (modCacheFile.exists() && deleterFile.exists()) { + + ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.getTagMW() + EnumChatFormatting.RED + EnumChatFormatting.BOLD + "Mega Walls Enhancements " + EnumChatFormatting.GOLD + "version v" + version + EnumChatFormatting.GREEN + " has been downloaded and will be installed automatically when closing your game.")); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + final File oldJarFile = MegaWallsEnhancementsMod.jarFile; + final File newJarFile = new File(oldJarFile.getParent(), newModFileName); + if (newJarFile.createNewFile() && modCacheFile.exists() && oldJarFile.exists()) { + try (InputStream source = new FileInputStream(modCacheFile); OutputStream dest = new FileOutputStream(newJarFile)) { + byte[] buffer = new byte[1024]; + int length; + while ((length = source.read(buffer)) > 0) { + dest.write(buffer, 0, length); + } + } + modCacheFile.delete(); + deleteOldJar(oldJarFile.getAbsolutePath(), deleterFile); + } + } catch (IOException e) { + e.printStackTrace(); + } + })); + + } + + } + } else { + isUpTodate = true; + } } + private static void downloadFileTo(String browser_download_url, File cacheFile) throws IOException { + URLConnection connection = new URL(browser_download_url).openConnection(); + connection.setRequestProperty("User-Agent", "Updater"); + InputStream inputStream = connection.getInputStream(); + Files.copy(inputStream, cacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + inputStream.close(); + } + + private static String getFileName(String downloadUrl) { + return downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1); + } + + private static void deleteOldJar(String absolutePathToDelete, File deleter) throws IOException { + if (Util.getOSType() == Util.EnumOS.LINUX) { + Runtime.getRuntime().exec("chmod +x \"" + deleter.getAbsolutePath() + "\""); + } else if (Util.getOSType() == Util.EnumOS.OSX) { + Runtime.getRuntime().exec("chmod 755 \"" + deleter.getAbsolutePath() + "\""); + } + Runtime.getRuntime().exec( + "java -jar " + deleter.getName() + " \"" + absolutePathToDelete + "\"",// TODO tester de changer + null, + deleter.getParentFile() + ); + } + } From b05dfd8560ed9e95d53dd87f2d3935920c9ca197 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+alexdoru@users.noreply.github.com> Date: Sat, 28 May 2022 03:06:20 +0200 Subject: [PATCH 34/34] RELEASE 1.9---------------------------------- --- build.gradle | 2 +- .../megawallsenhancementsmod/MegaWallsEnhancementsMod.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 384dbeae..b3de4838 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { } apply plugin: 'net.minecraftforge.gradle.forge' -version = "1.8" +version = "1.9" group = "fr.alexdoru" archivesBaseName = "[1.8.9]MegaWallsEnhancements" diff --git a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java index d667b064..be59dc19 100644 --- a/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java +++ b/src/main/java/fr/alexdoru/megawallsenhancementsmod/MegaWallsEnhancementsMod.java @@ -24,7 +24,7 @@ public class MegaWallsEnhancementsMod { public static final String modid = "mwenhancements"; public static final String modName = "MegaWallsEnhancements"; - public static final String version = "1.8"; + public static final String version = "1.9"; public static final KeyBinding toggleDroppedItemLimit = new KeyBinding("Toggle dropped item limit", 0, "MegaWallsEnhancements"); public static final KeyBinding newNickKey = new KeyBinding("New Random Nick", 0, "MegaWallsEnhancements"); public static File configurationFile;