Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edithome permission logic check & warn against bad rtp spawn radius #531

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixup edithome logic
  • Loading branch information
WiIIiam278 committed Dec 5, 2023
commit 9bc01e94e31557ee81cb252c72f962a66bfcfa15
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,19 @@ private void setHomePrivacy(@NotNull CommandUser executor, @NotNull Home home, b

// Set the home privacy
home.setPublic(parseStringArg(args, 1)
.map(String::toLowerCase).map("public"::equals)
.map("public"::equalsIgnoreCase)
.orElse(!home.isPublic()));

// Fire the event
plugin.fireEvent(plugin.getHomeEditEvent(home, executor), (event) -> {
try {
plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic());
plugin.getManager().homes().setHomePrivacy(
home.getOwner().equals(executor) ? (OnlineUser) executor : home.getOwner(),
home,
home.isPublic()
);
} catch (ValidationException e) {
int maxHomes = plugin.getManager().homes()
.getMaxPublicHomes(executor instanceof OnlineUser user ? user : null);
int maxHomes = plugin.getManager().homes().getMaxPublicHomes(executor instanceof OnlineUser user ? user : null);
e.dispatchHomeError(executor, false, plugin, Integer.toString(maxHomes));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@ public void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean is
throw new ValidationException(ValidationException.Type.NOT_FOUND);
}

this.setHomePrivacy(optionalHome.get(), isPublic);
this.setHomePrivacy(owner, optionalHome.get(), isPublic);
}

public void setHomePrivacy(@NotNull Home home, boolean isPublic) {
if (isPublic && home.getOwner() instanceof OnlineUser online) {
final int publicHomes = plugin.getDatabase().getHomes(home.getOwner()).stream()
.filter(Home::isPublic)
.toList().size();
this.setHomePrivacy(home.getOwner(), home, isPublic);
}

public void setHomePrivacy(@NotNull User owner, @NotNull Home home, boolean isPublic) {
if (isPublic && owner instanceof OnlineUser online) {
int publicHomes = plugin.getDatabase().getHomes(owner).stream().filter(Home::isPublic).toList().size();
if (publicHomes >= getMaxPublicHomes(online)) {
throw new ValidationException(ValidationException.Type.REACHED_MAX_PUBLIC_HOMES);
}
Expand Down