Skip to content

Commit

Permalink
small project structure changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Oct 28, 2023
1 parent ebb083b commit 6ffe9cd
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 72 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ publishing {

version = findProperty('wrapper_version')

//noinspection GroovyAssignabilityCheck
from components.java
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.emcw.core;
package io.github.emcw;

import io.github.emcw.caching.CacheOptions;
import io.github.emcw.caching.CacheStrategy;
import io.github.emcw.map.Nations;
import io.github.emcw.map.Players;
import io.github.emcw.map.Residents;
import io.github.emcw.map.Towns;
import io.github.emcw.map.api.Nations;
import io.github.emcw.map.api.Players;
import io.github.emcw.map.api.Residents;
import io.github.emcw.map.api.Towns;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.core;
package io.github.emcw;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/github/emcw/interfaces/ILocatable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.emcw.interfaces;

import io.github.emcw.entities.*;
import io.github.emcw.map.entities.Location;
import io.github.emcw.map.entities.Nation;
import io.github.emcw.map.entities.Player;
import io.github.emcw.map.entities.Town;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.emcw.interfaces;

import io.github.emcw.entities.BaseEntity;
import io.github.emcw.entities.Resident;
import io.github.emcw.map.entities.BaseEntity;
import io.github.emcw.map.entities.Resident;
import io.github.emcw.utils.Funcs;

import java.util.List;
Expand All @@ -11,9 +11,9 @@
public interface IPlayerCollective {
/**
* Returns a new list of residents who are found to be online in the parent map.
* @param residents The {@link io.github.emcw.entities.Resident} list to perform filtering on.
* @param residents The {@link Resident} list to perform filtering on.
* @param parent The parent of this entity who provides the map name of the current instance.
* @return A new list of {@link io.github.emcw.entities.Resident} objects who are online.
* @return A new list of {@link Resident} objects who are online.
*/
default Map<String, Resident> onlineResidents(List<Resident> residents, BaseEntity<?> parent) {
return Funcs.streamList(residents).filter(p -> p.online(parent.getName()))
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/github/emcw/map/api/GPS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.emcw.map.api;

import io.github.emcw.map.entities.Location;

public class GPS {
private final Location lastLoc = null;
private final Location emittedHidden = null;


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.emcw.map;
package io.github.emcw.map.api;

import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Nation;
import io.github.emcw.EMCMap;
import io.github.emcw.map.entities.Nation;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.utils.DataParser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.github.emcw.map;
package io.github.emcw.map.api;

import com.github.benmanes.caffeine.cache.Cache;
import com.google.gson.JsonObject;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Location;
import io.github.emcw.EMCMap;
import io.github.emcw.map.entities.Location;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.entities.Player;
import io.github.emcw.entities.Resident;
import io.github.emcw.map.entities.Player;
import io.github.emcw.map.entities.Resident;
import io.github.emcw.utils.DataParser;

import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.emcw.map;
package io.github.emcw.map.api;

import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Resident;
import io.github.emcw.EMCMap;
import io.github.emcw.map.entities.Resident;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.utils.DataParser;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.emcw.map;
package io.github.emcw.map.api;

import com.github.benmanes.caffeine.cache.Cache;
import io.github.emcw.caching.BaseCache;
import io.github.emcw.caching.CacheOptions;
import io.github.emcw.core.EMCMap;
import io.github.emcw.entities.Town;
import io.github.emcw.EMCMap;
import io.github.emcw.map.entities.Town;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.utils.DataParser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonObject;
import io.github.emcw.interfaces.ISerializable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.IPlayerCollective;
import io.github.emcw.interfaces.ISerializable;
import io.github.emcw.map.Towns;
import io.github.emcw.map.api.Towns;
import io.github.emcw.utils.Funcs;
import io.github.emcw.utils.GsonUtil;
import lombok.Getter;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;

import static io.github.emcw.utils.Funcs.collectEntities;
import static io.github.emcw.utils.Funcs.*;
import static io.github.emcw.utils.GsonUtil.*;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -55,7 +56,7 @@ private void init(JsonObject obj) {
}

public Town getCapital() {
Towns towns = Funcs.mapByName(mapName).Towns;
Towns towns = mapInstance(mapName).Towns;
try {
return towns.single(capital.getName());
} catch (MissingEntryException e) {
Expand All @@ -64,26 +65,23 @@ public Town getCapital() {
}

// TODO: Finish invitableTowns
public Map<String, Town> invitableTowns(String mapName) {
Towns towns = Funcs.mapByName(mapName).Towns;

Stream<Entry<String, Town>> townsStream = streamEntries(towns.all());
Stream<Town> townsMap = townsStream.map(entry -> {
public Map<String, Town> invitableTowns() {
Stream<Entry<String, Town>> towns = GsonUtil.streamEntries(mapInstance(mapName).Towns.all());
return collectEntities(towns.map(entry -> {
Town town = entry.getValue();

Location townLoc = town.getLocation();
Location capitalLoc = getCapital().getLocation();

// In range, return the town
if (Funcs.manhattan(capitalLoc, townLoc) < 2500) {
return town;
if (town.nation == null) {
Location townLoc = town.getLocation();
Location capitalLoc = getCapital().getLocation();

// In range, return the town
int inviteRange = mapName.equals("nova") ? 3000 : 3500;
if (manhattan(capitalLoc, townLoc) < inviteRange) {
return town;
}
}

// Otherwise null
return null;
});

return collectEntities(townsMap);
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonObject;
import io.github.emcw.core.EMCMap;
import io.github.emcw.EMCMap;
import io.github.emcw.exceptions.MissingEntryException;
import io.github.emcw.interfaces.ILocatable;
import io.github.emcw.interfaces.ISerializable;
Expand All @@ -12,7 +12,7 @@

import java.util.Objects;

import static io.github.emcw.core.EMCWrapper.instance;
import static io.github.emcw.EMCWrapper.instance;
import static io.github.emcw.utils.GsonUtil.*;

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.map;
package io.github.emcw.map.entities;

import com.google.gson.JsonObject;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -39,7 +39,7 @@ public ProcessedTown(JsonObject obj) {

public static List<String> processFlags(@NotNull String str) {
return strArrAsStream(str.split("<br />"))
.map(e -> Jsoup.clean(e, whitelist))
.collect(Collectors.toList());
.map(e -> Jsoup.clean(e, whitelist))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.emcw.entities;
package io.github.emcw.map.entities;

import com.google.gson.JsonObject;
import io.github.emcw.interfaces.IPlayerCollective;
Expand All @@ -12,7 +12,6 @@
import java.util.Map;
import java.util.Objects;

import static io.github.emcw.entities.Resident.fromArr;
import static io.github.emcw.utils.GsonUtil.*;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -41,7 +40,7 @@ void init(JsonObject obj) {

nation = keyAsStr(obj, "nation");
mayor = keyAsStr(obj, "mayor");
residents = fromArr(keyAsArr(obj, "residents"), "name");
residents = Resident.fromArr(keyAsArr(obj, "residents"), "name");

location = Location.of(obj);
area = keyAsInt(obj, "area");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/emcw/utils/DataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import io.github.emcw.entities.Nation;
import io.github.emcw.entities.Player;
import io.github.emcw.entities.Resident;
import io.github.emcw.entities.Town;
import io.github.emcw.map.entities.Nation;
import io.github.emcw.map.entities.Player;
import io.github.emcw.map.entities.Resident;
import io.github.emcw.map.entities.Town;

import io.github.emcw.utils.http.DynmapAPI;
import lombok.AccessLevel;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/github/emcw/utils/Funcs.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.emcw.utils;

import io.github.emcw.core.EMCMap;
import io.github.emcw.core.EMCWrapper;
import io.github.emcw.entities.BaseEntity;
import io.github.emcw.entities.Location;
import io.github.emcw.EMCMap;
import io.github.emcw.EMCWrapper;
import io.github.emcw.map.entities.BaseEntity;
import io.github.emcw.map.entities.Location;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;
Expand Down Expand Up @@ -86,8 +86,8 @@ public static <T> List<T> removeListDuplicates(@NotNull List<T> list) {

public static <T> List<T> collectList(Stream<T> stream, Boolean noDuplicates) {
return (noDuplicates ? stream.distinct() : stream)
.filter(Objects::nonNull)
.collect(Collectors.toList());
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

@Contract(pure = true)
Expand All @@ -103,7 +103,7 @@ public static <T> Stream<T> streamList(@NotNull List<T> list) {
return IntStream.of(ints).parallel();
}

public static EMCMap mapByName(@NotNull String name) {
public static EMCMap mapInstance(@NotNull String name) {
EMCWrapper wrapper = EMCWrapper.instance();
return name.equals("nova") ? wrapper.getNova() : wrapper.getAurora();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/emcw/utils/GsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.google.gson.reflect.TypeToken;
import io.github.emcw.adapters.ColorAdapter;
import io.github.emcw.adapters.DurationAdapter;
import io.github.emcw.entities.BaseEntity;
import io.github.emcw.entities.Player;
import io.github.emcw.map.entities.BaseEntity;
import io.github.emcw.map.entities.Player;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/emcw/utils/http/OfficialAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class OfficialAPI {
public OfficialAPI() { }

static String OAPI_DOMAIN = "https://api.earthmc.net/v2/aurora/";
static final String OAPI_DOMAIN = "https://api.earthmc.net/v2/aurora/";

@Contract("_, -> new")
private static @NotNull CompletableFuture<JsonObject> get(String url) {
Expand Down

0 comments on commit 6ffe9cd

Please sign in to comment.