mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Add /delhome and /delwarp all
This commit is contained in:
1 parent
54e4b5ddef
commit
51dcad3843
2 files changed
+76
-9
No files matched your search
@@ -3,13 +3,16 @@ package net.william278.huskhomes.command;
|
|||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.player.User;
|
import net.william278.huskhomes.player.User;
|
||||||
|
import net.william278.huskhomes.position.Home;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import net.william278.huskhomes.util.RegexUtil;
|
import net.william278.huskhomes.util.RegexUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DelHomeCommand extends CommandBase implements TabCompletable {
|
public class DelHomeCommand extends CommandBase implements TabCompletable {
|
||||||
@@ -20,8 +23,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
|
switch (args.length) {
|
||||||
switch (args.length) { //todo delhome all
|
|
||||||
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
|
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
|
||||||
if (homes.size() == 1) {
|
if (homes.size() == 1) {
|
||||||
homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name));
|
homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name));
|
||||||
@@ -65,19 +67,51 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
if (deleter.uuid.equals(homeOwner.uuid)) {
|
if (deleter.uuid.equals(homeOwner.uuid)) {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
|
plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage);
|
||||||
} else {
|
return;
|
||||||
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
|
|
||||||
}
|
}
|
||||||
|
if (homeName.equals("all")) {
|
||||||
|
deleteAllHomes(deleter, homeOwner);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
|
||||||
} else {
|
} else {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("home_deleted_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
plugin.getLocales().getLocale("home_deleted_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
||||||
} else {
|
return;
|
||||||
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
|
||||||
}
|
}
|
||||||
|
if (homeName.equals("all")) {
|
||||||
|
deleteAllHomes(deleter, homeOwner);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all of a player's homes
|
||||||
|
*
|
||||||
|
* @param deleter the player who is deleting the homes
|
||||||
|
* @param homeOwner the player who owns the homes
|
||||||
|
*/
|
||||||
|
private void deleteAllHomes(@NotNull OnlineUser deleter, @NotNull User homeOwner) {
|
||||||
|
plugin.getDatabase().getHomes(homeOwner).thenAccept(homes -> {
|
||||||
|
if (homes.isEmpty()) {
|
||||||
|
plugin.getLocales().getLocale("error_no_warps_set")
|
||||||
|
.ifPresent(deleter::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
||||||
|
for (final Home toDelete : homes) {
|
||||||
|
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteHome(homeOwner, toDelete.meta.name));
|
||||||
|
}
|
||||||
|
CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRun(() ->
|
||||||
|
plugin.getLocales().getLocale("delete_all_homes_success", Integer.toString(homeDeletionFuture.size()))
|
||||||
|
.ifPresent(deleter::sendMessage)).join();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
|
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|||||||
@@ -2,12 +2,17 @@ package net.william278.huskhomes.command;
|
|||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
|
import net.william278.huskhomes.player.User;
|
||||||
|
import net.william278.huskhomes.position.Home;
|
||||||
|
import net.william278.huskhomes.position.Warp;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DelWarpCommand extends CommandBase implements TabCompletable {
|
public class DelWarpCommand extends CommandBase implements TabCompletable {
|
||||||
@@ -24,10 +29,15 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("warp_deleted", warpName)
|
plugin.getLocales().getLocale("warp_deleted", warpName)
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
} else {
|
return;
|
||||||
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
|
||||||
.ifPresent(onlineUser::sendMessage);
|
|
||||||
}
|
}
|
||||||
|
if (warpName.equals("all")) {
|
||||||
|
deleteAllWarps(onlineUser);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delwarp <name>")
|
plugin.getLocales().getLocale("error_invalid_syntax", "/delwarp <name>")
|
||||||
@@ -35,6 +45,29 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all the server warps
|
||||||
|
*
|
||||||
|
* @param deleter the player who is deleting the warps
|
||||||
|
*/
|
||||||
|
private void deleteAllWarps(@NotNull OnlineUser deleter) {
|
||||||
|
plugin.getDatabase().getWarps().thenAccept(warps -> {
|
||||||
|
if (warps.isEmpty()) {
|
||||||
|
plugin.getLocales().getLocale("error_no_warps_set")
|
||||||
|
.ifPresent(deleter::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
||||||
|
for (final Warp toDelete : warps) {
|
||||||
|
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteWarp(toDelete.meta.name));
|
||||||
|
}
|
||||||
|
CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRun(() ->
|
||||||
|
plugin.getLocales().getLocale("delete_all_warps_success", Integer.toString(homeDeletionFuture.size()))
|
||||||
|
.ifPresent(deleter::sendMessage)).join();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> onTabComplete(@NotNull String[] args, @Nullable OnlineUser user) {
|
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()
|
||||||
|
|||||||
Reference in new issue
Block a user