Skip to content

Commit

Permalink
E
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Oct 26, 2023
1 parent c2c4e37 commit ec77158
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 29 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ publishing {
mavenJava(MavenPublication) {
groupId = findProperty('maven_group')
artifactId = findProperty('lib_name')

version = findProperty('wrapper_version')

from components.java
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/io/github/emcw/entities/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
import static io.github.emcw.utils.GsonUtil.*;

public class Location implements ISerializable {
@Getter
final Integer x;
@Getter
final Integer z;
@Getter
Integer y;
@Getter final Integer x;
@Getter final Integer z;
@Getter Integer y;

/**
* <p>A location in 3D space.</p>
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/io/github/emcw/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,42 @@ public Resident asResident(String mapName) throws MissingEntryException {
return new Resident(asTree(res), this);
}

/**
* If this player has set a nickname.
* @return true/false if {@link #nickname} is same as their account {@link #name}.
*/
public boolean hasCustomNickname() {
return nickname != null && !Objects.equals(nickname, name);
}

public boolean aboveGround() {
/**
* If this player is visible on the Dynmap.
* @return true/false if {@link #world} is "earth" and player is not under a block.
*/
public boolean visible() {
return Objects.equals(world, "earth");
}

public boolean underground() {
return locationIsDefault() && !aboveGround();
/**
* Essentially the opposite of {@link #visible}.
* <p><b>NOTE:</b>
* This returns true for players under a tree, in the nether etc.
* @return true/false if {@link #world} is NOT "earth" and {@link #location} is 0, 64, 0.
*/
public boolean hidden() {
return locationIsDefault() && !visible();
}

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

/**
* <p>Check if this player is also a resident on the map this instance was retrieved from.</p>
* Check if this player is also a resident on the map this instance was retrieved from.
*/
public boolean isResident() {
return isResident != null && isResident;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/emcw/entities/Resident.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

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

@SuppressWarnings("unused")
public class Resident extends Player implements ISerializable {
@Getter private String town, nation, rank;

Expand Down Expand Up @@ -46,6 +45,7 @@ public boolean hasAuthority() {
return Objects.equals(rank, "Mayor") || Objects.equals(rank, "Leader");
}

@SuppressWarnings("SameParameterValue")
protected static List<Resident> fromArr(@NotNull JsonArray arr, String key) {
return StreamSupport.stream(arr.spliterator(), true).map(curRes -> {
JsonObject obj = new JsonObject();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/emcw/interfaces/ILocatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private boolean checkNearby(T val) {
Location loc = null;

if (val instanceof Player player) {
if (!player.aboveGround()) return false;
if (!player.visible()) return false;
loc = player.getLocation();
}
else if (val instanceof Town town) loc = town.getLocation();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/emcw/map/Nations.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.caching.CacheStrategy;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Nation;
import io.github.emcw.exceptions.MissingEntryException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/emcw/map/Players.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.JsonObject;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.caching.CacheStrategy;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Location;
import io.github.emcw.exceptions.MissingEntryException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/emcw/map/Residents.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.caching.CacheStrategy;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Resident;
import io.github.emcw.exceptions.MissingEntryException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/emcw/map/Towns.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.caching.CacheStrategy;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Town;
import io.github.emcw.exceptions.MissingEntryException;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/emcw/utils/DataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.emcw.entities.Resident;
import io.github.emcw.entities.Town;

import io.github.emcw.utils.http.DynmapAPI;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static void parseMapData(String map) {
}

public static void parseMapData(String map, Boolean parseTowns, Boolean parseNations, Boolean parseResidents) {
JsonObject mapData = API.mapData(map);
JsonObject mapData = DynmapAPI.mapData(map);
if (mapData.size() < 1) return;

if (parseTowns) rawTowns.invalidateAll();
Expand Down Expand Up @@ -218,7 +219,7 @@ private static void parseResidents(String[] members, String town, String nation,
}

public static void parsePlayerData(String map) {
JsonArray pData = API.playerData(map).getAsJsonArray("players");
JsonArray pData = DynmapAPI.playerData(map).getAsJsonArray("players");
if (pData.size() < 1) return;

rawPlayers.invalidateAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.utils;
package io.github.emcw.utils.http;

import com.google.gson.JsonObject;
import org.jetbrains.annotations.Contract;
Expand All @@ -11,8 +11,8 @@
* <b>Note:</b>
* <br>This class is used internally to obtain fresh data, you should never need to use it directly.
*/
public final class API {
private API() {}
public final class DynmapAPI {
private DynmapAPI() {}

@Contract("_, _ -> new")
private static @NotNull CompletableFuture<JsonObject> get(String map, String key) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/emcw/utils/http/OfficialAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.emcw.utils.http;

public class OfficialAPI {
public OfficialAPI() { }

static String Domain = "https://api.earthmc.net/v2/aurora/";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.utils;
package io.github.emcw.utils.http;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
Expand Down Expand Up @@ -30,6 +30,7 @@ public class Request {
static final String epUrl = "https://raw.githubusercontent.com/EarthMC-Toolkit/EarthMC-NPM/main/src/endpoints.json";
static final Cache<String, JsonObject> endpoints = Caffeine.newBuilder().build();

@SuppressWarnings("SameReturnValue")
static Cache<String, JsonObject> getEndpoints() {
if (endpoints.asMap().isEmpty()) {
JsonObject eps = updateEndpoints();
Expand All @@ -43,14 +44,10 @@ static Cache<String, JsonObject> getEndpoints() {
}

static @Nullable JsonObject updateEndpoints() {
try { return send(epUrl); }
catch (APIException e) {
System.out.println(e.getMessage());
return null;
}
return send(epUrl);
}

public static <T> T send(String url) throws APIException {
public static <T> T send(String url) {
return (T) JsonParser.parseString(fetch(url));
}

Expand Down

0 comments on commit ec77158

Please sign in to comment.