Fix list and TAB completion issues; close #272, #273

This commit is contained in:
William committed 2022-11-27 20:17:23 +00:00
1 parent 1dc45b8286
commit b7cf0fa590
18 files changed
+111 -67

No files matched your search

@@ -3,6 +3,8 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.intellij.lang.annotations.Pattern;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;
/**
@@ -26,6 +28,7 @@ public abstract class CommandBase {
* The permission node required to use this command
*/
@NotNull
@Pattern(Permission.PERMISSION_PATTERN)
public final String permission;
/**
@@ -34,8 +37,8 @@ public abstract class CommandBase {
@NotNull
protected final HuskHomes plugin;
protected CommandBase(@NotNull String command, @NotNull Permission permission, @NotNull HuskHomes implementor,
@NotNull String... aliases) {
protected CommandBase(@NotNull String command, @NotNull @Subst("huskhomes") Permission permission,
@NotNull HuskHomes implementor, @NotNull String... aliases) {
this.command = command;
this.permission = permission.node;
this.plugin = implementor;
@@ -69,7 +69,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName,
final boolean delHomeAllConfirm) {
plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
if (deleter.uuid.equals(homeOwner.uuid)) {
if (deleter.equals(homeOwner)) {
if (deleted) {
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
return;
@@ -85,7 +85,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
private void editHome(@NotNull Home home, @NotNull OnlineUser editor,
@Nullable String editOperation, @Nullable String editArgs) {
final AtomicBoolean showMenuFlag = new AtomicBoolean(false);
final boolean otherOwner = !editor.uuid.equals(home.owner.uuid);
final boolean otherOwner = !editor.equals(home.owner);
if (editOperation == null) {
getHomeEditorWindow(home, true, otherOwner,
@@ -119,7 +119,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(newHomeName, home.meta.description))
.thenAccept(renameResult -> (switch (renameResult.resultType()) {
case SUCCESS -> {
if (home.owner.uuid.equals(editor.uuid)) {
if (home.owner.equals(editor)) {
yield plugin.getLocales().getLocale("edit_home_update_name",
oldHomeName, newHomeName);
} else {
@@ -140,7 +140,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(home.meta.name, newDescription))
.thenAccept(descriptionUpdateResult -> (switch (descriptionUpdateResult.resultType()) {
case SUCCESS -> {
if (home.owner.uuid.equals(editor.uuid)) {
if (home.owner.equals(editor)) {
yield plugin.getLocales().getLocale("edit_home_update_description",
home.meta.name,
oldHomeDescription.isBlank() ? plugin.getLocales()
@@ -166,7 +166,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
}
case "relocate" ->
plugin.getSavedPositionManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
if (home.owner.uuid.equals(editor.uuid)) {
if (home.owner.equals(editor)) {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
home.meta.name).orElse(new MineDown("")));
} else {
@@ -233,7 +233,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
// Execute the update
plugin.getSavedPositionManager().updateHomePrivacy(home, newIsPublic.get()).thenRun(() -> {
if (home.owner.uuid.equals(editor.uuid)) {
if (home.owner.equals(editor)) {
editor.sendMessage(plugin.getLocales().getLocale(
"edit_home_privacy_" + privacyKeyedString + "_success",
home.meta.name).orElse(new MineDown("")));
@@ -57,7 +57,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
}
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
final boolean otherHome = !owner.equals(teleporter);
plugin.getDatabase()
.getHome(owner, homeName)
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
@@ -66,7 +66,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
}
plugin.getDatabase().getHomes(userData.user()).thenAcceptAsync(homes -> {
if (homes.isEmpty()) {
if (!onlineUser.uuid.equals(userData.user().uuid)) {
if (!onlineUser.equals(userData.user())) {
plugin.getLocales().getLocale("error_no_homes_set_other",
userData.user().username).ifPresent(onlineUser::sendMessage);
} else {
@@ -69,7 +69,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
}
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
final boolean otherHome = !owner.equals(teleporter);
plugin.getDatabase()
.getHome(owner, homeName)
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
@@ -114,7 +114,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
.orElse(null)),
() -> matchedHome.set(plugin.getDatabase().getPublicHomes().join()
.stream()
.filter(home -> home.owner.uuid.equals(playerToTeleport.uuid) && home.meta.name.equalsIgnoreCase(args[1]))
.filter(home -> home.owner.equals(playerToTeleport) && home.meta.name.equalsIgnoreCase(args[1]))
.findFirst()
.orElse(null)));
@@ -54,7 +54,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
final OnlineUser userToTeleport = target;
final boolean isExecutorTeleporting = userToTeleport.uuid.equals(onlineUser.uuid);
final boolean isExecutorTeleporting = userToTeleport.equals(onlineUser);
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
// Check the user is not still on /rtp cooldown
if (userData.isEmpty()) {
@@ -6,7 +6,6 @@ import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TimedTeleport;
import net.william278.huskhomes.util.Permission;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,30 +22,30 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
switch (args.length) {
case 0 -> plugin.getDatabase().getWarps().thenAcceptAsync(warps -> {
if (warps.isEmpty()) {
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
return;
}
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
plugin.getSettings().permissionRestrictWarps,
plugin.getSettings().listItemsPerPage, 1)
.ifPresent(onlineUser::sendMessage);
});
case 0 -> plugin.getDatabase().getWarps()
.thenApply(warps -> warps.stream()
.filter(warp -> warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser))
.collect(Collectors.toList()))
.thenAccept(warps -> {
if (warps.isEmpty()) {
plugin.getLocales().getLocale("error_no_warps_set")
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
plugin.getSettings().listItemsPerPage, 1)
.ifPresent(onlineUser::sendMessage);
});
case 1 -> {
final String warpName = args[0];
plugin.getDatabase()
.getWarp(warpName)
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> {
// Handle permission restrictions
if (plugin.getSettings().permissionRestrictWarps) {
@Subst("huskhomes.command.warp") final String warpPermission = Permission.COMMAND_WARP.node + "." + warp.meta.name;
if (!onlineUser.hasPermission(warpPermission) && !onlineUser.hasPermission(Permission.COMMAND_SET_WARP.node)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
return;
}
if (!warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
return;
}
Teleport.builder(plugin, onlineUser)
@@ -65,8 +64,7 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
@Override
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
return plugin.getCache().warps.stream()
.filter(s -> user == null || plugin.getSettings().permissionRestrictWarps && !user.hasPermission(
Permission.COMMAND_SET_WARP.node) && user.hasPermission(Warp.getPermissionNode(s)))
.filter(s -> user == null || Warp.hasPermission(plugin.getSettings().permissionRestrictWarps, user, s))
.filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : ""))
.sorted()
.collect(Collectors.toList());
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.StringJoiner;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class WarpListCommand extends CommandBase implements ConsoleExecutable {
@@ -45,17 +46,19 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
}
// Dispatch the warp list event
plugin.getDatabase().getWarps().thenAcceptAsync(warps -> {
if (warps.isEmpty()) {
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
return;
}
plugin.getCache().getWarpList(onlineUser,
plugin.getLocales(), warps,
plugin.getSettings().permissionRestrictWarps,
plugin.getSettings().listItemsPerPage,
pageNumber).ifPresent(onlineUser::sendMessage);
});
plugin.getDatabase().getWarps()
.thenApply(warps -> warps.stream()
.filter(warp -> warp.hasPermission(plugin.getSettings().permissionRestrictWarps, onlineUser))
.collect(Collectors.toList()))
.thenAccept(warps -> {
if (warps.isEmpty()) {
plugin.getLocales().getLocale("error_no_warps_set").ifPresent(onlineUser::sendMessage);
return;
}
plugin.getCache().getWarpList(onlineUser, plugin.getLocales(), warps,
plugin.getSettings().listItemsPerPage, pageNumber)
.ifPresent(onlineUser::sendMessage);
});
}
@Override