mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Add /tpoffline
This commit is contained in:
1 parent
b6fed95fba
commit
d4f4d5b0b0
3 files changed
+54
-1
No files matched your search
@@ -28,6 +28,7 @@ public enum BukkitCommandType {
|
||||
TPDECLINE_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), false)),
|
||||
RTP_COMMAND(new RtpCommand(BukkitHuskHomes.getInstance())),
|
||||
TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())),
|
||||
TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())),
|
||||
BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance()));
|
||||
|
||||
public final CommandBase commandBase;
|
||||
|
||||
@@ -58,6 +58,8 @@ commands:
|
||||
rtp:
|
||||
usage: /rtp [player]
|
||||
tpignore:
|
||||
usage: /tpignore <player>
|
||||
usage: /tpignore
|
||||
tpoffline:
|
||||
usage: /tpoffline <player>
|
||||
back:
|
||||
usage: /back
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TpOfflineCommand extends CommandBase implements TabCompletable {
|
||||
|
||||
protected TpOfflineCommand(@NotNull HuskHomes implementor) {
|
||||
super("tpoffline", Permission.COMMAND_TPOFFLINE, implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length != 1) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tpoffline <player>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
final String targetUser = args[0];
|
||||
plugin.getDatabase().getUserDataByName(targetUser).thenAccept(userData -> {
|
||||
if (userData.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_player_not_found", targetUser)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getDatabase().getOfflinePosition(userData.get().user()).thenAccept(offlinePosition -> {
|
||||
if (offlinePosition.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_offline_position", targetUser)
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().teleport(onlineUser, offlinePosition.get()).thenAccept(
|
||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)).join();
|
||||
}).join();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
return args.length <= 1 ? plugin.getCache().players.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
|
||||
.sorted().collect(Collectors.toList()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user