Add /edithome, use instant for timestamps, new locales

This commit is contained in:
William committed 2022-08-16 00:58:26 +01:00
1 parent eddae1051c
commit a91128ca3d
24 files changed
+793 -205

No files matched your search

@@ -1,9 +1,16 @@
package net.william278.huskhomes.position;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.player.User;
import org.jetbrains.annotations.NotNull;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
/**
* Represents a home set by a {@link User}
@@ -30,9 +37,63 @@ public class Home extends SavedPosition {
this.isPublic = isPublic;
}
public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
super(position, meta);
this.owner = owner;
this.isPublic = false;
}
@NotNull
public List<MineDown> getHomeEditorWindow(@NotNull Locales locales, final boolean otherViewer,
final boolean showServerInformation, final boolean showButtons) {
return new ArrayList<>() {{
if (!otherViewer) {
locales.getLocale("edit_home_menu_title", meta.name)
.ifPresent(this::add);
} else {
locales.getLocale("edit_home_menu_title_other", owner.username, meta.name)
.ifPresent(this::add);
}
locales.getLocale("edit_home_menu_metadata",
DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm")
.format(meta.creationTime.atZone(ZoneId.systemDefault())),
uuid.toString().split(Pattern.quote("-"))[0],
uuid.toString())
.ifPresent(this::add);
if (!isPublic) {
locales.getLocale("edit_home_menu_privacy_private").ifPresent(this::add);
} else {
locales.getLocale("edit_home_menu_privacy_public").ifPresent(this::add);
}
if (meta.description.length() > 0) {
locales.getLocale("edit_home_menu_description", MineDown.escape(meta.description))
.ifPresent(this::add);
}
if (!showServerInformation) {
locales.getLocale("edit_home_menu_world", world.name).ifPresent(this::add);
} else {
locales.getLocale("edit_home_menu_world_server", world.name, server.name).ifPresent(this::add);
}
locales.getLocale("edit_home_menu_coordinates",
String.format("%.1f", x), String.format("%.1f", y), String.format("%.1f", z),
String.format("%.2f", yaw), String.format("%.2f", pitch))
.ifPresent(this::add);
if (showButtons) {
final String formattedName = owner.username + "." + meta.name;
locales.getLocale("edit_home_menu_manage_buttons",
formattedName)
.ifPresent(this::add);
locales.getLocale("edit_home_menu_meta_edit_buttons",
formattedName)
.ifPresent(this::add);
}
}};
}
}