aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2023-06-08 09:34:19 +0200
committerGitHub <noreply@github.com>2023-06-08 17:34:19 +1000
commit5a422e5b879bf62b562bd811ebeba2877c005f78 (patch)
tree737c5b80e9d7abf40a64df2c690780e5013a78ae /src/main
parent0876e2e7936cdaeee630a5f6d9477f6269e2b3fb (diff)
downloadNotEnoughUpdates-5a422e5b879bf62b562bd811ebeba2877c005f78.tar.gz
NotEnoughUpdates-5a422e5b879bf62b562bd811ebeba2877c005f78.tar.bz2
NotEnoughUpdates-5a422e5b879bf62b562bd811ebeba2877c005f78.zip
Fix navigation warps being broken by reading chat messages instead of… (#707)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java80
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java2
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt1
3 files changed, 47 insertions, 36 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java
index 86e49aec..8b032acd 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java
@@ -22,24 +22,25 @@ package io.github.moulberry.notenoughupdates.miscfeatures;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
+import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent;
import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
-import io.github.moulberry.notenoughupdates.listener.RenderListener;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
import io.github.moulberry.notenoughupdates.miscgui.GuiNavigation;
-import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.util.JsonUtils;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
+import io.github.moulberry.notenoughupdates.util.brigadier.DslKt;
+import kotlin.Unit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
-import net.minecraft.client.gui.inventory.GuiChest;
-import net.minecraft.inventory.ContainerChest;
-import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.Vec3i;
+import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -47,6 +48,7 @@ import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Keyboard;
+import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
@@ -105,7 +107,8 @@ public class Navigation {
private String displayName = null;
private String internalname = null;
private String warpAgainTo = null;
- private int lastInvHashcode = 0;
+ private Instant lastWarpAttemptedTime = null;
+ private String lastWarpAttempted;
private Instant warpAgainTiming = null;
private Teleporter nextTeleporter = null;
@@ -203,46 +206,51 @@ public class Navigation {
}
}
+ public Map<String, WarpPoint> getWarps() {
+ return warps;
+ }
+
@SubscribeEvent
- public void onGuiTick(TickEvent.ClientTickEvent event) {
- if (event.phase != TickEvent.Phase.START) return;
- if (Minecraft.getMinecraft().theWorld == null) return;
- if (Minecraft.getMinecraft().thePlayer == null) return;
- if (neu.config.getProfileSpecific() == null) return;
-
- if (Minecraft.getMinecraft().currentScreen instanceof GuiChest && RenderListener.inventoryLoaded) {
- GuiChest currentScreen = (GuiChest) Minecraft.getMinecraft().currentScreen;
- ContainerChest container = (ContainerChest) currentScreen.inventorySlots;
- if (container.getLowerChestInventory().getDisplayName().getUnformattedText().equals("Fast Travel")) {
- int hashCode = container.getInventory().hashCode();
- if (hashCode == lastInvHashcode) return;
- lastInvHashcode = hashCode;
- for (ItemStack stackInSlot : container.getInventory()) {
- if (stackInSlot == null) continue;
- List<String> lore = ItemUtils.getLore(stackInSlot);
- if (lore.isEmpty())
- continue;
- String warpLine = Utils.cleanColour(lore.get(0));
- if (!warpLine.startsWith("/warp ")) continue;
- String warpName = warpLine.substring(6);
- boolean isUnlocked = !lore.contains("§cWarp not unlocked!");
- neu.config.getProfileSpecific().unlockedWarpScrolls.put(warpName, isUnlocked);
- }
- }
+ public void onChatMessage(ClientChatReceivedEvent event) {
+ if (event.type == 2) return;
+ if (StringUtils.cleanColour(event.message.getUnformattedText()).startsWith("§r§eYou may now fast travel to")) {
+ getNonUnlockedWarpScrolls().clear();
+ return;
}
+ if (!"§r§cYou haven't unlocked this fast travel destination!§r".equals(event.message.getFormattedText())) return;
+ Instant lwa = lastWarpAttemptedTime;
+ if (lwa == null) return;
+ if (Duration.between(lwa, Instant.now()).compareTo(Duration.ofSeconds(1)) > 0) return;
+ lastWarpAttemptedTime = null;
+ getNonUnlockedWarpScrolls().add(lastWarpAttempted);
+ Utils.addChatMessage("§e[NEU] This warp has been marked as non available.");
+ Utils.addChatMessage(
+ "§e[NEU] Try navigating to that same position again to check if you have another warp available on that island.");
+ Utils.addChatMessage("§e[NEU] To reset, type /neuclearwarps");
}
- public Map<String, WarpPoint> getWarps() {
- return warps;
+ @SubscribeEvent
+ public void onCommands(RegisterBrigadierCommandEvent event) {
+ event.command("neuclearwarps", builder -> DslKt.thenExecute(builder, context -> {
+ getNonUnlockedWarpScrolls().clear();
+ DslKt.reply(context, "Reset all blocked warps.");
+ return Unit.INSTANCE;
+ }));
+ }
+
+ private Set<String> getNonUnlockedWarpScrolls() {
+ NEUConfig.HiddenProfileSpecific profileSpecific = neu.config.getProfileSpecific();
+ if (profileSpecific == null) return new HashSet<>();
+ return profileSpecific.nonUnlockedWarpScrolls;
}
public WarpPoint getClosestWarp(String mode, Vec3i position, boolean checkAvailable) {
double minDistance = -1;
- HashMap<String, Boolean> unlockedWarpScrolls = neu.config.getProfileSpecific().unlockedWarpScrolls;
+ Set<String> nonUnlockedWarpScrolls = getNonUnlockedWarpScrolls();
WarpPoint minWarp = null;
for (WarpPoint value : warps.values()) {
if (value.modeName.equals(mode)) {
- if (checkAvailable && !unlockedWarpScrolls.getOrDefault(value.warpName, false))
+ if (checkAvailable && nonUnlockedWarpScrolls.contains(value.warpName))
continue;
double distance = value.blockPos.distanceSq(position);
if (distance < minDistance || minWarp == null) {
@@ -270,6 +278,8 @@ public class Navigation {
showError("You are already on the same island and nearer than the closest unlocked warp scroll.", false);
return;
}
+ lastWarpAttemptedTime = Instant.now();
+ lastWarpAttempted = closestWarp.warpName;
thePlayer.sendChatMessage("/warp " + closestWarp.warpName);
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
index 3b5cb53e..2d66f595 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
@@ -574,7 +574,7 @@ public class NEUConfig extends Config {
@Expose
public long dailyMithrilPowerCompleted = 0L;
@Expose
- public HashMap<String, Boolean> unlockedWarpScrolls = new HashMap<>();
+ public Set<String> nonUnlockedWarpScrolls = new HashSet<>();
@Expose
public long dailyHeavyPearlCompleted = 0L;
@Expose
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
index 1ce00d99..2cd5133e 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
@@ -83,6 +83,7 @@ fun <T : ICommandSender, C : CommandContext<T>> C.reply(component: IChatComponen
source.addChatMessage(ChatComponentText("§e[NEU] ").appendSibling(component))
}
+@JvmOverloads
fun <T : ICommandSender, C : CommandContext<T>> C.reply(text: String, block: ChatComponentText.() -> Unit = {}) {
source.addChatMessage(ChatComponentText(text.split("\n").joinToString("\n") { "§e[NEU] $it" }).also(block))
}