Plex/src/main/java/dev/plex/command/impl/SurvivalCMD.java

67 lines
2.4 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.command.impl;
2022-01-04 03:04:39 +00:00
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
2021-01-03 07:21:15 +00:00
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
2022-01-27 21:23:01 +00:00
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
2022-01-30 01:08:07 +00:00
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
@CommandParameters(name = "survival", aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
public class SurvivalCMD extends PlexCommand
{
@Override
2022-01-27 05:28:30 +00:00
public Component execute(CommandSender sender, String[] args)
{
2022-01-30 21:03:47 +00:00
Player player = (Player)sender;
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("You must define a player when using the console!");
}
player.setGameMode(GameMode.SURVIVAL);
return tl("gameModeSetTo", "survival");
}
2022-01-30 01:08:07 +00:00
if (checkRank(player, Rank.ADMIN, "plex.gamemode.survival.others"))
{
if (args[0].equals("-a"))
{
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.SURVIVAL);
}
return tl("gameModeSetTo", "survival");
}
2022-01-30 01:08:07 +00:00
Player nPlayer = getNonNullPlayer(args[0]);
// use send
2022-01-30 01:08:07 +00:00
send(nPlayer, tl("playerSetOtherGameMode", sender.getName(), "survival"));
nPlayer.setGameMode(GameMode.SURVIVAL);
return tl("setOtherPlayerGameModeTo", nPlayer.getName(), "survival");
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (isAdmin(sender))
{
return PlexUtils.getPlayerNameList();
}
2020-11-06 04:39:27 +00:00
return ImmutableList.of();
}
}