mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
/offlinetp command
This commit is contained in:
@@ -72,6 +72,7 @@ public final class SModerationPaper extends JavaPlugin {
|
|||||||
registerCommand(commands, new UnbanCommand());
|
registerCommand(commands, new UnbanCommand());
|
||||||
registerCommand(commands, new MuteCommand());
|
registerCommand(commands, new MuteCommand());
|
||||||
registerCommand(commands, new BanCommand());
|
registerCommand(commands, new BanCommand());
|
||||||
|
registerCommand(commands, new OfflineTPCommand());
|
||||||
});
|
});
|
||||||
|
|
||||||
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::onTick, 1, 1);
|
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::onTick, 1, 1);
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.OfflinePlayerArgument;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public final class OfflineTPCommand implements CommandProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("offlinetp")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.offlinetp"))
|
||||||
|
.then(argument("player", new OfflinePlayerArgument())
|
||||||
|
.executes(this::offlineTeleport)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int offlineTeleport(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
OfflinePlayer player = context.getArgument("player", OfflinePlayer.class);
|
||||||
|
|
||||||
|
Location location = player.getLocation();
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
CommandUtil.error("This player's location is unknown.");
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.teleportAsync(location, PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||||
|
sender.sendMessage(CHAT_PREFIX.append(
|
||||||
|
text("Teleporting you to ").color(PRIMARY_COLOR)
|
||||||
|
.append(text(PlayerUtil.offlinePlayerName(player.getUniqueId())).colorIfAbsent(SECONDARY_COLOR))
|
||||||
|
.append(text("."))
|
||||||
|
));
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Teleports you to an offline player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodofflinetp");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command.argument;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public final class OfflinePlayerArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(nativeType);
|
||||||
|
if (player != null){
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
CommandUtil.error("That player is not cached.");
|
||||||
|
throw new AssertionError(); // can't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ArgumentType<String> getNativeType() {
|
||||||
|
return StringArgumentType.word();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -71,4 +71,7 @@ permissions:
|
|||||||
description: Allows the player to see vanished players
|
description: Allows the player to see vanished players
|
||||||
smod.socialspy:
|
smod.socialspy:
|
||||||
default: op
|
default: op
|
||||||
description: Allows the player to enable SocialSpy
|
description: Allows the player to enable SocialSpy
|
||||||
|
smod.offlinetp:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to teleport themself to offline players
|
||||||
Reference in New Issue
Block a user