mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
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:
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);
|
||||
|
||||
@@ -38,7 +38,7 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Manages {@link TeleportRequest}s between players
|
||||
* Manages {@link TeleportRequest}s between players.
|
||||
*/
|
||||
public class RequestsManager {
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a user is ignoring tpa requests
|
||||
* Return if a user is ignoring tpa requests.
|
||||
*
|
||||
* @param user the user to check
|
||||
* @return {@code true} if the user is ignoring tpa requests
|
||||
@@ -63,7 +63,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a teleport request to a user's request queue
|
||||
* Add a teleport request to a user's request queue.
|
||||
*
|
||||
* @param request the {@link TeleportRequest} to add
|
||||
* @param recipient the {@link User} recipient of the request
|
||||
@@ -73,7 +73,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link TeleportRequest}(s) sent by a requester, by name, from a recipient's queue
|
||||
* Remove {@link TeleportRequest}(s) sent by a requester, by name, from a recipient's queue.
|
||||
*
|
||||
* @param requesterName the sender's username, whose requests should be removed
|
||||
* @param recipient the {@link User} recipient of the request
|
||||
@@ -86,7 +86,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last received teleport request for a user
|
||||
* Get the last received teleport request for a user.
|
||||
*
|
||||
* @param recipient the user to get the request for
|
||||
* @return the last received request, if present
|
||||
@@ -200,7 +200,7 @@ public class RequestsManager {
|
||||
plugin.fireEvent(plugin.getReceiveTeleportRequestEvent(recipient, request), (event -> {
|
||||
addTeleportRequest(request, recipient);
|
||||
plugin.getLocales().getLocale((request.getType() == TeleportRequest.Type.TPA ? "tpa" : "tpahere")
|
||||
+ "_request_received", request.getRequesterName())
|
||||
+ "_request_received", request.getRequesterName())
|
||||
.ifPresent(recipient::sendMessage);
|
||||
plugin.getLocales().getLocale("teleport_request_buttons", request.getRequesterName())
|
||||
.ifPresent(recipient::sendMessage);
|
||||
@@ -210,7 +210,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a teleport request with the given status by name of the sender
|
||||
* Respond to a teleport request with the given status by name of the sender.
|
||||
*
|
||||
* @param recipient The user receiving the request
|
||||
* @param senderName The name of the user sending the request
|
||||
@@ -236,7 +236,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to the last received teleport request for a user, if there is one
|
||||
* Respond to the last received teleport request for a user if there is one.
|
||||
*
|
||||
* @param recipient The user receiving the request
|
||||
* @param accepted Whether the request should be accepted or not
|
||||
@@ -266,13 +266,14 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle; respond to; a teleport request
|
||||
* Handle the response to a teleport request.
|
||||
*
|
||||
* @param request The request to handle
|
||||
* @param recipient The recipient of the request
|
||||
* @param accepted Whether the request should be accepted or not
|
||||
*/
|
||||
private void handleRequestResponse(@NotNull TeleportRequest request, @NotNull OnlineUser recipient, boolean accepted) {
|
||||
private void handleRequestResponse(@NotNull TeleportRequest request, @NotNull OnlineUser recipient,
|
||||
boolean accepted) {
|
||||
// Remove the request(s) from the sender from the recipient's queue
|
||||
removeTeleportRequest(request.getRequesterName(), recipient);
|
||||
|
||||
@@ -329,7 +330,7 @@ public class RequestsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a teleport request response for a local user
|
||||
* Handle a teleport request response for a local user.
|
||||
*
|
||||
* @param requester The user who sent the request
|
||||
* @param request The {@link TeleportRequest} to handle
|
||||
|
||||
@@ -94,7 +94,7 @@ public class WarpsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached warp names
|
||||
* Cached warp names.
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getWarps() {
|
||||
@@ -112,7 +112,8 @@ public class WarpsManager {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void createWarp(@NotNull String name, @NotNull Position position, boolean overwrite) throws ValidationException {
|
||||
public void createWarp(@NotNull String name, @NotNull Position position,
|
||||
boolean overwrite) throws ValidationException {
|
||||
final Optional<Warp> existingWarp = plugin.getDatabase().getWarp(name);
|
||||
if (existingWarp.isPresent() && !overwrite) {
|
||||
throw new ValidationException(ValidationException.Type.NAME_TAKEN);
|
||||
|
||||
Reference in new issue
Block a user