mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
New player list caching system, further refinements and fixes
This commit is contained in:
59 files changed
+445
-317
No files matched your search
@@ -2,7 +2,6 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,11 +23,6 @@ public abstract class Command extends Node implements TabProvider {
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
if (executor instanceof ConsoleUser && !isConsoleExecutable()) {
|
||||
plugin.getLocales().getLocale("error_in_game_only")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.runAsync(() -> this.execute(executor, args));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.william278.desertwell.AboutMenu;
|
||||
import net.william278.desertwell.UpdateChecker;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
@@ -14,13 +15,18 @@ import java.util.stream.Collectors;
|
||||
public class HuskHomesCommand extends Command {
|
||||
|
||||
private static final List<String> SUB_COMMANDS = List.of("about", "help", "reload", "update");
|
||||
|
||||
private final UpdateChecker updateChecker;
|
||||
private final AboutMenu aboutMenu;
|
||||
|
||||
protected HuskHomesCommand(@NotNull HuskHomes implementor) {
|
||||
super("huskhomes", List.of(), "[" + String.join("|", SUB_COMMANDS) + "]", implementor);
|
||||
protected HuskHomesCommand(@NotNull HuskHomes plugin) {
|
||||
super("huskhomes", List.of(), "[" + String.join("|", SUB_COMMANDS) + "]", plugin);
|
||||
setOperatorCommand(true);
|
||||
|
||||
this.updateChecker = plugin.getUpdateChecker();
|
||||
this.aboutMenu = AboutMenu.create("HuskHomes")
|
||||
.withDescription("A powerful, intuitive and flexible teleportation suite")
|
||||
.withVersion(implementor.getVersion())
|
||||
.withVersion(plugin.getVersion())
|
||||
.addAttribution("Author",
|
||||
AboutMenu.Credit.of("William278").withDescription("Click to visit website").withUrl("https://william278.net"))
|
||||
.addAttribution("Contributors",
|
||||
@@ -57,20 +63,22 @@ public class HuskHomesCommand extends Command {
|
||||
case "help" -> executor.sendMessage(getCommandList(executor)
|
||||
.getNearestValidPage(parseIntArg(args, 0).orElse(1)));
|
||||
case "reload" -> {
|
||||
if (!plugin.reload()) {
|
||||
if (!plugin.loadConfigs()) {
|
||||
executor.sendMessage(new MineDown("[Error:](#ff3300) [Failed to reload the plugin. Check console for errors.](#ff7e5e)"));
|
||||
return;
|
||||
}
|
||||
executor.sendMessage(new MineDown("[HuskHomes](#00fb9a bold) �fb9a&| Reloaded config & message files."));
|
||||
}
|
||||
case "update" -> plugin.getLatestVersionIfOutdated()
|
||||
.thenAccept(newestVersion -> newestVersion.ifPresentOrElse(
|
||||
newVersion -> executor.sendMessage(
|
||||
new MineDown("[HuskHomes](#00fb9a bold) [| A new version of HuskHomes is available!"
|
||||
+ " (v" + newVersion + " (Running: v" + plugin.getVersion() + ")](#00fb9a)")),
|
||||
() -> executor.sendMessage(
|
||||
new MineDown("[HuskHomes](#00fb9a bold) [| HuskHomes is up-to-date."
|
||||
+ " (Running: v" + plugin.getVersion() + ")](#00fb9a)"))));
|
||||
case "update" -> updateChecker.isUpToDate().thenAccept(upToDate -> {
|
||||
if (upToDate) {
|
||||
plugin.getLocales().getLocale("up_to_date", plugin.getVersion().toString())
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
updateChecker.getLatestVersion().thenAccept(latest -> plugin.getLocales()
|
||||
.getLocale("update_available", latest.toString(), plugin.getVersion().toString())
|
||||
.ifPresent(executor::sendMessage));
|
||||
});
|
||||
default -> plugin.getLocales().getLocale("error_invalid_syntax", getUsage())
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
@@ -97,10 +105,7 @@ public class HuskHomesCommand extends Command {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
if (args.length < 2) {
|
||||
return filter(SUB_COMMANDS, args);
|
||||
}
|
||||
return List.of();
|
||||
return args.length < 2 ? SUB_COMMANDS : List.of();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.teleport.Teleportable;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -21,7 +20,6 @@ public abstract class Node implements Executable {
|
||||
protected final HuskHomes plugin;
|
||||
private final String name;
|
||||
private final List<String> aliases;
|
||||
private boolean consoleExecutable = false;
|
||||
private boolean operatorCommand = false;
|
||||
|
||||
protected Node(@NotNull String name, @NotNull List<String> aliases, @NotNull HuskHomes plugin) {
|
||||
@@ -43,10 +41,6 @@ public abstract class Node implements Executable {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public final boolean matchesInput(@NotNull String input) {
|
||||
return input.equalsIgnoreCase(getName()) || getAliases().contains(input.toLowerCase());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPermission(@NotNull String... child) {
|
||||
return new StringJoiner(".")
|
||||
@@ -56,21 +50,6 @@ public abstract class Node implements Executable {
|
||||
.toString();
|
||||
}
|
||||
|
||||
public boolean canPerform(@NotNull CommandUser user) {
|
||||
if (user instanceof ConsoleUser) {
|
||||
return isConsoleExecutable();
|
||||
}
|
||||
return user.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
public boolean isConsoleExecutable() {
|
||||
return consoleExecutable;
|
||||
}
|
||||
|
||||
public void setConsoleExecutable(boolean consoleExecutable) {
|
||||
this.consoleExecutable = consoleExecutable;
|
||||
}
|
||||
|
||||
public boolean isOperatorCommand() {
|
||||
return operatorCommand;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.william278.huskhomes.user.User;
|
||||
import net.william278.paginedown.PaginatedList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PrivateHomeListCommand extends ListCommand {
|
||||
|
||||
@@ -2,9 +2,9 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.paginedown.PaginatedList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
||||
|
||||
final Home home = optionalHome.get();
|
||||
if (executor instanceof OnlineUser user && !home.isPublic() && !user.equals(home.getOwner())
|
||||
&& !user.hasPermission(getOtherPermission())) {
|
||||
&& !user.hasPermission(getOtherPermission())) {
|
||||
plugin.getLocales().getLocale("error_public_home_invalid",
|
||||
splitHomeName[0], splitHomeName[1])
|
||||
.ifPresent(executor::sendMessage);
|
||||
@@ -91,8 +91,8 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
||||
|
||||
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 && (plugin.getSettings().isPermissionRestrictWarps()
|
||||
&& user.hasPermission(Warp.getWildcardPermission()) || user.hasPermission(Warp.getPermission(warpName)))) {
|
||||
if (warp.isPresent() && executor instanceof OnlineUser user && plugin.getSettings().isPermissionRestrictWarps()
|
||||
&& (!user.hasPermission(Warp.getWildcardPermission()) && !user.hasPermission(Warp.getPermission(warpName)))) {
|
||||
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||
.ifPresent(executor::sendMessage);
|
||||
return Optional.empty();
|
||||
@@ -123,22 +123,30 @@ public abstract class SavedPositionCommand<T extends SavedPosition> extends Comm
|
||||
@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())) {
|
||||
if (positionType == Home.class) {
|
||||
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);
|
||||
}
|
||||
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();
|
||||
};
|
||||
case 2 -> filter(arguments.stream().toList(), args);
|
||||
default -> List.of();
|
||||
};
|
||||
} else {
|
||||
return switch (args.length) {
|
||||
case 0, 1 -> filter(plugin.getCache().getWarps(), args);
|
||||
case 2 -> filter(arguments.stream().toList(), args);
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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.position.Home;
|
||||
import net.william278.huskhomes.util.ValidationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ public class SetSpawnCommand extends InGameCommand {
|
||||
|
||||
protected SetSpawnCommand(@NotNull HuskHomes plugin) {
|
||||
super("setspawn", List.of(), "", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SetWarpCommand extends SetPositionCommand {
|
||||
|
||||
protected SetWarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("setwarp", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -29,15 +28,4 @@ public interface TabProvider {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static List<String> getMatchingNames(@Nullable String argument, @NotNull CommandUser user,
|
||||
@NotNull List<? extends Node> providers) {
|
||||
return providers.stream()
|
||||
.filter(command -> !(user instanceof ConsoleUser) || command.isConsoleExecutable())
|
||||
.map(Node::getName)
|
||||
.filter(commandName -> argument == null || argument.isBlank() || commandName.toLowerCase()
|
||||
.startsWith(argument.toLowerCase().trim()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,9 @@ package net.william278.huskhomes.command;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.network.Message;
|
||||
import net.william278.huskhomes.network.Payload;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -15,6 +14,7 @@ public class TpAllCommand extends InGameCommand {
|
||||
|
||||
protected TpAllCommand(@NotNull HuskHomes plugin) {
|
||||
super("tpall", List.of(), "", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.*;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TpCommand extends Command implements TabProvider {
|
||||
|
||||
protected TpCommand(@NotNull HuskHomes implementor) {
|
||||
super("tp", List.of("tpo"), "[<player|position>] [target]", implementor);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +88,7 @@ public class TpCommand extends Command implements TabProvider {
|
||||
((int) basePosition.getX() + " " + (int) basePosition.getY()),
|
||||
((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ()))
|
||||
: List.of());
|
||||
completions.addAll(plugin.getCache().getPlayers());
|
||||
completions.addAll(plugin.getPlayerList());
|
||||
return completions.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList());
|
||||
@@ -102,7 +105,7 @@ public class TpCommand extends Command implements TabProvider {
|
||||
((int) basePosition.getX() + " " + (int) basePosition.getY()),
|
||||
((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ()))
|
||||
: List.of());
|
||||
completions.addAll(plugin.getCache().getPlayers());
|
||||
completions.addAll(plugin.getPlayerList());
|
||||
}
|
||||
return completions.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.teleport.Target;
|
||||
import net.william278.huskhomes.teleport.Teleportable;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
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.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TpHereCommand extends InGameCommand implements UserListTabProvider {
|
||||
|
||||
protected TpHereCommand(@NotNull HuskHomes plugin) {
|
||||
super("tphere", List.of("tpohere"), "<player>", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.manager.RequestsManager;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,6 +16,7 @@ public class TpOfflineCommand extends InGameCommand implements UserListTabProvid
|
||||
|
||||
protected TpOfflineCommand(@NotNull HuskHomes plugin) {
|
||||
super("tpoffline", List.of(), "<player>", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.network.Message;
|
||||
import net.william278.huskhomes.network.Payload;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TeleportBuilder;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TpaAllCommand extends InGameCommand {
|
||||
|
||||
protected TpaAllCommand(@NotNull HuskHomes plugin) {
|
||||
super("tpaall", List.of(), "", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,18 +5,14 @@ import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface UserListTabProvider extends TabProvider {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
default List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
|
||||
return args.length <= 1 ? getPlugin().getCache().getPlayers().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
return args.length < 2 ? getPlugin().getPlayerList() : List.of();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.teleport.Teleportable;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +13,7 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
protected WarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("warp", List.of(), Warp.class, List.of(), plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user