New lists via PagineDown, update edithome locales

This commit is contained in:
William committed 2022-08-17 17:14:49 +01:00
1 parent 3651e1ea90
commit 423f18b2c3
20 files changed
+170 -413

No files matched your search

@@ -1,16 +1,20 @@
package net.william278.huskhomes.cache;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.database.Database;
import net.william278.huskhomes.list.ChatList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Warp;
import net.william278.paginedown.ListOptions;
import net.william278.paginedown.PaginatedList;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* A cache used to hold frequently accessed data (i.e. TAB-completed homes and warps)
@@ -38,9 +42,19 @@ public class Cache {
public final List<String> players;
/**
* Cached position lists for optimized list navigating
* Cached lists of private homes for pagination
*/
public final HashMap<UUID, ChatList> positionLists;
public final HashMap<UUID, PaginatedList> privateHomeLists;
/**
* Cached lists of public homes for pagination
*/
public final HashMap<UUID, PaginatedList> publicHomeLists;
/**
* Cached lists of warps for pagination
*/
public final HashMap<UUID, PaginatedList> warpLists;
/**
* Create a new cache
@@ -50,7 +64,9 @@ public class Cache {
this.publicHomes = new HashMap<>();
this.warps = new ArrayList<>();
this.players = new ArrayList<>();
this.positionLists = new HashMap<>();
this.privateHomeLists = new HashMap<>();
this.publicHomeLists = new HashMap<>();
this.warpLists = new HashMap<>();
}
/**
@@ -74,7 +90,7 @@ public class Cache {
*
* @param plugin the implementing plugin
*/
public void updatePlayerList(@NotNull HuskHomes plugin, @NotNull OnlineUser requester) {
public void updateOnlinePlayerList(@NotNull HuskHomes plugin, @NotNull OnlineUser requester) {
if (plugin.getSettings().crossServer) {
assert plugin.getNetworkMessenger() != null;
CompletableFuture.runAsync(() -> plugin.getNetworkMessenger().
@@ -88,4 +104,68 @@ public class Cache {
}
}
private ListOptions.Builder getBaseList(@NotNull Locales locales, int itemsPerPage) {
return new ListOptions.Builder().setFooterFormat(locales.getRawLocale("list_footer",
"%previous_page_button%", "%current_page%",
"%total_pages%", "%next_page_button%", "%page_jumpers%").orElse(""))
.setNextButtonFormat(locales.getRawLocale("list_next_page_button",
"%next_page_index%", "%command%").orElse(""))
.setPreviousButtonFormat(locales.getRawLocale("list_previous_page_button",
"%previous_page_index%", "%command%").orElse(""))
.setPageJumpersFormat(locales.getRawLocale("list_page_jumpers",
"%page_jump_buttons%").orElse(""))
.setPageJumperPageFormat(locales.getRawLocale("list_page_jumper_button",
"%target_page_index%", "%command%").orElse(""))
.setPageJumperCurrentPageFormat(locales.getRawLocale("list_page_jumper_current_page",
"%current_page%").orElse(""))
.setPageJumperPageSeparator(locales.getRawLocale("list_page_jumper_separator").orElse(""))
.setPageJumperGroupSeparator(locales.getRawLocale("list_page_jumper_group_separator").orElse(""))
.setItemSeparator(locales.getRawLocale("list_item_divider").orElse(" "))
.setItemsPerPage(itemsPerPage)
.setEscapeItemsMineDown(false);
}
public MineDown getHomeList(@NotNull OnlineUser onlineUser, @NotNull User listOwner, @NotNull Locales locales,
@NotNull List<Home> homes, final int itemsPerPage, final int page) {
final PaginatedList homeList = PaginatedList.of(homes.stream().map(home ->
locales.getRawLocale("home_list_item",
home.meta.name, home.owner.username + "." + home.meta.name)
.orElse(home.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
.setHeaderFormat(locales.getRawLocale("home_list_page_title",
listOwner.username, "%first_item_on_page_index%",
"%last_item_on_page_index%", "%total_items%").orElse(""))
.setCommand("/huskhomes:homelist").build());
this.privateHomeLists.put(onlineUser.uuid, homeList);
return homeList.getNearestValidPage(page);
}
@NotNull
public MineDown getPublicHomeList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
@NotNull List<Home> publicHomes, final int itemsPerPage, final int page) {
final PaginatedList publicHomeList = PaginatedList.of(publicHomes.stream().map(home ->
locales.getRawLocale("public_home_list_item",
home.meta.name, home.owner.username + "." + home.meta.name)
.orElse(home.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
.setHeaderFormat(locales.getRawLocale("public_home_list_page_title",
"%first_item_on_page_index%", "%last_item_on_page_index%",
"%total_items%").orElse(""))
.setCommand("/huskhomes:publichomelist").build());
publicHomeLists.put(onlineUser.uuid, publicHomeList);
return publicHomeList.getNearestValidPage(page);
}
@NotNull
public MineDown getWarpList(@NotNull OnlineUser onlineUser, @NotNull Locales locales,
@NotNull List<Warp> warps, final int itemsPerPage, final int page) {
final PaginatedList warpList = PaginatedList.of(warps.stream().map(warp ->
locales.getRawLocale("warp_list_item", warp.meta.name)
.orElse(warp.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
.setHeaderFormat(locales.getRawLocale("warp_list_page_title",
"%first_item_on_page_index%", "%last_item_on_page_index%",
"%total_items%").orElse(""))
.setCommand("/huskhomes:warplist").build());
warpLists.put(onlineUser.uuid, warpList);
return warpList.getNearestValidPage(page);
}
}
@@ -270,7 +270,9 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons
.ifPresent(this::add);
if (home.meta.description.length() > 0) {
final String escapedDescription = MineDown.escape(home.meta.description);
final String escapedDescription = MineDown.escape(home.meta.description
.replaceAll(Pattern.quote("("), "\\(")
.replaceAll(Pattern.quote(")"), "\\)"));
plugin.getLocales().getLocale("edit_home_menu_description",
escapedDescription.length() > 50
? escapedDescription.substring(0, 49).trim() + "…" : escapedDescription,
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.PrivateHomeList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import net.william278.huskhomes.util.RegexUtil;
@@ -21,20 +20,12 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
switch (args.length) {
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
// Send the home list if they have homes set. If they have just one home set, teleport the player
try {
switch (homes.size()) {
case 0 ->
plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
case 1 -> plugin.getTeleportManager().teleport(onlineUser, homes.get(0)).thenAccept(result ->
plugin.getTeleportManager().finishTeleport(onlineUser, result)).join();
default -> {
final PrivateHomeList homeList = new PrivateHomeList(homes, onlineUser, plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, homeList);
homeList.getDisplay(1).forEach(onlineUser::sendMessage);
}
}
} catch (Exception e) {
e.printStackTrace();
switch (homes.size()) {
case 0 -> plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
case 1 -> plugin.getTeleportManager().teleport(onlineUser, homes.get(0)).thenAccept(result ->
plugin.getTeleportManager().finishTeleport(onlineUser, result)).join();
default -> onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, onlineUser,
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage,1));
}
});
case 1 -> {
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.PrivateHomeList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -41,16 +40,14 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
/**
* Show a (cached) list of a {@link OnlineUser}'s homes
*
* @param onlineUser the user to display the homes to
* @param onlineUser the user to display the homes to
* @param homeOwner the user whose homes should be displayed
* @param pageNumber page number to display
*/
private void showHomeList(@NotNull OnlineUser onlineUser, @NotNull String homeOwner, int pageNumber) {
if (plugin.getCache().positionLists.containsKey(onlineUser.uuid)) {
if (plugin.getCache().positionLists.get(onlineUser.uuid) instanceof PrivateHomeList privateHomeList) {
privateHomeList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
return;
}
if (plugin.getCache().privateHomeLists.containsKey(onlineUser.uuid)) {
onlineUser.sendMessage(plugin.getCache().privateHomeLists.get(onlineUser.uuid).getNearestValidPage(pageNumber));
return;
}
plugin.getDatabase().getUserDataByName(homeOwner).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(userData -> {
if (!userData.getUserUuid().equals(onlineUser.uuid)) {
@@ -64,9 +61,8 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
return;
}
final PrivateHomeList homeList = new PrivateHomeList(homes, userData.user(), plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, homeList);
homeList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, userData.user(),
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage, pageNumber));
});
}, () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage)));
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.PublicHomeList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
@@ -29,9 +28,8 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
return;
}
final PublicHomeList homeList = new PublicHomeList(publicHomes, plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, homeList);
homeList.getDisplay(1).forEach(onlineUser::sendMessage);
onlineUser.sendMessage(plugin.getCache().getPublicHomeList(onlineUser, plugin.getLocales(), publicHomes,
plugin.getSettings().listItemsPerPage,1));
});
case 1 -> {
final String homeName = args[0];
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.PublicHomeList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -37,21 +36,18 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta
* @param pageNumber page number to display
*/
private void showPublicHomeList(@NotNull OnlineUser onlineUser, int pageNumber) {
if (plugin.getCache().positionLists.containsKey(onlineUser.uuid)) {
if (plugin.getCache().positionLists.get(onlineUser.uuid) instanceof PublicHomeList publicHomeList) {
publicHomeList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
return;
}
if (plugin.getCache().publicHomeLists.containsKey(onlineUser.uuid)) {
onlineUser.sendMessage(plugin.getCache().publicHomeLists.get(onlineUser.uuid).getNearestValidPage(pageNumber));
return;
}
plugin.getDatabase().getPublicHomes().thenAccept(warps -> {
if (warps.isEmpty()) {
plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> {
if (publicHomes.isEmpty()) {
plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage);
return;
}
final PublicHomeList warpList = new PublicHomeList(warps, plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, warpList);
warpList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
onlineUser.sendMessage(plugin.getCache().getPublicHomeList(onlineUser, plugin.getLocales(), publicHomes,
plugin.getSettings().listItemsPerPage, pageNumber));
});
}
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.WarpList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -23,9 +22,8 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
return;
}
final WarpList warpList = new WarpList(warps, plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, warpList);
warpList.getDisplay(1).forEach(onlineUser::sendMessage);
onlineUser.sendMessage(plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
plugin.getSettings().listItemsPerPage, 1));
});
case 1 -> {
final String warpName = args[0];
@@ -1,7 +1,6 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.list.WarpList;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
@@ -37,11 +36,9 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
* @param pageNumber page number to display
*/
private void showWarpList(@NotNull OnlineUser onlineUser, int pageNumber) {
if (plugin.getCache().positionLists.containsKey(onlineUser.uuid)) {
if (plugin.getCache().positionLists.get(onlineUser.uuid) instanceof WarpList warpList) {
warpList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
return;
}
if (plugin.getCache().warpLists.containsKey(onlineUser.uuid)) {
onlineUser.sendMessage(plugin.getCache().warpLists.get(onlineUser.uuid).getNearestValidPage(pageNumber));
return;
}
plugin.getDatabase().getWarps().thenAccept(warps -> {
@@ -49,9 +46,8 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
return;
}
final WarpList warpList = new WarpList(warps, plugin);
plugin.getCache().positionLists.put(onlineUser.uuid, warpList);
warpList.getDisplay(pageNumber).forEach(onlineUser::sendMessage);
onlineUser.sendMessage(plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
plugin.getSettings().listItemsPerPage, pageNumber));
});
}
@@ -1,152 +0,0 @@
package net.william278.huskhomes.list;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.config.Locales;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;
/**
* A list used to display saved positions
*/
public abstract class ChatList {
/**
* Instance of the plugin {@link Locales}
*/
private final Locales locales;
/**
* List of {@link ListItem}s to display
*/
protected final List<ListItem> positions;
/**
* The number of items to be displayed on each page
*/
protected final int itemsPerPage;
/**
* The command used to switch players
*/
protected final String command;
public ChatList(@NotNull List<ListItem> positions, int itemsPerPage, @NotNull String command, @NotNull Locales locales) {
this.positions = positions;
this.itemsPerPage = itemsPerPage;
this.command = command;
this.locales = locales;
Collections.sort(this.positions);
}
/**
* Gets a list of formatted MineDown sequences to form a page
*/
public List<MineDown> getDisplay(int pageNumber) {
final List<MineDown> display = new ArrayList<>();
final int pageCount = (int) Math.ceil((double) positions.size() / (double) itemsPerPage);
if (pageNumber <= 0 || pageNumber > pageCount) {
return Collections.singletonList(locales.getLocale("error_invalid_page_number").orElse(new MineDown("")));
}
// Calculate display bounds
final int lastItemIndex = positions.size() - 1;
final int itemIndexStart = Math.min(itemsPerPage * (pageNumber - 1), lastItemIndex);
final int itemIndexEnd = Math.min((itemsPerPage * pageNumber) - 1, lastItemIndex);
// Add the header with page information
display.add(getHeader(itemIndexStart + 1, itemIndexEnd + 1, lastItemIndex + 1));
// Add the items
if (itemIndexEnd - itemIndexStart < 0) {
display.add(locales.getLocale("page_no_items").orElse(new MineDown("")));
} else {
final StringJoiner itemJoiner = new StringJoiner(getItemSeparator());
for (int i = itemIndexStart; i <= itemIndexEnd; i++) {
itemJoiner.add(getItemDisplayLocale(positions.get(i)));
}
display.add(new MineDown(itemJoiner.toString()));
}
// Add the footer with navigation buttons
display.add(getFooter(determineFooterLayout(pageNumber, pageCount), pageNumber, pageCount));
return display;
}
/**
* Determines the {@link FooterLayout} to use for a given page
*
* @param pageNumber number of page to get layout for
* @param pageCount total number of pages
* @return the {@link FooterLayout} for the page
*/
private FooterLayout determineFooterLayout(int pageNumber, int pageCount) {
final boolean isNextPage = pageNumber + 1 <= pageCount;
final boolean isPreviousPage = pageNumber - 1 > 0;
if (isNextPage && isPreviousPage) {
return FooterLayout.BOTH_BUTTONS;
}
if (isNextPage) {
return FooterLayout.NEXT_BUTTON;
}
if (isPreviousPage) {
return FooterLayout.PREVIOUS_BUTTON;
}
return FooterLayout.NO_BUTTONS;
}
protected abstract String getItemDisplayLocale(@NotNull ListItem item);
protected abstract String getItemSeparator();
protected abstract MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount);
private MineDown getFooter(@NotNull FooterLayout layout, int pageNumber, int maxPages) {
return switch (layout) {
case NEXT_BUTTON -> locales.getLocale("page_options_min",
Integer.toString(pageNumber), Integer.toString(maxPages),
"/" + command + " " + (pageNumber + 1))
.orElse(new MineDown(""));
case PREVIOUS_BUTTON -> locales.getLocale("page_options_max",
"/" + command + " " + (pageNumber - 1), Integer.toString(pageNumber),
Integer.toString(maxPages))
.orElse(new MineDown(""));
case NO_BUTTONS -> locales.getLocale("page_options_min_max",
Integer.toString(pageNumber), Integer.toString(maxPages))
.orElse(new MineDown(""));
case BOTH_BUTTONS -> locales.getLocale("page_options",
"/" + command + " " + (pageNumber - 1), Integer.toString(pageNumber),
Integer.toString(maxPages), "/" + command + " " + (pageNumber + 1))
.orElse(new MineDown(""));
};
}
/**
* Used for identifying the layout of a list footer
*/
protected enum FooterLayout {
/**
* List footer with a previous page button
*/
PREVIOUS_BUTTON,
/**
* List footer with a next page button
*/
NEXT_BUTTON,
/**
* List footer with both a previous page and a next page button.
*/
BOTH_BUTTONS,
/**
* List footer with no buttons
*/
NO_BUTTONS
}
}
@@ -1,39 +0,0 @@
package net.william278.huskhomes.list;
import net.william278.huskhomes.config.Locales;
import org.jetbrains.annotations.NotNull;
/**
* An item on a {@link ChatList}
*/
public record ListItem(@NotNull String itemDisplayName,
@NotNull String... itemDisplayMeta) implements Comparable<ListItem> {
/**
* Returns the chat list formatted {@link ListItem} string
*
* @param localeId id of the locale to use when formatting this item
* @param locales Instance of the {@link Locales} set
* @return the pre-formatted MineDown of this ListItem
*/
public String getFormattedItem(String localeId, Locales locales) {
final String[] itemDisplayComponents = new String[itemDisplayMeta.length + 1];
itemDisplayComponents[0] = itemDisplayName;
if (itemDisplayMeta.length >= 1) {
System.arraycopy(itemDisplayMeta, 0, itemDisplayComponents, 1, itemDisplayMeta.length);
}
return locales.getRawLocale(localeId, itemDisplayComponents).orElse(itemDisplayName);
}
/**
* Compare two {@link ListItem}s, returns alphabetical compareTo result
*
* @param other the other ListItem to be compared.
* @return the alphabetical comparison with another {@link ListItem}'s item display name
*/
@Override
public int compareTo(@NotNull ListItem other) {
return itemDisplayName.compareToIgnoreCase(other.itemDisplayName);
}
}
@@ -1,42 +0,0 @@
package net.william278.huskhomes.list;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Home;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class PrivateHomeList extends ChatList {
private final HuskHomes plugin;
private final User homeOwner;
public PrivateHomeList(@NotNull List<Home> homes, @NotNull User homeOwner, @NotNull HuskHomes implementor) {
super(homes.stream().map(position -> new ListItem(position.meta.name, position.owner.username,
position.meta.description)).collect(Collectors.toList()),
10, "homelist", implementor.getLocales()); //todo config settable items per page
this.plugin = implementor;
this.homeOwner = homeOwner;
}
@Override
protected String getItemDisplayLocale(@NotNull ListItem item) {
return item.getFormattedItem("home_list_item", plugin.getLocales());
}
@Override
protected String getItemSeparator() {
return plugin.getLocales().getRawLocale("list_item_divider").orElse(" ");
}
@Override
protected MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount) {
return plugin.getLocales().getLocale("private_home_list_page_top", homeOwner.username,
Integer.toString(pageItemStart), Integer.toString(pageItemEnd), Integer.toString(totalItemCount))
.orElseGet(() -> new MineDown(""));
}
}
@@ -1,38 +0,0 @@
package net.william278.huskhomes.list;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Home;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class PublicHomeList extends ChatList {
private final HuskHomes plugin;
public PublicHomeList(@NotNull List<Home> homes, @NotNull HuskHomes implementor) {
super(homes.stream().map(position -> new ListItem(position.meta.name, position.owner.username,
position.meta.description)).collect(Collectors.toList()),
10, "phomelist", implementor.getLocales()); //todo config settable items per page
this.plugin = implementor;
}
@Override
protected String getItemDisplayLocale(@NotNull ListItem item) {
return item.getFormattedItem("public_home_list_item", plugin.getLocales());
}
@Override
protected String getItemSeparator() {
return plugin.getLocales().getRawLocale("list_item_divider").orElse(" ");
}
@Override
protected MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount) {
return plugin.getLocales().getLocale("public_home_list_page_top", Integer.toString(pageItemStart),
Integer.toString(pageItemEnd), Integer.toString(totalItemCount)).orElseGet(() -> new MineDown(""));
}
}
@@ -1,39 +0,0 @@
package net.william278.huskhomes.list;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Warp;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class WarpList extends ChatList {
private final HuskHomes plugin;
public WarpList(@NotNull List<Warp> warps, @NotNull HuskHomes implementor) {
super(warps.stream().map(position -> new ListItem(position.meta.name, position.meta.description))
.collect(Collectors.toList()), 10, "warplist", implementor.getLocales());
//todo config settable items per page
this.plugin = implementor;
}
@Override
protected String getItemDisplayLocale(@NotNull ListItem item) {
return item.getFormattedItem("warp_list_item", plugin.getLocales());
}
@Override
protected String getItemSeparator() {
return plugin.getLocales().getRawLocale("list_item_divider").orElse(" ");
}
@Override
protected MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount) {
return plugin.getLocales().getLocale("warp_list_page_top",
Integer.toString(pageItemStart), Integer.toString(pageItemEnd), Integer.toString(totalItemCount))
.orElseGet(() -> new MineDown(""));
}
}
@@ -61,7 +61,7 @@ public class EventListener {
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))));
// Update the player list
assert plugin.getNetworkMessenger() != null;
plugin.getCache().updatePlayerList(plugin, onlineUser);
plugin.getCache().updateOnlinePlayerList(plugin, onlineUser);
}
// Cache this user's homes
@@ -91,7 +91,7 @@ public class EventListener {
plugin.getOnlinePlayers().stream().filter(
onlinePlayer -> !onlinePlayer.uuid.equals(onlineUser.uuid))
.findAny().ifPresent(updater ->
plugin.getCache().updatePlayerList(plugin, updater));
plugin.getCache().updateOnlinePlayerList(plugin, updater));
}
// Set offline position
@@ -1,16 +1,9 @@
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}
@@ -7,7 +7,7 @@ import java.util.UUID;
/**
* Represents a persistently-saved {@link Position}
*/
public abstract class SavedPosition extends Position {
public abstract class SavedPosition extends Position implements Comparable<SavedPosition> {
/**
* Metadata about this position (name, description)
@@ -42,4 +42,9 @@ public abstract class SavedPosition extends Position {
this.uuid = UUID.randomUUID();
}
// Compare based on names for alphabetical sorting
@Override
public int compareTo(@NotNull SavedPosition o) {
return this.meta.name.compareTo(o.meta.name);
}
}
@@ -47,7 +47,7 @@ public class SavedPositionManager {
final Home home = new Home(position, homeMeta, homeOwner);
cache.homes.putIfAbsent(home.owner.uuid, new ArrayList<>());
cache.homes.get(home.owner.uuid).add(home.meta.name);
cache.positionLists.clear();
cache.privateHomeLists.remove(home.owner.uuid);
return database.setHome(home).thenApply(value ->
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join();
}
@@ -72,7 +72,8 @@ public class SavedPositionManager {
homeNames.remove(home.meta.name);
return homeNames;
});
cache.positionLists.clear();
cache.privateHomeLists.remove(home.owner.uuid);
cache.publicHomeLists.clear();
return true;
}).join();
}
@@ -118,7 +119,8 @@ public class SavedPositionManager {
cache.homes.get(home.owner.uuid).remove(existingHomeName);
cache.homes.get(home.owner.uuid).add(newHomeMeta.name);
}
cache.positionLists.clear();
cache.privateHomeLists.remove(home.owner.uuid);
cache.publicHomeLists.clear();
return database.setHome(home).thenApply(value ->
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join();
});
@@ -197,7 +199,8 @@ public class SavedPositionManager {
} else if (cache.publicHomes.containsKey(home.owner.username)) {
cache.publicHomes.get(home.owner.username).remove(home.meta.name);
}
cache.positionLists.clear();
cache.privateHomeLists.remove(home.owner.uuid);
cache.publicHomeLists.clear();
return true;
});
}
@@ -216,7 +219,7 @@ public class SavedPositionManager {
if (optionalWarp.isEmpty()) {
final Warp warp = new Warp(position, warpMeta);
cache.warps.add(warp.meta.name);
cache.positionLists.clear();
cache.warpLists.clear();
return database.setWarp(warp).thenApply(ignored ->
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join();
}
@@ -237,7 +240,7 @@ public class SavedPositionManager {
final Warp warp = optionalWarp.get();
return database.deleteWarp(warp.uuid).thenApply(ignored -> {
cache.warps.remove(warp.meta.name);
cache.positionLists.clear();
cache.warpLists.clear();
return true;
}).join();
}
@@ -282,7 +285,7 @@ public class SavedPositionManager {
cache.warps.remove(existingWarpName);
cache.warps.add(newWarpMeta.name);
}
cache.positionLists.clear();
cache.warpLists.clear();
return database.setWarp(warp).thenApply(value ->
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join();
});
+29 -23
View File
@@ -13,15 +13,15 @@ warp_deleted: '[Successfully deleted the warp,](#00fb9a) [%1%](#00fb9a bold)'
edit_home_menu_title: '[Viewing home details for](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)'
edit_home_menu_title_other: '[Viewing details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)'
edit_home_menu_metadata_private: '[⌚ %1%](#ffc43b-#f5c962 show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#999999-#bcbcbc show_text=&7Home ID:\n&8%3%) [● Private Home](#ff9f0f show_text=&7Privacy: ● Private Home\n&8The home is private to the owner)'
edit_home_menu_metadata_public: '[⌚ %1%](#ffc43b-#f5c962 show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#999999-#bcbcbc show_text=&7Home ID:\n&8%3%) [☀ Public Home](#d8ff2b show_text=&7Privacy: ☀ Public Home\n&8Anyone can teleport to the home)'
edit_home_menu_description: '[ℹ %1%](#62a9f5-#7ab8fa show_text=&7Home Description:\n&8%2%)\n'
edit_home_menu_world: '[⭘ %1%](dark_aqua show_text=&7World:\n&8The world where the home is set)'
edit_home_menu_world_server: '[⭘ %1%](dark_aqua show_text=&7World:\n&8The world where the home is set) [☁ %2%](#36f539 show_text=&7Server:\n&8The server where the home is set)'
edit_home_menu_coordinates: '[⚐ x: %1%, y: %2%, z: %3%](#ffc43b-#f5c962 show_text=&#ffc43b&yaw: %4%, pitch: %5%\n&7Coordinates:\n&8Location of the home in the world)\n'
edit_home_menu_metadata_private: '[⌚ %1%](#999999-#ababab show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#ababab-#c7c7c7 show_text=&7Home ID:\n&8%3%) [● Private Home](#ff9f0f show_text=&#ff9f0f&Privacy:\n&8The home is private to the owner)'
edit_home_menu_metadata_public: '[⌚ %1%](#999999-#ababab show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#ababab-#c7c7c7 show_text=&7Home ID:\n&8%3%) [☀ Public Home](#6fff00 show_text=&#6fff00&Privacy:\n&8Anyone can teleport to the home)'
edit_home_menu_description: '[ℹ %1%](#c160ff-#b43fff show_text=&#c160ff&Description:\n&8%2%)\n'
edit_home_menu_world: '[⭘ %1%](#3b76ff-#5286ff show_text=&#3b76ff&World:\n&8The world where the home is set)'
edit_home_menu_world_server: '[⭘ %1%](#3b76ff-#477fff show_text=&#3b76ff&World:\n&8The world where the home is set) [☁ %2%](#477fff-#5286ff show_text=&#3b76ff&Server:\n&8The server where the home is set)'
edit_home_menu_coordinates: '[⚐ x: %1%, y: %2%, z: %3%](#ffc43b-#f5c962 show_text=&#ffc43b&Coordinates:\n&8Location of the home in the world\n&8\(yaw: %4%, pitch: %5%\) )\n'
edit_home_menu_use_buttons: '[Use:](gray) [[⏩ Teleport…]](#00fb9a show_text=&7Click to teleport to this home run_command=/huskhomes:home %1%)'
edit_home_menu_manage_buttons: '[Manage:](gray) [[❌ Delete…]](#ff3300 show_text=&7Click to delete this home\n&#ff3300&⚠ This cannot be undone! run_command=/huskhomes:delhome %1%) [[⚐ Relocate…]](#ffc43b show_text=&7Click to relocate this home to your position run_command=/huskhomes:edithome %1% relocate -m) [[☀ Public/Private…]](#d8ff2b show_text=&7Click to toggle the privacy of this home run_command=/huskhomes:edithome %1% privacy -m)'
edit_home_menu_meta_edit_buttons: '[Edit:](gray) [[✎ Rename…]](#62a9f5 show_text=&7Click to suggest the rename command suggest_command=/huskhomes:edithome %1% rename ) [[ℹ Description…]](#7ab8fa show_text=&7Click to suggest the edit description command suggest_command=/huskhomes:edithome %1% description )'
edit_home_menu_manage_buttons: '[Manage:](gray) [[❌ Delete…]](#ff3300 show_text=&7Click to delete this home\n&#ff3300&⚠ This cannot be undone! run_command=/huskhomes:delhome %1%) [[⚐ Relocate…]](#ffc43b-#f5c962 show_text=&7Click to relocate this home to your position run_command=/huskhomes:edithome %1% relocate -m) [[☀ Public/Private…]](#6fff00 show_text=&7Click to toggle the privacy of this home run_command=/huskhomes:edithome %1% privacy -m)'
edit_home_menu_meta_edit_buttons: '[Edit:](gray) [[✎ Rename…]](#c160ff-#bb50ff show_text=&7Click to suggest the rename command suggest_command=/huskhomes:edithome %1% rename ) [[ℹ Description…]](#bb50ff-#b43fff show_text=&7Click to suggest the edit description command suggest_command=/huskhomes:edithome %1% description )'
edit_home_privacy_public_success: '[Successfully made your home,](#00fb9a) [%1%](#00fb9a bold)[, open to the public.](#00fb9a)'
edit_home_privacy_private_success: '[Successfully made your home,](#00fb9a) [%1%](#00fb9a bold)[, private.](#00fb9a)'
@@ -38,9 +38,27 @@ edit_warp_options: '\n[[Teleport]](green show_text=&7Teleport to this warp run_c
edit_warp_update_location: '[Re-located the warp](#00fb9a) [%1%](#00fb9a bold) [to your current position.](#00fb9a)'
edit_warp_update_description: '[Changed the description for the warp](#00fb9a) [%1%](#00fb9a bold) [to "%2%".](#00fb9a)'
edit_warp_update_name: '[Successfully changed a warp''s name: %1% →](#00fb9a) [%2%](#00fb9a bold)'
private_home_list_page_top: '\n[%1%''s Homes:](#00fb9a) [(](#00fb9a)[%2%-%3%](#00fb9a bold) [of](#00fb9a) [%4%](#00fb9a bold)[)](#00fb9a)\n'
public_home_list_page_top: '\n[Public Homes:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n'
warp_list_page_top: '\n[Warps:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n'
home_list_page_title: '[%1%''s Homes:](#00fb9a) [(%2%-%3% of](#00fb9a) [%4%](#00fb9a bold)[)](#00fb9a)'
public_home_list_page_title: '[☀ Public Homes:](#00fb9a) [(%1%-%2% of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)'
warp_list_page_title: '[Warps:](#00fb9a) [(%1%-%2% of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)'
command_list_title: '[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
home_list_item: '[[%1%]](show_text=&7%3% run_command=/huskhomes:edithome %2%)'
public_home_list_item: '[[%1%]](show_text=&#00fb9a&%2%: &7%3% run_command=/huskhomes:publichome %2%)'
warp_list_item: '[[%1%]](show_text=&7%2% run_command=/huskhomes:warp %1%)'
command_list_item: '[/%1%](#00fb9a show_text=&#00fb9a&%2% suggest_command=/%1%) [•](white) [%3%](gray)'
list_item_divider: ' [•](gray) '
list_footer: '%1%[Page](#00fb9a) [%2%](#00fb9a)/[%3%](#00fb9a)%4% %5%'
list_previous_page_button: '[◀](white show_text=&7View previous page run_command=%2% %1%) '
list_next_page_button: ' [▶](white show_text=&7View next page run_command=%2% %1%)'
list_page_jumpers: '(%1%)'
list_page_jumper_button: '[%1%](show_text=&7Jump to page %1% run_command=%2% %1%)'
list_page_jumper_current_page: '[%1%](#00fb9a)'
list_page_jumper_separator: ' '
list_page_jumper_group_separator: '…'
set_home_spent_money: '[Successfully spent %1% to set an additional home!](gray)'
set_home_used_free_slots: '[You''ve used all of your free set home slots (%1%); setting additional homes will cost %2% each.](gray)'
set_home_success: '[Successfully set a new home called](#00fb9a) [%1%](#00fb9a bold)'
@@ -72,18 +90,6 @@ tpignore_on_reminder: '[You are currently ignoring incoming teleport requests!](
tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)'
teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)'
page_options: '[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a) [→](gray show_text=&7View next page run_command=%4%)'
page_options_min: '[Viewing Page %1%/%2%](#00fb9a) [→](gray show_text=&7View next page run_command=%3%)'
page_options_min_max: '[Viewing Page %1%/%2%](#00fb9a)'
page_options_max: '[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a)'
page_no_items: '[(No items to display on this page)](gray show_text=&7Try a different page number)'
command_list_header: '\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)'
command_list_item: '[/%1%](#00fb9a show_text=&#00fb9a&%2% suggest_command=/%1%) [•](white) [%3%](gray)'
list_item_divider: ' [•](gray) '
home_list_item: '[[%1%]](show_text=&7%3% run_command=/huskhomes:edithome %2%.%1%)'
public_home_list_item: '[[%1%]](show_text=&#00fb9a&%2%: &7%3% run_command=/huskhomes:phome %2%.%1%)'
warp_list_item: '[[%1%]](show_text=&7%2% run_command=/huskhomes:warp %1%)'
error_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)'
error_home_name_length: '[Error:](#ff3300) [Home names can only contain up to 16 characters!](#ff7e5e)'
error_home_name_characters: '[Error:](#ff3300) [Home names must be alphanumeric (A-Z, 0-9, -_)](#ff7e5e)'