2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.command.impl;
|
2020-11-06 03:50:16 +00:00
|
|
|
|
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;
|
2022-02-14 05:55:50 +00:00
|
|
|
import dev.plex.event.GameModeUpdateEvent;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.rank.enums.Rank;
|
|
|
|
import dev.plex.util.PlexUtils;
|
2022-01-27 21:23:01 +00:00
|
|
|
import java.util.List;
|
2022-01-27 09:00:50 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2020-11-06 03:50:16 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.GameMode;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2020-11-06 03:50:16 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-02-04 04:49:05 +00:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-11-06 03:50:16 +00:00
|
|
|
|
2022-01-30 01:08:07 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
2022-01-27 09:00:50 +00:00
|
|
|
@CommandParameters(name = "survival", aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
|
2020-11-06 03:50:16 +00:00
|
|
|
public class SurvivalCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
2022-02-04 04:49:05 +00:00
|
|
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
2020-11-06 03:50:16 +00:00
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
if (isConsole(sender))
|
2020-11-06 03:50:16 +00:00
|
|
|
{
|
2022-02-25 07:09:55 +00:00
|
|
|
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
2022-02-14 05:55:50 +00:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
|
2022-03-03 23:24:15 +00:00
|
|
|
return null;
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 05:55:50 +00:00
|
|
|
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
2020-11-06 03:50:16 +00:00
|
|
|
{
|
|
|
|
if (args[0].equals("-a"))
|
|
|
|
{
|
|
|
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
|
|
|
{
|
|
|
|
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
2022-02-25 07:09:55 +00:00
|
|
|
send(targetPlayer, messageComponent("gameModeSetTo", "survival"));
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
2022-02-25 07:09:55 +00:00
|
|
|
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "survival"));
|
2022-02-14 05:55:50 +00:00
|
|
|
return null;
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 01:08:07 +00:00
|
|
|
Player nPlayer = getNonNullPlayer(args[0]);
|
2022-02-14 05:55:50 +00:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SURVIVAL));
|
|
|
|
return null;
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
return null;
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-01-27 09:00:50 +00:00
|
|
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
2020-11-06 03:50:16 +00:00
|
|
|
{
|
2022-02-14 05:55:50 +00:00
|
|
|
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
2020-11-06 03:50:16 +00:00
|
|
|
{
|
|
|
|
return PlexUtils.getPlayerNameList();
|
|
|
|
}
|
2020-11-06 04:39:27 +00:00
|
|
|
return ImmutableList.of();
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|
|
|
|
}
|