Re-implement privacy toggle, close #344

This commit is contained in:
William278 committed 2023-04-05 12:51:51 +01:00
1 parent ae52178692
commit 06b572b0c9
1 file changed
+5 -9
@@ -152,20 +152,16 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
return; return;
} }
final Optional<String> privacyArg = parseStringArg(args, 1).map(String::toLowerCase);
if (privacyArg.isEmpty() || !(privacyArg.get().equals("public") || privacyArg.get().equals("private"))) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/edithome " + home.getName() + " privacy <public|private>")
.ifPresent(executor::sendMessage);
return;
}
// Check against economy // Check against economy
if (executor instanceof OnlineUser user && !plugin.validateEconomyCheck(user, EconomyHook.Action.MAKE_HOME_PUBLIC)) { if (executor instanceof OnlineUser user && !plugin.validateEconomyCheck(user, EconomyHook.Action.MAKE_HOME_PUBLIC)) {
return; return;
} }
home.setPublic(privacyArg.get().equals("public")); // Set the home privacy
home.setPublic(parseStringArg(args, 1)
.map(String::toLowerCase).map("public"::equals)
.orElse(!home.isPublic()));
plugin.fireEvent(plugin.getHomeEditEvent(home, executor), (event) -> { plugin.fireEvent(plugin.getHomeEditEvent(home, executor), (event) -> {
try { try {
plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic()); plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic());