More implementation, timed teleports, regex, etc

This commit is contained in:
William committed 2022-05-26 15:54:19 +01:00
1 parent 7ac52d747f
commit e335a48888
25 files changed
+803 -157

No files matched your search

@@ -2,6 +2,7 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -26,15 +27,15 @@ public abstract class CommandBase {
public final String[] aliases;
/**
* Instance of the proxy plugin implementor
* Instance of the implementing plugin
*/
public final HuskHomes implementor;
public final HuskHomes plugin;
public CommandBase(String command, String permission, HuskHomes implementingPlugin, String... aliases) {
public CommandBase(@NotNull String command, @NotNull String permission, @NotNull HuskHomes implementor, String... aliases) {
this.command = command;
this.permission = permission;
this.implementor = implementingPlugin;
this.plugin = implementor;
this.aliases = aliases;
}
@@ -44,15 +45,25 @@ public abstract class CommandBase {
* @param player {@link Player} executing the command
* @param args Command arguments
*/
public abstract void onExecute(Player player, String[] args);
public abstract void onExecute(@NotNull Player player, @NotNull String[] args);
/**
* What should be returned when the player attempts to TAB complete the command
* What should be returned when the player attempts to TAB-complete the command
*
* @param player {@link Player} doing the TAB completion
* @param args Current command arguments
* @return List of String arguments to offer TAB suggestions
*/
public abstract List<String> onTabComplete(Player player, String[] args);
public abstract List<String> onTabComplete(@NotNull Player player, @NotNull String[] args);
/**
* Returns the localised description string of this command
*
* @return the command description
*/
public String getDescription() {
return plugin.getLocales().getRawLocale(command + "_command_description")
.orElse("A HuskHomes command");
}
}
@@ -0,0 +1,9 @@
package net.william278.huskhomes.command;
import org.jetbrains.annotations.NotNull;
public interface ConsoleExecutable {
void onConsoleExecute(@NotNull String[] args);
}
@@ -0,0 +1,44 @@
package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.Player;
import net.william278.huskhomes.player.User;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class HomeCommand extends CommandBase {
private final static String PERMISSION = "huskhomes.command.home";
public HomeCommand(@NotNull HuskHomes implementor) {
super("home", PERMISSION, implementor);
}
@Override
public void onExecute(@NotNull Player player, @NotNull String[] args) {
if (args.length >= 1) {
//todo check if its a public home, process. Support sending a player
plugin.getTeleportManager().teleportToHome(player, new User(player), args[0]);
} else {
plugin.getDatabase().getHomes(new User(player)).thenAccept(homes -> {
switch (homes.size()) {
case 0 -> plugin.getLocales().getLocale("error_no_homes_set").ifPresent(player::sendMessage);
case 1 -> plugin.getTeleportManager().executeTeleport(player, homes.get(0)).thenAccept(result ->
plugin.getTeleportManager().finishTeleport(player, result));
default -> {
//todo show home list
}
}
});
}
}
@Override
public List<String> onTabComplete(@NotNull Player player, @NotNull String[] args) {
return plugin.getCache().homes.get(player.getUuid()).stream()
.filter(s -> s.startsWith(args.length >= 1 ? args[0] : ""))
.sorted().collect(Collectors.toList());
}
}