mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Add /tpa, /tpahere, /tpaccept, /tpdeny, strict teleporting (Closes #139)
This commit is contained in:
1 parent
11d05efcfa
commit
4b01e1bdec
13 files changed
+221
-72
No files matched your search
@@ -64,7 +64,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
|
||||
onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, userData.user(),
|
||||
plugin.getLocales(), homes, plugin.getSettings().listItemsPerPage, pageNumber));
|
||||
});
|
||||
}, () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage)));
|
||||
}, () -> plugin.getLocales().getLocale("error_player_not_found", homeOwner).ifPresent(onlineUser::sendMessage)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* A command used for responding to tp requests - can either be a /tpaccept or /tpdecline command, controlled by the
|
||||
* acceptRequestCommand flag
|
||||
*/
|
||||
public class TpRespondCommand extends CommandBase implements TabCompletable {
|
||||
|
||||
private final boolean acceptRequestCommand;
|
||||
|
||||
protected TpRespondCommand(@NotNull HuskHomes implementor, boolean acceptRequestCommand) {
|
||||
super(acceptRequestCommand ? "tpaccept" : "tpdecline", acceptRequestCommand ? Permission.COMMAND_TPACCEPT : Permission.COMMAND_TPDECLINE, implementor);
|
||||
this.acceptRequestCommand = acceptRequestCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length > 1) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/" + command + " [player]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
// Respond to the request from specified sender name
|
||||
plugin.getRequestManager().respondToTeleportRequestBySenderName(onlineUser, args[0], acceptRequestCommand);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getRequestManager().respondToTeleportRequest(onlineUser, acceptRequestCommand);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.request.TeleportRequest;
|
||||
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 TpaCommand extends CommandBase implements TabCompletable {
|
||||
|
||||
protected TpaCommand(@NotNull HuskHomes implementor) {
|
||||
super("tpa", Permission.COMMAND_TPA, implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA).thenAccept(sent -> {
|
||||
if (!sent) {
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0]).ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("tpa_request_sent", args[0]).ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tpa <player>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.request.TeleportRequest;
|
||||
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 TpaHereCommand extends CommandBase implements TabCompletable {
|
||||
|
||||
protected TpaHereCommand(@NotNull HuskHomes implementor) {
|
||||
super("tpahere", Permission.COMMAND_TPAHERE, implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
plugin.getRequestManager().sendTeleportRequest(onlineUser, args[0], TeleportRequest.RequestType.TPA_HERE).thenAccept(sent -> {
|
||||
if (!sent) {
|
||||
plugin.getLocales().getLocale("error_player_not_found", args[0]).ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("tpahere_request_sent", args[0]).ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tpahere <player>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@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