Skip to content

Commit

Permalink
buh
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 19, 2024
1 parent 113a8a6 commit 734d63a
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 374 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gradle-app.setting
**/build/
!src/**/build/
/src/test/
/src/archive/
out/
bin/
run/
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/github/emcw/map/api/GPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public Route fastestRoute(Location loc) {

public Route findRoute(Location loc, RouteType route) {
if (loc == null || !loc.valid()) {
new IllegalArgumentException(
"Cannot find route! Inputted location is invalid:\n" + loc
).printStackTrace();
new IllegalArgumentException("Cannot find route! Inputted location is invalid:\n" + loc)
.printStackTrace();
}

Map<String, Town> towns = this.parent.Towns.all();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/emcw/map/api/Nations.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.utils.parsers.DynmapParser;
import io.github.emcw.utils.parsers.SquaremapParser;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand Down Expand Up @@ -36,8 +37,8 @@ private void updateCache(Boolean force) {
if (!empty() && !force) return;

// Parse map data into usable Nation objects.
DynmapParser.parseMapData(parent.getMapName(), true, true, false);
Cache<String, Nation> nations = DynmapParser.parsedNations(parent.getMapName());
SquaremapParser.parseMapData(parent.getMapName(), true, true, false);
Cache<String, Nation> nations = SquaremapParser.parsedNations(parent.getMapName());

if (!nations.asMap().isEmpty())
setCache(nations);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/github/emcw/map/api/Players.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.map.entities.Player;
import io.github.emcw.map.entities.Resident;
import io.github.emcw.utils.parsers.DynmapParser;

import io.github.emcw.utils.parsers.SquaremapParser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -48,8 +47,8 @@ public void updateCache(Boolean force) {
if (!empty() && !force) return;

// Parse player data into usable Player objects.
DynmapParser.parsePlayerData(parent.getMapName());
Cache<String, Player> players = DynmapParser.parsedPlayers();
SquaremapParser.parsePlayerData();
Cache<String, Player> players = SquaremapParser.parsedPlayers();

// Make sure we have data to use.
if (!players.asMap().isEmpty())
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/emcw/map/api/Residents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.emcw.map.entities.Resident;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.utils.parsers.DynmapParser;
import io.github.emcw.utils.parsers.SquaremapParser;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand Down Expand Up @@ -37,8 +38,8 @@ private void updateCache(Boolean force) {
if (!empty() && !force) return;

// Parse player data into usable Player objects.
DynmapParser.parseMapData(parent.getMapName(), false, false, true);
Cache<String, Resident> residents = DynmapParser.parsedResidents();
SquaremapParser.parseMapData(false, false, true);
Cache<String, Resident> residents = SquaremapParser.parsedResidents();

// Make sure we're using valid data
if (!residents.asMap().isEmpty())
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/github/emcw/map/api/Towns.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.github.emcw.map.entities.Town;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.utils.parsers.DynmapParser;
import io.github.emcw.utils.parsers.SquaremapParser;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand Down Expand Up @@ -36,8 +36,8 @@ private void updateCache(Boolean force) {
if (!empty() && !force) return;

// Parse map data into usable Town objects.
DynmapParser.parseMapData(parent.getMapName(), true, false, true);
Cache<String, Town> towns = DynmapParser.parsedTowns();
SquaremapParser.parseMapData(true, false, true);
Cache<String, Town> towns = SquaremapParser.parsedTowns();

// Make sure were using valid data.
if (!towns.asMap().isEmpty())
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/emcw/map/entities/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
public class Location implements ISerializable {
@Getter final Integer x;
@Getter final Integer z;
@Getter Integer y;
@Getter Integer yaw;

/**
* <p>A location in 3D space.</p>
* @param x The coordinate on the x-axis (left/right)
* @param y The coordinate on the y-axis (up/down)
* @param z The coordinate on the z-axis (forward/backward)
* @param yaw I have no fucking clue
*/
public Location(Integer x, Integer y, Integer z) {
public Location(Integer x, Integer z, Integer yaw) {
this(x, z);
this.y = y;
this.yaw = yaw;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/github/emcw/map/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public boolean hidden() {
}

/**
* Whether this player is located at the default Dynmap location.
* @return true/false if {@link #location} is 0, 64, 0
* Whether this player is located at the default map location.
* @return true/false if {@link #location} is 0, 0
*/
public boolean locationIsDefault() {
return location.y == 64 && location.x == 0 && location.z == 0;
return location.x == 0 && location.z == 0;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/emcw/utils/Funcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jsoup.safety.Safelist;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -21,6 +22,12 @@
@SuppressWarnings("unused")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Funcs {
private static final Safelist whitelist = new Safelist().addAttributes("a", "href");

public static Safelist getWhitelist() {
return whitelist;
}

public static <T> @NotNull Map<String, T> listToMap(@NotNull List<BaseEntity<T>> list) {
ConcurrentHashMap<String, T> map = new ConcurrentHashMap<>();
list.parallelStream().forEach(el -> map.put(el.getName(), el.getParent()));
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/io/github/emcw/utils/http/DynmapAPI.java

This file was deleted.

11 changes: 6 additions & 5 deletions src/main/java/io/github/emcw/utils/http/SquaremapAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.StreamSupport;

import static io.github.emcw.utils.GsonUtil.arrAsStream;
import static io.github.emcw.utils.GsonUtil.keyAsStr;

public final class SquaremapAPI {
private SquaremapAPI() {
Expand Down Expand Up @@ -39,9 +40,9 @@ public static JsonArray mapData() {

try {
JsonArray markersets = data.join().getAsJsonArray();
JsonElement towny = markersets.asList().parallelStream()
JsonElement towny = arrAsStream(markersets)
.map(JsonElement::getAsJsonObject)
.filter(el -> el.get("id").getAsString().equals("towny"))
.filter(el -> Objects.equals(keyAsStr(el, "id"), "towny"))
.findFirst()
.orElseThrow();

Expand Down
Loading

0 comments on commit 734d63a

Please sign in to comment.