From 74b3bf01cf21ea4fab81067de258ddef53d7ade1 Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Sat, 25 Nov 2023 19:01:52 +0100 Subject: [PATCH] Update to support api v0.8.3 --- build.gradle.kts | 2 +- .../darkbot/core/manager/MapManager.java | 23 ++++--------------- .../darkbot/core/manager/StarManager.java | 20 ++++------------ 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 64eccd699..0568d93f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,7 +43,7 @@ publishing { } dependencies { - val apiVersion = "0.8.2" + val apiVersion = "0.8.3" val flatLafVersion = "3.1.1" // use this if you want to use local(mavenLocal) darkbot API diff --git a/src/main/java/com/github/manolo8/darkbot/core/manager/MapManager.java b/src/main/java/com/github/manolo8/darkbot/core/manager/MapManager.java index c4c0f2d05..68497bbb9 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/manager/MapManager.java +++ b/src/main/java/com/github/manolo8/darkbot/core/manager/MapManager.java @@ -31,13 +31,11 @@ import eu.darkbot.api.managers.EventBrokerAPI; import eu.darkbot.api.managers.StarSystemAPI; import eu.darkbot.util.Timer; -import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.function.Consumer; import static com.github.manolo8.darkbot.Main.API; @@ -57,7 +55,6 @@ public class MapManager implements Manager, StarSystemAPI { private long viewAddress; private long boundsAddress; public long eventAddress; - private long settings3DAddress; public static int id = -1; public Lazy mapChange = new Lazy.NoCache<>(); @@ -485,6 +482,11 @@ public GameMap getOrCreateMap(int mapId) { return starManager.byId(mapId); } + @Override + public GameMap getOrCreateMap(String mapName) { + return starManager.byName(mapName); + } + @Override public Optional findMap(int mapId) { return starManager.getMaps().stream() @@ -501,21 +503,6 @@ public Optional findMap(String mapName) { .findFirst(); } - @Override - public GameMap getById(int mapId) throws MapNotFoundException { - return starManager.getById(mapId); - } - - @Override - public GameMap getOrCreateMapById(int mapId) { - return starManager.byId(mapId); - } - - @Override - public GameMap getByName(@NotNull String mapName) throws MapNotFoundException { - return starManager.getByName(mapName); - } - @Override public Portal findNext(GameMap targetMap) { return starManager.next(main.hero, starManager.byId(targetMap.getId())); diff --git a/src/main/java/com/github/manolo8/darkbot/core/manager/StarManager.java b/src/main/java/com/github/manolo8/darkbot/core/manager/StarManager.java index c69b80fac..1de1dea60 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/manager/StarManager.java +++ b/src/main/java/com/github/manolo8/darkbot/core/manager/StarManager.java @@ -5,7 +5,7 @@ import com.github.manolo8.darkbot.core.objects.Map; import eu.darkbot.api.API; import eu.darkbot.api.config.annotations.Dropdown; -import eu.darkbot.api.managers.StarSystemAPI; +import org.jetbrains.annotations.NotNull; import org.jgrapht.Graph; import org.jgrapht.alg.shortestpath.DijkstraShortestPath; @@ -242,16 +242,6 @@ public Portal next(HeroManager hero, Map target) { .thenComparing(p -> hero.locationInfo.distance(p.locationInfo))).orElse(null); } - public Map byName(String name) { - return starSystem.vertexSet().stream().filter(m -> m.name.equals(name)).findAny() - .orElseGet(() -> addMap(new Map(--INVALID_MAP_ID, name, false, false))); - } - - public Map getByName(String name) throws StarSystemAPI.MapNotFoundException { - return starSystem.vertexSet().stream().filter(m -> m.name.equals(name)).findAny() - .orElseThrow(() -> new StarSystemAPI.MapNotFoundException(name)); - } - public Stream mapSet() { return starSystem.vertexSet().stream(); } @@ -265,9 +255,9 @@ public Map byId(int id) { .orElseGet(() -> addMap(new Map(id, "Unknown map " + id, false, false))); } - public Map getById(int id) throws StarSystemAPI.MapNotFoundException { - return starSystem.vertexSet().stream().filter(m -> m.id == id).findAny() - .orElseThrow(() -> new StarSystemAPI.MapNotFoundException(id)); + public Map byName(String name) { + return starSystem.vertexSet().stream().filter(m -> m.name.equals(name)).findAny() + .orElseGet(() -> addMap(new Map(--INVALID_MAP_ID, name, false, false))); } private Map addMap(Map map) { @@ -346,7 +336,7 @@ public List options() { } @Override - public String getText(Integer option) { + public @NotNull String getText(Integer option) { if (option == null) return ""; return star.byId(option).getName(); }