mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Continue command refactor work
This commit is contained in:
31 files changed
+319
-391
No files matched your search
@@ -23,7 +23,7 @@ import java.util.stream.Collectors;
|
||||
public class Cache {
|
||||
|
||||
private final HuskHomes plugin;
|
||||
private final Map<UUID, List<String>> homes = new HashMap<>();
|
||||
private final Map<String, List<String>> homes = new HashMap<>();
|
||||
private final Map<String, List<String>> publicHomes = new HashMap<>();
|
||||
private final List<String> warps = new ArrayList<>();
|
||||
private final Set<String> players = new HashSet<>();
|
||||
@@ -124,7 +124,7 @@ public class Cache {
|
||||
locales.getRawLocale("home_list_item",
|
||||
Locales.escapeText(home.getMeta().getName()),
|
||||
Locales.escapeText(home.getOwner().getUsername() + "." + home.getMeta().getName()),
|
||||
Locales.escapeText(locales.wrapText(home.getMeta().getDescription())))
|
||||
Locales.escapeText(locales.wrapText(home.getMeta().getDescription(), 40)))
|
||||
.orElse(home.getMeta().getName())).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
|
||||
.setHeaderFormat(locales.getRawLocale("home_list_page_title",
|
||||
homeOwner.getUsername(), "%first_item_on_page_index%",
|
||||
@@ -145,7 +145,7 @@ public class Cache {
|
||||
Locales.escapeText(home.getMeta().getName()),
|
||||
Locales.escapeText(home.getOwner().getUsername() + "." + home.getMeta().getName()),
|
||||
Locales.escapeText(home.getOwner().getUsername()),
|
||||
Locales.escapeText(locales.wrapText(home.getMeta().getDescription())))
|
||||
Locales.escapeText(locales.wrapText(home.getMeta().getDescription(), 40)))
|
||||
.orElse(home.getMeta().getName())).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%",
|
||||
@@ -164,7 +164,7 @@ public class Cache {
|
||||
final PaginatedList warpList = PaginatedList.of(warps.stream()
|
||||
.map(warp -> locales.getRawLocale("warp_list_item",
|
||||
Locales.escapeText(warp.getMeta().getName()),
|
||||
Locales.escapeText(locales.wrapText(warp.getMeta().getDescription())))
|
||||
Locales.escapeText(locales.wrapText(warp.getMeta().getDescription(), 40)))
|
||||
.orElse(warp.getMeta().getName())).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage)
|
||||
.setHeaderFormat(locales.getRawLocale("warp_list_page_title",
|
||||
"%first_item_on_page_index%", "%last_item_on_page_index%",
|
||||
@@ -184,7 +184,7 @@ public class Cache {
|
||||
Locales.escapeText(command.getDescription().length() > 50
|
||||
? command.getDescription().substring(0, 49).trim() + "…"
|
||||
: command.getDescription()),
|
||||
Locales.escapeText(locales.wrapText(command.getDescription())))
|
||||
Locales.escapeText(locales.wrapText(command.getDescription(), 40)))
|
||||
.orElse(command.getName()))
|
||||
.collect(Collectors.toList()),
|
||||
getBaseList(locales, Math.min(itemsPerPage, 6))
|
||||
@@ -196,7 +196,7 @@ public class Cache {
|
||||
/**
|
||||
* Cached home names - maps a {@link UUID} to a list of their homes
|
||||
*/
|
||||
public Map<UUID, List<String>> getHomes() {
|
||||
public Map<String, List<String>> getHomes() {
|
||||
return homes;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,27 +14,25 @@ import java.util.Optional;
|
||||
public class BackCommand extends Command {
|
||||
|
||||
protected BackCommand(@NotNull HuskHomes plugin) {
|
||||
super("back", List.of(), plugin);
|
||||
super("back", List.of(), "", plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
final OnlineUser player = (OnlineUser) executor;
|
||||
plugin.runAsync(() -> {
|
||||
final Optional<Position> lastPosition = plugin.getDatabase().getLastPosition(player);
|
||||
if (lastPosition.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_last_position")
|
||||
.ifPresent(player::sendMessage);
|
||||
return;
|
||||
}
|
||||
final Optional<Position> lastPosition = plugin.getDatabase().getLastPosition(player);
|
||||
if (lastPosition.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_last_position")
|
||||
.ifPresent(player::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
Teleport.builder(plugin)
|
||||
.teleporter(player)
|
||||
.target(lastPosition.get())
|
||||
.economyActions(EconomyHook.Action.BACK_COMMAND)
|
||||
.toTimedTeleport()
|
||||
.execute();
|
||||
});
|
||||
Teleport.builder(plugin)
|
||||
.teleporter(player)
|
||||
.target(lastPosition.get())
|
||||
.economyActions(EconomyHook.Action.BACK_COMMAND)
|
||||
.toTimedTeleport()
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public abstract class ChildCommand extends Node {
|
||||
protected final Command parent;
|
||||
private final String usage;
|
||||
|
||||
protected ChildCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull Command parent,
|
||||
@NotNull String usage, @NotNull HuskHomes plugin) {
|
||||
super(name, aliases, plugin);
|
||||
this.parent = parent;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getPermission() {
|
||||
return new StringJoiner(".")
|
||||
.add(parent.getPermission())
|
||||
.add(getName()).toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getUsage() {
|
||||
return "/" + parent.getName() + " " + getName() + ((" " + usage).isBlank() ? "" : " " + usage);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final Optional<String> getDescription() {
|
||||
return plugin.getLocales().getRawLocale("command_" + parent.getName() + "_" + getName() + "_description");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +1,44 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import net.william278.paginedown.PaginatedList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class Command extends Node implements TabProvider {
|
||||
|
||||
public List<ChildCommand> children;
|
||||
private Executable defaultExecutor;
|
||||
|
||||
protected Command(@NotNull String name, @NotNull List<String> aliases, @NotNull HuskHomes plugin) {
|
||||
private final String usage;
|
||||
protected Command(@NotNull String name, @NotNull List<String> aliases, @NotNull String usage, @NotNull HuskHomes plugin) {
|
||||
super(name, aliases, plugin);
|
||||
}
|
||||
|
||||
public void setDefaultExecutor(@NotNull Executable defaultExecutor) {
|
||||
this.defaultExecutor = defaultExecutor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Executable getDefaultExecutor() {
|
||||
if (defaultExecutor == null) {
|
||||
throw new IllegalStateException("Default executor not set");
|
||||
}
|
||||
return defaultExecutor;
|
||||
}
|
||||
|
||||
public void setChildren(@NotNull List<ChildCommand> children) {
|
||||
this.children = children;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
public final void onExecuted(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
if (!executor.hasPermission(getPermission())) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (args.length >= 1 && !children.isEmpty()) {
|
||||
for (Node child : children) {
|
||||
if (child.matchesInput(args[0])) {
|
||||
if (!executor.hasPermission(child.getPermission())) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (executor instanceof ConsoleUser && !isConsoleExecutable()) {
|
||||
plugin.getLocales().getLocale("error_command_in_game_only")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
child.execute(executor, removeFirstArg(args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
plugin.getLocales().getLocale("error_unknown_command",
|
||||
"/" + getName() + " " + getHelpCommand().getName())
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (executor instanceof ConsoleUser && !isConsoleExecutable()) {
|
||||
plugin.getLocales().getLocale("error_command_in_game_only")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
this.defaultExecutor.execute(executor, args);
|
||||
plugin.runAsync(() -> this.execute(executor, args));
|
||||
}
|
||||
|
||||
public abstract void execute(@NotNull CommandUser executor, @NotNull String[] args);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
if (args.length <= 1) {
|
||||
return TabProvider.getMatchingNames(args[0], user, children);
|
||||
} else {
|
||||
for (final Node child : children) {
|
||||
if (child.matchesInput(args[0]) && child instanceof TabProvider provider) {
|
||||
return provider.getSuggestions(user, removeFirstArg(args));
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<String> suggest(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String[] removeFirstArg(String[] args) {
|
||||
protected String[] removeFirstArg(String[] args) {
|
||||
String[] newArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
|
||||
return newArgs;
|
||||
@@ -99,8 +46,7 @@ public abstract class Command extends Node implements TabProvider {
|
||||
|
||||
@NotNull
|
||||
public final String getUsage() {
|
||||
final String arguments = children.stream().map(Node::getName).collect(Collectors.joining("|"));
|
||||
return "/" + getName() + " [" + plugin.getLocales().truncateText(arguments, 40) + "]";
|
||||
return "/" + getName() + " " + usage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -110,59 +56,4 @@ public abstract class Command extends Node implements TabProvider {
|
||||
.orElse(getUsage());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ChildCommand> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected MineDown getChildCommandList(@NotNull CommandUser user, final int page) {
|
||||
final Locales locales = plugin.getLocales();
|
||||
return PaginatedList.of(getChildren().stream()
|
||||
.filter(child -> child.canPerform(user))
|
||||
.map(command -> locales.getRawLocale("command_list_item",
|
||||
Locales.escapeText(command.getUsage()),
|
||||
"/" + command.parent.getName() + " " + command.getName(),
|
||||
command.getDescription().map(description ->
|
||||
Locales.escapeText(description.length() > 50
|
||||
? description.substring(0, 49).trim() + "…"
|
||||
: description)).orElse(""),
|
||||
command.getDescription().map(description ->
|
||||
Locales.escapeText(locales.wrapText(description, 40))).orElse(""))
|
||||
.orElse(command.getUsage()))
|
||||
.toList(),
|
||||
locales.getBaseList(plugin.getSettings().getListItemsPerPage())
|
||||
.setHeaderFormat(locales.getRawLocale("child_command_list_title",
|
||||
"/" + getName()).orElse(""))
|
||||
.setItemSeparator("\n").setCommand("/huskhomes:" + getName() + " help")
|
||||
.build())
|
||||
.getNearestValidPage(page);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Command.HelpCommand getHelpCommand() {
|
||||
return new HelpCommand(this, plugin);
|
||||
}
|
||||
|
||||
public static class HelpCommand extends ChildCommand implements TabProvider {
|
||||
|
||||
protected HelpCommand(@NotNull Command parent, @NotNull HuskHomes plugin) {
|
||||
super("help", List.of(), parent, "[page]", plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
int page = parseIntArg(args, 0).orElse(1);
|
||||
executor.sendMessage(parent.getChildCommandList(executor, page));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return Stream.iterate(1, i -> i + 1)
|
||||
.limit(9)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,134 +1,61 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DelHomeCommand extends Command implements TabProvider {
|
||||
public class DelHomeCommand extends SavedPositionCommand<Home> implements TabProvider {
|
||||
|
||||
protected DelHomeCommand(@NotNull HuskHomes implementor) {
|
||||
super("delhome", Permission.COMMAND_DELETE_HOME, implementor);
|
||||
public DelHomeCommand(@NotNull HuskHomes implementor) {
|
||||
super("delhome", List.of(), Home.class, List.of(), implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
|
||||
if (homes.size() == 1) {
|
||||
homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name, false));
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
});
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
if (executor instanceof OnlineUser user && handleDeleteAll(user, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length <= 2) {
|
||||
final String homeName = args[0];
|
||||
final boolean confirm = args.length == 2 && args[1].equalsIgnoreCase("confirm");
|
||||
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier ->
|
||||
plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept(
|
||||
optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
|
||||
if (!userData.getUserUuid().equals(onlineUser.getUuid())) {
|
||||
if (!onlineUser.hasPermission(Permission.COMMAND_DELETE_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
deletePlayerHome(onlineUser, userData.user(), homeIdentifier.homeName(), confirm);
|
||||
},
|
||||
() -> plugin.getLocales().getLocale("error_home_invalid_other",
|
||||
homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))),
|
||||
() -> deletePlayerHome(onlineUser, onlineUser, homeName, confirm));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
super.execute(executor, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a player's home
|
||||
*
|
||||
* @param deleter the player who is deleting the home
|
||||
* @param homeOwner The player who owns the home
|
||||
* @param homeName The home name to delete
|
||||
* @param delHomeAllConfirm Whether to skip the confirmation prompt for deleting all homes
|
||||
*/
|
||||
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName,
|
||||
final boolean delHomeAllConfirm) {
|
||||
plugin.getManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
|
||||
if (deleter.equals(homeOwner)) {
|
||||
if (deleted) {
|
||||
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (homeName.equalsIgnoreCase("all")) {
|
||||
deleteAllHomes(deleter, homeOwner, delHomeAllConfirm);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
|
||||
} else {
|
||||
if (deleted) {
|
||||
plugin.getLocales().getLocale("home_deleted_other", homeOwner.getUsername(), homeName).ifPresent(deleter::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (homeName.equalsIgnoreCase("all")) {
|
||||
deleteAllHomes(deleter, homeOwner, delHomeAllConfirm);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.getUsername(), homeName).ifPresent(deleter::sendMessage);
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull Home home, @NotNull String[] args) {
|
||||
if (executor instanceof OnlineUser user && !home.getOwner().equals(user) && !user.hasPermission(getOtherPermission())) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(user::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getManager().homes().deleteHome(home.getOwner(), home.getName());
|
||||
plugin.getLocales().getLocale("home_deleted", home.getName())
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
|
||||
private boolean handleDeleteAll(@NotNull OnlineUser user, @NotNull String[] args) {
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("all")) {
|
||||
if (!parseStringArg(args, 1)
|
||||
.map(confirm -> confirm.equalsIgnoreCase("confirm"))
|
||||
.orElse(false)) {
|
||||
plugin.getLocales().getLocale("delete_all_homes_confirm")
|
||||
.ifPresent(user::sendMessage);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of a player's homes
|
||||
*
|
||||
* @param deleter the player who is deleting the homes
|
||||
* @param homeOwner the player who owns the homes
|
||||
* @param confirm whether to skip the confirmation prompt
|
||||
*/
|
||||
private void deleteAllHomes(@NotNull OnlineUser deleter, @NotNull User homeOwner,
|
||||
final boolean confirm) {
|
||||
if (!confirm) {
|
||||
plugin.getLocales().getLocale("delete_all_homes_confirm")
|
||||
.ifPresent(deleter::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getManager().deleteAllHomes(homeOwner).thenAccept(deleted -> {
|
||||
final int deleted = plugin.getManager().homes().deleteAllHomes(user);
|
||||
if (deleted == 0) {
|
||||
plugin.getLocales().getLocale("error_no_warps_set")
|
||||
.ifPresent(deleter::sendMessage);
|
||||
return;
|
||||
plugin.getLocales().getLocale("error_no_homes_set")
|
||||
.ifPresent(user::sendMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.getLocales().getLocale("delete_all_homes_success", Integer.toString(deleted))
|
||||
.ifPresent(deleter::sendMessage);
|
||||
});
|
||||
.ifPresent(user::sendMessage);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
if (user == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return args.length > 1 ? Collections.emptyList() : plugin.getCache().getHomes()
|
||||
.getOrDefault(user.getUuid(), new ArrayList<>())
|
||||
.stream()
|
||||
.filter(s -> s.startsWith(args.length == 1 ? args[0] : ""))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,61 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DelWarpCommand extends Command implements TabProvider {
|
||||
public class DelWarpCommand extends SavedPositionCommand<Warp> implements TabProvider {
|
||||
|
||||
protected DelWarpCommand(@NotNull HuskHomes implementor) {
|
||||
super("delwarp", Permission.COMMAND_DELETE_WARP, implementor);
|
||||
public DelWarpCommand(@NotNull HuskHomes implementor) {
|
||||
super("delwarp", List.of(), Warp.class, List.of(), implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delwarp <name>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
if (handleDeleteAll(executor, args)) {
|
||||
return;
|
||||
}
|
||||
if (args.length <= 2) {
|
||||
final String warpName = args[0];
|
||||
final boolean confirm = args.length == 2 && args[1].equalsIgnoreCase("confirm");
|
||||
plugin.getManager().deleteWarp(warpName).thenAccept(deleted -> {
|
||||
if (deleted) {
|
||||
plugin.getLocales().getLocale("warp_deleted", warpName)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (warpName.equalsIgnoreCase("all")) {
|
||||
deleteAllWarps(onlineUser, confirm);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delwarp <name>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
super.execute(executor, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the server warps
|
||||
*
|
||||
* @param deleter the player who is deleting the warps
|
||||
* @param confirm whether to skip the confirmation prompt
|
||||
*/
|
||||
private void deleteAllWarps(@NotNull OnlineUser deleter, final boolean confirm) {
|
||||
if (!confirm) {
|
||||
plugin.getLocales().getLocale("delete_all_warps_confirm")
|
||||
.ifPresent(deleter::sendMessage);
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
||||
if (executor instanceof OnlineUser user && !warp.hasPermission(plugin.getSettings().isPermissionRestrictWarps(), user)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(user::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getManager().warps().deleteWarp(warp.getName());
|
||||
plugin.getLocales().getLocale("warp_deleted", warp.getName())
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
|
||||
plugin.getManager().deleteAllWarps().thenAccept(deleted -> {
|
||||
private boolean handleDeleteAll(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("all")) {
|
||||
if (!parseStringArg(args, 1)
|
||||
.map(confirm -> confirm.equalsIgnoreCase("confirm"))
|
||||
.orElse(false)) {
|
||||
plugin.getLocales().getLocale("delete_all_warps_confirm")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
final int deleted = plugin.getManager().warps().deleteAllWarps();
|
||||
if (deleted == 0) {
|
||||
plugin.getLocales().getLocale("error_no_warps_set")
|
||||
.ifPresent(deleter::sendMessage);
|
||||
return;
|
||||
.ifPresent(executor::sendMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.getLocales().getLocale("delete_all_warps_success", Integer.toString(deleted))
|
||||
.ifPresent(deleter::sendMessage);
|
||||
});
|
||||
.ifPresent(executor::sendMessage);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
return args.length > 1 ? Collections.emptyList() : plugin.getCache().getWarps()
|
||||
.stream()
|
||||
.filter(s -> s.startsWith(args.length == 1 ? args[0] : ""))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DisabledCommand extends Command {
|
||||
|
||||
public DisabledCommand(@NotNull HuskHomes implementor) {
|
||||
super("", Permission.COMMAND_DISABLED_MESSAGE, implementor);
|
||||
public DisabledCommand(@NotNull HuskHomes plugin) {
|
||||
super("", List.of(), "", plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
plugin.getLocales().getLocale("error_command_disabled").ifPresent(onlineUser::sendMessage);
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
plugin.getLocales().getLocale("error_command_disabled")
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,8 @@ public class EditHomeCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
if (user == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -198,7 +198,8 @@ public class EditWarpCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return switch (args.length) {
|
||||
case 0, 1 -> plugin.getCache().getWarps()
|
||||
.stream()
|
||||
|
||||
@@ -5,6 +5,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface Executable {
|
||||
|
||||
void execute(@NotNull CommandUser executor, @NotNull String[] args);
|
||||
void onExecuted(@NotNull CommandUser executor, @NotNull String[] args);
|
||||
|
||||
}
|
||||
@@ -119,7 +119,8 @@ public class HomeCommand extends Command implements TabProvider, ConsoleExecutab
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
if (user == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -158,7 +158,8 @@ public class HuskHomesCommand extends Command implements ConsoleExecutable, TabP
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
if (args.length == 0 || args.length == 1) {
|
||||
return Arrays.stream(SUB_COMMANDS)
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
|
||||
@@ -133,7 +133,8 @@ public class PublicHomeCommand extends Command implements TabProvider, ConsoleEx
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
// Return every public home name as username.home_name from the cache
|
||||
final List<String> publicHomes = new ArrayList<>();
|
||||
plugin.getCache().getPublicHomes().forEach((ownerName, homeNames) ->
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.SavedPosition;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class SavedPositionCommand<T extends SavedPosition> extends Command {
|
||||
|
||||
private final Class<T> positionType;
|
||||
private final List<String> arguments;
|
||||
|
||||
protected SavedPositionCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull Class<T> positionType,
|
||||
@NotNull List<String> arguments, @NotNull HuskHomes plugin) {
|
||||
super(name, aliases, "<name>" + ((arguments.size() > 0) ? " [" + String.join("|", arguments) + "]" : ""), plugin);
|
||||
this.positionType = positionType;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getOtherPermission() {
|
||||
return (positionType == Home.class ? super.getPermission() + ".other" : super.getPermission());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
final Optional<String> name = parseStringArg(args, 0);
|
||||
if (name.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<?> position = (positionType == Home.class
|
||||
? resolveHome(executor, name.get())
|
||||
: resolveWarp(executor, name.get()));
|
||||
position.ifPresent(p -> execute(executor, (T) p, args));
|
||||
}
|
||||
|
||||
public abstract void execute(@NotNull CommandUser executor, @NotNull T position, @NotNull String[] arguments);
|
||||
|
||||
private Optional<Home> resolveHome(@NotNull CommandUser executor, @NotNull String homeName) {
|
||||
if (homeName.contains(".")) {
|
||||
final String[] splitHomeName = homeName.split("\\.");
|
||||
final Optional<Home> optionalHome = plugin.getDatabase().getUserDataByName(splitHomeName[0])
|
||||
.flatMap(owner -> plugin.getDatabase().getHome(owner.user(), splitHomeName[1]));
|
||||
|
||||
if (optionalHome.isEmpty()) {
|
||||
plugin.getLocales().getLocale(executor.hasPermission(getOtherPermission())
|
||||
? "error_home_invalid_other" : "error_public_home_invalid",
|
||||
splitHomeName[0], splitHomeName[1])
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final Home home = optionalHome.get();
|
||||
if (executor instanceof OnlineUser user && !home.isPublic() && !user.equals(home.getOwner())
|
||||
&& !user.hasPermission(getOtherPermission())) {
|
||||
plugin.getLocales().getLocale("error_public_home_invalid",
|
||||
splitHomeName[0], splitHomeName[1])
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return optionalHome;
|
||||
} else if (executor instanceof OnlineUser owner) {
|
||||
final Optional<Home> optionalHome = plugin.getDatabase().getHome(owner, homeName);
|
||||
if (optionalHome.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
}
|
||||
return optionalHome;
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Warp> resolveWarp(@NotNull CommandUser executor, @NotNull String warpName) {
|
||||
final Optional<Warp> warp = plugin.getDatabase().getWarp(warpName);
|
||||
if (warp.isPresent() && executor instanceof OnlineUser user
|
||||
&& !warp.get().hasPermission(plugin.getSettings().isPermissionRestrictWarps(), user)) {
|
||||
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
}
|
||||
return warp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<String> suggest(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
return switch (args.length) {
|
||||
case 0, 1 -> {
|
||||
if (args.length == 1 && args[0].contains(".")) {
|
||||
if (executor.hasPermission(getOtherPermission())) {
|
||||
yield filter(reduceHomeList(plugin.getCache().getHomes()), args);
|
||||
}
|
||||
yield filter(reduceHomeList(plugin.getCache().getHomes()), args);
|
||||
}
|
||||
if (executor instanceof OnlineUser user) {
|
||||
yield filter(plugin.getCache().getHomes().get(user.getUsername()), args);
|
||||
}
|
||||
yield filter(reduceHomeList(plugin.getCache().getHomes()), args);
|
||||
}
|
||||
case 2 -> filter(arguments.stream().toList(), args);
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> reduceHomeList(@NotNull Map<String, List<String>> cachedMap) {
|
||||
final List<String> homeNames = new ArrayList<>();
|
||||
cachedMap.forEach((key, value) -> value.forEach(home -> homeNames.add(key + "." + home)));
|
||||
return homeNames;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -203,7 +203,8 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
final boolean serveCoordinateCompletions = user != null && user.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node);
|
||||
switch (args.length) {
|
||||
case 0, 1 -> {
|
||||
|
||||
@@ -52,7 +52,8 @@ public class TpHereCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
|
||||
@@ -53,7 +53,8 @@ public class TpOfflineCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
|
||||
@@ -41,7 +41,8 @@ public class TpRespondCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
|
||||
@@ -51,7 +51,8 @@ public class TpaCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
|
||||
@@ -51,7 +51,8 @@ public class TpaHereCommand extends Command implements TabProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
|
||||
@@ -62,7 +62,8 @@ public class WarpCommand extends Command implements TabProvider, ConsoleExecutab
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> suggest(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||
@NotNull
|
||||
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return plugin.getCache().getWarps().stream()
|
||||
.filter(s -> user == null || Warp.hasPermission(plugin.getSettings().isPermissionRestrictWarps(), user, s))
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : ""))
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.config;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.william278.annotaml.YamlFile;
|
||||
import net.william278.paginedown.ListOptions;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.commons.text.WordUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,6 +30,10 @@ public class Locales {
|
||||
*/
|
||||
public Map<String, String> rawLocales = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Locales() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw, un-formatted locale loaded from the locales file
|
||||
*
|
||||
@@ -132,15 +137,36 @@ public class Locales {
|
||||
* @return The line-break formatted string, or a String literal {@code "N/A"} if the input string is empty
|
||||
*/
|
||||
@NotNull
|
||||
public String wrapText(@NotNull String string) {
|
||||
public String wrapText(@NotNull String string, int wrapAfter) {
|
||||
if (string.isBlank()) {
|
||||
return this.getRawLocale("item_no_description").orElse("N/A");
|
||||
}
|
||||
return WordUtils.wrap(string, 40, "\n", true);
|
||||
return WordUtils.wrap(string, wrapAfter, "\n", true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Locales() {
|
||||
@NotNull
|
||||
public ListOptions.Builder getBaseList(int itemsPerPage) {
|
||||
return new ListOptions.Builder()
|
||||
.setFooterFormat(getRawLocale("list_footer",
|
||||
"%previous_page_button%", "%current_page%",
|
||||
"%total_pages%", "%next_page_button%", "%page_jumpers%").orElse(""))
|
||||
.setNextButtonFormat(getRawLocale("list_next_page_button",
|
||||
"%next_page_index%", "%command%").orElse(""))
|
||||
.setPreviousButtonFormat(getRawLocale("list_previous_page_button",
|
||||
"%previous_page_index%", "%command%").orElse(""))
|
||||
.setPageJumpersFormat(getRawLocale("list_page_jumpers",
|
||||
"%page_jump_buttons%").orElse(""))
|
||||
.setPageJumperPageFormat(getRawLocale("list_page_jumper_button",
|
||||
"%target_page_index%", "%command%").orElse(""))
|
||||
.setPageJumperCurrentPageFormat(getRawLocale("list_page_jumper_current_page",
|
||||
"%current_page%").orElse(""))
|
||||
.setPageJumperPageSeparator(getRawLocale("list_page_jumper_separator").orElse(""))
|
||||
.setPageJumperGroupSeparator(getRawLocale("list_page_jumper_group_separator").orElse(""))
|
||||
.setItemSeparator(getRawLocale("list_item_divider").orElse(" "))
|
||||
.setItemsPerPage(itemsPerPage)
|
||||
.setEscapeItemsMineDown(false)
|
||||
.setSpaceAfterHeader(false)
|
||||
.setSpaceBeforeFooter(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -352,7 +352,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -388,7 +388,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -424,7 +424,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -464,7 +464,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -502,7 +502,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -539,7 +539,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -573,7 +573,7 @@ public class MySqlDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
|
||||
@@ -348,7 +348,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -384,7 +384,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -420,7 +420,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -460,7 +460,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -498,7 +498,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -535,7 +535,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
@@ -569,7 +569,7 @@ public class SqLiteDatabase extends Database {
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
new Server(resultSet.getString("server_name")),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
|
||||
@@ -53,7 +53,7 @@ public class EventListener {
|
||||
});
|
||||
|
||||
// Cache this user's homes
|
||||
plugin.getCache().getHomes().put(onlineUser.getUuid(), plugin.getDatabase()
|
||||
plugin.getCache().getHomes().put(onlineUser.getUsername(), plugin.getDatabase()
|
||||
.getHomes(onlineUser).stream()
|
||||
.map(Home::getName)
|
||||
.toList());
|
||||
|
||||
@@ -50,6 +50,10 @@ public class HomesManager {
|
||||
plugin.getDatabase().deleteHome(home.get().getUuid());
|
||||
}
|
||||
|
||||
public int deleteAllHomes(@NotNull User owner) {
|
||||
return plugin.getDatabase().deleteAllHomes(owner);
|
||||
}
|
||||
|
||||
public void relocateHome(@NotNull User owner, @NotNull String name, @NotNull Position position) throws ValidationException {
|
||||
createHome(owner, name, position, true);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ public class WarpsManager {
|
||||
plugin.getDatabase().deleteWarp(warp.get().getUuid());
|
||||
}
|
||||
|
||||
public int deleteAllWarps() {
|
||||
return plugin.getDatabase().deleteAllWarps();
|
||||
}
|
||||
|
||||
public void relocateWarp(@NotNull String name, @NotNull Position position) {
|
||||
createWarp(name, position, true);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Home extends SavedPosition {
|
||||
private boolean isPublic;
|
||||
|
||||
public Home(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull Server server,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid,
|
||||
@NotNull User owner, boolean isPublic) {
|
||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||
|
||||
@@ -13,7 +13,7 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
||||
private final UUID uuid;
|
||||
|
||||
protected SavedPosition(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull Server server,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta meta, @NotNull UUID uuid) {
|
||||
super(x, y, z, yaw, pitch, world, server);
|
||||
this.setMeta(meta);
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
public class Warp extends SavedPosition {
|
||||
|
||||
public Warp(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull Server server,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user