Add fabric builds for older MC versions & add checkstyle (#449)

* Remove instance getters, improve command logic, register APi

* Publish multiple fabric builds, enforce checkstyle

* Bump guava

* Bump to 4.4.2
This commit is contained in:
William authored and GitHub committed 2023-07-02 13:26:12 +01:00
1 parent 51baf196b3
commit c9f5262292
219 files changed
+8032 -1392

No files matched your search

@@ -53,7 +53,9 @@ public class HomesManager {
}
/**
* Cached user homes - maps a username to a list of their homes
* Cached user homes - maps a username to a list of their homes.
*
* @return a map of usernames to a list of their home names.
*/
@NotNull
public Map<String, List<String>> getUserHomes() {
@@ -62,15 +64,20 @@ public class HomesManager {
HashMap::putAll);
}
/**
* Get a list of all cached set home identifiers.
*
* @return a list of all cached set home identifiers
*/
@NotNull
public List<String> getUserHomeNames() {
public List<String> getUserHomeIdentifiers() {
return userHomes.entrySet().stream()
.flatMap(e -> e.getValue().stream().map(Home::getIdentifier))
.toList();
}
/**
* Cached public homes - maps a username to a list of their public homes
* Cached public homes - maps a username to a list of their public homes.
*/
@NotNull
public Map<String, List<String>> getPublicHomes() {
@@ -79,17 +86,33 @@ public class HomesManager {
HashMap::putAll);
}
/**
* Get a list of all cached public home identifiers.
*
* @return a list of all cached public home identifiers
*/
@NotNull
public List<String> getPublicHomeNames() {
public List<String> getPublicHomeIdentifiers() {
return publicHomes.stream()
.map(Home::getIdentifier)
.toList();
}
/**
* Cache user homes for a given user.
*
* @param user the user to cache homes for
*/
public void cacheUserHomes(@NotNull User user) {
userHomes.put(user.getUsername(), new ConcurrentLinkedQueue<>(plugin.getDatabase().getHomes(user)));
}
/**
* Cache a home for a given user.
*
* @param home the home to cache
* @param propagate whether to propagate the cache update to other servers (if cross-server is enabled)
*/
public void cacheHome(@NotNull Home home, boolean propagate) {
userHomes.computeIfPresent(home.getOwner().getUsername(), (k, v) -> {
v.remove(home);
@@ -132,6 +155,13 @@ public class HomesManager {
}
}
/**
* Propagate the update of a home/warp to other servers (if cross-server is enabled).
*
* <p>This works by broking a message requesting that other servers fetch the updated home from the database.
*
* @param homeId the UUID of the home/warp to update
*/
private void propagateCacheUpdate(@NotNull UUID homeId) {
if (plugin.getSettings().doCrossServer()) {
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
@@ -196,7 +226,8 @@ public class HomesManager {
this.cacheHome(home, true);
}
public void createHome(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) throws ValidationException {
public void createHome(@NotNull OnlineUser owner, @NotNull String name,
@NotNull Position position) throws ValidationException {
createHome(owner, name, position, plugin.getSettings().doOverwriteExistingHomesWarps(), true);
}
@@ -226,7 +257,8 @@ public class HomesManager {
return deleted;
}
public void setHomePosition(@NotNull User owner, @NotNull String name, @NotNull Position position) throws ValidationException {
public void setHomePosition(@NotNull User owner, @NotNull String name,
@NotNull Position position) throws ValidationException {
final Optional<Home> optionalHome = plugin.getDatabase().getHome(owner, name);
if (optionalHome.isEmpty()) {
throw new ValidationException(ValidationException.Type.NOT_FOUND);
@@ -241,7 +273,8 @@ public class HomesManager {
this.cacheHome(home, true);
}
public void setHomeName(@NotNull User owner, @NotNull String name, @NotNull String newName) throws ValidationException {
public void setHomeName(@NotNull User owner, @NotNull String name,
@NotNull String newName) throws ValidationException {
final Optional<Home> optionalHome = plugin.getDatabase().getHome(owner, name);
if (optionalHome.isEmpty()) {
throw new ValidationException(ValidationException.Type.NOT_FOUND);
@@ -260,7 +293,8 @@ public class HomesManager {
this.cacheHome(home, true);
}
public void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) throws ValidationException {
public void setHomeDescription(@NotNull User owner, @NotNull String name,
@NotNull String description) throws ValidationException {
final Optional<Home> optionalHome = plugin.getDatabase().getHome(owner, name);
if (optionalHome.isEmpty()) {
throw new ValidationException(ValidationException.Type.NOT_FOUND);
@@ -303,7 +337,8 @@ public class HomesManager {
this.cacheHome(home, true);
}
public void setHomeMetaTags(@NotNull User owner, @NotNull String name, @NotNull Map<String, String> tags) throws ValidationException {
public void setHomeMetaTags(@NotNull User owner, @NotNull String name,
@NotNull Map<String, String> tags) throws ValidationException {
final Optional<Home> optionalHome = plugin.getDatabase().getHome(owner, name);
if (optionalHome.isEmpty()) {
throw new ValidationException(ValidationException.Type.NOT_FOUND);