TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_staffmode.java

60 lines
1.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2019-01-29 04:57:41 +00:00
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NEW_ADMIN, source = SourceType.BOTH)
2020-08-15 22:42:46 +00:00
@CommandParameters(description = "Denies joining of operators and only allows staff members to join.", usage = "/<command> [on | off]")
public class Command_staffmode extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if (args[0].equalsIgnoreCase("off"))
{
2020-08-15 22:42:46 +00:00
ConfigEntry.STAFF_ONLY_MODE.setBoolean(false);
FUtil.staffAction(sender.getName(), "Opening the server to all players.", true);
return true;
}
else if (args[0].equalsIgnoreCase("on"))
{
2020-08-15 22:42:46 +00:00
ConfigEntry.STAFF_ONLY_MODE.setBoolean(true);
FUtil.staffAction(sender.getName(), "Closing the server to non-staff.", true);
for (Player player : server.getOnlinePlayers())
{
2020-08-15 22:42:46 +00:00
if (!isStaff(player))
{
2020-08-15 22:42:46 +00:00
player.kickPlayer("Server is now closed to non-staff.");
}
}
return true;
}
return false;
}
2019-01-29 04:57:41 +00:00
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
2020-08-15 22:42:46 +00:00
if (args.length == 1 && plugin.sl.isStaff(sender) && !(sender instanceof Player))
2019-01-29 04:57:41 +00:00
{
return Arrays.asList("on", "off");
}
return Collections.emptyList();
}
}