Prevent home command tab completion throwing exceptions for un-cached users

This commit is contained in:
William278 committed 2022-09-03 01:49:53 +03:00
1 parent 3232a38b63
commit 4832d69131
7 files changed
+35 -17

No files matched your search

@@ -132,8 +132,11 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
if (user == null) {
return Collections.emptyList();
}
return args.length > 1 ? Collections.emptyList() : plugin.getCache().homes.get(user.uuid).stream()
return args.length > 1 ? Collections.emptyList() : plugin.getCache().homes
.getOrDefault(user.uuid, new ArrayList<>())
.stream()
.filter(s -> s.startsWith(args.length == 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
}
}
@@ -76,8 +76,10 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
@Override
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
return args.length > 1 ? Collections.emptyList() : plugin.getCache().warps.stream()
return args.length > 1 ? Collections.emptyList() : plugin.getCache().warps
.stream()
.filter(s -> s.startsWith(args.length == 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
}
}
@@ -342,12 +342,15 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
return Collections.emptyList();
}
return switch (args.length) {
case 0, 1 -> plugin.getCache().homes.get(user.uuid).stream()
case 0, 1 -> plugin.getCache().homes.getOrDefault(user.uuid, new ArrayList<>())
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
case 2 -> Arrays.stream(EDIT_HOME_COMPLETIONS)
.filter(s -> s.toLowerCase().startsWith(args[1].toLowerCase()))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
default -> Collections.emptyList();
};
}
@@ -200,12 +200,15 @@ public class EditWarpCommand extends CommandBase implements TabCompletable {
@Override
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
return switch (args.length) {
case 0, 1 -> plugin.getCache().warps.stream()
case 0, 1 -> plugin.getCache().warps
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
case 2 -> Arrays.stream(EDIT_WARP_COMPLETIONS)
.filter(s -> s.toLowerCase().startsWith(args[1].toLowerCase()))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
default -> Collections.emptyList();
};
}
@@ -8,6 +8,7 @@ import net.william278.huskhomes.util.RegexUtil;
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.concurrent.CompletableFuture;
@@ -78,7 +79,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
+ home.owner.username + "." + home.meta.name);
+ home.owner.username + "." + home.meta.name);
plugin.getTeleportManager().teleport(playerToTeleport, home)
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
});
@@ -89,8 +90,11 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
if (user == null) {
return Collections.emptyList();
}
return args.length > 1 ? Collections.emptyList() : plugin.getCache().homes.get(user.uuid).stream()
return args.length > 1 ? Collections.emptyList() : plugin.getCache().homes
.getOrDefault(user.uuid, new ArrayList<>())
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
}
}
@@ -104,9 +104,11 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
final List<String> publicHomes = new ArrayList<>();
plugin.getCache().publicHomes.forEach((ownerName, homeNames) ->
homeNames.forEach(homeName -> publicHomes.add(ownerName + "." + homeName)));
return args.length > 1 ? Collections.emptyList() : publicHomes.stream().filter(publicHomeIdentifier ->
publicHomeIdentifier.split(Pattern.quote("."))[1].toLowerCase()
return args.length > 1 ? Collections.emptyList() : publicHomes
.stream()
.filter(publicHomeIdentifier -> publicHomeIdentifier.split(Pattern.quote("."))[1].toLowerCase()
.startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
}
}
@@ -42,7 +42,8 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
return plugin.getCache().warps.stream()
.filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : ""))
.sorted().collect(Collectors.toList());
.sorted()
.collect(Collectors.toList());
}
@Override