mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 06:28:49 +00:00
Internalize PAPI hook, cache SavedUser data
This commit is contained in:
1 parent
d4be673581
commit
15227ee702
14 files changed
+193
-67
No files matched your search
@@ -42,6 +42,31 @@ public class HomesManager {
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getUserHomeNames() {
|
||||
return userHomes.entrySet().stream()
|
||||
.flatMap(e -> e.getValue().stream()
|
||||
.map(home -> home.getOwner().getUsername() + "." + home.getName()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached public homes - maps a username to a list of their public homes
|
||||
*/
|
||||
@NotNull
|
||||
public Map<String, List<String>> getPublicHomes() {
|
||||
return publicHomes.stream()
|
||||
.collect(HashMap::new, (m, e) -> m.put(e.getOwner().getUsername(), List.of(e.getName())),
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getPublicHomeNames() {
|
||||
return publicHomes.stream()
|
||||
.map(home -> home.getOwner().getUsername() + "." + home.getName())
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void cacheUserHomes(@NotNull User user) {
|
||||
userHomes.put(user.getUsername(), new ConcurrentLinkedQueue<>(plugin.getDatabase().getHomes(user)));
|
||||
}
|
||||
@@ -107,15 +132,6 @@ public class HomesManager {
|
||||
userHomes.remove(user.getUuid().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached public homes - maps a username to a list of their public homes
|
||||
*/
|
||||
@NotNull
|
||||
public Map<String, List<String>> getPublicHomes() {
|
||||
return publicHomes.stream()
|
||||
.collect(HashMap::new, (m, e) -> m.put(e.getOwner().getUsername(), List.of(e.getName())),
|
||||
HashMap::putAll);
|
||||
}
|
||||
|
||||
public void createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
|
||||
boolean overwrite, boolean buyAdditionalSlots) throws ValidationException {
|
||||
@@ -138,7 +154,7 @@ public class HomesManager {
|
||||
}
|
||||
|
||||
// Validate against user home slots
|
||||
final SavedUser savedOwner = plugin.getDatabase().getUserData(owner.getUuid())
|
||||
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
||||
.orElseThrow(() -> new IllegalStateException("User data not found for " + owner.getUuid()));
|
||||
if (plugin.getSettings().doEconomy() && homeCount >= savedOwner.getHomeSlots()) {
|
||||
if (!buyAdditionalSlots || plugin.getEconomyHook().isEmpty() || !(owner instanceof OnlineUser online)) {
|
||||
@@ -150,8 +166,7 @@ public class HomesManager {
|
||||
}
|
||||
|
||||
plugin.performEconomyTransaction(online, EconomyHook.Action.ADDITIONAL_HOME_SLOT);
|
||||
savedOwner.setHomeSlots(savedOwner.getHomeSlots() + 1);
|
||||
plugin.getDatabase().updateUserData(savedOwner);
|
||||
plugin.editUserData(online, (SavedUser saved) -> saved.setHomeSlots(saved.getHomeSlots() + 1));
|
||||
}
|
||||
|
||||
final Home home = existingHome
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.william278.huskhomes.teleport.TeleportBuilder;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -23,27 +24,10 @@ public class RequestsManager {
|
||||
|
||||
// Map of user UUIDs to a queue of received teleport requests
|
||||
private final Map<UUID, Deque<TeleportRequest>> requests;
|
||||
// Set of users who are ignoring tpa requests
|
||||
private final Set<UUID> ignoringRequests;
|
||||
|
||||
public RequestsManager(@NotNull HuskHomes plugin) {
|
||||
this.plugin = plugin;
|
||||
this.requests = new HashMap<>();
|
||||
this.ignoringRequests = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a user as ignoring or listening to tpa requests
|
||||
*
|
||||
* @param user the user to update
|
||||
* @param ignoring whether the user should be ignoring requests
|
||||
*/
|
||||
public void setIgnoringRequests(@NotNull User user, boolean ignoring) {
|
||||
if (ignoring) {
|
||||
this.ignoringRequests.add(user.getUuid());
|
||||
} else {
|
||||
this.ignoringRequests.remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +37,7 @@ public class RequestsManager {
|
||||
* @return {@code true} if the user is ignoring tpa requests
|
||||
*/
|
||||
public boolean isIgnoringRequests(@NotNull User user) {
|
||||
return this.ignoringRequests.contains(user.getUuid());
|
||||
return plugin.getSavedUser(user).map(SavedUser::isIgnoringTeleports).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +173,7 @@ public class RequestsManager {
|
||||
// Add the request and display a message to the recipient
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user