Plex/server/src/main/java/dev/plex/command/impl/CreativeCMD.java

72 lines
2.7 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;
2022-08-02 12:08:52 +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;
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;
import org.jetbrains.annotations.Nullable;
2023-03-08 20:26:10 +00:00
import java.util.List;
2022-01-30 01:08:07 +00:00
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
2022-04-24 06:05:21 +00:00
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
public class CreativeCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
if (isConsole(sender))
{
2022-11-26 10:24:38 +00:00
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
}
if (!(playerSender == null))
{
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender.getPlayer(), GameMode.CREATIVE));
}
return null;
}
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
{
if (args[0].equals("-a"))
{
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.CREATIVE);
2022-02-25 07:09:55 +00:00
messageComponent("gameModeSetTo", "creative");
}
2022-02-25 07:09:55 +00:00
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "creative"));
return null;
}
2022-01-30 01:08:07 +00:00
Player nPlayer = getNonNullPlayer(args[0]);
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
return null;
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
{
return PlexUtils.getPlayerNameList();
}
2020-11-06 04:39:27 +00:00
return ImmutableList.of();
}
}