/home, /phome and /warp console commands

This commit is contained in:
William committed 2022-08-24 23:40:15 +01:00
1 parent f72c01d10b
commit 9b965ac1cd
3 files changed
+96 -5

No files matched your search

@@ -2,6 +2,7 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
import net.william278.huskhomes.util.RegexUtil;
import org.jetbrains.annotations.NotNull;
@@ -9,6 +10,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class HomeCommand extends CommandBase implements TabCompletable, ConsoleExecutable {
@@ -27,7 +31,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
case 1 -> plugin.getTeleportManager().timedTeleport(onlineUser, homes.get(0)).thenAccept(result ->
plugin.getTeleportManager().finishTeleport(onlineUser, result)).join();
default -> onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, onlineUser,
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage,1));
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage, 1));
}
});
case 1 -> {
@@ -48,7 +52,36 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: home <player> <home>");
return;
}
CompletableFuture.runAsync(() -> {
final OnlineUser playerToTeleport = plugin.findPlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final AtomicReference<Home> matchedHome = new AtomicReference<>(null);
RegexUtil.matchDisambiguatedHomeIdentifier(args[1]).ifPresentOrElse(
identifier -> matchedHome.set(plugin.getDatabase().getUserDataByName(identifier.ownerName()).join()
.flatMap(user -> plugin.getDatabase().getHome(user.user(), identifier.homeName()).join())
.orElse(null)),
() -> matchedHome.set(plugin.getDatabase().getUserDataByName(playerToTeleport.username).join()
.flatMap(user -> plugin.getDatabase().getHome(user.user(), args[1]).join())
.orElse(null)));
final Home home = matchedHome.get();
if (home == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find home '" + args[1] + "'");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
+ home.owner.username + "." + home.meta.name);
plugin.getTeleportManager().timedTeleport(playerToTeleport, home)
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
});
}
@Override
@@ -11,6 +11,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -31,7 +34,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
}
onlineUser.sendMessage(plugin.getCache().getPublicHomeList(onlineUser, plugin.getLocales(), publicHomes,
plugin.getSettings().listItemsPerPage,1));
plugin.getSettings().listItemsPerPage, 1));
});
case 1 -> {
final String homeName = args[0];
@@ -61,7 +64,38 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: publichome <player> <[owner_name].[home_name]>");
return;
}
CompletableFuture.runAsync(() -> {
final OnlineUser playerToTeleport = plugin.findPlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final AtomicReference<Home> matchedHome = new AtomicReference<>(null);
RegexUtil.matchDisambiguatedHomeIdentifier(args[1]).ifPresentOrElse(
identifier -> matchedHome.set(plugin.getDatabase().getUserDataByName(identifier.ownerName()).join()
.flatMap(user -> plugin.getDatabase().getHome(user.user(), identifier.homeName()).join())
.orElse(null)),
() -> matchedHome.set(plugin.getDatabase().getPublicHomes().join()
.stream()
.filter(home -> home.owner.uuid.equals(playerToTeleport.uuid) && home.meta.name.equalsIgnoreCase(args[1]))
.findFirst()
.orElse(null)));
final Home home = matchedHome.get();
if (home == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find public home '" + args[1] + "'");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to "
+ home.owner.username + "." + home.meta.name);
plugin.getTeleportManager().timedTeleport(playerToTeleport, home)
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
});
}
@Override
@@ -2,11 +2,14 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class WarpCommand extends CommandBase implements TabCompletable, ConsoleExecutable {
@@ -44,6 +47,27 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: warp <player> <warp>");
return;
}
CompletableFuture.runAsync(() -> {
final OnlineUser playerToTeleport = plugin.findPlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final Warp warp = plugin.getDatabase().getWarp(args[1]).join().orElse(null);
if (warp == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find warp '" + args[1] + "'");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username + " to " + warp.meta.name);
plugin.getTeleportManager().timedTeleport(playerToTeleport, warp)
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(playerToTeleport, result));
});
}
}