diff options
| author | nea <nea@nea.moe> | 2023-02-21 23:49:19 +0100 |
|---|---|---|
| committer | nea <nea@nea.moe> | 2023-02-21 23:49:19 +0100 |
| commit | 1d80d1148bd4f8402e238665dd47ed04de9d9003 (patch) | |
| tree | ceb186b95e1b8cbf613854f7690661d719f12b7e | |
| parent | 56cbcb12cea0b7bf69ea48f758d4644287bb1886 (diff) | |
| parent | 0d281d483909d71272783033b2aba8f33dcbce36 (diff) | |
| download | NotEnoughUpdates-1d80d1148bd4f8402e238665dd47ed04de9d9003.tar.gz NotEnoughUpdates-1d80d1148bd4f8402e238665dd47ed04de9d9003.tar.bz2 NotEnoughUpdates-1d80d1148bd4f8402e238665dd47ed04de9d9003.zip | |
Merge remote-tracking branch 'origin/master' into brigadier
40 files changed, 1272 insertions, 299 deletions
@@ -4,7 +4,7 @@ <div align="center"> <!-- release --> <a href="https://github.com/Moulberry/NotEnoughUpdates/releases/latest" target="_blank"> - <img src="https://img.shields.io/github/v/release/Moulberry/NotEnoughUpdates-REPO?color=informational&include_prereleases&label=release&logo=github&logoColor=white" alt="release"> + <img src="https://img.shields.io/github/v/release/Moulberry/NotEnoughUpdates?color=informational&include_prereleases&label=release&logo=github&logoColor=white" alt="release"> </a> <!-- lines --> <a href="https://github.com/NotEnoughUpdates/NotEnoughUpdates/graphs/code-frequency" target="_blank"> diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 7159ef89..927b5e76 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1500,7 +1500,14 @@ public class NEUOverlay extends Gui { int actualIndex = index + getSlotsXSize() * getSlotsYSize() * page; List<JsonObject> searchedItems = getSearchedItems(); if (0 <= actualIndex && actualIndex < searchedItems.size()) { - return searchedItems.get(actualIndex); + try { + return searchedItems.get(actualIndex); + } catch (IndexOutOfBoundsException e) { + System.out.println("searchedItems size: " + searchedItems.size()); + System.out.println("actualIndex: " + actualIndex); + e.printStackTrace(); + return null; + } } else { return null; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 35bb40bf..7f0136ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -97,7 +97,7 @@ import java.util.Set; guiFactory = "io.github.moulberry.notenoughupdates.core.config.MoulConfigGuiForgeInterop") public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; - public static final String VERSION = "2.1.0-REL"; + public static final String VERSION = "2.1.1-PRE"; public static final int VERSION_ID = 20101; //2.1.1 only so update notif works public static final int PRE_VERSION_ID = 0; public static final int HOTFIX_VERSION_ID = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 5ec3724a..ac60ffd9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -292,7 +292,7 @@ public class APIManager { .newMoulberryRequest("lowestbin.json.gz") .gunzip() .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (lowestBins == null) { lowestBins = new JsonObject(); } @@ -465,12 +465,12 @@ public class APIManager { }; manager.apiUtils.newMoulberryRequest("auctionLast.json.gz") - .gunzip().requestJson().thenAccept(process); + .gunzip().requestJson().thenAcceptAsync(process); manager.apiUtils .newMoulberryRequest("auction.json.gz") .gunzip().requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject.get("success").getAsBoolean()) { long apiUpdate = (long) jsonObject.get("time").getAsFloat(); if (lastApiUpdate == apiUpdate) { @@ -683,7 +683,7 @@ public class APIManager { manager.apiUtils .newAnonymousHypixelApiRequest("skyblock/auctions") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject == null) return; if (jsonObject.get("success").getAsBoolean()) { @@ -733,7 +733,7 @@ public class APIManager { manager.apiUtils .newAnonymousHypixelApiRequest("skyblock/bazaar") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (!jsonObject.get("success").getAsBoolean()) return; craftCost.clear(); @@ -789,7 +789,7 @@ public class APIManager { public void updateAvgPrices() { manager.apiUtils .newMoulberryRequest("auction_averages/3day.json.gz") - .gunzip().requestJson().thenAccept((jsonObject) -> { + .gunzip().requestJson().thenAcceptAsync((jsonObject) -> { craftCost.clear(); auctionPricesJson = jsonObject; lastAuctionAvgUpdate = System.currentTimeMillis(); @@ -797,7 +797,7 @@ public class APIManager { manager.apiUtils .newMoulberryRequest("auction_averages_lbin/1day.json.gz") .gunzip().requestJson() - .thenAccept((jsonObject) -> { + .thenAcceptAsync((jsonObject) -> { auctionPricesAvgLowestBinJson = jsonObject; }); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java index 920cb326..ddd1e71f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java @@ -30,6 +30,7 @@ public @interface ConfigOption { String name(); String desc(); + String[] searchTags() default ""; int subcategoryId() default -1; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java index 4a7c1939..984a7931 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java @@ -150,7 +150,7 @@ public class CapeManager { NotEnoughUpdates.INSTANCE.manager.apiUtils .newMoulberryRequest("activecapes.json") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (jsonObject.get("success").getAsBoolean()) { lastJsonSync = jsonObject; @@ -171,7 +171,7 @@ public class CapeManager { NotEnoughUpdates.INSTANCE.manager.apiUtils .newMoulberryRequest("permscapes.json") .requestJson() - .thenAccept(jsonObject -> { + .thenAcceptAsync(jsonObject -> { if (!jsonObject.get("success").getAsBoolean()) return; permSyncTries = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java index 80751371..f130a993 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java @@ -31,9 +31,13 @@ public class CookieWarning { private static boolean hasNotified; private static boolean hasErrorMessage; + private static long cookieEndTime = 0; + private static boolean hasCookie = true; + private static long lastChecked = 0; public static void resetNotification() { hasNotified = false; + hasCookie = true; NotificationHandler.cancelNotification(); } @@ -41,96 +45,135 @@ public class CookieWarning { * Checks the tab list for a cookie timer, and sends a notification if the timer is within the tolerance */ public static void checkCookie() { - if (NotEnoughUpdates.INSTANCE.config.notifications.doBoosterNotif && - NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - String[] lines; - try { - lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList()) - .getFooter() - .getUnformattedText() - .split("\n"); - } catch (NullPointerException e) { - return; // if the footer is null or somehow doesn't exist, stop + if (!NotEnoughUpdates.INSTANCE.config.notifications.doBoosterNotif || + !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return; + } + String timeLine = getTimeLine(); + if (!hasCookie) { + if (!hasNotified) { + NotificationHandler.displayNotification(Lists.newArrayList( + "§cBooster Cookie Ran Out!", + "§7Your Booster Cookie expired!", + "§7", + "§7Press X on your keyboard to close this notification" + ), true, true); + hasNotified = true; } - boolean hasCookie = true; - String timeLine = null; // the line that contains the cookie timer - for (int i = 0; i < lines.length; i++) { - if (lines[i].startsWith("Cookie Buff")) { - timeLine = lines[i + 1]; // the line after the "Cookie Buff" line - } - if (lines[i].startsWith("Not active! Obtain booster cookies from the")) { - hasCookie = false; - } + return; + } + if (timeLine == null) return; + + int minutes = getMinutesRemaining(timeLine); + if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) { + NotificationHandler.displayNotification(Lists.newArrayList( + "§cBooster Cookie Running Low!", + "§7Your Booster Cookie will expire in " + timeLine, + "§7", + "§7Press X on your keyboard to close this notification" + ), true, true); + hasNotified = true; + } + } + + private static int getMinutesRemaining(String timeLine) { + String clean = timeLine.replaceAll("(§.)", ""); + clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2"); + String[] digits = clean.split(" "); + int minutes = 0; + try { + for (int i = 0; i < digits.length; i++) { + if (i % 2 == 1) continue; + + String number = digits[i]; + String unit = digits[i + 1]; + long val = Integer.parseInt(number); + switch (unit) { + case "Years": + case "Year": + minutes += val * 525600; + break; + case "Months": + case "Month": + minutes += val * 43200; + break; + case "Days": + case "Day": + minutes += val * 1440; + break; + case "Hours": + case "Hour": + case "h": + minutes += val * 60; + break; + case "Minutes": + case "Minute": + case "m": + minutes += val; + break; + } // ignore seconds } - if (!hasCookie) { - if (!hasNotified) { - NotificationHandler.displayNotification(Lists.newArrayList( - "\u00a7cBooster Cookie Ran Out!", - "\u00a77Your Booster Cookie expired!", - "\u00a77", - "\u00a77Press X on your keyboard to close this notification" - ), true, true); - hasNotified = true; - } - return; + } catch (NumberFormatException e) { + if (!hasErrorMessage) { + e.printStackTrace(); + Utils.addChatMessage(EnumChatFormatting.RED + + "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."); + hasErrorMessage = true; } - if (timeLine != null) { - String clean = timeLine.replaceAll("(\u00a7.)", ""); - clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2"); - String[] digits = clean.split(" "); - int minutes = 0; - try { - for (int i = 0; i < digits.length; i++) { - if (i % 2 == 1) continue; + hasNotified = true; + } + return minutes; + } - String number = digits[i]; - String unit = digits[i + 1]; - long val = Integer.parseInt(number); - switch (unit) { - case "Years": - case "Year": - minutes += val * 525600; - break; - case "Months": - case "Month": - minutes += val * 43200; - break; - case "Days": - case "Day": - minutes += val * 1440; - break; - case "Hours": - case "Hour": - case "h": - minutes += val * 60; - break; - case "Minutes": - case "Minute": - case "m": - minutes += val; - break; - } // ignore seconds - } - } catch (NumberFormatException e) { - if (!hasErrorMessage) { - e.printStackTrace(); - Utils.addChatMessage(EnumChatFormatting.RED + - "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."); - hasErrorMessage = true; - } - hasNotified = true; - } - if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) { - NotificationHandler.displayNotification(Lists.newArrayList( - "\u00a7cBooster Cookie Running Low!", - "\u00a77Your Booster Cookie will expire in " + timeLine, - "\u00a77", - "\u00a77Press X on your keyboard to close this notification" - ), true, true); - hasNotified = true; - } + private static String getTimeLine() { + String[] lines; + try { + lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList()) + .getFooter() + .getUnformattedText() + .split("\n"); + } catch (NullPointerException ignored) { + return null; + } + String timeLine = null; // the line that contains the cookie timer + for (int i = 0; i < lines.length; i++) { + if (lines[i].startsWith("Cookie Buff")) { + timeLine = lines[i + 1]; // the line after the "Cookie Buff" line + } + if (lines[i].startsWith("Not active! Obtain booster cookies from the")) { + hasCookie = false; } } + return timeLine; + } + + public static boolean hasActiveBoosterCookie() { + long cookieEndTime = getCookieEndTime(); + return cookieEndTime > System.currentTimeMillis(); + } + + private static long getCookieEndTime() { + // Only updating every 10 seconds +// if (System.currentTimeMillis() > lastChecked + 10_000) return cookieEndTime; + if (lastChecked + 3_000 > System.currentTimeMillis()) return cookieEndTime; + + String timeLine = getTimeLine(); + if (hasCookie && timeLine != null) { + int minutes = getMinutesRemaining(timeLine); + cookieEndTime = System.currentTimeMillis() + (long) minutes * 60 * 1000; + } else { + cookieEndTime = 0; + } + + lastChecked = System.currentTimeMillis(); + return cookieEndTime; + } + public static void onProfileSwitch() { + resetNotification(); + hasErrorMessage = false; + cookieEndTime = 0; + hasCookie = true; + lastChecked = 0; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MutingComposter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MutingComposter.java new file mode 100644 index 00000000..4b4d655b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MutingComposter.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import net.minecraftforge.client.event.sound.PlaySoundEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.Arrays; +import java.util.List; + +@NEUAutoSubscribe +public class MutingComposter { + + private static final MutingComposter INSTANCE = new MutingComposter(); + private final List<String> mutableSounds = Arrays.asList( + "mob.wolf.growl", + "tile.piston.out", + "liquid.water", + "mob.chicken.plop" + ); + + public static MutingComposter getInstance() { + return INSTANCE; + } + + protected boolean isEnabled() { + return SBInfo.getInstance().getLocation().equals("garden") + && NotEnoughUpdates.INSTANCE.config.garden.muteComposterSounds; + } + + @SubscribeEvent + public void onSoundPlay(PlaySoundEvent event) { + if (mutableSounds.contains(event.name) && isEnabled() && event.sound.getXPosF() == -11.5 && event.sound.getYPosF() == 72.5 && event.sound.getZPosF() == -26.5) { + event.result = null; + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 716fb37d..ceae782b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -473,29 +473,44 @@ public class PetInfoOverlay extends TextOverlay { } } JsonObject pets = Constants.PETS; - if (pets != null && pets.has("custom_pet_leveling") && pets.get("custom_pet_leveling").getAsJsonObject().has(pet.petType.toUpperCase()) && - pets.get("custom_pet_leveling").getAsJsonObject().get(pet.petType.toUpperCase()).getAsJsonObject().has("xp_multiplier")) { - xp *= pets.get("custom_pet_leveling").getAsJsonObject().get(pet.petType.toUpperCase()).getAsJsonObject().get("xp_multiplier").getAsFloat(); + if (pets != null && pets.has("custom_pet_leveling") && + pets.get("custom_pet_leveling").getAsJsonObject().has(pet.petType.toUpperCase()) && + pets.get("custom_pet_leveling").getAsJsonObject().get(pet.petType.toUpperCase()).getAsJsonObject().has( + "xp_multiplier")) { + xp *= pets.get("custom_pet_leveling").getAsJsonObject().get(pet.petType.toUpperCase()).getAsJsonObject().get( + "xp_multiplier").getAsFloat(); } return xp; } + private int firstPetLines = 0; + private int secondPetLines = 0; + @Override public void updateFrequent() { Pet currentPet = getCurrentPet(); if (!NotEnoughUpdates.INSTANCE.config.petOverlay.enablePetInfo || currentPet == null) { overlayStrings = null; } else { + firstPetLines = 0; + secondPetLines = 0; overlayStrings = new ArrayList<>(); |
