Plex/src/main/java/me/totalfreedom/plex/command/impl/AdventureCMD.java

74 lines
2.4 KiB
Java
Raw Normal View History

package me.totalfreedom.plex.command.impl;
import java.util.Collections;
import java.util.List;
2020-11-06 04:39:27 +00:00
import com.google.common.collect.ImmutableList;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions;
import me.totalfreedom.plex.command.exception.CommandFailException;
import me.totalfreedom.plex.command.source.CommandSource;
import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@CommandParameters(aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
public class AdventureCMD extends PlexCommand
{
public AdventureCMD()
{
super("adventure");
}
@Override
public void execute(CommandSource sender, String[] args)
{
if (args.length == 0)
{
// doesn't work
2020-11-10 04:53:45 +00:00
if (sender.isConsoleSender())
{
throw new CommandFailException("You must define a player when using the console!");
}
sender.getPlayer().setGameMode(GameMode.ADVENTURE);
send(tl("gameModeSetTo", "adventure"));
return;
}
if (isAdmin(sender.getPlexPlayer()))
{
if (args[0].equals("-a"))
{
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.ADVENTURE);
}
send(tl("gameModeSetTo", "adventure"));
return;
}
Player player = getNonNullPlayer(args[0]);
send(tl("setOtherPlayerGameModeTo", player.getName(), "adventure"));
// use send
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "adventure"));
player.setGameMode(GameMode.ADVENTURE);
}
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
{
if (isAdmin(sender.getPlexPlayer()))
{
return PlexUtils.getPlayerNameList();
}
2020-11-06 04:39:27 +00:00
return ImmutableList.of();
}
}